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

# ffnncontroller.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 by                                            *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00005  *                                                                         *
    00006  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00007  *   LICENSE:                                                              *
    00008  *   This work is licensed under the Creative Commons                      *
    00009  *   Attribution-NonCommercial-ShareAlike 2.5 License. To view a copy of   *
    00010  *   this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ *
    00011  *   or send a letter to Creative Commons, 543 Howard Street, 5th Floor,   *
    00012  *   San Francisco, California, 94105, USA.                                *
    00013  *                                                                         *
    00014  *   This program is distributed in the hope that it will be useful,       *
    00015  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00016  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *
    00017  *                                                                         *
    00018  ***************************************************************************/
    00019 #ifndef __FFNNCONTROLLER_H
    00020 #define __FFNNCONTROLLER_H
    00021
    00022 #include "abstractcontroller.h"
    00023 #include <assert.h>
    00024 #include <cmath>
    00025
    00026 #include <selforg/matrix.h>
    00027 #include <selforg/multilayerffnn.h>
    00028
    00029 /**
    00030  * class for robot controller with a fixed neural network
    00031  */
    00032 class FFNNController : public AbstractController {
    00033
    00034 public:
    00035   /** @param networkfilename file to load the network
    00036       @param history  number of time steps the network gets input (in sense of dimension of input)
    00037       @param input_only_x if true then the input vector is \f[ (x_{t},x_{t-1},...,x_{t-history})^T \f]
    00038        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]
    00039       @param init_wait number of timesteps to wait before controlling
    00040   */
    00041   FFNNController(const std::string& networkfilename, int history, bool input_only_x, unsigned int init_wait=0);
    00042
    00043   /** @param net pointer to network (it must have the right dimensions)
    00044       @param history  number of time steps the network gets input (in sense of dimension of input)
    00045       @param input_only_x if true then the input vector is \f[ (x_{t},x_{t-1},...,x_{t-history})^T \f]
    00046        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]
    00047       @param init_wait number of timesteps to wait before controlling
    00048   */
    00049   FFNNController(MultiLayerFFNN* net, int history, bool input_only_x, unsigned int init_wait=0);
    00050
    00051   virtual void init(int sensornumber, int motornumber, RandGen* randGen = 0);
    00052
    00053   virtual ~FFNNController();
    00054
    00055   /// returns the number of sensors the controller was initialised with or 0 if not initialised
    00056   virtual int getSensorNumber() const { return number_sensors; }
    00057   /// returns the mumber of motors the controller was initialised with or 0 if not initialised
    00058   virtual int getMotorNumber() const  { return number_motors; }
    00059
    00060   virtual void step(const sensor* , int number_sensors, motor* , int number_motors);
    00061   virtual void stepNoLearning(const sensor* , int number_sensors,
    00062                               motor* , int number_motors);
    00063
    00064   /**** CONFIGURABLE ****/
    00065   void notifyOnChange(const paramkey& key);
    00066
    00067   /**** STOREABLE ****/
    00068   /** stores the controller values to a given file (binary).  */
    00069   virtual bool store(FILE* f) const;
    00070   /** loads the controller values from a given file (binary). */
    00071   virtual bool restore(FILE* f);
    00072
    00073   // inspectable interface
    00074   virtual std::list<iparamkey> getInternalParamNames()const  { return std::list<iparamkey>(); }
    00075   virtual std::list<iparamval> getInternalParams() const { return std::list<iparamval>(); }
    00076
    00077 protected:
    00078   void putInBuffer(matrix::Matrix* buffer, const matrix::Matrix& vec, int delay = 0);
    00079
    00080   matrix::Matrix calculateSmoothValues(const matrix::Matrix* buffer, int number_steps_for_averaging_) const;
    00081
    00082   virtual matrix::Matrix assembleNetworkInputXY(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
    00083
    00084   virtual matrix::Matrix assembleNetworkInputX(matrix::Matrix* xbuffer, matrix::Matrix* ybuffer) const;
    00085
    00086   virtual matrix::Matrix assembleNetworkOutput(const matrix::Matrix& output) const;
    00087
    00088
    00089 protected:
    00090   unsigned short number_motors;
    00091   unsigned short number_sensors;
    00092   unsigned short history;
    00093   unsigned short buffersize;
    00094   bool input_only_x;
    00095   int s4avg;
    00096   unsigned int t;
    00097   unsigned int init_wait;
    00098
    00099   matrix::Matrix* x_buffer;
    00100   matrix::Matrix* y_buffer;
    00101   matrix::Matrix x_smooth;
    00102
    00103   MultiLayerFFNN* net;
    00104   bool initialised;
    00105
    00106 };
    00107
    00108 #endif