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

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

- Search for |

- File List
- File Members

# regularisation.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  *  This file contains activation function and there derivatives in        *
    00026  *  different regularised versions                                         *
    00027  *                                                                         *
    00028  *                                                                         *
    00029  *   $Log: regularisation.h,v $
    00030  *   Revision 1.8  2008/05/02 17:20:04  martius
    00031  *   *** empty log message ***
    00032  *
    00033  *   Revision 1.7  2008/02/05 10:08:47  der
    00034  *   new function g_derivative
    00035  *
    00036  *   Revision 1.6  2008/01/29 09:38:02  der
    00037  *   function g_s changed
    00038  *
    00039  *   Revision 1.5  2007/04/03 16:37:57  der
    00040  *   *** empty log message ***
    00041  *
    00042  *   Revision 1.4  2007/02/23 09:25:52  der
    00043  *   regularisation with taylor expansion
    00044  *
    00045  *   Revision 1.3  2006/11/29 16:22:43  martius
    00046  *   name is a variable of configurable and is used as such
    00047  *
    00048  *   Revision 1.2  2006/10/23 10:47:59  martius
    00049  *   g and derivatives and inverses
    00050  *
    00051  *   Revision 1.1  2006/10/20 15:22:15  martius
    00052  *   regularisation terms for g
    00053  *
    00054  *   Revision 1.2  2006/07/14 12:23:56  martius
    00055  *   selforg becomes HEAD
    00056  *
    00057  *   Revision 1.1.2.1  2005/12/06 17:38:21  martius
    00058  *   *** empty log message ***
    00059  *
    00060  *                                                                 *
    00061  ***************************************************************************/
    00062 #ifndef __REGULARISATION_H
    00063 #define __REGULARISATION_H
    00064
    00065 double inline sqr(double x) {
    00066   return x*x;
    00067 }
    00068
    00069 /// neuron transfer function
    00070 double inline g(double z)
    00071 {
    00072   return tanh(z);
    00073 };
    00074
    00075 /// first dervative
    00076 double inline g_s(double z)
    00077 {
    00078   //double k=tanh(z);
    00079   // return 1.025 - k*k;
    00080    return 1/((1+0.5 * z*z)*(1+0.5 * z*z));    // softer
    00081   //return 1/(1+log(1+z*z)); // even softer
    00082 };
    00083
    00084
    00085 /// first dervative with smoothing for large z
    00086 double inline g_derivative(double z)
    00087 {
    00088
    00089    return 1/((1+0.5 * z*z)*(1+0.5 * z*z));
    00090 };
    00091
    00092 /// inverse of the first derivative
    00093 double inline g_s_inv(double z)
    00094 {
    00095   double k=tanh(z);
    00096    return 1/(1.025 - k*k);
    00097   // return 1+z*z; // softer
    00098   //return 1+log(1+z*z); // even softer
    00099 };
    00100
    00101 /** \f[ g'(z+xsi) = 1-(tanh(z+xsi))^2 \f] with additional clipping */
    00102 double inline g_s(double z, double xsi) {
    00103   double Z = clip(z, -3.0, 3.0) + clip(xsi, -1.0, 1.0);
    00104   // double k=tanh(Z);  // approximation with Mittelwertsatz
    00105   // return 1 - k*k;
    00106   return 1/(1 + Z*Z);//TEST
    00107 };
    00108
    00109
    00110 /// an exact formula for g''/g', with clipped Z = z+xsi
    00111 double inline g_ss_div_s(double z, double xsi) {
    00112   // for consistency reasons we use the same clipped z as for g'.
    00113   double Z = clip(z, -3.0, 3.0) + clip(xsi, -1.0, 1.0);
    00114   // approximation with Mittelwertsatz (z is clipped)
    00115   //  return -2*g(Z);
    00116   return -2*Z;//TEST
    00117 };
    00118
    00119 /** with \f[ g'(z) = 1-(g(z+\xi))^2 \f] we get
    00120     \f[\frac{\partial}{\partial z} \frac{1}{g'(Z)} = \frac{g''}{g'^2} \f]
    00121     again with clipped Z
    00122  */
    00123 double inline derive_g_s_inv_exact_clip(double z, double xsi){
    00124   double Z = clip(z, -3.0, 3.0) + clip(xsi, -1.0, 1.0);
    00125   double k=tanh(Z);  // approximation with Mittelwertsatz
    00126   return -2*k/(1-k*k);
    00127 }
    00128
    00129 /** \f[ g'(z) = 1-(z+\xi)^2 \f] which is the series expansion to the second order
    00130 */
    00131 double inline g_s_expand2(double z, double xsi){
    00132   double Z = z + clip(xsi, -fabs(z), fabs(z));
    00133   return 1/(1+sqr(Z));
    00134 }
    00135
    00136 /** \f[ \frac{1}{g'(z)} \approx 1+(z+\xi)^2 \f] with geometric series approximation
    00137 */
    00138 double inline g_s_inv_expand2(double z, double xsi){
    00139   double Z = z + clip(xsi, -fabs(z)/2.0, fabs(z)/2.0);
    00140   return 1+sqr(Z);
    00141 }
    00142
    00143 /** \f[ \frac{g''(z)}{g'(z)} \approx 2(z+\xi)(1+(z+\xi)^2) \f] with geometric series approximation
    00144 */
    00145 double inline g_ss_div_s_expand2(double z, double xsi){
    00146   double Z = z + clip(xsi, -fabs(z)/2.0, fabs(z)/2.0);
    00147   //  double Z = z + clip(xsi, -fabs(z), fabs(z));
    00148   return -2*tanh(Z);
    00149 }
    00150
    00151
    00152   /// squashing function (-0.1 to 0.1), to protect against to large weight updates
    00153 double inline squash(double z)
    00154   {
    00155     return clip(z, -0.1, 0.1);
    00156     //return 0.1 * tanh(10.0 * z);
    00157   };
    00158
    00159   /// squashing function with adjustable clipping size, to protect against too large weight updates
    00160 double inline squash(void* d, double z) {
    00161     double size = *((double*)d);
    00162     return clip(z, -size, size);
    00163   };
    00164
    00165
    00166
    00167 #endif
    00168