iCub-main
DatasetRecorder.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_DATASETRECORDER__
20 #define LM_DATASETRECORDER__
21 
22 #include <fstream>
23 
25 
26 
27 namespace iCub {
28 namespace learningmachine {
29 
42 private:
46  std::string filename;
47 
51  std::ofstream stream;
52 
56  int precision;
57 
61  int sampleCount;
62 
63 public:
67  DatasetRecorder() : filename("dataset.dat"), precision(8), sampleCount(0) {
68  this->setName("Recorder");
69  }
70 
75  : IMachineLearner(other), filename(other.filename),
76  precision(other.precision), sampleCount(other.sampleCount) {
77  }
78 
82  virtual ~DatasetRecorder() {
83  if(!this->stream.is_open()) {
84  this->stream.close();
85  }
86  }
87 
92 
93  /*
94  * Inherited from IMachineLearner.
95  */
96  virtual void feedSample(const yarp::sig::Vector& input, const yarp::sig::Vector& output);
97 
98  /*
99  * Inherited from IMachineLearner.
100  */
101  virtual void train() { }
102 
103  /*
104  * Inherited from IMachineLearner.
105  */
106  Prediction predict(const yarp::sig::Vector& input) {
107  return Prediction();
108  }
109 
110  /*
111  * Inherited from IMachineLearner.
112  */
113  void reset() {
114  this->stream.close();
115  this->sampleCount = 0;
116  }
117 
118  /*
119  * Inherited from IMachineLearner.
120  */
122  return new DatasetRecorder(*this);
123  }
124 
125  /*
126  * Inherited from IMachineLearner.
127  */
129 
130  /*
131  * Inherited from IMachineLearner.
132  */
133  virtual std::string getConfigHelp();
134 
135  /*
136  * Inherited from IMachineLearner.
137  */
138  virtual void writeBottle(yarp::os::Bottle& bot) const;
139 
140  /*
141  * Inherited from IMachineLearner.
142  */
143  virtual void readBottle(yarp::os::Bottle& bot);
144 
145  /*
146  * Inherited from IConfig.
147  */
148  virtual bool configure(yarp::os::Searchable& config);
149 };
150 
151 } // learningmachine
152 } // iCub
153 #endif
iCub::learningmachine::DatasetRecorder::train
virtual void train()
Train the learning machine on the examples that have been supplied so far.
Definition: DatasetRecorder.h:101
iCub
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.
Definition: emotionInterface.h:17
iCub::learningmachine::DatasetRecorder::getInfo
std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
Definition: DatasetRecorder.cpp:68
IMachineLearner.h
iCub::learningmachine::IMachineLearner
Definition: IMachineLearner.h:89
iCub::learningmachine::DatasetRecorder::getConfigHelp
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
Definition: DatasetRecorder.cpp:87
iCub::learningmachine::DatasetRecorder::DatasetRecorder
DatasetRecorder(const DatasetRecorder &other)
Copy constructor.
Definition: DatasetRecorder.h:74
iCub::learningmachine::DatasetRecorder::DatasetRecorder
DatasetRecorder()
Constructor.
Definition: DatasetRecorder.h:67
iCub::learningmachine::DatasetRecorder::operator=
DatasetRecorder & operator=(const DatasetRecorder &other)
Assignment operator.
Definition: DatasetRecorder.cpp:27
iCub::learningmachine::DatasetRecorder::configure
virtual bool configure(yarp::os::Searchable &config)
Definition: DatasetRecorder.cpp:95
iCub::learningmachine::DatasetRecorder::predict
Prediction predict(const yarp::sig::Vector &input)
Ask the learning machine to predict the output for a given input.
Definition: DatasetRecorder.h:106
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::test::Prediction
PortablePair< Vector, Vector > Prediction
Definition: test.cpp:52
iCub::learningmachine::DatasetRecorder::clone
DatasetRecorder * clone()
Asks the learning machine to return a clone of its type.
Definition: DatasetRecorder.h:121
iCub::learningmachine::DatasetRecorder::reset
void reset()
Forget everything and start over.
Definition: DatasetRecorder.h:113
iCub::learningmachine::DatasetRecorder::writeBottle
virtual void writeBottle(yarp::os::Bottle &bot) const
Writes a serialization of the machine into a bottle.
Definition: DatasetRecorder.cpp:77
iCub::learningmachine::DatasetRecorder::feedSample
virtual void feedSample(const yarp::sig::Vector &input, const yarp::sig::Vector &output)
Provide the learning machine with an example of the desired mapping.
Definition: DatasetRecorder.cpp:39
iCub::learningmachine::DatasetRecorder
Definition: DatasetRecorder.h:41
iCub::learningmachine::DatasetRecorder::readBottle
virtual void readBottle(yarp::os::Bottle &bot)
Unserializes a machine from a bottle.
Definition: DatasetRecorder.cpp:82
iCub::learningmachine::IMachineLearner::setName
void setName(const std::string &name)
Set the name of this machine learning technique.
Definition: IMachineLearner.h:237
iCub::learningmachine::DatasetRecorder::~DatasetRecorder
virtual ~DatasetRecorder()
Destructor.
Definition: DatasetRecorder.h:82