iCub-main
FixedRangeScaler.cpp
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 #include <cfloat>
20 #include <sstream>
21 
22 #include <yarp/os/Value.h>
23 
26 
28 
29 namespace iCub {
30 namespace learningmachine {
31 
32 FixedRangeScaler::FixedRangeScaler(double li, double ui, double lo, double uo)
33  : lowerBoundIn(li), upperBoundIn(ui), lowerBoundOut(lo), upperBoundOut(uo) {
34  this->setName("Fixed");
35  this->updateScales();
36 }
37 
39  this->scale = (this->getUpperBoundIn() - this->getLowerBoundIn()) /
40  (this->getUpperBoundOut() - this->getLowerBoundOut());
41  this->offset = this->getLowerBoundIn() - (this->getLowerBoundOut() * this->scale);
42 }
43 
45  std::ostringstream buffer;
46  buffer << this->IScaler::getInfo() << ", ";
47  buffer << "In Bounds: [" << this->getLowerBoundIn() << ","
48  << this->getUpperBoundIn() << "], ";
49  buffer << "Out Bounds: [" << this->getLowerBoundOut() << ","
50  << this->getUpperBoundOut() << "]";
51  return buffer.str();
52 }
53 
54 void FixedRangeScaler::writeBottle(yarp::os::Bottle& bot) {
55  bot << this->lowerBoundOut << this->upperBoundOut
56  << this->lowerBoundIn << this->upperBoundIn;
57  // make sure to call the superclass's method
58  this->IScaler::writeBottle(bot);
59 }
60 
61 void FixedRangeScaler::readBottle(yarp::os::Bottle& bot) {
62  // make sure to call the superclass's method (will reset transformer)
63  this->IScaler::readBottle(bot);
64 
65  bot >> this->upperBoundIn >> this->lowerBoundIn
66  >> this->upperBoundOut >> this->lowerBoundOut;
67 }
68 
69 
70 bool FixedRangeScaler::configure(yarp::os::Searchable& config) {
71  bool success = this->IScaler::configure(config);
72 
73  // set the expected incoming lower bound (double)
74  if(config.find("lowerin").isFloat64() || config.find("lowerin").isInt32()) {
75  this->setLowerBoundIn(config.find("lowerin").asFloat64());
76  success = true;
77  }
78  // set the expected incoming upper bound (double)
79  if(config.find("upperin").isFloat64() || config.find("upperin").isInt32()) {
80  this->setUpperBoundIn(config.find("upperin").asFloat64());
81  success = true;
82  }
83 
84  // set the desired outgoing lower bound (double)
85  if(config.find("lowerout").isFloat64() || config.find("lowerout").isInt32()) {
86  this->setLowerBoundOut(config.find("lowerout").asFloat64());
87  success = true;
88  }
89  // set the desired outgoing bound (double)
90  if(config.find("upperout").isFloat64() || config.find("upperout").isInt32()) {
91  this->setUpperBoundOut(config.find("upperout").asFloat64());
92  success = true;
93  }
94 
95  if(!config.findGroup("in").isNull()) {
96  yarp::os::Bottle& bot = config.findGroup("in");
97  if(bot.size() == 3 && (bot.get(1).isInt32() || bot.get(1).isFloat64()) &&
98  (bot.get(2).isInt32() || bot.get(2).isFloat64())) {
99 
100  this->setLowerBoundIn(bot.get(1).asFloat64());
101  this->setUpperBoundIn(bot.get(2).asFloat64());
102  success = true;
103  }
104  }
105 
106  if(!config.findGroup("out").isNull()) {
107  yarp::os::Bottle& bot = config.findGroup("out");
108  if(bot.size() == 3 && (bot.get(1).isInt32() || bot.get(1).isFloat64()) &&
109  (bot.get(2).isInt32() || bot.get(2).isFloat64())) {
110 
111  this->setLowerBoundOut(bot.get(1).asFloat64());
112  this->setUpperBoundOut(bot.get(2).asFloat64());
113  success = true;
114  }
115  }
116 
117  return success;
118 }
119 
120 } // learningmachine
121 } // iCub
122 
virtual double getLowerBoundOut()
Accessor for the desired lower bound.
virtual double getLowerBoundIn()
Accessor for the expected lower bound.
double upperBoundIn
The expected upper bound in the sample values.
double upperBoundOut
The desired upper bound for the output range.
virtual std::string getInfo()
Asks the learning machine to return a string containing statistics on its operation so far.
virtual void writeBottle(yarp::os::Bottle &bot)
Writes a serialization of the scaler into a bottle.
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a scaler from a bottle.
FixedRangeScaler(double li=-1., double ui=1., double lo=-1., double uo=1.)
Constructor.
virtual void setUpperBoundOut(double uo)
Mutator for the desired upper bound.
virtual double getUpperBoundIn()
Accessor for the expected upper bound.
virtual void setUpperBoundIn(double ui)
Mutator for the expected upper bound.
virtual void setLowerBoundOut(double lo)
Mutator for the desired lower bound.
double lowerBoundIn
The expected lower bound in the sample values.
double lowerBoundOut
The desired lower bound for the output range.
virtual double getUpperBoundOut()
Accessor for the desired upper bound.
void updateScales()
Updates the scale and offset according to the specified expected and desired ranges.
virtual void setLowerBoundIn(double li)
Mutator for the expected lower bound.
virtual bool configure(yarp::os::Searchable &config)
virtual std::string getInfo()
Asks the learning machine to return a string containing statistics on its operation so far.
Definition: IScaler.cpp:40
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 readBottle(yarp::os::Bottle &bot)
Unserializes a scaler from a bottle.
Definition: IScaler.cpp:67
double offset
The offset for the linear transformation.
Definition: IScaler.h:46
virtual bool configure(yarp::os::Searchable &config)
Definition: IScaler.cpp:73
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.