Starting on the model.h, but need to make layer structs and structs for loss and optimizers

This commit is contained in:
2026-05-30 09:13:52 +02:00
parent cb65174cf4
commit edad247227
30 changed files with 1879 additions and 159 deletions
@@ -4,13 +4,17 @@
#include "utils/vector.h"
#include "utils/matrix.h"
#include "Layer.h"
#include "utils/random.h"
#include "random/random.h"
namespace neural_networks{
template <typename T>
struct Dense_Layer{
struct Dense_Layer : Layer<T>{
T weight_regularizer_l1 = {0};
T weight_regularizer_l2 = {0};
@@ -48,7 +52,7 @@ namespace neural_networks{
this->bias_regularizer_l1 = bias_regularizer_l1;
this->bias_regularizer_l2 = bias_regularizer_l2;
weights.random(n_inputs, n_neurons, -1, 1);
weights = numerics::mul( rng::normal(n_inputs, n_neurons, 0.0f, 1.0f), 0.1f);
//weights = numerics::random_matrix(n_inputs, n_neurons, -1, 1);
biases.resize(n_neurons, T{0});
@@ -4,13 +4,15 @@
#include "utils/vector.h"
#include "utils/matrix.h"
#include "modules/neural_networks/layers/Layer.h"
#include "random/random.h"
namespace neural_networks{
template <typename T>
struct Dropout_Layer{
struct Dropout_Layer : Layer<T>{
// Store rate, we invert it as for example for dropout
// of 0.1 we need a success rate of 0.9
@@ -0,0 +1,21 @@
#pragma once
#include "core/omp_config.h"
#include "utils/vector.h"
#include "utils/matrix.h"
namespace neural_networks{
template <typename T>
struct Layer {
utils::Matrix<T> outputs;
utils::Matrix<T> dinputs;
virtual void forward(const utils::Matrix<T>& inputs) = 0;
virtual void backward(const utils::Matrix<T>& dvalues) = 0;
virtual ~Layer() = default;
};
}