iCub-main
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
iCub::ctrl::ff2LayNN Class Referenceabstract

Feed-Forward 2 layers Neural Network. More...

#include <neuralNetworks.h>

+ Inheritance diagram for iCub::ctrl::ff2LayNN:

Classes

struct  minmax
 

Public Member Functions

 ff2LayNN ()
 Create an empty network. More...
 
 ff2LayNN (const yarp::os::Property &options)
 Create and configure the network. More...
 
virtual bool configure (const yarp::os::Property &options)
 Configure/reconfigure the network. More...
 
virtual bool isValid () const
 Return the internal status after a configuration. More...
 
virtual yarp::sig::Vector predict (const yarp::sig::Vector &x) const
 Predict the output given a certain input to the network. More...
 
virtual bool getStructure (yarp::os::Property &options) const
 Retrieve the network structure as a Property object. More...
 
virtual bool printStructure (std::ostream &stream=std::cout) const
 Dump tadily the network structure on the stream. More...
 
std::deque< yarp::sig::Vector > & get_IW ()
 Retrieve first layer weights. More...
 
std::deque< yarp::sig::Vector > & get_LW ()
 Retrieve second layer weights. More...
 
yarp::sig::Vector & get_b1 ()
 Retrieve first layer bias. More...
 
yarp::sig::Vector & get_b2 ()
 Retrieve second layer bias. More...
 
virtual yarp::sig::Vector scaleInputToNetFormat (const yarp::sig::Vector &x) const
 Scale input to be used with the network. More...
 
virtual yarp::sig::Vector scaleInputFromNetFormat (const yarp::sig::Vector &x) const
 Scale back input from the network's format. More...
 
virtual yarp::sig::Vector scaleOutputToNetFormat (const yarp::sig::Vector &x) const
 Scale output to be used with the network. More...
 
virtual yarp::sig::Vector scaleOutputFromNetFormat (const yarp::sig::Vector &x) const
 Scale back output from the network's format. More...
 
virtual yarp::sig::Vector hiddenLayerFcn (const yarp::sig::Vector &x) const =0
 Hidden Layer Function. More...
 
virtual yarp::sig::Vector outputLayerFcn (const yarp::sig::Vector &x) const =0
 Output Layer Function. More...
 
virtual yarp::sig::Vector hiddenLayerGrad (const yarp::sig::Vector &x) const =0
 Gradient of the Hidden Layer Function. More...
 
virtual yarp::sig::Vector outputLayerGrad (const yarp::sig::Vector &x) const =0
 Gradient of the Output Layer Function. More...
 

Protected Member Functions

void prepare ()
 
void setItem (yarp::os::Property &options, const std::string &tag, const yarp::sig::Vector &item) const
 
bool getItem (const yarp::os::Property &options, const std::string &tag, yarp::sig::Vector &item) const
 

Protected Attributes

std::deque< yarp::sig::Vector > IW
 
yarp::sig::Vector b1
 
std::deque< yarp::sig::Vector > LW
 
yarp::sig::Vector b2
 
std::deque< minmaxinMinMaxX
 
std::deque< minmaxinMinMaxY
 
std::deque< minmaxoutMinMaxX
 
std::deque< minmaxoutMinMaxY
 
yarp::sig::Vector inMinX
 
yarp::sig::Vector inMinY
 
yarp::sig::Vector inRatio
 
yarp::sig::Vector outMinX
 
yarp::sig::Vector outMinY
 
yarp::sig::Vector outRatio
 
bool configured
 

Detailed Description

Feed-Forward 2 layers Neural Network.

Useful to implement the networks trained via MATLAB (e.g. through nftool).

Definition at line 47 of file neuralNetworks.h.

Constructor & Destructor Documentation

◆ ff2LayNN() [1/2]

ff2LayNN::ff2LayNN ( )

Create an empty network.

Definition at line 26 of file neuralNetworks.cpp.

◆ ff2LayNN() [2/2]

iCub::ctrl::ff2LayNN::ff2LayNN ( const yarp::os::Property &  options)

Create and configure the network.

Parameters
optionscontains the parameters to configure the network.
See also
configure

Member Function Documentation

◆ configure()

bool ff2LayNN::configure ( const yarp::os::Property &  options)
virtual

Configure/reconfigure the network.

Parameters
optionscontains the parameters to configure the network according to the convention derived from MATLAB.
Returns
true/false on success/fail.
Note
Available options are:

numInputNodes <int> : input dimension.

numHiddenNodes <int> : number of nodes of the first layer (hidden).

numOutputNodes <int> : number of nodes of the second layer (output).

IW_<j> (<double> <double> ...) : jth weights vector of the hidden layer.

LW_<j> (<double> <double> ...) : jth weights vector of the output layer.

b1 (<double> <double> ...) : bias vector of the hidden layer.

b2 (<double> <double> ...) : bias vector of the output layer.

inMinMaxX_<j> (<min> <max>) : range of the jth input element.

inMinMaxY_<j> (<min> <max>) : range where to map the jth input element.

outMinMaxY_<j> (<min> <max>) : range of the jth output element.

outMinMaxX_<j> (<min> <max>) : range where to remap back the jth output element.

Note
all indexes are 0-based.

Definition at line 101 of file neuralNetworks.cpp.

◆ get_b1()

yarp::sig::Vector& iCub::ctrl::ff2LayNN::get_b1 ( )
inline

Retrieve first layer bias.

Returns
the list of first layer bias.

Definition at line 189 of file neuralNetworks.h.

◆ get_b2()

yarp::sig::Vector& iCub::ctrl::ff2LayNN::get_b2 ( )
inline

Retrieve second layer bias.

Returns
the list of second layer bias.

Definition at line 195 of file neuralNetworks.h.

◆ get_IW()

std::deque<yarp::sig::Vector>& iCub::ctrl::ff2LayNN::get_IW ( )
inline

Retrieve first layer weights.

Returns
the list of first layer weights.

Definition at line 177 of file neuralNetworks.h.

◆ get_LW()

std::deque<yarp::sig::Vector>& iCub::ctrl::ff2LayNN::get_LW ( )
inline

Retrieve second layer weights.

Returns
the list of second layer weights.

Definition at line 183 of file neuralNetworks.h.

◆ getItem()

bool ff2LayNN::getItem ( const yarp::os::Property &  options,
const std::string &  tag,
yarp::sig::Vector &  item 
) const
protected

Definition at line 58 of file neuralNetworks.cpp.

◆ getStructure()

bool ff2LayNN::getStructure ( yarp::os::Property &  options) const
virtual

Retrieve the network structure as a Property object.

Parameters
optionsis the output stream.
Returns
true/false on success/fail.
See also
configure

Definition at line 260 of file neuralNetworks.cpp.

◆ hiddenLayerFcn()

virtual yarp::sig::Vector iCub::ctrl::ff2LayNN::hiddenLayerFcn ( const yarp::sig::Vector &  x) const
pure virtual

Hidden Layer Function.

Parameters
xis the input vector.
Returns
the output vector.

Implemented in iCub::ctrl::ff2LayNN_tansig_purelin.

◆ hiddenLayerGrad()

virtual yarp::sig::Vector iCub::ctrl::ff2LayNN::hiddenLayerGrad ( const yarp::sig::Vector &  x) const
pure virtual

Gradient of the Hidden Layer Function.

Parameters
xis the input vector.
Returns
the output vector.

Implemented in iCub::ctrl::ff2LayNN_tansig_purelin.

◆ isValid()

bool ff2LayNN::isValid ( ) const
virtual

Return the internal status after a configuration.

Returns
true/false on success/fail.

Definition at line 40 of file neuralNetworks.cpp.

◆ outputLayerFcn()

virtual yarp::sig::Vector iCub::ctrl::ff2LayNN::outputLayerFcn ( const yarp::sig::Vector &  x) const
pure virtual

Output Layer Function.

Parameters
xis the input vector.
Returns
the output vector.

Implemented in iCub::ctrl::ff2LayNN_tansig_purelin.

◆ outputLayerGrad()

virtual yarp::sig::Vector iCub::ctrl::ff2LayNN::outputLayerGrad ( const yarp::sig::Vector &  x) const
pure virtual

Gradient of the Output Layer Function.

Parameters
xis the input vector.
Returns
the output vector.

Implemented in iCub::ctrl::ff2LayNN_tansig_purelin.

◆ predict()

Vector ff2LayNN::predict ( const yarp::sig::Vector &  x) const
virtual

Predict the output given a certain input to the network.

Parameters
xis the actual input to the network.
Returns
the predicted output.

Definition at line 232 of file neuralNetworks.cpp.

◆ prepare()

void ff2LayNN::prepare ( )
protected

Definition at line 74 of file neuralNetworks.cpp.

◆ printStructure()

bool ff2LayNN::printStructure ( std::ostream &  stream = std::cout) const
virtual

Dump tadily the network structure on the stream.

Parameters
streamis the output stream.
Returns
true/false on success/fail.

Definition at line 329 of file neuralNetworks.cpp.

◆ scaleInputFromNetFormat()

Vector ff2LayNN::scaleInputFromNetFormat ( const yarp::sig::Vector &  x) const
virtual

Scale back input from the network's format.

Parameters
xis the input vector.
Returns
the output vector.

Definition at line 211 of file neuralNetworks.cpp.

◆ scaleInputToNetFormat()

Vector ff2LayNN::scaleInputToNetFormat ( const yarp::sig::Vector &  x) const
virtual

Scale input to be used with the network.

Parameters
xis the input vector.
Returns
the output vector.

Definition at line 204 of file neuralNetworks.cpp.

◆ scaleOutputFromNetFormat()

Vector ff2LayNN::scaleOutputFromNetFormat ( const yarp::sig::Vector &  x) const
virtual

Scale back output from the network's format.

Parameters
xis the input vector.
Returns
the output vector.

Definition at line 225 of file neuralNetworks.cpp.

◆ scaleOutputToNetFormat()

Vector ff2LayNN::scaleOutputToNetFormat ( const yarp::sig::Vector &  x) const
virtual

Scale output to be used with the network.

Parameters
xis the input vector.
Returns
the output vector.

Definition at line 218 of file neuralNetworks.cpp.

◆ setItem()

void ff2LayNN::setItem ( yarp::os::Property &  options,
const std::string &  tag,
const yarp::sig::Vector &  item 
) const
protected

Definition at line 47 of file neuralNetworks.cpp.

Member Data Documentation

◆ b1

yarp::sig::Vector iCub::ctrl::ff2LayNN::b1
protected

Definition at line 58 of file neuralNetworks.h.

◆ b2

yarp::sig::Vector iCub::ctrl::ff2LayNN::b2
protected

Definition at line 62 of file neuralNetworks.h.

◆ configured

bool iCub::ctrl::ff2LayNN::configured
protected

Definition at line 80 of file neuralNetworks.h.

◆ inMinMaxX

std::deque<minmax> iCub::ctrl::ff2LayNN::inMinMaxX
protected

Definition at line 65 of file neuralNetworks.h.

◆ inMinMaxY

std::deque<minmax> iCub::ctrl::ff2LayNN::inMinMaxY
protected

Definition at line 66 of file neuralNetworks.h.

◆ inMinX

yarp::sig::Vector iCub::ctrl::ff2LayNN::inMinX
protected

Definition at line 72 of file neuralNetworks.h.

◆ inMinY

yarp::sig::Vector iCub::ctrl::ff2LayNN::inMinY
protected

Definition at line 73 of file neuralNetworks.h.

◆ inRatio

yarp::sig::Vector iCub::ctrl::ff2LayNN::inRatio
protected

Definition at line 74 of file neuralNetworks.h.

◆ IW

std::deque<yarp::sig::Vector> iCub::ctrl::ff2LayNN::IW
protected

Definition at line 57 of file neuralNetworks.h.

◆ LW

std::deque<yarp::sig::Vector> iCub::ctrl::ff2LayNN::LW
protected

Definition at line 61 of file neuralNetworks.h.

◆ outMinMaxX

std::deque<minmax> iCub::ctrl::ff2LayNN::outMinMaxX
protected

Definition at line 69 of file neuralNetworks.h.

◆ outMinMaxY

std::deque<minmax> iCub::ctrl::ff2LayNN::outMinMaxY
protected

Definition at line 70 of file neuralNetworks.h.

◆ outMinX

yarp::sig::Vector iCub::ctrl::ff2LayNN::outMinX
protected

Definition at line 76 of file neuralNetworks.h.

◆ outMinY

yarp::sig::Vector iCub::ctrl::ff2LayNN::outMinY
protected

Definition at line 77 of file neuralNetworks.h.

◆ outRatio

yarp::sig::Vector iCub::ctrl::ff2LayNN::outRatio
protected

Definition at line 78 of file neuralNetworks.h.


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