iCub-main
IMachineLearner.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_IMACHINELEARNER__
20 #define LM_IMACHINELEARNER__
21 
22 #include <string>
23 #include <sstream>
24 
25 #include <yarp/sig/Vector.h>
26 #include <yarp/os/IConfig.h>
27 #include <yarp/os/Portable.h>
28 #include <yarp/os/Bottle.h>
29 #include <yarp/os/Value.h>
30 
32 
33 namespace iCub {
34 namespace learningmachine {
35 
89 class IMachineLearner : public yarp::os::IConfig, public yarp::os::Portable {
90 protected:
95 
103  virtual void writeBottle(yarp::os::Bottle& bot) const = 0;
104 
112  virtual void readBottle(yarp::os::Bottle& bot) = 0;
113 
114 public:
118  IMachineLearner() : name("") { }
119 
123  virtual ~IMachineLearner() { }
124 
131  virtual void feedSample(const yarp::sig::Vector& input, const yarp::sig::Vector& output) = 0;
132 
139  virtual void train() { }
140 
147  virtual Prediction predict(const yarp::sig::Vector& input) = 0;
148 
154  virtual IMachineLearner* clone() = 0;
155 
159  virtual void reset() = 0;
160 
161  /*
162  * Inherited from Portable.
163  */
164  bool write(yarp::os::ConnectionWriter& connection) const {
165  yarp::os::Bottle model;
166  this->writeBottle(model);
167  return model.write(connection);
168  }
169 
170  /*
171  * Inherited from Portable.
172  */
173  bool read(yarp::os::ConnectionReader& connection) {
174  yarp::os::Bottle model;
175  model.read(connection);
176  this->readBottle(model);
177  return true;
178  }
179 
186  virtual std::string getInfo() {
187  return std::string("Type: ") + this->getName() + std::string("\n");
188  }
189 
197  return std::string("Machine configuration options for '") +
198  this->getName() + "'\n";
199  }
200 
206  virtual std::string toString() {
207  yarp::os::Bottle model;
208  this->writeBottle(model);
209  return model.toString().c_str();
210  }
211 
217  virtual bool fromString(const std::string& str) {
218  yarp::os::Bottle model(str.c_str());
219  this->readBottle(model);
220  return true;
221  }
222 
229  return this->name;
230  }
231 
237  void setName(const std::string& name) {
238  this->name = name;
239  }
240 };
241 
242 } // learningmachine
243 } // iCub
244 
245 #endif
iCub
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Definition: emotionInterface.h:17
Prediction.h
iCub::learningmachine::IMachineLearner::getName
std::string getName() const
Retrieve the name of this machine learning technique.
Definition: IMachineLearner.h:228
iCub::learningmachine::IMachineLearner::writeBottle
virtual void writeBottle(yarp::os::Bottle &bot) const =0
Writes a serialization of the machine into a bottle.
iCub::learningmachine::IMachineLearner::train
virtual void train()
Train the learning machine on the examples that have been supplied so far.
Definition: IMachineLearner.h:139
iCub::learningmachine::IMachineLearner::getConfigHelp
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
Definition: IMachineLearner.h:196
iCub::learningmachine::IMachineLearner
Definition: IMachineLearner.h:89
iCub::learningmachine::IMachineLearner::fromString
virtual bool fromString(const std::string &str)
Asks the learning machine to initialize from a string serialization.
Definition: IMachineLearner.h:217
iCub::learningmachine::IMachineLearner::~IMachineLearner
virtual ~IMachineLearner()
Destructor (empty).
Definition: IMachineLearner.h:123
iCub::learningmachine::IMachineLearner::readBottle
virtual void readBottle(yarp::os::Bottle &bot)=0
Unserializes a machine from a bottle.
iCub::learningmachine::IMachineLearner::read
bool read(yarp::os::ConnectionReader &connection)
Definition: IMachineLearner.h:173
iCub::learningmachine::IMachineLearner::toString
virtual std::string toString()
Asks the learning machine to return a string serialization.
Definition: IMachineLearner.h:206
iCub::learningmachine::IMachineLearner::clone
virtual IMachineLearner * clone()=0
Asks the learning machine to return a clone of its type.
iCub::learningmachine::IMachineLearner::predict
virtual Prediction predict(const yarp::sig::Vector &input)=0
Ask the learning machine to predict the output for a given input.
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
iCub::learningmachine::Prediction
Definition: Prediction.h:44
iCub::learningmachine::IMachineLearner::reset
virtual void reset()=0
Forget everything and start over.
iCub::learningmachine::IMachineLearner::name
std::string name
The name of this type of machine learner.
Definition: IMachineLearner.h:94
iCub::learningmachine::IMachineLearner::setName
void setName(const std::string &name)
Set the name of this machine learning technique.
Definition: IMachineLearner.h:237
iCub::learningmachine::IMachineLearner::write
bool write(yarp::os::ConnectionWriter &connection) const
Definition: IMachineLearner.h:164
iCub::learningmachine::IMachineLearner::getInfo
virtual std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
Definition: IMachineLearner.h:186
iCub::learningmachine::IMachineLearner::IMachineLearner
IMachineLearner()
Constructor.
Definition: IMachineLearner.h:118
iCub::learningmachine::IMachineLearner::feedSample
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)=0
Provide the learning machine with an example of the desired mapping.