iCub-main
IFixedSizeTransformer.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 yarp::sig::Vector IFixedSizeTransformer::transform(const yarp::sig::Vector& input) {
28  yarp::sig::Vector output = ITransformer::transform(input);
29  output.resize(this->getCoDomainSize());
30  this->validateDomainSizes(input, output);
31  return output;
32 }
33 
34 void IFixedSizeTransformer::validateDomainSizes(const yarp::sig::Vector& input, const yarp::sig::Vector& output) {
35  if(!this->checkDomainSize(input)) {
36  throw std::runtime_error("Input sample has invalid dimensionality");
37  }
38  if(!this->checkCoDomainSize(output)) {
39  throw std::runtime_error("Output sample has invalid dimensionality");
40  }
41 }
42 
43 bool IFixedSizeTransformer::configure(yarp::os::Searchable& config) {
44  bool success = false;
45  // set the domain size (int)
46  if(config.find("dom").isInt32()) {
47  this->setDomainSize(config.find("dom").asInt32());
48  success = true;
49  }
50  // set the codomain size (int)
51  if(config.find("cod").isInt32()) {
52  this->setCoDomainSize(config.find("cod").asInt32());
53  success = true;
54  }
55 
56  return success;
57 }
58 
59 void IFixedSizeTransformer::writeBottle(yarp::os::Bottle& bot) const {
60  bot.addInt32(this->getDomainSize());
61  bot.addInt32(this->getCoDomainSize());
62 }
63 
64 void IFixedSizeTransformer::readBottle(yarp::os::Bottle& bot) {
65  this->setCoDomainSize(bot.pop().asInt32());
66  this->setDomainSize(bot.pop().asInt32());
67 }
68 
69 
71  std::ostringstream buffer;
72  buffer << this->ITransformer::getInfo();
73  buffer << "Domain size: " << this->getDomainSize() << ", ";
74  buffer << "Codomain size: " << this->getCoDomainSize() << std::endl;
75  return buffer.str();
76 }
77 
79  std::ostringstream buffer;
80  buffer << this->ITransformer::getConfigHelp();
81  buffer << " dom size Domain size" << std::endl;
82  buffer << " cod size Codomain size" << std::endl;
83  return buffer.str();
84 }
85 
86 
87 } // learningmachine
88 } // iCub
virtual std::string getConfigHelp()
Asks the transformer to return a string containing the list of configuration options that it supports...
virtual yarp::sig::Vector transform(const yarp::sig::Vector &input)
Transforms an input vector.
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a transformer from a bottle.
virtual void setDomainSize(unsigned int size)
Mutator for the domain size.
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 void writeBottle(yarp::os::Bottle &bot) const
Writes a serialization of the transformer into a bottle.
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 configure(yarp::os::Searchable &config)
virtual void setCoDomainSize(unsigned int size)
Mutator for the codomain size.
virtual std::string getInfo()
Asks the transformer to return a string containing statistics on its operation so far.
unsigned int getDomainSize() const
Returns the size (dimensionality) of the input domain.
virtual bool checkCoDomainSize(const yarp::sig::Vector &output)
Checks whether the output is of the desired dimensionality.
virtual std::string getConfigHelp()
Asks the transformer to return a string containing the list of configuration options that it supports...
Definition: ITransformer.h:153
virtual yarp::sig::Vector transform(const yarp::sig::Vector &input)
Transforms an input vector.
Definition: ITransformer.h:104
virtual std::string getInfo()
Asks the transformer to return a string containing statistics on its operation so far.
Definition: ITransformer.h:115
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.