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 __NETWORKLAYER_H 00025 #define __NETWORKLAYER_H 00026 00027 #include <vector> 00028 00029 #include "feedforwardnn.h" 00030 00031 class Layer : public Storeable { 00032 public: 00033 /** constructor for Layer. 00034 The derivative and inverse of activation function is derived automatically. 00035 @param size number neurons 00036 @param factor_bias size of bias neuron , if 0 no bias is used 00037 @param actfun activation function. see also FeedForwardNN 00038 */ 00039 Layer(int size, double factor_bias=0.1, 00040 ActivationFunction actfun = FeedForwardNN::linear); 00041 00042 /** obsolete, use the other constructor for Layer. 00043 @param size number neurons 00044 @param factor_bias size of bias neuron , if 0 no bias is used 00045 @param actfun activation function. see also FeedForwardNN 00046 @param dactfun derivative of activation function (should be consistent with actfun) 00047 */ 00048 Layer(int size, double factor_bias, 00049 ActivationFunction actfun, 00050 ActivationFunction dactfun) { 00051 fprintf(stderr, "%s %s\n", "Layer::Layer(): this contructor is obsolete! ", 00052 "Please use the one without dactfun now!\n"); 00053 exit(1); 00054 } 00055 00056 /***STOREABLE ******/ 00057 /// stores the layer binary into file stream 00058 bool store(FILE* f) const; 00059 /// restores the layer binary from file stream 00060 bool restore(FILE* f); 00061 00062 /// sets the activation function of the layer 00063 void setActFun(ActivationFunction actfun); 00064 00065 int size; 00066 double factor_bias; 00067 ActivationFunction actfun; ///< callback activation function 00068 ActivationFunction dactfun; ///< first derivative of the activation function 00069 InvActivationFunction invactfun; ///< inversion of activation function 00070 00071 // prints the Layer data-structure 00072 friend std::ostream& operator<<(std::ostream& , const Layer&); 00073 }; 00074 00075 #endif