NeuralNet 1.0
Loading...
Searching...
No Matches
NeuralNet::Network Class Reference
Inheritance diagram for NeuralNet::Network:
NeuralNet::Model

Public Member Functions

void setup (const std::shared_ptr< Optimizer > &optimizer, LOSS loss=LOSS::QUADRATIC)
 Method that sets up the model's hyperparameter.
 
void addLayer (std::shared_ptr< Layer > &layer)
 Method to add a layer to the network.
 
void setLoss (LOSS loss)
 This method will set the network's loss function.
 
std::shared_ptr< LayergetLayer (int index) const
 This method will return the Layer residing at the specified index.
 
std::shared_ptr< LayergetOutputLayer () const
 This method will return the output layer (the last layer of the network)
 
size_t getNumLayers () const
 This method will get you the number of layers currently in the Network.
 
std::string getSlug () const
 Get the slug of the network based on it's architecture.
 
double train (std::vector< std::vector< double > > X, std::vector< double > y, int epochs=1, const std::vector< std::shared_ptr< Callback > > callbacks={}, bool progBar=true)
 This method will Train the model with the given inputs and labels.
 
double train (std::vector< std::vector< std::vector< double > > > X, std::vector< double > y, int epochs=1, const std::vector< std::shared_ptr< Callback > > callbacks={}, bool progBar=true)
 This method will Train the model with the given inputs and labels.
 
double train (TrainingData< std::vector< std::vector< double > >, std::vector< double > > trainingData, int epochs=1, const std::vector< std::shared_ptr< Callback > > callbacks={}, bool progBar=true)
 This method will train the model with the given TrainingData.
 
double train (TrainingData< std::vector< std::vector< std::vector< double > > >, std::vector< double > > trainingData, int epochs=1, const std::vector< std::shared_ptr< Callback > > callbacks={}, bool progBar=true)
 This method will train the model with the given TrainingData.
 
Eigen::MatrixXd predict (std::vector< std::vector< double > > inputs)
 This model will try to make predictions based off the inputs passed.
 
Eigen::MatrixXd predict (std::vector< std::vector< std::vector< double > > > inputs)
 This model will try to make predictions based off the inputs passed.
 
void to_file (const std::string &filename) override
 Save the current model to a binary file.
 
void from_file (const std::string &filename) override
 Load a model's params from a file.
 

Friends

class cereal::access
 

Additional Inherited Members

- Static Public Member Functions inherited from NeuralNet::Model
template<typename T , typename = typename std::enable_if< std::is_base_of<Model, T>::value>::type>
static void save_to_file (const std::string &filename, T model)
 This method will save (by serializing) the model passed as argument to a .bin file.
 
template<typename T , typename = typename std::enable_if< std::is_base_of<Model, T>::value>::type>
static void load_from_file (const std::string &filename, T &model)
 This static method loads a Model from a file and assigns it to the supposedly "empty" model passed as argument.
 
- Protected Member Functions inherited from NeuralNet::Model
void registerSignals () const
 
- Protected Attributes inherited from NeuralNet::Model
int cEpoch = 0
 
double loss = 0
 
double accuracy = 0
 
double testLoss = 0
 
double testAccuracy = 0
 

Member Function Documentation

◆ addLayer()

void Network::addLayer ( std::shared_ptr< Layer > & layer)

Method to add a layer to the network.

Parameters
layerthe layer to add to the model it should be of type Layer

◆ from_file()

void NeuralNet::Network::from_file ( const std::string & filename)
inlineoverridevirtual

Load a model's params from a file.

Parameters
filenamethe name of the from which to load the model params

Implements NeuralNet::Model.

◆ getLayer()

std::shared_ptr< Layer > Network::getLayer ( int index) const

This method will return the Layer residing at the specified index.

Parameters
indexThe index from which to fetch the layer
Returns
Layer at specified index

◆ getNumLayers()

size_t Network::getNumLayers ( ) const

This method will get you the number of layers currently in the Network.

Returns
A size_t representing the number of layers in the Network

◆ getOutputLayer()

std::shared_ptr< Layer > Network::getOutputLayer ( ) const

This method will return the output layer (the last layer of the network)

Returns
The output Layer

◆ getSlug()

std::string Network::getSlug ( ) const

Get the slug of the network based on it's architecture.

Returns
A string representing the combined slug of the different components in the Network

◆ predict() [1/2]

Eigen::MatrixXd Network::predict ( std::vector< std::vector< double > > inputs)

This model will try to make predictions based off the inputs passed.

Parameters
inputsThe inputs that will be passed through the network
Returns
This method will return the outputs of the neural network

◆ predict() [2/2]

Eigen::MatrixXd Network::predict ( std::vector< std::vector< std::vector< double > > > inputs)

This model will try to make predictions based off the inputs passed.

Parameters
inputsThe inputs that will be passed through the network
Returns
This method will return the outputs of the neural network

◆ setLoss()

void Network::setLoss ( LOSS loss)

This method will set the network's loss function.

Parameters
lossThe loss function (choose from the list of LOSS enums)

◆ setup()

void Network::setup ( const std::shared_ptr< Optimizer > & optimizer,
LOSS loss = LOSS::QUADRATIC )

Method that sets up the model's hyperparameter.

Parameters
optimizerAn Optimizer's child class
epochsThe number of epochs
lossThe loss function

◆ to_file()

void NeuralNet::Network::to_file ( const std::string & filename)
inlineoverridevirtual

Save the current model to a binary file.

Parameters
filenamethe name of the file in which to save the model params

Implements NeuralNet::Model.

◆ train() [1/4]

double Network::train ( std::vector< std::vector< double > > X,
std::vector< double > y,
int epochs = 1,
const std::vector< std::shared_ptr< Callback > > callbacks = {},
bool progBar = true )

This method will Train the model with the given inputs and labels.

Parameters
XThe inputs that will be passed to the model
yThe labels that represent the expected outputs of the model
epochs
callbacksA vector of Callback that will be called during training stages
progBarOuput a progress bar for the training process . Default: true
Returns
The last training's loss

◆ train() [2/4]

double Network::train ( std::vector< std::vector< std::vector< double > > > X,
std::vector< double > y,
int epochs = 1,
const std::vector< std::shared_ptr< Callback > > callbacks = {},
bool progBar = true )

This method will Train the model with the given inputs and labels.

Parameters
inputsThe inputs that will be passed to the model
labelsThe labels that represent the expected outputs of the model
epochs
callbacksA vector of Callback that will be called during training stages
progBarWhether to output a progress bar for the training process. Default: true
Returns
The last training's loss

◆ train() [3/4]

double Network::train ( TrainingData< std::vector< std::vector< double > >, std::vector< double > > trainingData,
int epochs = 1,
const std::vector< std::shared_ptr< Callback > > callbacks = {},
bool progBar = true )

This method will train the model with the given TrainingData.

Parameters
trainingDatathe data passed through the TrainingData class
epochs
callbacksA vector of Callback that will be called during training stages
progBarWhether to output a progress bar for the training process. Default: true
Returns
The last training's loss

◆ train() [4/4]

double Network::train ( TrainingData< std::vector< std::vector< std::vector< double > > >, std::vector< double > > trainingData,
int epochs = 1,
const std::vector< std::shared_ptr< Callback > > callbacks = {},
bool progBar = true )

This method will train the model with the given TrainingData.

Parameters
trainingDatathe data passed through the TrainingData class
epochs
callbacksA vector of Callback that will be called during training stages
progBarWhether to output a progress bar for the training process. Default: true
Returns
The last training's loss

The documentation for this class was generated from the following files: