Robotsystem of the Robot Group Leipzig: ffnncontroller.h Source File

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

- Search for |

- File List
- File Members

# ffnncontroller.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  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00008  *   LICENSE:                                                              *
    00009  *   This work is licensed under the Creative Commons                      *
    00010  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00011  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00012  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00013  *   San Francisco, California, 94105, USA.                                *
    00014  *                                                                         *
    00015  *   This program is distributed in the hope that it will be useful,       *
    00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00018  *                                                                         *
    00019  *   $Log: ffnncontroller.h,v $
    00020  *   Revision 1.5  2008/05/30 11:58:27  martius
    00021  *   use cmath instead of math.h
    00022  *
    00023  *   Revision 1.4  2008/04/17 14:54:44  martius
    00024  *   randomGen added, which is a random generator with long period and an
    00025  *    internal state. Each Agent has an instance and passed it to the controller
    00026  *    and the wiring. This is good for
    00027  *   a) repeatability on agent basis,
    00028  *   b) parallel execution as done in ode_robots
    00029  *
    00030  *   Revision 1.3  2007/06/14 13:57:08  martius
    00031  *   initial waiting time (no control before that)
    00032  *
    00033  *   Revision 1.2  2007/06/08 15:46:54  martius
    00034  *   support different static networks (e.g. satellite nets)
    00035  *
    00036  *   Revision 1.1  2006/11/29 16:21:35  martius
    00037  *   controller that uses a fixed feed forward neural network with some history
    00038  *
    00039  *
    00040  ***************************************************************************/
    00041 #ifndef __FFNNCONTROLLER_H
    00042 #define __FFNNCONTROLLER_H
    00043
    00044 #include "abstractcontroller.h"
    00045 #include <assert.h>
    00046 #include <cmath>
    00047
    00048 #include <selforg/matrix.h>
    00049 #include <selforg/multilayerffnn.h>
    00050
    00051 /**
    00052  * class for robot controller that uses the georg's matrixlib for
    00053  *  direct robnot control with a given neural feedforward network
    00054  */
    00055 class FFNNController : public AbstractController {
    00056
    00057 public:
    00058   /** networkfilename is the file to load the network from,
    00059       and history is the number of time steps the network gets input from (in sense of dimension of input)
    00060       \param input_only_x if true then the input vector is \f[ (x_{t},x_{t-1},...,x_{t-history})^T \f]
    00061       if false then also the y values are used: \f[ (x_{t}, y_{t-1}, x_{t-1},y_{t-2},...,x_{t-history})^T \f]
    00062   */
    00063   FFNNController(const std::string& networkfilename, int history, bool input_only_x, unsigned int init_wait=0);
    00064
    00065   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00066
    00067   virtual ~FFNNController();
    00068
    00069   /// returns the number of sensors the controller was initialised with or 0 if not initialised
    00070   virtual int getSensorNumber() const { return number_sensors; }
    00071   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
    00072   virtual int getMotorNumber() const  { return number_motors; }
    00073
    00074   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
    00075   virtual void stepNoLearning(const sensor* , int number_sensors,
    00076                               motor* , int number_motors);
    00077
    00078   /**** STOREABLE ****/
    00079   /** stores the controller values to a given file (binary).  */
    00080   virtual bool store(FILE* f) const;
    00081   /** loads the controller values from a given file (binary). */
    00082   virtual bool restore(FILE* f);
    00083
    00084   // inspectable interface
    00085   virtual std::list<iparamkey> getInternalParamNames()const  { return std::list<iparamkey>(); }
    00086   virtual std::list<iparamval> getInternalParams() const { return std::list<iparamval>(); }
    00087
    00088   // configureable interface
    00089   virtual paramval getParam(const paramkey& key) const;
    00090   virtual bool setParam(const paramkey& key, paramval val);
    00091   virtual paramlist getParamList() const ;
    00092
    00093 protected:
    00094   void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay = 0);
    00095
    00096   matrix::Matrix calculateSmoothValues(const matrix::Matrix* buffer, int number_steps_for_averaging_) const;
    00097
    00098   virtual matrix::Matrix assembleNetworkInputXY(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
    00099
    00100   virtual matrix::Matrix assembleNetworkInputX(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
    00101
    00102   virtual matrix::Matrix assembleNetworkOutput(const matrix::Matrix& output) const;
    00103
    00104
    00105 protected:
    00106   unsigned short number_motors;
    00107   unsigned short number_sensors;
    00108   unsigned short history;
    00109   unsigned short buffersize;
    00110   bool input_only_x;
    00111   unsigned short s4avg;
    00112   unsigned int t;
    00113   unsigned int init_wait;
    00114
    00115   matrix::Matrix* x_buffer;
    00116   matrix::Matrix* y_buffer;
    00117   matrix::Matrix x_smooth;
    00118
    00119   MultiLayerFFNN* net;
    00120   bool initialised;
    00121
    00122 };
    00123
    00124 #endif