Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
modelwithmemoryadapter.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __MODELWITHMEMORYADAPTER_H
25 #define __MODELWITHMEMORYADAPTER_H
26 
27 #include <vector>
28 
29 #include "invertablemodel.h"
30 
31 /// multi layer neural network with configurable activation functions
33 public:
34  /**
35  @param model pointer to model to accomplish by memory
36  @param memorySize number of pattern that are stored
37  @param numPatternsPerStep number of past patterns to learn each step
38  */
41 
42  virtual void init(unsigned int inputDim, unsigned int outputDim,
43  double unit_map = 0.0, RandGen* randGen = 0);
44 
45  /**
46  learn the input output mapping but also learn mappings from the memory.
47  \see InvertableModel::learn
48  */
49  virtual const matrix::Matrix learn (const matrix::Matrix& input,
50  const matrix::Matrix& nom_output,
51  double learnRateFactor = 1);
52 
53  /* ********* Delegations *****************/
54 
55  virtual const matrix::Matrix process (const matrix::Matrix& input){
56  return model->process(input);
57  }
58 
59  virtual const matrix::Matrix response(const matrix::Matrix& input) const{
60  return model->response(input);
61  }
62 
63  virtual const matrix::Matrix inversion(const matrix::Matrix& input,
64  const matrix::Matrix& xsi) const{
65  return model->inversion(input, xsi);
66  }
67  virtual unsigned int getInputDim() const {
68  return model->getInputDim();
69  }
70  virtual unsigned int getOutputDim() const {
71  return model->getOutputDim();
72  }
73  virtual void damp(double damping) { model->damp(damping);}
74 
75  /* ************** Accessors **********************************/
76 
78  return model;
79  }
80  const Inspectable* getModel() const {
81  return model;
82  }
83 
84 
85  /* ************* STOREABLE **********************************/
86  /// stores the layer binary into file stream
87  bool store(FILE* f) const { return model->store(f);}
88  /// restores the layer binary from file stream
89  bool restore(FILE* f){ return model->restore(f);}
90 
91  /* ************* Inspectable **********************************/
92  virtual iparamkeylist getInternalParamNames() const { return model->getInternalParamNames();}
93  virtual iparamvallist getInternalParams() const { return model->getInternalParams();}
94  virtual ilayerlist getStructuralLayers() const { return model->getStructuralLayers();}
96  return model->getStructuralConnections();
97  }
98 
99 
100 protected:
101  // Pattern
102  struct Pat{
103  Pat(){}
104  Pat(const matrix::Matrix& inp, const matrix::Matrix& out, const double& lrFactor):
105  inp(inp), out(out), lrFactor(lrFactor){}
108  double lrFactor;
109  };
110 
114  /// vector of input output mappings
115  std::vector <Pat> memory;
117 };
118 
119 #endif
Matrix type.
Definition: matrix.h:65
virtual ilayerlist getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: modelwithmemoryadapter.h:94
virtual void init(unsigned int inputDim, unsigned int outputDim, double unit_map=0.0, RandGen *randGen=0)
initialisation of the network with the given number of input and output units
Definition: modelwithmemoryadapter.cpp:41
abstract class (interface) for invertable models.
Definition: invertablemodel.h:33
std::list< IConnection > iconnectionlist
Definition: inspectable.h:88
std::vector< Pat > memory
vector of input output mappings
Definition: modelwithmemoryadapter.h:115
virtual unsigned int getInputDim() const =0
returns the number of input neurons
Definition: modelwithmemoryadapter.h:102
int memorySize
Definition: modelwithmemoryadapter.h:112
virtual const matrix::Matrix process(const matrix::Matrix &input)=0
passive processing of the input (this function is not constant since a recurrent network for example ...
virtual unsigned int getOutputDim() const =0
returns the number of output neurons
virtual unsigned int getOutputDim() const
returns the number of output neurons
Definition: modelwithmemoryadapter.h:70
Inspectable * getModel()
Definition: modelwithmemoryadapter.h:77
virtual void damp(double damping)=0
damps the weights and the biases by multiplying (1-damping)
RandGen * randGen
Definition: modelwithmemoryadapter.h:116
random generator with 48bit integer arithmentic
Definition: randomgenerator.h:34
virtual ~ModelWithMemoryAdapter()
Definition: modelwithmemoryadapter.h:40
double lrFactor
Definition: modelwithmemoryadapter.h:108
virtual iparamkeylist getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: modelwithmemoryadapter.h:92
virtual iparamvallist getInternalParams() const
Definition: inspectable.cpp:52
virtual iparamvallist getInternalParams() const
Definition: modelwithmemoryadapter.h:93
virtual const matrix::Matrix response(const matrix::Matrix &input) const =0
calculates the partial derivative of the of the output with repect to the input (Jacobi matrix)...
virtual iconnectionlist getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: modelwithmemoryadapter.h:95
matrix::Matrix inp
Definition: modelwithmemoryadapter.h:106
InvertableModel * model
Definition: modelwithmemoryadapter.h:111
virtual const matrix::Matrix inversion(const matrix::Matrix &input, const matrix::Matrix &xsi) const
calculates the input shift v to given output shift xsi via pseudo inversion.
Definition: modelwithmemoryadapter.h:63
virtual unsigned int getInputDim() const
returns the number of input neurons
Definition: modelwithmemoryadapter.h:67
Interface for inspectable objects.
Definition: inspectable.h:48
virtual const matrix::Matrix learn(const matrix::Matrix &input, const matrix::Matrix &nom_output, double learnRateFactor=1)
learn the input output mapping but also learn mappings from the memory.
Definition: modelwithmemoryadapter.cpp:53
int numPatternsPerStep
Definition: modelwithmemoryadapter.h:113
Pat(const matrix::Matrix &inp, const matrix::Matrix &out, const double &lrFactor)
Definition: modelwithmemoryadapter.h:104
const Inspectable * getModel() const
Definition: modelwithmemoryadapter.h:80
virtual ilayerlist getStructuralLayers() const
Specifies which parameter vector forms a structural layer (in terms of a neural network) The ordering...
Definition: inspectable.cpp:77
virtual const matrix::Matrix inversion(const matrix::Matrix &input, const matrix::Matrix &xsi) const =0
calculates the input shift v to given output shift xsi via pseudo inversion.
virtual const matrix::Matrix process(const matrix::Matrix &input)
passive processing of the input (this function is not constant since a recurrent network for example ...
Definition: modelwithmemoryadapter.h:55
bool store(FILE *f) const
stores the layer binary into file stream
Definition: modelwithmemoryadapter.h:87
bool restore(FILE *f)
restores the layer binary from file stream
Definition: modelwithmemoryadapter.h:89
virtual iconnectionlist getStructuralConnections() const
Specifies which parameter matrix forms a connection between layers (in terms of a neural network) The...
Definition: inspectable.cpp:81
virtual iparamkeylist getInternalParamNames() const
The list of the names of all internal parameters given by getInternalParams().
Definition: inspectable.cpp:33
virtual bool store(FILE *f) const =0
stores the object to the given file stream (ASCII preferred).
virtual void damp(double damping)
damps the weights and the biases by multiplying (1-damping)
Definition: modelwithmemoryadapter.h:73
Pat()
Definition: modelwithmemoryadapter.h:103
std::list< ILayer > ilayerlist
Definition: inspectable.h:87
virtual bool restore(FILE *f)=0
loads the object from the given file stream (ASCII preferred).
virtual const matrix::Matrix response(const matrix::Matrix &input) const
calculates the partial derivative of the of the output with repect to the input (Jacobi matrix)...
Definition: modelwithmemoryadapter.h:59
std::list< iparamkey > iparamkeylist
Definition: inspectable.h:59
std::list< iparamval > iparamvallist
Definition: inspectable.h:61
multi layer neural network with configurable activation functions
Definition: modelwithmemoryadapter.h:32
ModelWithMemoryAdapter(InvertableModel *model, int memorySize, int numPatternsPerStep)
Definition: modelwithmemoryadapter.cpp:31
matrix::Matrix out
Definition: modelwithmemoryadapter.h:107