iCub-main
IScaler.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2011 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_ISCALER__
20 #define LM_ISCALER__
21 
22 #include <string>
23 
24 #include <yarp/os/IConfig.h>
25 
26 namespace iCub {
27 namespace learningmachine {
28 
41 class IScaler : public yarp::os::IConfig {
42 protected:
46  double offset;
47 
51  double scale;
52 
57 
62 
68  virtual void writeBottle(yarp::os::Bottle& bot);
69 
75  virtual void readBottle(yarp::os::Bottle& bot);
76 
77 public:
84  IScaler(double s = 1., double o = 0.)
85  : offset(o), scale(s), name(""), updateEnabled(true) { }
86 
90  virtual ~IScaler() { }
91 
98  virtual void update(double val) { }
99 
107  virtual double transform(double val);
108 
116  virtual double unTransform(double val) {
117  return (val * this->scale) + this->offset;
118  }
119 
126  virtual std::string getInfo();
127 
133  std::string getName() const { return this->name; }
134 
140  void setName(std::string name) { this->name = name; }
141 
147  virtual void setUpdateEnabled(bool u) { this->updateEnabled = u; }
148 
154  virtual bool getUpdateEnabled() { return this->updateEnabled; }
155 
161  virtual IScaler* clone() = 0;
162 
168  virtual std::string toString();
169 
175  virtual bool fromString(const std::string& str);
176 
177  /*
178  * Inherited from IConfig.
179  */
180  virtual bool configure(yarp::os::Searchable& config);
181 };
182 
197 class NullScaler : public IScaler {
198 private:
199 public:
204  this->setName("null");
205  }
206 
207  /*
208  * Inherited from IScaler.
209  */
210  virtual double transform(double val) {
211  return val;
212  }
213 
214  /*
215  * Inherited from IScaler.
216  */
217  virtual double unTransform(double val) {
218  return val;
219  }
220 
221  /*
222  * Inherited from IScaler.
223  */
224  virtual NullScaler* clone() {
225  return new NullScaler(*this);
226  }
227 };
228 
229 } // learningmachine
230 } // iCub
231 
232 #endif
iCub::learningmachine::IScaler::configure
virtual bool configure(yarp::os::Searchable &config)
Definition: IScaler.cpp:73
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::learningmachine::IScaler::toString
virtual std::string toString()
Asks the scaler to return a string serialization.
Definition: IScaler.cpp:49
iCub::learningmachine::IScaler::setName
void setName(std::string name)
Set the name of this machine learning technique.
Definition: IScaler.h:140
iCub::learningmachine::NullScaler::transform
virtual double transform(double val)
Transforms a single sample value according to the state of the scaler.
Definition: IScaler.h:210
iCub::learningmachine::IScaler::offset
double offset
The offset for the linear transformation.
Definition: IScaler.h:46
iCub::learningmachine::IScaler::getInfo
virtual std::string getInfo()
Asks the learning machine to return a string containing statistics on its operation so far.
Definition: IScaler.cpp:40
iCub::learningmachine::NullScaler::NullScaler
NullScaler()
Constructor.
Definition: IScaler.h:203
iCub::learningmachine::IScaler::transform
virtual double transform(double val)
Transforms a single sample value according to the state of the scaler.
Definition: IScaler.cpp:30
iCub::learningmachine::IScaler::IScaler
IScaler(double s=1., double o=0.)
Constructor.
Definition: IScaler.h:84
iCub::learningmachine::IScaler::setUpdateEnabled
virtual void setUpdateEnabled(bool u)
Mutator for the update state.
Definition: IScaler.h:147
iCub::learningmachine::IScaler::~IScaler
virtual ~IScaler()
Destructor (empty).
Definition: IScaler.h:90
iCub::learningmachine::IScaler
Definition: IScaler.h:41
iCub::learningmachine::IScaler::updateEnabled
bool updateEnabled
Boolean indicating whether the scaler has to update each sample.
Definition: IScaler.h:61
iCub::learningmachine::IScaler::readBottle
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a scaler from a bottle.
Definition: IScaler.cpp:67
iCub::learningmachine::IScaler::scale
double scale
The scale for the linear transformation.
Definition: IScaler.h:51
iCub::learningmachine::NullScaler::clone
virtual NullScaler * clone()
Asks the scaler to return a new object of its type.
Definition: IScaler.h:224
iCub::learningmachine::NullScaler::unTransform
virtual double unTransform(double val)
Untransforms a single sample value according to the state of the scaler.
Definition: IScaler.h:217
iCub::learningmachine::NullScaler
Definition: IScaler.h:197
iCub::learningmachine::IScaler::fromString
virtual bool fromString(const std::string &str)
Asks the scaler to initialize from a string serialization.
Definition: IScaler.cpp:55
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
iCub::learningmachine::IScaler::getName
std::string getName() const
Retrieve the name of this scaler.
Definition: IScaler.h:133
iCub::learningmachine::IScaler::name
std::string name
The name of this type of scaler.
Definition: IScaler.h:56
iCub::learningmachine::IScaler::clone
virtual IScaler * clone()=0
Asks the scaler to return a new object of its type.
iCub::learningmachine::IScaler::unTransform
virtual double unTransform(double val)
Untransforms a single sample value according to the state of the scaler.
Definition: IScaler.h:116
iCub::learningmachine::IScaler::writeBottle
virtual void writeBottle(yarp::os::Bottle &bot)
Writes a serialization of the scaler into a bottle.
Definition: IScaler.cpp:61
iCub::learningmachine::IScaler::update
virtual void update(double val)
Feeds a single sample into the scaler, so that it can use this sample to update the offset and scale.
Definition: IScaler.h:98
iCub::learningmachine::IScaler::getUpdateEnabled
virtual bool getUpdateEnabled()
Accessor for the update state.
Definition: IScaler.h:154