Robot Simulator of the Robotics Group for Self-Organization of Control: modelwithmemoryadapter.h Source File

# modelwithmemoryadapter.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __MODELWITHMEMORYADAPTER_H
    00025 #define __MODELWITHMEMORYADAPTER_H
    00026
    00027 #include <vector>
    00028
    00029 #include "invertablemodel.h"
    00030
    00031 /// multi layer neural network with configurable activation functions
    00032 class ModelWithMemoryAdapter : public InvertableModel {
    00033 public:
    00034   /**
    00035      @param model pointer to model to accomplish by memory
    00036      @param memorySize number of pattern that are stored
    00037      @param numPatternsPerStep number of past patterns to learn each step
    00038   */
    00039   ModelWithMemoryAdapter(InvertableModel* model, int memorySize, int numPatternsPerStep);
    00040   virtual ~ModelWithMemoryAdapter(){ }
    00041
    00042   virtual void init(unsigned int inputDim, unsigned  int outputDim,
    00043                     double unit_map = 0.0, RandGen* randGen = 0);
    00044
    00045   /**
    00046      learn the input output mapping but also learn mappings from the memory.
    00047      \see InvertableModel::learn
    00048    */
    00049   virtual const matrix::Matrix learn (const matrix::Matrix& input,
    00050                                       const matrix::Matrix& nom_output,
    00051                                       double learnRateFactor = 1);
    00052
    00053   /* ********* Delegations *****************/
    00054
    00055   virtual const matrix::Matrix process (const matrix::Matrix& input){
    00056     return model->process(input);
    00057   }
    00058
    00059   virtual const matrix::Matrix response(const matrix::Matrix& input) const{
    00060     return model->response(input);
    00061   }
    00062
    00063   virtual const matrix::Matrix inversion(const matrix::Matrix& input,
    00064                                          const matrix::Matrix& xsi) const{
    00065     return model->inversion(input, xsi);
    00066   }
    00067   virtual unsigned int getInputDim() const {
    00068     return model->getInputDim();
    00069   }
    00070   virtual unsigned int getOutputDim() const {
    00071     return model->getOutputDim();
    00072   }
    00073   virtual void damp(double damping) { model->damp(damping);}
    00074
    00075   /* ************** Accessors **********************************/
    00076
    00077   Inspectable* getModel(){
    00078     return model;
    00079   }
    00080   const Inspectable* getModel() const {
    00081     return model;
    00082   }
    00083
    00084
    00085   /* *************  STOREABLE **********************************/
    00086   /// stores the layer binary into file stream
    00087   bool store(FILE* f) const { return model->store(f);}
    00088   /// restores the layer binary from file stream
    00089   bool restore(FILE* f){ return model->restore(f);}
    00090
    00091   /* ************* Inspectable **********************************/
    00092   virtual iparamkeylist getInternalParamNames() const { return model->getInternalParamNames();}
    00093   virtual iparamvallist getInternalParams() const { return model->getInternalParams();}
    00094   virtual ilayerlist getStructuralLayers() const { return model->getStructuralLayers();}
    00095   virtual iconnectionlist getStructuralConnections() const {
    00096     return model->getStructuralConnections();
    00097   }
    00098
    00099
    00100 protected:
    00101   // Pattern
    00102   struct Pat{
    00103     Pat(){}
    00104     Pat(const matrix::Matrix& inp, const matrix::Matrix& out, const double& lrFactor):
    00105       inp(inp), out(out), lrFactor(lrFactor){}
    00106     matrix::Matrix inp;
    00107     matrix::Matrix out;
    00108     double lrFactor;
    00109   };
    00110
    00111   InvertableModel* model;
    00112   int memorySize;
    00113   int numPatternsPerStep;
    00114   /// vector of input output mappings
    00115   std::vector <Pat> memory;
    00116   RandGen* randGen;
    00117 };
    00118
    00119 #endif