25#include <yarp/math/Math.h> 
   26#include <yarp/math/Rand.h> 
   34using namespace yarp::math;
 
   39namespace learningmachine {
 
   42                                             yarp::sig::Vector ell) {
 
   43    this->
setName(
"SparseSpectrumFeature");
 
 
   55    yarp::sig::Vector inputW = (this->
W * input);
 
   57    double factor = this->
sigma / sqrt((
double)nproj);
 
   58    for(
int i = 0; i < nproj; i++) {
 
   59        output(i)       = cos(inputW(i)) * factor;
 
   60        output(i+nproj) = sin(inputW(i)) * factor;
 
 
   73    if((size & 0x1) == 0) {
 
   79        throw std::runtime_error(
"Size of codomain of Sparse Spectrum Features has to be even");
 
 
   87    yarp::math::RandnScalar prng_normal;
 
   93    for(
int r = 0; r < this->
W.rows(); r++) {
 
   94        for(
int c = 0; c < this->
W.cols(); c++) {
 
   95            this->
W(r, c) = prng_normal.get() / this->
ell(c);
 
 
  112    bot >> this->
W >> this->
ell >> this->
sigma;
 
 
  117    yarp::sig::Vector ls = yarp::sig::Vector(this->
getDomainSize());
 
  119    for(
unsigned int i = 0; (int)i < std::min(
ell.size(), ls.size()); i++) {
 
 
  128    std::ostringstream buffer;
 
  130    buffer << 
" sigma: " << this->
sigma << 
" | ";
 
  131    buffer << 
" ell: " << this->
ell.toString();
 
 
  136    std::ostringstream buffer;
 
  138    buffer << 
"  sigma val             Set sigma parameter" << std::endl;
 
  139    buffer << 
"  ell (list)            Set lambda parameter" << std::endl;
 
 
  147    if(config.find(
"sigma").isFloat64() || config.find(
"sigma").isInt32()) {
 
  148        this->
setSigma(config.find(
"sigma").asFloat64());
 
  153    if(config.find(
"ell").isFloat64() || config.find(
"ell").isInt32()) {
 
  154        yarp::sig::Vector ls = yarp::sig::Vector(this->
getDomainSize());
 
  155        ls = config.find(
"ell").asFloat64();
 
  158    } 
else if(config.find(
"ell").isList()) {
 
  159        yarp::os::Bottle* b = config.find(
"ell").asList();
 
  160        assert(b != (yarp::os::Bottle*) 0x0);
 
  161        yarp::sig::Vector ls(0);
 
  162        for(
int i = 0; i < b->size(); i++) {
 
  163            if(b->get(i).isFloat64() || b->get(i).isInt32()) {
 
  164                ls.push_back(b->get(i).asFloat64());
 
 
double sigma
Noise parameter sigma.
 
yarp::sig::Vector ell
Characteristic length-scales ell, analoguous to same parameter in asymmetric RBF kernel.
 
virtual std::string getConfigHelp()
Asks the transformer to return a string containing the list of configuration options that it supports...
 
virtual void reset()
Forget everything and start over.
 
virtual double getSigma()
Accessor for the sigma parameter.
 
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a transformer from a bottle.
 
virtual void setSigma(double s)
Mutator for the sigma parameter.
 
virtual void setDomainSize(unsigned int size)
Mutator for the domain size.
 
virtual bool configure(yarp::os::Searchable &config)
 
virtual yarp::sig::Vector transform(const yarp::sig::Vector &input)
Transforms an input vector.
 
virtual std::string getInfo()
Asks the transformer to return a string containing statistics on its operation so far.
 
virtual void setEll(yarp::sig::Vector &ell)
Mutator for the characteristic length-scales parameter ell.
 
virtual void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
 
SparseSpectrumFeature(unsigned int dom=1, unsigned int cod=2, double sigma=1., yarp::sig::Vector ell=yarp::sig::Vector(0))
Constructor.
 
yarp::sig::Matrix W
Projection matrix W.
 
virtual void writeBottle(yarp::os::Bottle &bot)
 
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.