iCub-main
adaptWinPolyEstimator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms
7  * of the BSD-3-Clause license. See the accompanying LICENSE file for
8  * details.
9 */
10 
25 #ifndef __ADAPTWINPOLYESTIMATOR_H__
26 #define __ADAPTWINPOLYESTIMATOR_H__
27 
28 #include <deque>
29 
30 #include <yarp/sig/Vector.h>
31 #include <iCub/ctrl/math.h>
32 
33 
34 namespace iCub
35 {
36 
37 namespace ctrl
38 {
39 
46 {
47 public:
48  yarp::sig::Vector data;
49  double time;
50 
55 
61  AWPolyElement(const yarp::sig::Vector &d, const double t): data(d), time(t) { }
62 };
63 
64 
65 typedef std::deque<AWPolyElement> AWPolyList;
66 
74 {
75 protected:
77  unsigned int order;
78  unsigned int N;
79  double D;
80 
81  yarp::sig::Vector t;
82  yarp::sig::Vector x;
83  yarp::sig::Vector coeff;
84  yarp::sig::Vector winLen;
85  yarp::sig::Vector mse;
86 
87  bool firstRun;
88 
97  virtual yarp::sig::Vector fit(const yarp::sig::Vector &x,
98  const yarp::sig::Vector &y, const unsigned int n=0);
99 
105  virtual double eval(double x);
106 
112  virtual double getEsteeme() = 0;
113 
114 public:
122  AWPolyEstimator(unsigned int _order, unsigned int _N, const double _D);
123 
128  AWPolyList &getList() { return elemList; }
129 
134  void feedData(const AWPolyElement &el);
135 
140  yarp::sig::Vector getWinLen() { return winLen; }
141 
147  yarp::sig::Vector getMSE() { return mse; }
148 
154  yarp::sig::Vector estimate();
155 
162  yarp::sig::Vector estimate(const AWPolyElement &el);
163 
169  void reset();
170 
174  virtual ~AWPolyEstimator() { }
175 };
176 
177 
185 {
186 protected:
191  virtual yarp::sig::Vector fit(const yarp::sig::Vector &x,
192  const yarp::sig::Vector &y, const unsigned int n=0);
193 
194  virtual double getEsteeme() { return coeff[1]; }
195 
196 public:
197  AWLinEstimator(unsigned int _N, const double _D) : AWPolyEstimator(1,_N,_D) { }
198 };
199 
200 
208 {
209 protected:
210  virtual double getEsteeme() { return 2.0*coeff[2]; }
211 
212 public:
213  AWQuadEstimator(unsigned int _N, const double _D) : AWPolyEstimator(2,_N,_D) { }
214 };
215 
216 }
217 
218 }
219 
220 #endif
221 
222 
iCub::ctrl::AWQuadEstimator::getEsteeme
virtual double getEsteeme()
Return the current estimation.
Definition: adaptWinPolyEstimator.h:210
iCub::ctrl::AWPolyEstimator::D
double D
Definition: adaptWinPolyEstimator.h:79
iCub::ctrl::AWPolyEstimator::fit
virtual yarp::sig::Vector fit(const yarp::sig::Vector &x, const yarp::sig::Vector &y, const unsigned int n=0)
Find the regressor which best fits in least square sense the last n data sample couples,...
Definition: adaptWinPolyEstimator.cpp:55
iCub::ctrl::AWQuadEstimator
Definition: adaptWinPolyEstimator.h:207
iCub
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Definition: emotionInterface.h:17
iCub::ctrl::AWPolyElement::AWPolyElement
AWPolyElement(const yarp::sig::Vector &d, const double t)
Create an element for adaptive polynomial fitting.
Definition: adaptWinPolyEstimator.h:61
iCub::ctrl::AWPolyEstimator::t
yarp::sig::Vector t
Definition: adaptWinPolyEstimator.h:81
iCub::ctrl::AWPolyEstimator::order
unsigned int order
Definition: adaptWinPolyEstimator.h:77
iCub::ctrl::AWLinEstimator::AWLinEstimator
AWLinEstimator(unsigned int _N, const double _D)
Definition: adaptWinPolyEstimator.h:197
iCub::ctrl::AWPolyList
std::deque< AWPolyElement > AWPolyList
Definition: adaptWinPolyEstimator.h:65
iCub::ctrl::AWPolyEstimator::getMSE
yarp::sig::Vector getMSE()
Return the mean squared error (MSE) computed over the current windows lengths between the predictions...
Definition: adaptWinPolyEstimator.h:147
iCub::ctrl::AWPolyEstimator::AWPolyEstimator
AWPolyEstimator(unsigned int _order, unsigned int _N, const double _D)
Create a polynomial estimator object of order _order on an adaptive window of a maximum length _N an ...
Definition: adaptWinPolyEstimator.cpp:27
iCub::ctrl::AWPolyEstimator::estimate
yarp::sig::Vector estimate()
Execute the algorithm upon the elements list, with the max deviation threshold given by D.
Definition: adaptWinPolyEstimator.cpp:100
iCub::ctrl::AWPolyEstimator::N
unsigned int N
Definition: adaptWinPolyEstimator.h:78
iCub::ctrl::AWPolyEstimator::getWinLen
yarp::sig::Vector getWinLen()
Return the current windows lengths.
Definition: adaptWinPolyEstimator.h:140
iCub::ctrl::AWPolyEstimator::x
yarp::sig::Vector x
Definition: adaptWinPolyEstimator.h:82
iCub::ctrl::AWPolyEstimator::elemList
AWPolyList elemList
Definition: adaptWinPolyEstimator.h:76
math.h
iCub::ctrl::AWPolyElement
Definition: adaptWinPolyEstimator.h:45
iCub::ctrl::AWPolyEstimator::coeff
yarp::sig::Vector coeff
Definition: adaptWinPolyEstimator.h:83
iCub::ctrl::AWLinEstimator::getEsteeme
virtual double getEsteeme()
Return the current estimation.
Definition: adaptWinPolyEstimator.h:194
iCub::ctrl::AWPolyElement::time
double time
Definition: adaptWinPolyEstimator.h:49
iCub::ctrl::AWPolyEstimator::~AWPolyEstimator
virtual ~AWPolyEstimator()
Destructor.
Definition: adaptWinPolyEstimator.h:174
n
int n
Definition: debugFunctions.cpp:58
iCub::ctrl::AWQuadEstimator::AWQuadEstimator
AWQuadEstimator(unsigned int _N, const double _D)
Definition: adaptWinPolyEstimator.h:213
iCub::ctrl::AWPolyEstimator::reset
void reset()
Reinitialize the internal state.
Definition: adaptWinPolyEstimator.cpp:193
y
y
Definition: show_eyes_axes.m:21
iCub::ctrl::AWPolyEstimator::firstRun
bool firstRun
Definition: adaptWinPolyEstimator.h:87
iCub::ctrl::AWPolyElement::data
yarp::sig::Vector data
Definition: adaptWinPolyEstimator.h:48
iCub::ctrl::AWPolyEstimator::eval
virtual double eval(double x)
Evaluate regressor at certain point.
Definition: adaptWinPolyEstimator.cpp:41
iCub::ctrl::AWLinEstimator
Definition: adaptWinPolyEstimator.h:184
iCub::ctrl::AWPolyEstimator::feedData
void feedData(const AWPolyElement &el)
Feed data into the algorithm.
Definition: adaptWinPolyEstimator.cpp:93
iCub::ctrl::AWPolyEstimator::getEsteeme
virtual double getEsteeme()=0
Return the current estimation.
iCub::ctrl::AWPolyElement::AWPolyElement
AWPolyElement()
Default constructor.
Definition: adaptWinPolyEstimator.h:54
iCub::ctrl::AWPolyEstimator
Definition: adaptWinPolyEstimator.h:73
iCub::ctrl::AWPolyEstimator::winLen
yarp::sig::Vector winLen
Definition: adaptWinPolyEstimator.h:84
iCub::ctrl::AWLinEstimator::fit
virtual yarp::sig::Vector fit(const yarp::sig::Vector &x, const yarp::sig::Vector &y, const unsigned int n=0)
Redefine method to improve computation just for first-order estimator.
Definition: adaptWinPolyEstimator.cpp:204
iCub::ctrl::AWPolyEstimator::getList
AWPolyList & getList()
Return a reference to internal elements list.
Definition: adaptWinPolyEstimator.h:128
iCub::ctrl::AWPolyEstimator::mse
yarp::sig::Vector mse
Definition: adaptWinPolyEstimator.h:85