iCub-main
Loading...
Searching...
No Matches
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/Bottle.h>
25
26namespace iCub {
27namespace learningmachine {
28
41class IScaler {
42protected:
46 double offset;
47
51 double scale;
52
56 std::string name;
57
62
68 virtual void writeBottle(yarp::os::Bottle& bot);
69
75 virtual void readBottle(yarp::os::Bottle& bot);
76
77public:
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 * Configure.
179 */
180 virtual bool configure(yarp::os::Searchable& config);
181};
182
197class NullScaler : public IScaler {
198private:
199public:
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
The IScaler is a linear scaler based scaler.
Definition IScaler.h:41
virtual std::string getInfo()
Asks the learning machine to return a string containing statistics on its operation so far.
Definition IScaler.cpp:40
virtual std::string toString()
Asks the scaler to return a string serialization.
Definition IScaler.cpp:49
IScaler(double s=1., double o=0.)
Constructor.
Definition IScaler.h:84
virtual IScaler * clone()=0
Asks the scaler to return a new object of its type.
std::string getName() const
Retrieve the name of this scaler.
Definition IScaler.h:133
std::string name
The name of this type of scaler.
Definition IScaler.h:56
virtual void writeBottle(yarp::os::Bottle &bot)
Writes a serialization of the scaler into a bottle.
Definition IScaler.cpp:61
void setName(std::string name)
Set the name of this machine learning technique.
Definition IScaler.h:140
double scale
The scale for the linear transformation.
Definition IScaler.h:51
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
bool updateEnabled
Boolean indicating whether the scaler has to update each sample.
Definition IScaler.h:61
virtual double transform(double val)
Transforms a single sample value according to the state of the scaler.
Definition IScaler.cpp:30
virtual void setUpdateEnabled(bool u)
Mutator for the update state.
Definition IScaler.h:147
virtual bool fromString(const std::string &str)
Asks the scaler to initialize from a string serialization.
Definition IScaler.cpp:55
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a scaler from a bottle.
Definition IScaler.cpp:67
virtual bool getUpdateEnabled()
Accessor for the update state.
Definition IScaler.h:154
double offset
The offset for the linear transformation.
Definition IScaler.h:46
virtual double unTransform(double val)
Untransforms a single sample value according to the state of the scaler.
Definition IScaler.h:116
virtual ~IScaler()
Destructor (empty).
Definition IScaler.h:90
virtual bool configure(yarp::os::Searchable &config)
Definition IScaler.cpp:73
The NullScaler is a scaler that does nothing, the output of the transform function is equal to its in...
Definition IScaler.h:197
virtual double unTransform(double val)
Untransforms a single sample value according to the state of the scaler.
Definition IScaler.h:217
virtual NullScaler * clone()
Asks the scaler to return a new object of its type.
Definition IScaler.h:224
virtual double transform(double val)
Transforms a single sample value according to the state of the scaler.
Definition IScaler.h:210
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.