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

A neural network. More...

#include <NeuralNet.h>

Public Member Functions

 NeuralNet ()
 Constructs an empty neural network. More...
 
 NeuralNet (unsigned int numInputs, unsigned int numOutputs, unsigned int numHiddenLayers, unsigned int numNeuronsPerHiddenLayer, std::string activationFunctionName)
 Manually initializes a neural network. More...
 
 NeuralNet (NeuralNet *otherNet)
 Constructs a neural network copying another networks architecture with random weights. More...
 
 NeuralNet (std::ifstream *input)
 Restores a neural network from the specified file. More...
 
void store (std::ofstream *output)
 Stores a neural network in the specified file. More...
 
std::vector< double > getWeights ()
 Gets the weights of each neuron in the net. More...
 
std::vector< std::vector
< std::vector< double > > > 
getWeights3D ()
 Gets the weights of each neuron in the net. More...
 
void setWeights (std::vector< double > w)
 Sets the weights of each input for each neuron in the net. More...
 
void setWeights3D (std::vector< std::vector< std::vector< double > > > w)
 Sets the weights of each input for each neuron in the net. More...
 
void randomizeWeights ()
 Randomizes all the weights of the neurons in the net. More...
 
std::vector< double > getOutput (std::vector< double > input)
 Gets the outputs of the network for a set of inputs. More...
 
std::vector< std::vector
< double > > 
feedForward (std::vector< double > input)
 Gets the output of each layer of neurons as an input is fed for just as it is fed forward in getOutput. More...
 
std::vector< std::vector
< std::vector< double > > > 
getGradients (const std::vector< double > &input, const std::vector< double > &correctOutput)
 Computes the error gradients of each layer in the NeuralNet. More...
 
void printWeights ()
 Prints the weights of the neurons of the layers of the net. More...
 
unsigned int numberOfHiddenLayers ()
 Gets the number of hidden layers in the neural net. More...
 
unsigned int numberOfInputs ()
 Gets the number of input neurons in the NeuralNet. More...
 
unsigned int numberOfOutputs ()
 Gets the number of output neurons in the NeuralNet. More...
 
unsigned int numberOfHiddenNeurons ()
 Gets the number of hidden neurons in the NeuralNet. More...
 
void setOutputActivationFunction (std::string name)
 Sets the activation function of the output layer. More...
 
std::string getHiddenActivationFunctionName ()
 Gets the name of the activation function used for hidden layers. More...
 
std::string getOutputActivationFunctionName ()
 Gets the name of the activation function used for output layers. More...
 
void removeNeuron (unsigned int hiddenLayerIndex, unsigned int neuronIndex)
 Removes a neuron from the network. More...
 

Public Attributes

std::vector< Layernet
 A two dimensional network of neurons. More...
 

Detailed Description

A neural network.

A flexible implementation designed to be usable in a wide scope of projects.

Constructor & Destructor Documentation

NeuralNet::NeuralNet ( )

Constructs an empty neural network.

NeuralNet::NeuralNet ( unsigned int  numInputs,
unsigned int  numOutputs,
unsigned int  numHiddenLayers,
unsigned int  numNeuronsPerHiddenLayer,
std::string  activationFunctionName 
)

Manually initializes a neural network.

Parameters
numInputsthe number of inputs to the network (or neurons in the input layer)
numOutputsthe number of outputs to the network (or neurons in the output layer)
numHiddenLayersthe number of hidden layers
numNeuronsPerHiddenLayerthe number of neurons per hidden layer.
activationFunctionNamethe name of the activation function to be used in the NN
NeuralNet::NeuralNet ( NeuralNet otherNet)
explicit

Constructs a neural network copying another networks architecture with random weights.

The new network has the same number of inputs, outputs, hidden layers, and neurons per hidden layer as the network given.

Parameters
otherNetthe network to be copied
NeuralNet::NeuralNet ( std::ifstream *  input)
explicit

Restores a neural network from the specified file.

Parameters
inputthe file the network is to be constructed from

Member Function Documentation

std::vector< std::vector< double > > NeuralNet::feedForward ( std::vector< double >  input)

Gets the output of each layer of neurons as an input is fed for just as it is fed forward in getOutput.

Parameters
inputthe inputs to the neural network
Returns
a 2d vector containing the outputs of each layer
std::vector< std::vector< std::vector< double > > > NeuralNet::getGradients ( const std::vector< double > &  input,
const std::vector< double > &  correctOutput 
)

Computes the error gradients of each layer in the NeuralNet.

Parameters
inputthe input to the neural net
correctOutputwhat the neural net would ideally output when fed the provided input
Returns
a 2d vector containing the gradients of each layer starting from the first layer and ending with the last
std::string NeuralNet::getHiddenActivationFunctionName ( )

Gets the name of the activation function used for hidden layers.

Returns
the string representing the activation function
std::vector< double > NeuralNet::getOutput ( std::vector< double >  input)

Gets the outputs of the network for a set of inputs.

The crowning function of this class ;)

Parameters
inputthe inputs to the neural network
Returns
the outputs of the neural network
std::string NeuralNet::getOutputActivationFunctionName ( )

Gets the name of the activation function used for output layers.

Returns
the string representing the activation function
std::vector< double > NeuralNet::getWeights ( )

Gets the weights of each neuron in the net.

Returns
A 1d vector of neuron weights starting from the first neuron in the first layer to the last neuron in the output layer.
std::vector< std::vector< std::vector< double > > > NeuralNet::getWeights3D ( )

Gets the weights of each neuron in the net.

Returns
A 3d vector of neuron weights.
unsigned int NeuralNet::numberOfHiddenLayers ( )

Gets the number of hidden layers in the neural net.

Returns
the number of layers minus 1
unsigned int NeuralNet::numberOfHiddenNeurons ( )

Gets the number of hidden neurons in the NeuralNet.

Returns
the number of hidden neurons in the network
unsigned int NeuralNet::numberOfInputs ( )

Gets the number of input neurons in the NeuralNet.

Returns
the number of inputs to the network
unsigned int NeuralNet::numberOfOutputs ( )

Gets the number of output neurons in the NeuralNet.

Returns
the number of outputs to the network
void NeuralNet::printWeights ( )

Prints the weights of the neurons of the layers of the net.

void NeuralNet::randomizeWeights ( )

Randomizes all the weights of the neurons in the net.

void NeuralNet::removeNeuron ( unsigned int  hiddenLayerIndex,
unsigned int  neuronIndex 
)

Removes a neuron from the network.

Deletes all weights associated with the deleted neuron.

Returns
hiddenLayerIndex the index of the layer of the neuron to be deleted; 0 is input layer
neuronIndex the index of the neuron; same as the neuron's index in the neurons vector of its layer
void NeuralNet::setOutputActivationFunction ( std::string  name)

Sets the activation function of the output layer.

Parameters
namethe name of the activation function
void NeuralNet::setWeights ( std::vector< double >  w)

Sets the weights of each input for each neuron in the net.

Parameters
wthe vector of weights from which neuron weights are set, starting from the first neuron in the first layer to the last neuron in the output layer
void NeuralNet::setWeights3D ( std::vector< std::vector< std::vector< double > > >  w)

Sets the weights of each input for each neuron in the net.

Parameters
wthe 3d vector of weights from which neuron weights are set
void NeuralNet::store ( std::ofstream *  output)

Stores a neural network in the specified file.

Stores a neural network using ofstream. Useful for appending a network to the end of a file without overwriting it. WARNING: will not close ofstream.

Parameters
outputthe file the network is to be written to

Member Data Documentation

std::vector< Layer > net::NeuralNet::net

A two dimensional network of neurons.


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