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).
double getThreshold () const
 Get the threshold of the neurons in the network.
std::vector< double > getOutputs ()
 It gets the output of the network in case the output layer contains more neurons.
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 propagate ()
 It propagates values through the network.
void setInput (std::vector< double > v)
 It sets the input for the network.
void link ()
 It links the layers of the network (input, hidden, output).
void save (const char *fname) throw (NetworkFileWriteException)
 Save a trained neural network to a binary file.
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::vector< double > split (char delim, std::string str)
 Splits a string into a vector of doubles, given a delimitator.
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.
void commitChanges (Layer &l)
 It commits the changes made by updateWeights() to the layer l.
double error (double ex)
 Get the error made on the expected result as squared deviance.

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/adderFromScratch.cpp, examples/doAdd.cpp, and examples/learnAdd.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

void neuralpp::NeuralNet::commitChanges ( Layer l  )  [private]

It commits the changes made by updateWeights() to the layer l.

In-class use only

Parameters:
l Layer to commit the changes

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::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/doAdd.cpp.

double neuralpp::NeuralNet::getThreshold (  )  const

Get the threshold of the neurons in the network.

Returns:
The threshold of the neurons

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/adderFromScratch.cpp.

double neuralpp::NeuralNet::expected (  )  const

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

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  ) 

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  ) 

Set the values you expect from your network.

Parameters:
ex Expected output values

void neuralpp::NeuralNet::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 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/adderFromScratch.cpp, and examples/doAdd.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/adderFromScratch.cpp, and examples/doAdd.cpp.

void neuralpp::NeuralNet::link (  ) 

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

Don't use unless you exactly know what you're doing, it is already called by the constructor

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::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/adderFromScratch.cpp, and examples/learnAdd.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::vector<double> neuralpp::NeuralNet::split ( char  delim,
std::string  str 
) [static]

Splits a string into a vector of doubles, given a delimitator.

Parameters:
delim Delimitator
str String to be splitted
Returns:
Vector of doubles containing splitted values

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 Sun Aug 16 20:53:42 2009 for Neural++ by  doxygen 1.5.6