88227a38fc
Started on implementing neural network from NNFS. I've done ReLU and stopped at p.104. Softmax is not ready.
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "./core/omp_config.h"
|
|
#include "./utils/matrix.h"
|
|
#include "./utils/vector.h"
|
|
#include "./utils/random.h"
|
|
|
|
//#include <math.h>
|
|
|
|
|
|
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) {
|
|
|
|
const uint64_t rows = samples*classes;
|
|
T r, t;
|
|
uint64_t row_idx;
|
|
|
|
|
|
if ((rows != X.rows()) || (X.cols() != 2)){
|
|
X.resize(samples*classes, 2);
|
|
}
|
|
if (rows != y.size()){
|
|
y.resize(rows);
|
|
}
|
|
|
|
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);
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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];
|
|
}
|
|
}*/
|
|
}
|
|
|
|
|
|
} // end namesoace NN
|