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.
This commit is contained in:
@@ -4,7 +4,11 @@
|
||||
|
||||
#include "./utils/vector.h"
|
||||
#include "./utils/matrix.h"
|
||||
#include "./utils/random.h"
|
||||
|
||||
#include "./numerics/max.h"
|
||||
#include "./numerics/matsubtract.h"
|
||||
#include "./numerics/exponential.h"
|
||||
#include "./numerics/matdiv.h"
|
||||
|
||||
|
||||
namespace neural_networks{
|
||||
@@ -12,15 +16,20 @@ namespace neural_networks{
|
||||
template <typename T>
|
||||
struct activation_softmax{
|
||||
|
||||
utils::Matrix<T> exp_values;
|
||||
utils::Matrix<T> probabilities;
|
||||
utils::Matrix<T> outputs;
|
||||
|
||||
void forward(utils::Matrix<T> inputs){
|
||||
//outputs = numerics::max(inputs, T{0});
|
||||
//outputs.print();
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user