25 #include <yarp/math/Math.h>
31 using namespace yarp::math;
39 namespace learningmachine {
41 LinearGPRLearner::LinearGPRLearner(
unsigned int dom,
unsigned int cod,
double sigma) {
42 this->setName(
"LinearGPR");
43 this->sampleCount = 0;
46 this->setDomainSize(dom);
48 this->setCoDomainSize(cod);
49 this->setSigma(sigma);
54 B(other.B), W(other.W), sigma(other.sigma) {
61 if(
this == &other)
return *
this;
63 this->IFixedSizeLearner::operator=(other);
64 this->sampleCount = other.sampleCount;
69 this->sigma = other.sigma;
81 this->B = this->B +
outerprod(output, input);
96 yarp::sig::Vector output = (this->W * input);
100 yarp::sig::Vector v =
trsolve(this->R, input,
true);
101 yarp::sig::Vector std(output.size());
102 std = this->sigma * sqrt(1. +
dot(v,v));
108 this->sampleCount = 0;
115 std::ostringstream buffer;
117 buffer <<
"Sigma: " << this->
getSigma() <<
" | ";
118 buffer <<
"Sample Count: " << this->sampleCount << std::endl;
128 std::ostringstream buffer;
130 buffer <<
" sigma val Signal noise sigma" << std::endl;
135 bot << this->R << this->B << this->W << this->sigma << this->sampleCount;
143 bot >> this->sampleCount >> this->sigma >> this->W >> this->B >> this->R;
161 throw std::runtime_error(
"Signal noise sigma has to be larger than 0");
174 if(config.find(
"sigma").isFloat64() || config.find(
"sigma").isInt32()) {
175 this->
setSigma(config.find(
"sigma").asFloat64());
An generalized interface for a learning machine with a fixed domain and codomain size.
virtual void writeBottle(yarp::os::Bottle &bot) const
Writes a serialization of the machine into a bottle.
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)
Provide the learning machine with an example of the desired mapping.
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a machine from a bottle.
virtual bool checkDomainSize(const yarp::sig::Vector &input)
Checks whether the input is of the desired dimensionality.
unsigned int getCoDomainSize() const
Returns the size (dimensionality) of the output domain (codomain).
virtual std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
virtual void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
virtual bool configure(yarp::os::Searchable &config)
Change parameters.
virtual void setDomainSize(unsigned int size)
Mutator for the domain size.
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
unsigned int getDomainSize() const
Returns the size (dimensionality) of the input domain.
Standard linear Bayesian regression or, equivalently, Gaussian Process Regression with a linear covar...
virtual Prediction predict(const yarp::sig::Vector &input)
Ask the learning machine to predict the output for a given input.
virtual ~LinearGPRLearner()
Destructor.
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a machine from a bottle.
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
virtual std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
LinearGPRLearner & operator=(const LinearGPRLearner &other)
Assignment operator.
double getSigma()
Accessor for the signal noise \sigma.
void setSigma(double s)
Sets the signal noise \sigma to a specified value.
virtual bool configure(yarp::os::Searchable &config)
Change parameters.
virtual void train()
Train the learning machine on the examples that have been supplied so far.
virtual void writeBottle(yarp::os::Bottle &bot)
void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
void setDomainSize(unsigned int size)
Mutator for the domain size.
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)
Provide the learning machine with an example of the desired mapping.
void reset()
Forget everything and start over.
A class that represents a prediction result.
double dot(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the dot product between two vectors given in the form: matrix(:,col).
void cholupdate(yarp::sig::Matrix &R, const yarp::sig::Vector &x, yarp::sig::Vector &c, yarp::sig::Vector &s, yarp::sig::Matrix &Z, const yarp::sig::Vector &y, yarp::sig::Vector &rho, bool rtrans=0, bool ztrans=0)
Perform a rank-1 update to a Cholesky factor, while updating additional vectors using the used Given'...
yarp::sig::Matrix outerprod(const yarp::sig::Vector &v1, const yarp::sig::Vector &v2)
Computes the outer product of two vectors.
void cholsolve(const yarp::sig::Matrix &R, const yarp::sig::Matrix &B, yarp::sig::Matrix &X)
Solves a system A*x=b for multiple row vectors in B using a precomputed Cholesky factor R.
void trsolve(const yarp::sig::Matrix &A, const yarp::sig::Vector &b, yarp::sig::Vector &x, bool transa=false)
Solves a triangular linear system Ax=b where A is triangular.
PortablePair< Vector, Vector > Prediction
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.