Skip to content

Commit

Permalink
Added neural network in-place randomization method
Browse files Browse the repository at this point in the history
  • Loading branch information
FuexFollets committed Feb 8, 2024
1 parent 897ca10 commit 5f57c93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lexocraft/neural_network/neural_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/lexocraft/neural_network/neural_network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace lc {

explicit NeuralNetwork(std::vector<std::size_t> layer_sizes, bool randomize = true);

void randomize();
void modify(NeuralNetworkDiff diff, bool apply_biases = true, bool apply_weights = true);

void train(float cost);
Expand Down

0 comments on commit 5f57c93

Please sign in to comment.