diff --git a/src/lexocraft/neural_network/neural_network.cpp b/src/lexocraft/neural_network/neural_network.cpp index e51ce39..406ebd5 100644 --- a/src/lexocraft/neural_network/neural_network.cpp +++ b/src/lexocraft/neural_network/neural_network.cpp @@ -39,6 +39,16 @@ namespace lc { return 0.5F + value / (2 * (1 + std::abs(value))); } + void NeuralNetwork::randomize() { + for (auto& weight: weights) { + weight = Eigen::MatrixXf::Random(weight.rows(), weight.cols()); + } + + for (auto& bias: biases) { + bias = Eigen::VectorXf::Random(bias.rows()); + } + } + void NeuralNetwork::modify(NeuralNetwork::NeuralNetworkDiff diff, bool apply_biases, bool apply_weights) { if (apply_biases) { diff --git a/src/lexocraft/neural_network/neural_network.hpp b/src/lexocraft/neural_network/neural_network.hpp index 806ce14..7754876 100644 --- a/src/lexocraft/neural_network/neural_network.hpp +++ b/src/lexocraft/neural_network/neural_network.hpp @@ -78,6 +78,7 @@ namespace lc { explicit NeuralNetwork(std::vector layer_sizes, bool randomize = true); + void randomize(); void modify(NeuralNetworkDiff diff, bool apply_biases = true, bool apply_weights = true); void train(float cost);