#include "./core/omp_config.h" #include "utils/utils.h" #include "numerics/numerics.h" #include "decomp/decomp.h" #include "modules/neural_networks/neural_networks.h" //#include //#include //#include int main(int argc, char const *argv[]) { utils::Mf X(10,2, 0); utils::Matrix y(10,1, 0); utils::Vector class_targets; float loss; float accuracy; //neural_networks::create_spital_data(10000, 3, X, y); neural_networks::create_vertical_data(100, 3, X, y); neural_networks::Dense_Layer dense1(2, 3); neural_networks::Activation_ReLU activation1; neural_networks::Dense_Layer dense2(3, 3); neural_networks::Activation_Softmax activation2; neural_networks::Loss_CategoricalCrossentrophy loss_funtion; float lowest_loss = 9999999; utils::Mf best_dense_1_weights = dense1.weights; utils::Vf best_dense_1_biases = dense1.biases; utils::Mf best_dense_2_weights = dense2.weights; utils::Vf best_dense_2_biases = dense2.biases; utils::Vf vectRND; utils::Vector predections; for (uint64_t i = 0; i < 10; ++i){ // Generate a new set of weights for iteration numerics::inplace_matrandom_mul(dense1.weights,0.98f, 1.02f); numerics::inplace_vecrandom_mul(dense1.biases,0.98f, 1.02f); numerics::inplace_matrandom_mul(dense2.weights,0.98f, 1.02f); numerics::inplace_vecrandom_mul(dense2.biases,0.98f, 1.02f); // Perform a forward pass of the training data through this layer dense1.forward(X); activation1.forward(dense1.outputs); dense2.forward(activation1.outputs); activation2.forward(dense2.outputs); // Perform a farward pass through activation function // it takes the output of the second dense layer here and returns loss loss = loss_funtion.calculate(activation2.outputs, y); predections = numerics::matargmax_row(activation2.outputs); if (y.cols() < 1){ class_targets = numerics::matargmax_row(y); }else{ class_targets = y.get_col(0); } accuracy = numerics::vecmean_equal(predections, class_targets); if (loss < lowest_loss){ //std::cout << "New set of weights found, iteration:" << i << ", loss:" << loss << ", acc:" << accuracy << std::endl; best_dense_1_weights = dense1.weights; best_dense_1_biases = dense1.biases; best_dense_2_weights = dense2.weights; best_dense_2_biases = dense2.biases; lowest_loss = loss; } else{ //std::cout << "HERE" << std::endl; dense1.weights = best_dense_1_weights; dense1.biases = best_dense_1_biases; dense2.weights = best_dense_2_weights; dense2.biases = best_dense_2_biases; } } //std::cout << loss << std::endl; //std::cout << accuracy << std::endl; utils::Matrix softmax_outputs{{0.7, 0.1, 0.2}, {0.1, 0.5, 0.4}, {0.02, 0.9, 0.08}}; utils::Matrix clas_targets{{0},{1},{1}}; neural_networks::Activation_Softmax_Loss_CategoricalCrossentropy softmax_loss; softmax_loss.backward(softmax_outputs, clas_targets); utils::Matrix dvalues1 = softmax_loss.dinputs; neural_networks::Activation_Softmax activation; activation.outputs = softmax_outputs; //neural_networks::Loss_CategoricalCrossentrophy loss; dvalues1.print(); /* utils::Vd a = utils::linspace(1, 10, 10, true); a.print(); mesh::Mesh1D mesh(a); mesh.generate_vertices(0.5, 10.5); double Gamma = 1.0; utils::Md A; utils::Vd b, s(10,1); core::Configs& cfg = core::Configs::defaults(); cfg.grid = core::GridKind::Uniform; cfg.left = {core::FDKind::Forward, core::BCKind::Neumann, 0.0}; cfg.right = {core::FDKind::Backward, core::BCKind::Neumann, 0.0}; cfg.solver = core::SolverKind::LU; fluids::Diffusion1D diffusion(cfg, mesh, Gamma); diffusion.assemble(A, b, s); */ return 0; }