iCub-main
IFixedSizeLearner.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 <stdexcept>
20 #include <sstream>
21 
23 
24 namespace iCub {
25 namespace learningmachine {
26 
27 
28 void IFixedSizeLearner::feedSample(const yarp::sig::Vector& input, const yarp::sig::Vector& output) {
29  this->validateDomainSizes(input, output);
30 }
31 
33 }
34 
35 bool IFixedSizeLearner::configure(yarp::os::Searchable& config) {
36  bool success = false;
37  // set the domain size (int)
38  if(config.find("dom").isInt32()) {
39  this->setDomainSize(config.find("dom").asInt32());
40  success = true;
41  }
42  // set the codomain size (int)
43  if(config.find("cod").isInt32()) {
44  this->setCoDomainSize(config.find("cod").asInt32());
45  success = true;
46  }
47 
48  return success;
49 }
50 
51 bool IFixedSizeLearner::checkDomainSize(const yarp::sig::Vector& input) {
52  return (input.size() == this->getDomainSize());
53 }
54 
55 bool IFixedSizeLearner::checkCoDomainSize(const yarp::sig::Vector& output) {
56  return (output.size() == this->getCoDomainSize());
57 }
58 
59 void IFixedSizeLearner::validateDomainSizes(const yarp::sig::Vector& input, const yarp::sig::Vector& output) {
60  if(!this->checkDomainSize(input)) {
61  throw std::runtime_error("Input sample has invalid dimensionality");
62  }
63  if(!this->checkCoDomainSize(output)) {
64  throw std::runtime_error("Output sample has invalid dimensionality");
65  }
66 }
67 
68 void IFixedSizeLearner::writeBottle(yarp::os::Bottle& bot) const {
69  bot.addInt32(this->getDomainSize());
70  bot.addInt32(this->getCoDomainSize());
71 }
72 
73 void IFixedSizeLearner::readBottle(yarp::os::Bottle& bot) {
74  this->setCoDomainSize(bot.pop().asInt32());
75  this->setDomainSize(bot.pop().asInt32());
76 }
77 
79  std::ostringstream buffer;
80  buffer << this->IMachineLearner::getInfo();
81  buffer << "Domain size: " << this->getDomainSize() << std::endl;
82  buffer << "Codomain size: " << this->getCoDomainSize() << std::endl;
83  return buffer.str();
84 }
85 
87  std::ostringstream buffer;
88  buffer << this->IMachineLearner::getConfigHelp();
89  buffer << " dom size Domain size" << std::endl;
90  buffer << " cod size Codomain size" << std::endl;
91  return buffer.str();
92 }
93 
94 
95 } // learningmachine
96 } // iCub
virtual void writeBottle(yarp::os::Bottle &bot) const
Writes a serialization of the machine into a bottle.
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)
Provide the learning machine with an example of the desired mapping.
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a machine from a bottle.
virtual void train()
Train the learning machine on the examples that have been supplied so far.
virtual bool checkDomainSize(const yarp::sig::Vector &input)
Checks whether the input is of the desired dimensionality.
unsigned int getCoDomainSize() const
Returns the size (dimensionality) of the output domain (codomain).
virtual std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
virtual void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
virtual bool configure(yarp::os::Searchable &config)
Change parameters.
virtual void setDomainSize(unsigned int size)
Mutator for the domain size.
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
void validateDomainSizes(const yarp::sig::Vector &input, const yarp::sig::Vector &output)
Validates whether the input and output are of the desired dimensionality.
virtual bool checkCoDomainSize(const yarp::sig::Vector &output)
Checks whether the output is of the desired dimensionality.
unsigned int getDomainSize() const
Returns the size (dimensionality) of the input domain.
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
virtual std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.