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:
2025-10-05 19:45:37 +02:00
parent 1b59713565
commit ea359f3b09
18 changed files with 407 additions and 56 deletions
@@ -10,11 +10,11 @@
namespace neural_networks{
template <typename T>
void create_spital_data(const uint64_t samples, const uint64_t classes, utils::Matrix<T>& X, utils::Vector<T>& y) {
template <typename TX, typename Ty>
void create_spital_data(const uint64_t samples, const uint64_t classes, utils::Matrix<TX>& X, utils::Vector<Ty>& y) {
const uint64_t rows = samples*classes;
T r, t;
TX r, t;
uint64_t row_idx;
@@ -27,34 +27,15 @@ namespace neural_networks{
for (uint64_t i = 0; i < classes; ++i){
for (uint64_t j = 0; j < samples; ++j){
r = static_cast<T>(j)/static_cast<T>(samples);
t = static_cast<T>(i)*4.0 + (4.0+r);
r = static_cast<TX>(j)/static_cast<TX>(samples);
t = static_cast<TX>(i)*4.0 + (4.0+r);
row_idx = (i*samples) + j;
X(row_idx, 0) = r*std::cos(t*2.5) + utils::random(T{-0.15}, T{0.15});
X(row_idx, 1) = r*std::sin(t*2.5) + utils::random(T{-0.15}, T{0.15});
y[row_idx] = i;
X(row_idx, 0) = r*std::cos(t*2.5) + utils::random(TX{-0.15}, TX{0.15});
X(row_idx, 1) = r*std::sin(t*2.5) + utils::random(TX{-0.15}, TX{0.15});
y[row_idx] = static_cast<Ty>(i);
}
}
/*
utils::Matrix<T> X(static_cast<uint64_t>(samples*classes), 3, T{0});
const uint64_t rows = A.rows();
const uint64_t cols = A.cols();
if (rows != x.size()) {
throw std::runtime_error("inplace_matadd_colvec: dimension mismatch");
}
for (uint64_t i = 0; i < cols; ++i) {
for (uint64_t j = 0; j < rows; ++j) {
A(j, i) += x[j];
}
}*/
}