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

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages
- Examples

- Search for |

- File List
- File Members

# elman.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   This program is free software; you can redistribute it and/or modify  *
    00008  *   it under the terms of the GNU General Public License as published by  *
    00009  *   the Free Software Foundation; either version 2 of the License, or     *
    00010  *   (at your option) any later version.                                   *
    00011  *                                                                         *
    00012  *   This program is distributed in the hope that it will be useful,       *
    00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00015  *   GNU General Public License for more details.                          *
    00016  *                                                                         *
    00017  *   You should have received a copy of the GNU General Public License     *
    00018  *   along with this program; if not, write to the                         *
    00019  *   Free Software Foundation, Inc.,                                       *
    00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00021  ***************************************************************************
    00022  *                                                                         *
    00023  *  DESCRIPTION                                                            *
    00024  *                                                                         *
    00025  *   $Log: elman.h,v $
    00026  *   Revision 1.7  2008/04/17 14:54:44  martius
    00027  *   randomGen added, which is a random generator with long period and an
    00028  *    internal state. Each Agent has an instance and passed it to the controller
    00029  *    and the wiring. This is good for
    00030  *   a) repeatability on agent basis,
    00031  *   b) parallel execution as done in ode_robots
    00032  *
    00033  *   Revision 1.6  2007/12/11 14:22:38  martius
    00034  *   splitted update calculation and application
    00035  *
    00036  *   Revision 1.5  2007/12/09 16:25:18  martius
    00037  *   update calculation and weight changes separately
    00038  *
    00039  *   Revision 1.4  2007/02/20 15:41:06  martius
    00040  *   big model stuff, elman and co
    00041  *
    00042  *   Revision 1.3  2007/02/15 10:02:20  martius
    00043  *   elman and jordan context layers
    00044  *
    00045  *   Revision 1.2  2006/11/29 16:22:43  martius
    00046  *   name is a variable of configurable and is used as such
    00047  *
    00048  *   Revision 1.1  2006/07/27 15:22:31  martius
    00049  *   activations stored (processing must preceed learning and reponse calculation)
    00050  *
    00051  *
    00052  *                                                                 *
    00053  ***************************************************************************/
    00054 #ifndef __ELMAN_H
    00055 #define __ELMAN_H
    00056
    00057 #include <vector>
    00058
    00059 #include "multilayerffnn.h"
    00060
    00061 /// updates for network
    00062 class NetUpdate {
    00063 public:
    00064   NetUpdate(){}
    00065   NetUpdate(int numweights, int numbias, int numothers)
    00066     : weights(numweights), bias(numweights), other(numothers) {}
    00067   std::vector<matrix::Matrix> weights;
    00068   std::vector<matrix::Matrix> bias;
    00069   std::vector<matrix::Matrix> other;
    00070 };
    00071
    00072 /** Multilayer Neural Network with context neurons (after Elman and Jordan)
    00073 Example of 2 hidden layer network with both, elman and jordan context units.
    00074 \pre{
    00075 +--<-----O O O
    00076 |        | | |
    00077 |        H H H
    00078 |        | | |
    00079 |        | | |
    00080 |        | | |
    00081 |        H H H ----->-----+ 1:1 fixed connections (time delayed)
    00082 |   >->-/| | |\-<-<       |
    00083 |  / / / | | | \ \ \      |
    00084 | J J J  I I I  E E E     |
    00085 +-^-^-^         ^-^-^--<--+
    00086 }
    00087  */
    00088 class Elman : public MultiLayerFFNN {
    00089 public:
    00090   /**
    00091      @param eps learning rate
    00092      @param layers Layer description (the input layer is not specified (always linear))
    00093      @param lambda self-recurrent feedback strength of context neurons
    00094   */
    00095   Elman(double eps, const std::vector<Layer>& layers,
    00096         bool useElman, bool useJordan=false, bool useBypass=false)
    00097     : MultiLayerFFNN(eps,layers,useBypass), useElman(useElman), useJordan(useJordan) {
    00098
    00099     initialised = false;
    00100   }
    00101
    00102   virtual ~Elman(){ }
    00103
    00104   /// initialisation of the network with the given number of input and output units
    00105   virtual void init(unsigned int inputDim, unsigned  int outputDim,
    00106                     double unit_map = 0.0, RandGen* randGen = 0);
    00107
    00108   /** passive processing of the input
    00109       (this will be different for every input, since it is a recurrent network)
    00110   */
    00111   virtual const matrix::Matrix process (const matrix::Matrix& input);
    00112
    00113   /// performs learning and returns the network output before learning
    00114   virtual const matrix::Matrix learn (const matrix::Matrix& input,
    00115                                       const matrix::Matrix& nom_output,
    00116                                       double learnRateFactor = 1);
    00117
    00118   /** determines the weight and bias updates
    00119    */
    00120   virtual NetUpdate weightIncrement(const matrix::Matrix& xsi);
    00121
    00122   /** like weightIncrement but with blocked backprop flow for some neurons.
    00123       @param blockedlayer index of layer with blocked neurons
    00124       @param blockfrom index of neuron in blockedlayer to start blocking
    00125       @param blockto index of neuron in blockedlayer to end blocking (if -1 then to end)
    00126       (not included)
    00127    */
    00128   virtual NetUpdate weightIncrementBlocked(const matrix::Matrix& xsi_,
    00129                                            int blockedlayer,
    00130                                            int blockfrom, int blockto);
    00131
    00132
    00133   /** applies the weight increments to the weight (and bias) matrices
    00134       with the learningrate and the learnRateFactor */
    00135   virtual void updateWeights(const NetUpdate& updates);
    00136
    00137
    00138   /* Is implemented in multilayerfnn
    00139      virtual const matrix::Matrix response(const matrix::Matrix& input) const;
    00140    */
    00141
    00142   void damp(double damping);
    00143
    00144   /**************  STOREABLE **********************************/
    00145   /// stores the layer binary into file stream
    00146   bool store(FILE* f) const;
    00147   /// restores the layer binary from file stream
    00148   bool restore(FILE* f);
    00149
    00150
    00151   /************** CONFIGURABLE INTERFACE ************************/
    00152   virtual paramkey getName() const {
    00153     return std::string("elmanNN");
    00154   }
    00155
    00156
    00157
    00158   /************** Inspectable INTERFACE ************************/
    00159   virtual iparamkeylist getInternalParamNames() const;
    00160   virtual iparamvallist getInternalParams() const;
    00161   virtual ilayerlist getStructuralLayers() const;
    00162   virtual iconnectionlist getStructuralConnections() const;
    00163
    00164 protected:
    00165   matrix::Matrix elmanWeights;
    00166   matrix::Matrix elmanContext;
    00167   matrix::Matrix jordanWeights;
    00168   matrix::Matrix jordanContext;
    00169   bool useElman;
    00170   bool useJordan;
    00171
    00172 };
    00173
    00174 #endif