Files
Flux/include/modules/neural_networks/activation_functions/Softmax.h
T
Bausager ea359f3b09 Started Loss, done softmax, up to p.125
I've implemented alot of support functions that needs to be refactored, optimised and tested; mean.h, exponential.h, matdiv.h matsum.h matsubtract.h. Maybe we need to have a look at if matdiv/matmul should be in the same. Same with matadd/matsubtract and if some of it should be in matvec.h.
2025-10-05 19:47:56 +02:00

37 lines
766 B
C++

#pragma once
#include "./core/omp_config.h"
#include "./utils/vector.h"
#include "./utils/matrix.h"
#include "./numerics/max.h"
#include "./numerics/matsubtract.h"
#include "./numerics/exponential.h"
#include "./numerics/matdiv.h"
namespace neural_networks{
template <typename T>
struct activation_softmax{
utils::Matrix<T> exp_values;
utils::Matrix<T> probabilities;
utils::Matrix<T> outputs;
void forward(const utils::Matrix<T> inputs){
exp_values = numerics::exponential(numerics::matsubtract(inputs, numerics::max(inputs, "rows"), "col"));
probabilities = numerics::matdiv(exp_values, numerics::matsum(exp_values, "col"), "col");
outputs = probabilities;
}
};
} // end namespace neural_networks