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

# feedforwardnn.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 __FEEDFORWARDNN_H
    00025 #define __FEEDFORWARDNN_H
    00026
    00027 #include "invertablemodel.h"
    00028 #include "controller_misc.h"
    00029 #include "regularisation.h"
    00030
    00031 #include <cmath>
    00032
    00033 /// activation function type: input: membrane potential
    00034 typedef double (*ActivationFunction) (double);
    00035 /** inverse of Activation function with respect to some membrane potential
    00036     and a certain output error.
    00037  */
    00038 typedef double (*InvActivationFunction) (double, double);
    00039
    00040 /// abstract class (interface) for feed forward rate based neural networks
    00041 class FeedForwardNN : public InvertableModel {
    00042  public:
    00043   // 20110317, guettler: disabled default constructor since it is not needed and would cause difficulties
    00044   //FeedForwardNN() {}
    00045   FeedForwardNN(const std::string& name, const std::string& revision)
    00046     : InvertableModel(name, revision){};
    00047   virtual ~FeedForwardNN(){};
    00048
    00049   /// damps the weights and the biases by multiplying (1-damping)
    00050   virtual void damp(double damping) =0 ;
    00051
    00052   /******** Activation functions and there derivative
    00053             and inversion with certain output shift (regularised) */
    00054   static double linear(double z)   { return z;}
    00055   static double dlinear(double )   { return 1;}
    00056   static double invlinear(double z, double xsi) { return xsi;}
    00057
    00058   static double tanh(double z)     { return ::tanh(z); }
    00059   static double dtanh(double z)    { double k = ::tanh(z); return 1-k*k; }
    00060   static double invtanh(double z, double xsi) { return g_s_expand2(z,xsi)*xsi; }
    00061
    00062   // clipped tanh
    00063   static double tanhc(double z)     { return ::tanh(z); }
    00064   static double dtanhc(double z) { double k = ::tanh(clip(z, -3.0, 3.0)); return 1-k*k; }
    00065
    00066   // regularised tanh
    00067   static double tanhr(double z)     { return ::tanh(z); }
    00068   // static double dtanhr(double z)    { double k = tanh(z); return 1.01-k*k; }
    00069   static double dtanhr(double z) { return 1.0/(1.0+z*z); }
    00070
    00071
    00072   static double sigmoid(double z)  { return 1/(1+exp(-z)); }
    00073   static double dsigmoid(double z) { double k = sigmoid(clip(z, -3.0, 3.0)); return k*(1-k); }
    00074   static double invsigmoid(double z, double xsi) { return 1/(0.01+dsigmoid(z))*xsi;}
    00075 };
    00076
    00077
    00078 #endif