Fido
 All Classes Namespaces Files Functions Variables Typedefs Macros Pages
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
net::SGDTrainer Class Referenceabstract

A classic backpropagation SGD Trainer. More...

#include <SGDTrainer.h>

Inherits net::Trainer.

Inherited by net::Adadelta, and net::Backpropagation.

Public Member Functions

 SGDTrainer ()
 Initialize empty Backpropagation object. More...
 
 SGDTrainer (double targetErrorLevel_, int maximumEpochs_)
 Initialize the object with necessary constants. More...
 
double train (net::NeuralNet *network, const std::vector< std::vector< double > > &input, const std::vector< std::vector< double > > &correctOutput)
 Trains a neural network on a training set until the target error level is reached. More...
 
double trainEpocs (double numberOfEpochs, net::NeuralNet *network, const std::vector< std::vector< double > > &input, const std::vector< std::vector< double > > &correctOutput)
 Trains a neural network on a training set for a specified number of epochs. More...
 
void store (std::ofstream *out)
 Stores a Trainer object using specified stream. More...
 
bool initFromStream (std::ifstream *in)
 
- Public Member Functions inherited from net::Trainer
std::vector< std::vector
< std::vector< std::vector
< double > > > > 
getGradients ()
 
std::vector< std::vector
< std::vector< std::vector
< double > > > > 
getWeightChanges ()
 
std::vector< std::vector
< std::vector< double > > > 
getInitialWeights ()
 
std::vector< std::vector
< std::vector< double > > > 
getFinalWeights ()
 

Public Attributes

double targetErrorLevel
 The target error level, set by constructor. More...
 
int maximumEpochs
 The maximum number of iterations, set by constructor. More...
 

Protected Member Functions

double trainOnDataPoint (net::NeuralNet *network, const std::vector< double > &input, const std::vector< double > &correctOutput)
 Gets the output of the neural network, calculates the error of each neuron, and edits the weights of the neurons to reduce error. More...
 
virtual void resetNetworkVectors (net::NeuralNet *network)
 Resets the Backpropagation object's neural network specific vectors using a neural network (NN is needed because the number of layers, neurons, and weights are needed). More...
 
virtual double getChangeInWeight (double weight, int layerIndex, int neuronIndex, int weightIndex)=0
 

Additional Inherited Members

- Protected Attributes inherited from net::Trainer
std::vector< std::vector
< std::vector< std::vector
< double > > > > 
gradients
 
std::vector< std::vector
< std::vector< std::vector
< double > > > > 
weightChanges
 
std::vector< std::vector
< std::vector< double > > > 
initialWeights
 
std::vector< std::vector
< std::vector< double > > > 
finalWeights
 

Detailed Description

A classic backpropagation SGD Trainer.

Constructor & Destructor Documentation

SGDTrainer::SGDTrainer ( )

Initialize empty Backpropagation object.

SGDTrainer::SGDTrainer ( double  targetErrorLevel_,
int  maximumEpochs_ 
)

Initialize the object with necessary constants.

Parameters
targetErrorLevel_at this error level, a net will be considered trained
maximumEpochs_after this number of training iterations (one pass through all of the data points), a net will stop being trained no matter what

Member Function Documentation

virtual double net::SGDTrainer::getChangeInWeight ( double  weight,
int  layerIndex,
int  neuronIndex,
int  weightIndex 
)
protectedpure virtual

Implemented in net::Backpropagation, and net::Adadelta.

bool SGDTrainer::initFromStream ( std::ifstream *  in)
void SGDTrainer::resetNetworkVectors ( net::NeuralNet network)
protectedvirtual

Resets the Backpropagation object's neural network specific vectors using a neural network (NN is needed because the number of layers, neurons, and weights are needed).

Reimplemented in net::Adadelta.

void SGDTrainer::store ( std::ofstream *  output)
virtual

Stores a Trainer object using specified stream.

Parameters
outputpointer to the output stream which the neural network will be written to

Implements net::Trainer.

double SGDTrainer::train ( net::NeuralNet network,
const std::vector< std::vector< double > > &  input,
const std::vector< std::vector< double > > &  correctOutput 
)
virtual

Trains a neural network on a training set until the target error level is reached.

Edits the weights of the neural network until its error in predicting the correctOutput of each input reaches the value of targetErrorLevel or the number of training cycles reaches the value of maximumIterations. NOTE: If learning rate is not low enough, the weights of the neural network may got to infinity due to the nature of backpropagation.

Parameters
networkthe neural network to be trained
inputa vector of neural network inputs; each element in input, should have a corresponding output in correctOutput
correctOutputnetwork is trained to output an element of correctOutput when fed a corresponding element of the input vector

Implements net::Trainer.

double SGDTrainer::trainEpocs ( double  numberOfEpochs,
net::NeuralNet network,
const std::vector< std::vector< double > > &  input,
const std::vector< std::vector< double > > &  correctOutput 
)

Trains a neural network on a training set for a specified number of epochs.

Edits the weights of the neural network until its error in predicting the correctOutput of each input reaches the value of targetErrorLevel or the number of training cycles reaches the value of maximumIterations. NOTE: If learning rate is not low enough, the weights of the neural network may got to infinity due to the nature of backpropagation.

Parameters
numberOfEpochsthe number of training passes that will be made through the data
networkthe neural network to be trained
inputa vector of neural network inputs; each element in input, should have a corresponding output in correctOutput
correctOutputnetwork is trained to output an element of correctOutput when fed a corresponding element of the input vector
double SGDTrainer::trainOnDataPoint ( net::NeuralNet network,
const std::vector< double > &  input,
const std::vector< double > &  correctOutput 
)
protected

Gets the output of the neural network, calculates the error of each neuron, and edits the weights of the neurons to reduce error.

Parameters
networkthe neural network to be trained
inputthe input fed to the neural network
correctOutputnetwork is trained to output this when fed the input vector

Member Data Documentation

int net::SGDTrainer::maximumEpochs

The maximum number of iterations, set by constructor.

double net::SGDTrainer::targetErrorLevel

The target error level, set by constructor.


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