A neural network model.
More...
#include <NeuralNetwork.hpp>
|
| NeuralNetwork (std::shared_ptr< Loss > loss=nullptr, std::shared_ptr< Optimizer > optimizer=nullptr) |
| Constructor for NeuralNetwork.
|
|
void | fit (const Eigen::MatrixXd &examples, const Eigen::MatrixXd &labels, const Eigen::MatrixXd &test_examples, const Eigen::MatrixXd &test_labels, int epochs, int batch_size, bool verbose=true) override |
| Fit the neural network model to the given data.
|
|
void | add_layer (std::shared_ptr< Layer > layer) |
| Adds a layer to the neural network model.
|
|
void | compile () |
| Compiles the neural network model.
|
|
void | save (std::string path) |
| Saves the model to a file in a custom binary format. The model can be loaded using the NNFS::load method.
|
|
void | load (std::string path) |
| Loads a model from a file in a custom binary format. The model must have been saved using the NNFS::save method.
|
|
void | accuracy (double &accuracy, const Eigen::MatrixXd &examples, const Eigen::MatrixXd &labels) |
| Calculates the accuracy of the neural network on the provided examples and labels.
|
|
Eigen::MatrixXd | predict (const Eigen::MatrixXd &sample) |
| Predicts the class of the provided sample(s).
|
|
virtual | ~Model ()=default |
| Basic destructor.
|
|
virtual void | fit (const Eigen::MatrixXd &examples, const Eigen::MatrixXd &labels, const Eigen::MatrixXd &test_examples, const Eigen::MatrixXd &test_labels, int epochs, int batch_size, bool verbose=false)=0 |
| Evaluate the model on the given examples.
|
|
A neural network model.
This class represents a neural network model capable of training on data and making predictions.
◆ NeuralNetwork()
NNFS::NeuralNetwork::NeuralNetwork |
( |
std::shared_ptr< Loss > |
loss = nullptr , |
|
|
std::shared_ptr< Optimizer > |
optimizer = nullptr |
|
) |
| |
|
inline |
Constructor for NeuralNetwork.
- Parameters
-
[in] | loss | The loss function, must be a subclass of Loss, defaults to nullptr. If nullptr, training will not be possible. |
[in] | optimizer | The optimizer, must be a subclass of Optimizer, defaults to nullptr. If nullptr, training will not be possible. |
◆ accuracy()
void NNFS::NeuralNetwork::accuracy |
( |
double & |
accuracy, |
|
|
const Eigen::MatrixXd & |
examples, |
|
|
const Eigen::MatrixXd & |
labels |
|
) |
| |
|
inline |
Calculates the accuracy of the neural network on the provided examples and labels.
- Parameters
-
[out] | accuracy | Accuracy of the neural network on the provided examples and labels. |
[in] | examples | Examples to calculate the accuracy on. |
[in] | labels | Labels to calculate the accuracy on. |
◆ add_layer()
void NNFS::NeuralNetwork::add_layer |
( |
std::shared_ptr< Layer > |
layer | ) |
|
|
inline |
Adds a layer to the neural network model.
This method adds a layer to the neural network model. The layer is added to the end of the neural network model.
- Parameters
-
[in] | layer | The layer to be added to the neural network model |
◆ compile()
void NNFS::NeuralNetwork::compile |
( |
| ) |
|
|
inline |
Compiles the neural network model.
This method compiles the neural network model by initializing the weights and biases of the layers and setting the input and output dimensions of each layer.
◆ fit()
void NNFS::NeuralNetwork::fit |
( |
const Eigen::MatrixXd & |
examples, |
|
|
const Eigen::MatrixXd & |
labels, |
|
|
const Eigen::MatrixXd & |
test_examples, |
|
|
const Eigen::MatrixXd & |
test_labels, |
|
|
int |
epochs, |
|
|
int |
batch_size, |
|
|
bool |
verbose = true |
|
) |
| |
|
inlineoverridevirtual |
Fit the neural network model to the given data.
This function trains the neural network model on the given data for the given number of epochs.
- Parameters
-
[in] | examples | Examples to evaluate the model on |
[in] | labels | Labels of the examples |
[in] | test_examples | Examples to validate the model on |
[in] | test_labels | Labels of the validation examples |
[in] | epochs | The number of epochs to train for |
[in] | batch_size | The batch size, i.e. the number of examples to train on in each batch |
[in] | verbose | Whether to print out information about the training process |
Implements NNFS::Model.
◆ load()
void NNFS::NeuralNetwork::load |
( |
std::string |
path | ) |
|
|
inline |
Loads a model from a file in a custom binary format. The model must have been saved using the NNFS::save method.
- Parameters
-
[in] | path | The path to load the model from |
◆ predict()
Eigen::MatrixXd NNFS::NeuralNetwork::predict |
( |
const Eigen::MatrixXd & |
sample | ) |
|
|
inline |
Predicts the class of the provided sample(s).
- Parameters
-
[in] | sample | Sample(s) to predict the class of. |
- Returns
- Predictions of the neural network for the provided sample(s).
◆ save()
void NNFS::NeuralNetwork::save |
( |
std::string |
path | ) |
|
|
inline |
Saves the model to a file in a custom binary format. The model can be loaded using the NNFS::load method.
- Parameters
-
[in] | path | The path to save the model to |
The documentation for this class was generated from the following file: