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< Layer > | net |
| A two dimensional network of neurons. More... | |
A neural network.
A flexible implementation designed to be usable in a wide scope of projects.
| 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.
| numInputs | the number of inputs to the network (or neurons in the input layer) |
| numOutputs | the number of outputs to the network (or neurons in the output layer) |
| numHiddenLayers | the number of hidden layers |
| numNeuronsPerHiddenLayer | the number of neurons per hidden layer. |
| activationFunctionName | the name of the activation function to be used in the NN |
|
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.
| otherNet | the network to be copied |
|
explicit |
Restores a neural network from the specified file.
| input | the file the network is to be constructed from |
| 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.
| input | the inputs to the neural network |
| 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.
| input | the input to the neural net |
| correctOutput | what the neural net would ideally output when fed the provided input |
| std::string NeuralNet::getHiddenActivationFunctionName | ( | ) |
Gets the name of the activation function used for hidden layers.
| 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 ;)
| input | the inputs to the neural network |
| std::string NeuralNet::getOutputActivationFunctionName | ( | ) |
Gets the name of the activation function used for output layers.
| std::vector< double > NeuralNet::getWeights | ( | ) |
Gets the weights of each neuron in the net.
| std::vector< std::vector< std::vector< double > > > NeuralNet::getWeights3D | ( | ) |
Gets the weights of each neuron in the net.
| unsigned int NeuralNet::numberOfHiddenLayers | ( | ) |
Gets the number of hidden layers in the neural net.
| unsigned int NeuralNet::numberOfHiddenNeurons | ( | ) |
Gets the number of hidden neurons in the NeuralNet.
| unsigned int NeuralNet::numberOfInputs | ( | ) |
Gets the number of input neurons in the NeuralNet.
| unsigned int NeuralNet::numberOfOutputs | ( | ) |
Gets the number of output neurons in the NeuralNet.
| 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.
| void NeuralNet::setOutputActivationFunction | ( | std::string | name | ) |
Sets the activation function of the output layer.
| name | the name of the activation function |
| void NeuralNet::setWeights | ( | std::vector< double > | w | ) |
Sets the weights of each input for each neuron in the net.
| w | the 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.
| w | the 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.
| output | the file the network is to be written to |
| std::vector< Layer > net::NeuralNet::net |
A two dimensional network of neurons.
1.8.6