20#include <yarp/math/Math.h>
21#include <yarp/math/SVD.h>
32using namespace yarp::os;
33using namespace yarp::sig;
34using namespace yarp::math;
45 Matrix U(m,
n),V(
n,
n); Vector S(
n);
60 Matrix R(4,4); R.zero(); R(3,3)=1.0;
61 R.setSubmatrix(V,0,0);
111 double cos_theta=
x[2]/
norm(
x);
112 double theta=acos(cos_theta);
113 double phi=atan2(
x[1],
x[0]);
116 double cos_phi=cos(phi);
122 return exp(-40.0*d*d);
133 Bottle &values=
data.addList();
143 info.put(
"spatial_competence",
data.get(0));
151 if (!info.check(
"spatial_competence"))
158 if (Bottle *values=info.find(
"spatial_competence").asList())
166 for (
int i=5; i<values->size(); i++)
197 if ((this->type!=
"se3") && (this->type!=
"se3+scale"))
226 if ((
in.length()>=3) && (
out.length()>=3))
228 Vector _in=
in.subVector(0,2);
229 Vector _out=
out.subVector(0,2);
231 this->in.push_back(_in);
232 this->out.push_back(_out);
280 Vector _in=
in.subVector(0,2);
296 Bottle &values=
data.addList();
297 values.addFloat64(
scale);
298 for (
int r=0; r<
H.rows(); r++)
299 for (
int c=0; c<
H.cols(); c++)
300 values.addFloat64(
H(r,c));
303 info.put(
"type",
type);
304 info.put(
"calibration_data",
data.get(0));
312 if (!info.check(
"type"))
315 string type=info.find(
"type").asString();
316 if ((
type==
"se3") || (
type==
"se3+scale"))
321 else if (
type==
"affine")
331 if (Bottle *values=info.find(
"calibration_data").asList())
333 scale=values->get(0).asFloat64();
336 for (
int i=1; i<values->size(); i++)
338 H(r,c)=values->get(i).asFloat64();
377 if ((
in.length()>=3) && (
out.length()>=3))
379 Vector _in=
in.subVector(0,2);
380 Vector _out=
out.subVector(0,2);
383 this->in.push_back(_in);
384 this->out.push_back(_out);
456 Bottle &values=
data.addList();
460 info.put(
"type",
type);
461 info.put(
"calibration_data",
data.get(0));
469 if (!info.check(
"type"))
472 string type=info.find(
"type").asString();
479 if (Bottle *values=info.find(
"calibration_data").asList())
480 if (values->size()>=1)
516 models.push_back(calibrator);
527 Vector _in=in.subVector(0,2);
528 Vector outExperts(_in.length(),0.0);
529 Vector outExtrapolators(_in.length(),0.0);
530 double sumExperts=0.0;
531 double sumExtrapolators=0.0;
534 for (
size_t i=0; i<
models.size(); i++)
536 double competence=
models[i]->getSpatialCompetence(_in);
540 models[i]->retrieve(_in,pred);
542 outExtrapolators+=competence*pred;
543 sumExtrapolators+=competence;
546 outExperts+=competence*pred;
547 sumExperts+=competence;
555 out=outExperts/sumExperts;
559 else if (sumExtrapolators!=0.0)
561 out=outExtrapolators/sumExtrapolators;
573 for (
size_t i=0; i<
models.size(); i++)
std::deque< yarp::sig::Vector > out
virtual bool toProperty(yarp::os::Property &info) const
virtual bool computeSpatialCompetence(const std::deque< yarp::sig::Vector > &points)
virtual bool fromProperty(const yarp::os::Property &info)
void copySuperClassData(const Calibrator &src)
virtual bool computeSpatialTransformation()
std::deque< yarp::sig::Vector > in
struct Calibrator::SpatialCompetence spatialCompetence
virtual size_t getNumPoints() const
virtual std::string getType() const
virtual double getSpatialCompetence(const yarp::sig::Vector &point)
virtual ~LSSVMCalibrator()
virtual bool addPoints(const yarp::sig::Vector &in, const yarp::sig::Vector &out)
virtual bool getPoints(std::deque< yarp::sig::Vector > &in, std::deque< yarp::sig::Vector > &out) const
LSSVMCalibrator(const std::string &type="lssvm")
virtual bool clearPoints()
iCub::learningmachine::IMachineLearner * impl
virtual bool toProperty(yarp::os::Property &info) const
virtual bool calibrate(double &error)
virtual bool fromProperty(const yarp::os::Property &info)
virtual bool retrieve(const yarp::sig::Vector &in, yarp::sig::Vector &out)
virtual LocallyWeightedExperts & operator<<(Calibrator &c)
virtual Calibrator * operator[](const size_t i)
virtual bool retrieve(const yarp::sig::Vector &in, yarp::sig::Vector &out)
std::deque< Calibrator * > models
virtual ~LocallyWeightedExperts()
virtual bool clearPoints()
virtual bool fromProperty(const yarp::os::Property &info)
virtual bool calibrate(double &error)
MatrixCalibrator(const std::string &type="se3")
virtual bool retrieve(const yarp::sig::Vector &in, yarp::sig::Vector &out)
virtual bool addPoints(const yarp::sig::Vector &in, const yarp::sig::Vector &out)
virtual bool toProperty(yarp::os::Property &info) const
virtual bool getPoints(std::deque< yarp::sig::Vector > &in, std::deque< yarp::sig::Vector > &out) const
iCub::optimization::MatrixTransformationWithMatchedPoints * impl
virtual ~MatrixCalibrator()
virtual bool fromString(const std::string &str)
Asks the learning machine to initialize from a string serialization.
virtual void reset()=0
Forget everything and start over.
virtual void train()
Train the learning machine on the examples that have been supplied so far.
virtual Prediction predict(const yarp::sig::Vector &input)=0
Ask the learning machine to predict the output for a given input.
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)=0
Provide the learning machine with an example of the desired mapping.
virtual std::string toString()
Asks the learning machine to return a string serialization.
This is basic implementation of the LSSVM algorithms.
void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
void setDomainSize(unsigned int size)
Mutator for the domain size.
virtual void setC(double C)
Mutator for the regularization parameter C.
virtual RBFKernel * getKernel()
Accessor for the kernel.
A class that represents a prediction result.
yarp::sig::Vector getPrediction()
Accessor for the expected value of the prediction.
virtual void setGamma(double g)
A class that deals with the problem of determining the affine transformation matrix A between two set...
A class that deals with the problem of determining the roto-translation matrix H and scaling factors ...
virtual bool calibrate(yarp::sig::Matrix &H, double &error)
Perform reference calibration to determine the matrix H.
bool minVolumeEllipsoid(const std::deque< yarp::sig::Vector > &points, const double tol, yarp::sig::Matrix &A, yarp::sig::Vector &c)
Find the minimum volume ellipsoide (MVEE) of a set of N d-dimensional data points.
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).
double norm(const yarp::sig::Matrix &M, int col)
Returns the norm of the vector given in the form: matrix(:,col).
yarp::sig::Vector cross(const yarp::sig::Matrix &A, int colA, const yarp::sig::Matrix &B, int colB)
Returns the cross product between two vectors given in the form: matrix(:,col).