Fittet new functions to everying in neural networks. Still need to optimise for uint64_t vs int64_t and vec vs mat in some places.

This commit is contained in:
2026-05-16 20:37:05 +02:00
parent 412a854c65
commit d2fe8aa65c
50 changed files with 489 additions and 1482 deletions
+8 -9
View File
@@ -1,13 +1,12 @@
#pragma once
#include "./core/omp_config.h"
#include "core/omp_config.h"
#include "./utils/vector.h"
#include "./utils/matrix.h"
#include "utils/vector.h"
#include "utils/matrix.h"
#include "numerics/vecmean.h"
#include "numerics/matabs.h"
#include "numerics/matmean.h"
#include "numerics/mean.h"
#include "numerics/abs.h"
namespace neural_networks{
@@ -28,7 +27,7 @@ namespace neural_networks{
sample_losses = forward(output, y);
// Calculate mean loss
data_loss = numerics::vecmean(sample_losses);
data_loss = numerics::mean(sample_losses);
return data_loss;
@@ -42,12 +41,12 @@ namespace neural_networks{
// L1 regularization - weights
// calculate only when factor greater than 0
if (layer.weight_regularizer_l1){
regularization_losss += layer.weight_regularizer_l1 * numerics::matsum_coeff(numerics::matabs(layer.weights));
regularization_losss += layer.weight_regularizer_l1 * numerics::sum(numerics::abs(layer.weights));
}
// L2 regularization - weights
if (layer.weight_regularizer_l2){
regularization_losss += layer.weight_regularizer_l2 * numerics::matsum_coeff(numerics::matmul(layer.weights,layer.weights)); // elementwise!
regularization_losss += layer.weight_regularizer_l2 * numerics::sum(numerics::mul(layer.weights,layer.weights)); // elementwise!
}
// L1 regularization - biases