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)
 Constructor.
 NeuralNet (const string file) throw (NetworkFileNotFoundException)
 Constructor.
 NeuralNet (size_t in_size, size_t hidden_size, size_t out_size, double(*actv)(double), double l, int e)
 Constructor.
double getOutput () const
 It gets the output of the network (note: the layer output should contain an only neuron).
vector< double > getOutputs ()
 It gets the output of the network in case the output layer contains more neurons.
double expected () const
 It gets the value expected.
void setExpected (double ex)
 It sets the value 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 (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 (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 (string &xml)
 Initialize the training XML for the neural network.
static vector< double > split (char delim, string str)
 Splits a string into a vector of doubles, given a delimitator.
static string XMLFromSet (int id, 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 (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) const
 Get the error made on the expected result as |v-v'|/v.

Private Attributes

int epochs
int ref_epochs
double l_rate
double ex
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


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 
)

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)

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

Constructor.

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

neuralpp::NeuralNet::NeuralNet ( size_t  in_size,
size_t  hidden_size,
size_t  out_size,
double(*)(double)  actv,
double  l,
int  e 
)

Constructor.

Parameters:
in_size Size of the input layer
hidden_size Size of the hidden layer
out_size Size of the output layer
actv Activation function to use (default: f(x)=x)
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)


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  )  const [private]

Get the error made on the expected result as |v-v'|/v.

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

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

double neuralpp::NeuralNet::expected (  )  const

It gets the value expected.

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.

Parameters:
ex Expected output value

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

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

It sets the input for the network.

Parameters:
v Vector of doubles, containing the values to give to your network

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

void neuralpp::NeuralNet::train ( 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 

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

Initialize the training XML for the neural network.

Parameters:
xml String that will contain the XML

static vector<double> neuralpp::NeuralNet::split ( char  delim,
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 string neuralpp::NeuralNet::XMLFromSet ( int  id,
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 ( 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]

double neuralpp::NeuralNet::ex [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 Sat Aug 15 02:56:02 2009 for Neural++ by  doxygen 1.5.6