iCub-main
Loading...
Searching...
No Matches
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
27namespace iCub {
28namespace learningmachine {
29
42private:
46 std::string filename;
47
51 std::ofstream stream;
52
56 int precision;
57
61 int sampleCount;
62
63public:
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 */
128 std::string getInfo();
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 IMachineLearner.
147 */
148 virtual bool configure(yarp::os::Searchable& config);
149};
150
151} // learningmachine
152} // iCub
153#endif
This 'machine learner' demonstrates how the IMachineLearner interface can be used to easily record sa...
DatasetRecorder(const DatasetRecorder &other)
Copy constructor.
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.
void reset()
Forget everything and start over.
Prediction predict(const yarp::sig::Vector &input)
Ask the learning machine to predict the output for a given input.
virtual void writeBottle(yarp::os::Bottle &bot) const
Writes a serialization of the machine into a bottle.
DatasetRecorder & operator=(const DatasetRecorder &other)
Assignment operator.
virtual void train()
Train the learning machine on the examples that have been supplied so far.
virtual std::string getConfigHelp()
Asks the learning machine to return a string containing the list of configuration options that it sup...
virtual bool configure(yarp::os::Searchable &config)
Change parameters.
DatasetRecorder * clone()
Asks the learning machine to return a clone of its type.
std::string getInfo()
Asks the learning machine to return a string containing information on its operation so far.
A generalized interface for a learning machine for offline and online learning machines (e....
void setName(const std::string &name)
Set the name of this machine learning technique.
A class that represents a prediction result.
Definition Prediction.h:44
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.