class NeuralNet: public Graph
This class implements a generic (acyclic, non-recurrent) neural network. It is a graph of neurons and weights, relying on the methods of the Neuron
and Weight
classes to calculate the output of the network and gradients for use in BP-based systems.
For the network to calculate gradients correctly, these steps must be performed:
- Set the inputs to the networks
- Calling N the function of the network outputs whose gradient we wish to calculate, set the 'delta' values to the partial derivatives dN/d(out), for each output neuron.
- Call
gradient()
for each weight.
Attributes:
std::vector<InputTerminal*> VI
- The input terminals. Note that each of them must be present also in the
V
set (inherited from Graph
) to avoid memory leaks.
std::vector<Neuron*> VO
- The output neurons. Note that each of them must be present also in the
V
set (inherited from Graph
) to avoid memory leaks.
Methods:
void setInput(const std::vector<double> &inV) throw (length_error)
- Sets the value of each input terminal to the given value (inV[0] to VI[0] and so on), throwing an exception if the two vectors have different sizes.
void value(std::vector<double> *outV) throw (length_error)
- Sets the given vector to the output values from the network (VO[0] to (*outV)[0] and so on), throwing an exception if the two vectors have different sizes.
void setDelta(const std::vector<double> &deltaV) throw (length_error)
- Sets the 'delta' value of each output neuron to the given value (deltaV[0] to VO[0] and so on), throwing an exception if the two vectors have different sizes.
Streamers:
ostream& operator<<(ostream &o,const NeuralNet &n)
- Writes a representation of the network to the given stream. Uses
writeNodes<>()
and writeLinks<>()
.
istream& operator>>(istream &i,NeuralNet &n)
- Reads back a representation of a network from the given stream. Uses
readNodes<>()
and readLinks<>()
, with NeuronInserter
, ITInserter
and LinkInserter
.