Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
feedforwardnn.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 #ifndef __FEEDFORWARDNN_H
25 #define __FEEDFORWARDNN_H
26 
27 #include "invertablemodel.h"
28 #include "controller_misc.h"
29 #include "regularisation.h"
30 
31 #include <cmath>
32 
33 /// activation function type: input: membrane potential
34 typedef double (*ActivationFunction) (double);
35 /** inverse of Activation function with respect to some membrane potential
36  and a certain output error.
37  */
38 typedef double (*InvActivationFunction) (double, double);
39 
40 /// abstract class (interface) for feed forward rate based neural networks
42  public:
43  // 20110317, guettler: disabled default constructor since it is not needed and would cause difficulties
44  //FeedForwardNN() {}
45  FeedForwardNN(const std::string& name, const std::string& revision)
46  : InvertableModel(name, revision){};
47  virtual ~FeedForwardNN(){};
48 
49  /// damps the weights and the biases by multiplying (1-damping)
50  virtual void damp(double damping) =0 ;
51 
52  /******** Activation functions and there derivative
53  and inversion with certain output shift (regularised) */
54  static double linear(double z) { return z;}
55  static double dlinear(double ) { return 1;}
56  static double invlinear(double z, double xsi) { return xsi;}
57 
58  static double tanh(double z) { return ::tanh(z); }
59  static double dtanh(double z) { double k = ::tanh(z); return 1-k*k; }
60  static double invtanh(double z, double xsi) { return g_s_expand2(z,xsi)*xsi; }
61 
62  // clipped tanh
63  static double tanhc(double z) { return ::tanh(z); }
64  static double dtanhc(double z) { double k = ::tanh(clip(z, -3.0, 3.0)); return 1-k*k; }
65 
66  // regularised tanh
67  static double tanhr(double z) { return ::tanh(z); }
68  // static double dtanhr(double z) { double k = tanh(z); return 1.01-k*k; }
69  static double dtanhr(double z) { return 1.0/(1.0+z*z); }
70 
71 
72  static double sigmoid(double z) { return 1/(1+exp(-z)); }
73  static double dsigmoid(double z) { double k = sigmoid(clip(z, -3.0, 3.0)); return k*(1-k); }
74  static double invsigmoid(double z, double xsi) { return 1/(0.01+dsigmoid(z))*xsi;}
75 };
76 
77 
78 #endif
static double tanhr(double z)
Definition: feedforwardnn.h:67
abstract class (interface) for invertable models.
Definition: invertablemodel.h:33
virtual void damp(double damping)=0
damps the weights and the biases by multiplying (1-damping)
double g_s_expand2(double z, double xsi)
which is the series expansion to the second order
Definition: regularisation.h:107
double(* InvActivationFunction)(double, double)
inverse of Activation function with respect to some membrane potential and a certain output error...
Definition: feedforwardnn.h:38
static double dsigmoid(double z)
Definition: feedforwardnn.h:73
static double invtanh(double z, double xsi)
Definition: feedforwardnn.h:60
static double dtanhc(double z)
Definition: feedforwardnn.h:64
FeedForwardNN(const std::string &name, const std::string &revision)
Definition: feedforwardnn.h:45
double clip(double r, double x)
clipping function for mapP
Definition: controller_misc.cpp:39
abstract class (interface) for feed forward rate based neural networks
Definition: feedforwardnn.h:41
static double invsigmoid(double z, double xsi)
Definition: feedforwardnn.h:74
static double dlinear(double)
Definition: feedforwardnn.h:55
static double tanhc(double z)
Definition: feedforwardnn.h:63
double(* ActivationFunction)(double)
activation function type: input: membrane potential
Definition: feedforwardnn.h:34
static double dtanhr(double z)
Definition: feedforwardnn.h:69
static double linear(double z)
Definition: feedforwardnn.h:54
static double dtanh(double z)
Definition: feedforwardnn.h:59
static double tanh(double z)
Definition: feedforwardnn.h:58
static double sigmoid(double z)
Definition: feedforwardnn.h:72
static double invlinear(double z, double xsi)
Definition: feedforwardnn.h:56
virtual ~FeedForwardNN()
Definition: feedforwardnn.h:47