15#include <yarp/math/Math.h> 
   19using namespace yarp::os;
 
   20using namespace yarp::sig;
 
   21using namespace yarp::math;
 
   49    Bottle b; Bottle &v=b.addList();
 
   50    for (
size_t i=0; i<item.length(); i++)
 
   51        v.addFloat64(item[i]);
 
   53    options.put(tag,b.get(0));
 
 
   60    if (Bottle *b=options.find(tag).asList())
 
   62        item.resize(b->size());
 
   63        for (
size_t i=0; i<item.length(); i++)
 
   64            item[i]=b->get(i).asFloat64();
 
 
   80    for (
size_t i=0; i<
inMinX.length(); i++)
 
   91    for (
size_t i=0; i<
outMinX.length(); i++)
 
 
  115    if (!options.check(
"numInputNodes") || !options.check(
"numHiddenNodes") || 
 
  116        !options.check(
"numOutputNodes"))
 
  119    int numHiddenNodes=options.find(
"numHiddenNodes").asInt32();
 
  120    for (
int i=0; i<numHiddenNodes; i++)
 
  126        if (
getItem(options,tag.str(),item))
 
  135    int numOutputNodes=options.find(
"numOutputNodes").asInt32();
 
  136    for (
int i=0; i<numOutputNodes; i++)
 
  142        if (
getItem(options,tag.str(),item))
 
  151    int numInputNodes=options.find(
"numInputNodes").asInt32();
 
  152    for (
int i=0; i<numInputNodes; i++)
 
  154        ostringstream tagX, tagY;
 
  157        tagX<<
"inMinMaxX_"<<i;
 
  158        tagY<<
"inMinMaxY_"<<i;
 
  159        if (!
getItem(options,tagX.str(),itemX) || !
getItem(options,tagY.str(),itemY))
 
  174    for (
int i=0; i<numOutputNodes; i++)
 
  176        ostringstream tagX, tagY;
 
  179        tagX<<
"outMinMaxX_"<<i;
 
  180        tagY<<
"outMinMaxY_"<<i;
 
  181        if (!
getItem(options,tagX.str(),itemX) || !
getItem(options,tagY.str(),itemY))
 
 
  240        Vector n1(
IW.size());
 
  241        for (
size_t i=0; i<n1.length(); i++)
 
  242            n1[i]=yarp::math::dot(
IW[i],
x1)+
b1[i];
 
  246        Vector n2(
LW.size());
 
  247        for (
size_t i=0; i<n2.length(); i++)
 
  248            n2[i]=yarp::math::dot(
LW[i],a1)+
b2[i];
 
 
  264    options.put(
"numHiddenNodes",(
int)
IW.size());
 
  265    options.put(
"numOutputNodes",(
int)
LW.size());
 
  266    options.put(
"numInputNodes",(
int)
inMinMaxX.size());
 
  268    for (
size_t i=0; i<
IW.size(); i++)
 
  278    for (
size_t i=0; i<
LW.size(); i++)
 
  288    for (
size_t i=0; i<
inMinMaxX.size(); i++)
 
  290        ostringstream tagX, tagY;
 
  291        tagX<<
"inMinMaxX_"<<i;
 
  292        tagY<<
"inMinMaxY_"<<i;
 
  308        ostringstream tagX, tagY;
 
  309        tagX<<
"outMinMaxX_"<<i;
 
  310        tagY<<
"outMinMaxY_"<<i;
 
 
  331    stream<<
"***** Input Layer Range *****"<<endl;
 
  332    for (
size_t i=0; i<
inMinMaxX.size(); i++)
 
  336    stream<<
"***** Hidden Layer Weights *****"<<endl;
 
  337    for (
size_t i=0; i<
IW.size(); i++)
 
  338        stream<<
"IW_"<<i<<
": ["<<
IW[i].toString(16,1)<<
"]"<<endl;
 
  340    stream<<
"***** Hidden Layer Bias *****"<<endl;
 
  341    stream<<
"b1: ["<<
b1.toString(16,1)<<
"]"<<endl;
 
  343    stream<<
"***** Output Layer Weights *****"<<endl;
 
  344    for (
size_t i=0; i<
LW.size(); i++)
 
  345        stream<<
"LW_"<<i<<
": ["<<
LW[i].toString(16,1)<<
"]"<<endl;
 
  347    stream<<
"***** Output Layer Bias *****"<<endl;
 
  348    stream<<
"b2: ["<<
b2.toString(16,1)<<
"]"<<endl;
 
  350    stream<<
"***** Output Layer Range *****"<<endl;
 
  355    return stream.good();
 
 
  376    Vector 
y(
x.length());
 
  377    for (
size_t i=0; i<
x.length(); i++)
 
  378        y[i]=2.0/(1.0+
exp(-2.0*
x[i]))-1.0;
 
 
  394    Vector 
y(
x.length());
 
  395    for (
size_t i=0; i<
x.length(); i++)
 
  397        double tmp1=
exp(-2.0*
x[i]);
 
  398        double tmp2=1.0+tmp1;
 
  399        y[i]=(4.0*tmp1)/(tmp2*tmp2);
 
 
  409    return Vector(
x.length(),1.0);
 
 
virtual yarp::sig::Vector hiddenLayerGrad(const yarp::sig::Vector &x) const
Gradient of the Hidden Layer Function.
 
ff2LayNN_tansig_purelin()
Create an empty network.
 
virtual yarp::sig::Vector outputLayerGrad(const yarp::sig::Vector &x) const
Gradient of the Output Layer Function.
 
virtual yarp::sig::Vector outputLayerFcn(const yarp::sig::Vector &x) const
Output Layer Function.
 
virtual yarp::sig::Vector hiddenLayerFcn(const yarp::sig::Vector &x) const
Hidden Layer Function.
 
Feed-Forward 2 layers Neural Network.
 
virtual yarp::sig::Vector hiddenLayerFcn(const yarp::sig::Vector &x) const =0
Hidden Layer Function.
 
yarp::sig::Vector outRatio
 
virtual yarp::sig::Vector scaleOutputToNetFormat(const yarp::sig::Vector &x) const
Scale output to be used with the network.
 
yarp::sig::Vector inRatio
 
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
 
virtual bool isValid() const
Return the internal status after a configuration.
 
std::deque< minmax > inMinMaxX
 
virtual bool printStructure(std::ostream &stream=std::cout) const
Dump tadily the network structure on the stream.
 
yarp::sig::Vector outMinY
 
std::deque< minmax > inMinMaxY
 
ff2LayNN()
Create an empty network.
 
std::deque< yarp::sig::Vector > IW
 
virtual yarp::sig::Vector scaleOutputFromNetFormat(const yarp::sig::Vector &x) const
Scale back output from the network's format.
 
virtual yarp::sig::Vector scaleInputToNetFormat(const yarp::sig::Vector &x) const
Scale input to be used with the network.
 
std::deque< minmax > outMinMaxX
 
virtual bool configure(const yarp::os::Property &options)
Configure/reconfigure the network.
 
virtual yarp::sig::Vector predict(const yarp::sig::Vector &x) const
Predict the output given a certain input to the network.
 
std::deque< minmax > outMinMaxY
 
yarp::sig::Vector outMinX
 
virtual yarp::sig::Vector outputLayerFcn(const yarp::sig::Vector &x) const =0
Output Layer Function.
 
std::deque< yarp::sig::Vector > LW
 
virtual bool getStructure(yarp::os::Property &options) const
Retrieve the network structure as a Property object.
 
virtual yarp::sig::Vector scaleInputFromNetFormat(const yarp::sig::Vector &x) const
Scale back input from the network's format.