iCub-main
TransformModule.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 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_TRANSFORMMODULE__
20 #define LM_TRANSFORMMODULE__
21 
22 #include <yarp/os/PortablePair.h>
23 
26 
27 
28 namespace iCub {
29 namespace learningmachine {
30 
41 protected:
46 
47 public:
54 
61  return this->transformerPortable;
62  }
63 
70  return this->getTransformerPortable().getWrapped();
71  }
72 };
73 
86 class TransformPredictProcessor : public ITransformProcessor, public yarp::os::PortReader {
87 protected:
91  yarp::os::Port& predictRelay_inout;
92 
93 public:
101 
102  /*
103  * Inherited from PortReader.
104  */
105  virtual bool read(yarp::os::ConnectionReader& connection);
106 
112  virtual yarp::os::Port& getOutputPort() {
113  return this->predictRelay_inout;
114  }
115 
116 };
117 
118 
129  : public ITransformProcessor, public yarp::os::TypedReaderCallback< yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> > {
130 private:
134  yarp::os::BufferedPort<yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> >& train_out;
135 
136 public:
143  yarp::os::BufferedPort< yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> >& p)
144  : ITransformProcessor(tp), train_out(p) { }
145 
146  /*
147  * Inherited from TypedReaderCallback.
148  */
149  virtual void onRead(yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector>& input);
150 
156  virtual yarp::os::BufferedPort<yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> >& getOutputPort() {
157  return this->train_out;
158  }
159 
160 };
161 
162 
163 
164 
177 private:
181  TransformerPortable transformerPortable;
182 
186  yarp::os::BufferedPort<yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> > train_in;
187 
191  yarp::os::BufferedPort<yarp::os::PortablePair<yarp::sig::Vector,yarp::sig::Vector> > train_out;
192 
196  yarp::os::BufferedPort<yarp::sig::Vector> predict_inout;
197 
201  yarp::os::Port predictRelay_inout;
202 
206  TransformTrainProcessor trainProcessor;
207 
211  TransformPredictProcessor predictProcessor;
212 
216  TransformModule(const TransformModule& other);
217 
221  TransformModule& operator=(const TransformModule& other);
222 
223  /*
224  * Inherited from IMachineLearnerModule.
225  */
226  void registerAllPorts();
227 
228  /*
229  * Inherited from IMachineLearnerModule.
230  */
231  void unregisterAllPorts();
232 
233  /*
234  * Inherited from IMachineLearnerModule.
235  */
236  void printOptions(std::string error = "");
237 
241  void printTransformerList();
242 
243 public:
249  TransformModule(std::string pp = "/lm/transform")
250  : IMachineLearnerModule(pp), transformerPortable((ITransformer*) 0),
251  trainProcessor(transformerPortable, train_out),
252  predictProcessor(transformerPortable, predictRelay_inout) {
253  }
254 
258  virtual ~TransformModule() { }
259 
260  /*
261  * Inherited from IMachineLearnerModule.
262  */
263  virtual bool configure(yarp::os::ResourceFinder& opt);
264 
265  /*
266  * Inherited from IMachineLearnerModule.
267  */
268  virtual bool interruptModule();
269 
270  /*
271  * Inherited from IMachineLearnerModule.
272  */
273  virtual bool respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& reply);
274 
281  return this->getTransformerPortable().getWrapped();
282  }
283 
290  return this->transformerPortable;
291  }
292 
293 };
294 
295 } // learningmachine
296 } // iCub
297 
298 #endif
An abstract base module for the machine learning YARP interface.
Generic abstract class for transformer based processors.
virtual ITransformer & getTransformer()
Retrieve the wrapped transformer.
ITransformProcessor(TransformerPortable &tp)
Constructor.
TransformerPortable & transformerPortable
A reference to a portable transformer.
virtual TransformerPortable & getTransformerPortable()
Retrieve the transformer portable wrapper.
A class that provides a preprocessing interface, which can be used to preprocess the data samples tha...
Definition: ITransformer.h:57
T & getWrapped() const
The accessor for the wrapped object.
Definition: PortableT.h:215
A module for transforming vectors.
virtual bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &reply)
TransformModule(std::string pp="/lm/transform")
Constructor.
virtual TransformerPortable & getTransformerPortable()
Retrieve the transformer portable.
virtual ~TransformModule()
Destructor (empty).
virtual bool configure(yarp::os::ResourceFinder &opt)
virtual ITransformer & getTransformer()
Retrieve the transformer that is used in this TransformModule.
Reply processor helper class for predictions.
virtual bool read(yarp::os::ConnectionReader &connection)
TransformPredictProcessor(TransformerPortable &tp, yarp::os::Port &p)
Constructor.
yarp::os::Port & predictRelay_inout
The relay port.
virtual yarp::os::Port & getOutputPort()
Accessor for the prediction output port.
Port processor helper class for incoming training samples.
TransformTrainProcessor(TransformerPortable &tp, yarp::os::BufferedPort< yarp::os::PortablePair< yarp::sig::Vector, yarp::sig::Vector > > &p)
Constructor.
virtual yarp::os::BufferedPort< yarp::os::PortablePair< yarp::sig::Vector, yarp::sig::Vector > > & getOutputPort()
Retrieve the training output port.
virtual void onRead(yarp::os::PortablePair< yarp::sig::Vector, yarp::sig::Vector > &input)
cmd
Definition: dataTypes.h:30
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.