iCub-main
Normalizer.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 Normalizer::Normalizer(double l, double u)
33  : lowest(DBL_MAX), highest(-DBL_MAX), lowerBound(l), upperBound(u) {
34  this->setName("Normalizer");
35 }
36 
37 void Normalizer::update(double val) {
38  bool changed = false;
39  if(val < this->lowest) {
40  this->lowest = val;
41  changed = true;
42  }
43  if(val > this->highest) {
44  this->highest = val;
45  changed = true;
46  }
47  if(changed) {
48  this->scale = (this->highest - this->lowest) / (this->getUpperBound() - this->getLowerBound());
49  this->offset = this->lowest - (this->getLowerBound() * this->scale);
50  }
51 }
52 
53 std::string Normalizer::getInfo() {
54  std::ostringstream buffer;
55  buffer << this->IScaler::getInfo() << ", ";
56  buffer << "Bounds: [" << this->getLowerBound() << "," << this->getUpperBound() << "], ";
57  buffer << "Sample Extrema: [" << this->lowest << "," << this->highest << "]";
58  return buffer.str();
59 }
60 
61 void Normalizer::writeBottle(yarp::os::Bottle& bot) {
62  bot << this->lowerBound << this->upperBound << this->lowest << this->highest;
63 
64  // make sure to call the superclass's method
65  this->IScaler::writeBottle(bot);
66 }
67 
68 void Normalizer::readBottle(yarp::os::Bottle& bot) {
69  // make sure to call the superclass's method (will reset transformer)
70  this->IScaler::readBottle(bot);
71 
72  bot >> this->highest >> this->lowest >> this->upperBound >> this->lowerBound;
73 }
74 
75 bool Normalizer::configure(yarp::os::Searchable& config) {
76  bool success = this->IScaler::configure(config);
77 
78  // set the desired lower bound (double)
79  if(config.find("lower").isFloat64() || config.find("lower").isInt32()) {
80  this->setLowerBound(config.find("lower").asFloat64());
81  success = true;
82  }
83  // set the desired upper bound (double)
84  if(config.find("upper").isFloat64() || config.find("upper").isInt32()) {
85  this->setUpperBound(config.find("upper").asFloat64());
86  success = true;
87  }
88 
89  return success;
90 }
91 
92 } // learningmachine
93 } // iCub
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
double highest
The actual highest value found in the sample values.
Definition: Normalizer.h:50
Normalizer(double l=-1, double u=1)
Constructor.
Definition: Normalizer.cpp:32
virtual double getUpperBound()
Accessor for the desired upper bound.
Definition: Normalizer.h:118
double lowest
The actual lowest value found in the sample values.
Definition: Normalizer.h:45
double lowerBound
The desired lower bound for the normalization range.
Definition: Normalizer.h:55
virtual void setLowerBound(double l)
Mutator for the desired lower bound.
Definition: Normalizer.h:113
virtual void setUpperBound(double u)
Mutator for the desired upper bound.
Definition: Normalizer.h:125
double upperBound
The desired upper bound for the normalization range.
Definition: Normalizer.h:60
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: Normalizer.cpp:37
virtual std::string getInfo()
Asks the learning machine to return a string containing statistics on its operation so far.
Definition: Normalizer.cpp:53
virtual double getLowerBound()
Accessor for the desired lower bound.
Definition: Normalizer.h:106
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a scaler from a bottle.
Definition: Normalizer.cpp:68
virtual void writeBottle(yarp::os::Bottle &bot)
Writes a serialization of the scaler into a bottle.
Definition: Normalizer.cpp:61
virtual bool configure(yarp::os::Searchable &config)
Definition: Normalizer.cpp:75
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.