41#ifndef CHISEI_NEURAL_NETWORK_HPP
42#define CHISEI_NEURAL_NETWORK_HPP
75 std::vector<size_t> layer_sizes;
84 std::vector<std::vector<std::vector<double>>> weights;
91 std::vector<std::vector<double>> biases;
98 std::function<double(
double)> activation;
105 std::function<double(
double)> activation_derivative;
110 std::random_device rd;
115 std::mt19937 gen{rd()};
122 std::normal_distribution<> weight_dist{0, 0.1};
133 const std::vector<size_t>& _layers,
134 std::function<
double(
double)> _activation,
135 std::function<
double(
double)> _activation_derivative
170 std::vector<double>
predict(
const std::vector<double>& input);
183 const std::vector<std::vector<double>>& inputs,
184 const std::vector<std::vector<double>>& targets,
185 double learning_rate = 0.1,
197 const std::vector<double>& prediction,
198 const std::vector<double>& target
209 const std::vector<double>& prediction,
210 const std::vector<double>& target
221 const std::vector<std::vector<double>>& inputs,
222 const std::vector<std::vector<double>>& targets
233 const std::vector<double>& prediction,
234 const std::vector<double>& target
Represents a fully connected feedforward neural network.
double compute_mse_loss(const std::vector< double > &prediction, const std::vector< double > &target)
Computes the mean squared error (MSE) loss.
NeuralNetwork(const NeuralNetwork &other)
Copy constructor.
NeuralNetwork & operator=(NeuralNetwork &&other) noexcept
Move assignment operator.
NeuralNetwork(const std::vector< size_t > &_layers, std::function< double(double)> _activation, std::function< double(double)> _activation_derivative)
Constructs a neural network with the specified layers and activation functions.
static NeuralNetwork loadFromModel(const std::string &filename)
Loads a neural network from a saved model file.
bool is_correct_prediction(const std::vector< double > &prediction, const std::vector< double > &target)
Determines whether a prediction is correct based on a target.
~NeuralNetwork()
Destructor for the neural network.
void train(const std::vector< std::vector< double > > &inputs, const std::vector< std::vector< double > > &targets, double learning_rate=0.1, int epochs=10000)
Trains the neural network using the provided training data.
void save_model(const std::string &filename)
Saves the current state of the neural network to a file.
std::vector< double > compute_output_gradient(const std::vector< double > &prediction, const std::vector< double > &target)
Computes the gradient of the loss with respect to the output layer.
double compute_accuracy(const std::vector< std::vector< double > > &inputs, const std::vector< std::vector< double > > &targets)
Computes the accuracy of the network on a dataset.
std::vector< double > predict(const std::vector< double > &input)
Predicts the output for a given input vector.