neuralpp::NeuralNet Class Reference

Main project's class. More...

#include <neural++.hpp>

List of all members.

Public Types

enum  source { file, str }
 Enum to choose the eventual training source for our network (XML from a file or from a string). More...

Public Member Functions

 NeuralNet ()
 Empty constructor for the class - it just makes nothing.
 NeuralNet (size_t in_size, size_t hidden_size, size_t out_size, double l, int e, double th=0.0, double(*a)(double)=__actv)
 Constructor.
 NeuralNet (const std::string file) throw (NetworkFileNotFoundException)
 Constructor.
double getOutput () const
 It gets the output of the network (note: the layer output should contain an only neuron).
std::vector< double > getOutputs ()
 It gets the output of the network in case the output layer contains more neurons.
double getThreshold () const
 Get the threshold of the neurons in the network.
void propagate ()
 It propagates values through the network.
void setInput (std::vector< double > v)
 It sets the input for the network.
void save (const char *fname) throw (NetworkFileWriteException)
 Save a trained neural network to a binary file.
void loadFromBinary (const std::string fname) throw (NetworkFileNotFoundException)
 DEPRECATED.
void saveToBinary (const char *fname) throw (NetworkFileWriteException)
 DEPRECATED.
void train (std::string xml, source src) throw (InvalidXMLException)
 Train a network using a training set loaded from an XML file.

Static Public Member Functions

static void initXML (std::string &xml)
 Initialize the training XML for the neural network.
static std::string XMLFromSet (int &id, std::string set)
 Get a training set from a string and copies it to an XML For example, these strings could be training sets for making sums: "2,3;5" - "5,6;11" - "2,2;4" - "4,5:9" This method called on the first string will return an XML such this: '<training id="0"><input id="0">2</input><input id="1">3</input><output id="0">5</output> &lt/training>'.
static void closeXML (std::string &xml)
 Closes an open XML document generated by "initXML" and "XMLFromSet".

Public Attributes

Layerinput
Layerhidden
Layeroutput

Private Member Functions

void updateWeights ()
 It updates the weights of the net's synapsis through back-propagation.
double error (double ex)
 Get the error made on the expected result as squared deviance.
double expected () const
 Get the expected value (in case you have an only neuron in output layer).
std::vector< double > getExpected () const
 Get the expected value (in case you have an only neuron in output layer).
void setExpected (double ex)
 It sets the value you expect from your network (in case the network has an only neuron in its output layer).
void setExpected (std::vector< double > ex)
 Set the values you expect from your network.
void update ()
 It updates through back-propagation the weights of the synapsis and computes again the output value for epochs times, calling back updateWeights and commitChanges functions.
void link ()
 It links the layers of the network (input, hidden, output).

Private Attributes

int epochs
int ref_epochs
double l_rate
double threshold
std::vector< double > expect
double(* actv_f )(double)
 Private pointer to function, containing the function to be used as activation function.


Detailed Description

Main project's class.

Use *ONLY* this class, unless you know what you're doing

Examples:

examples/adderFromString.cpp, examples/doAdd.cpp, examples/learnAdd.cpp, and examples/networkForSumsAndSubtractions.cpp.


Member Enumeration Documentation

Enum to choose the eventual training source for our network (XML from a file or from a string).

Enumerator:
file 
str 


Constructor & Destructor Documentation

neuralpp::NeuralNet::NeuralNet (  )  [inline]

Empty constructor for the class - it just makes nothing.

neuralpp::NeuralNet::NeuralNet ( size_t  in_size,
size_t  hidden_size,
size_t  out_size,
double  l,
int  e,
double  th = 0.0,
double(*)(double)  a = __actv 
)

Constructor.

Parameters:
in_size Size of the input layer
hidden_size Size of the hidden layer
out_size Size of the output layer
l learn rate (get it after doing some experiments, but generally try to keep its value quite low to be more accurate)
e Epochs (cycles) to execute (the most you execute, the most the network can be accurate for its purpose)
th Threshold, value in [0,1] that establishes how much a neuron must be 'sensitive' on variations of the input values
a Activation function to use (default: f(x)=x)

neuralpp::NeuralNet::NeuralNet ( const std::string  file  )  throw (NetworkFileNotFoundException)

Constructor.

Parameters:
file Binary file containing a neural network previously saved by save() method
Exceptions:
NetworkFileNotFoundException 


Member Function Documentation

void neuralpp::NeuralNet::updateWeights (  )  [private]

It updates the weights of the net's synapsis through back-propagation.

In-class use only

double neuralpp::NeuralNet::error ( double  ex  )  [private]

Get the error made on the expected result as squared deviance.

Parameters:
ex Expected value
Returns:
Mean error

double neuralpp::NeuralNet::expected (  )  const [private]

Get the expected value (in case you have an only neuron in output layer).

Of course you should specify this when you build your network by using setExpected.

Returns:
The expected output value for a certain training phase

std::vector<double> neuralpp::NeuralNet::getExpected (  )  const [private]

Get the expected value (in case you have an only neuron in output layer).

Of course you should specify this when you build your network by using setExpected.

Returns:
The expected output value for a certain training phase

void neuralpp::NeuralNet::setExpected ( double  ex  )  [private]

It sets the value you expect from your network (in case the network has an only neuron in its output layer).

Parameters:
ex Expected output value

void neuralpp::NeuralNet::setExpected ( std::vector< double >  ex  )  [private]

Set the values you expect from your network.

Parameters:
ex Expected output values

void neuralpp::NeuralNet::update (  )  [private]

It updates through back-propagation the weights of the synapsis and computes again the output value for epochs times, calling back updateWeights and commitChanges functions.

void neuralpp::NeuralNet::link (  )  [private]

It links the layers of the network (input, hidden, output).

double neuralpp::NeuralNet::getOutput (  )  const

It gets the output of the network (note: the layer output should contain an only neuron).

Returns:
The output value of the network
Examples:
examples/adderFromString.cpp, and examples/doAdd.cpp.

std::vector<double> neuralpp::NeuralNet::getOutputs (  ) 

It gets the output of the network in case the output layer contains more neurons.

Returns:
A vector containing the output values of the network
Examples:
examples/networkForSumsAndSubtractions.cpp.

double neuralpp::NeuralNet::getThreshold (  )  const

Get the threshold of the neurons in the network.

Returns:
The threshold of the neurons

void neuralpp::NeuralNet::propagate (  ) 

It propagates values through the network.

Use this when you want to give an already trained network some new values the get to the output

Examples:
examples/adderFromString.cpp, examples/doAdd.cpp, and examples/networkForSumsAndSubtractions.cpp.

void neuralpp::NeuralNet::setInput ( std::vector< double >  v  ) 

It sets the input for the network.

Parameters:
v Vector of doubles, containing the values to give to your network
Examples:
examples/adderFromString.cpp, examples/doAdd.cpp, and examples/networkForSumsAndSubtractions.cpp.

void neuralpp::NeuralNet::save ( const char *  fname  )  throw (NetworkFileWriteException)

Save a trained neural network to a binary file.

Parameters:
fname Binary file where you're going to save your network
Exceptions:
NetworkFileWriteException When you get an error writing the network's information to a file
Examples:
examples/learnAdd.cpp.

void neuralpp::NeuralNet::loadFromBinary ( const std::string  fname  )  throw (NetworkFileNotFoundException)

DEPRECATED.

Load a trained neural network from a binary file. This function is deprecated and kept for back-compatibility. Use the XML format instead to load and neural networks and, respectly, the NeuralNetwork(const std::string) constructor or the save(const char*) methods.

Parameters:
fname Name of the file to be loaded
Exceptions:
NetworkFileNotFoundException When you're trying to load an invalid network file

void neuralpp::NeuralNet::saveToBinary ( const char *  fname  )  throw (NetworkFileWriteException)

DEPRECATED.

Save a trained neural network to a binary file. This function is deprecated and kept for back-compatibility. Use the XML format instead to load and neural networks and, respectly, the NeuralNetwork(const std::string) constructor or the save(const char*) methods.

Parameters:
fname Name of the file to be saved with the network information
Exceptions:
NetworkFileWriteException When you try to write the network information to an invalid file

void neuralpp::NeuralNet::train ( std::string  xml,
source  src 
) throw (InvalidXMLException)

Train a network using a training set loaded from an XML file.

A sample XML file is available in examples/adder.xml

Parameters:
xml XML file containing our training set
src Source type from which the XML will be loaded (from a file [default] or from a string)
Exceptions:
InvalidXMLException 
Examples:
examples/adderFromString.cpp, examples/learnAdd.cpp, and examples/networkForSumsAndSubtractions.cpp.

static void neuralpp::NeuralNet::initXML ( std::string &  xml  )  [static]

Initialize the training XML for the neural network.

Parameters:
xml String that will contain the XML

static std::string neuralpp::NeuralNet::XMLFromSet ( int &  id,
std::string  set 
) [static]

Get a training set from a string and copies it to an XML For example, these strings could be training sets for making sums: "2,3;5" - "5,6;11" - "2,2;4" - "4,5:9" This method called on the first string will return an XML such this: '<training id="0"><input id="0">2</input><input id="1">3</input><output id="0">5</output> &lt/training>'.

Parameters:
id ID for the given training set (0,1,..,n)
set String containing input values and expected outputs
Returns:
XML string

static void neuralpp::NeuralNet::closeXML ( std::string &  xml  )  [static]

Closes an open XML document generated by "initXML" and "XMLFromSet".

Parameters:
xml XML string to be closed


Member Data Documentation

double neuralpp::NeuralNet::l_rate [private]

std::vector<double> neuralpp::NeuralNet::expect [private]

double(* neuralpp::NeuralNet::actv_f)(double) [private]

Private pointer to function, containing the function to be used as activation function.


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

Generated on Fri Sep 4 11:25:49 2009 for Neural++ by  doxygen 1.5.6