onelayerffnn.h

Go to the documentation of this file.
00001 #ifndef __ONELAYERFFNN_H 00002 #define __ONELAYERFFNN_H 00003 00004 #include "feedforwardnn.h" 00005 00006 /// simple one layer neural network with configurable activation function 00007 class OneLayerFFNN : public FeedForwardNN { 00008 public: 00009 /** 00010 Uses linear activation function 00011 @param eps learning rate 00012 @param factor_bias learning rate factor for bias learning 00013 */ 00014 OneLayerFFNN(double eps, 00015 double factor_bias = 0.1) 00016 : eps(eps), factor_bias(factor_bias){ 00017 actfun = linear; 00018 dactfun = dlinear; 00019 00020 initialised = false; 00021 } 00022 /** 00023 @param eps learning rate 00024 @param factor_bias learning rate factor for bias learning 00025 @param actfun callback activation function (see FeedForwardNN) 00026 @param dactfun callback for first derivative of the activation function 00027 */ 00028 OneLayerFFNN(double eps, 00029 double factor_bias, 00030 ActivationFunction actfun, 00031 ActivationFunction dactfun) 00032 : eps(eps), factor_bias(factor_bias), actfun(actfun), dactfun(dactfun) { 00033 initialised = false; 00034 } 00035 virtual ~OneLayerFFNN(){ } 00036 00037 /// initialisation of the network with the given number of input and output units 00038 virtual void init(unsigned int inputDim, unsigned int outputDim, double unit_map = 0.0); 00039 00040 /// passive processing of the input 00041 virtual const matrix::Matrix process (const matrix::Matrix& input); 00042 00043 /// performs learning and returns the network output before learning 00044 virtual const matrix::Matrix learn (const matrix::Matrix& input, 00045 const matrix::Matrix& nom_output, 00046 double learnRateFactor = 1); 00047 00048 /// returns the number of input neurons 00049 virtual unsigned int getInputDim() const { 00050 return weights.getN(); 00051 } 00052 /// returns the number of output neurons 00053 virtual unsigned int getOutputDim() const { 00054 return weights.getM(); 00055 } 00056 00057 virtual const matrix::Matrix& getWeights() const { return weights; } 00058 virtual const matrix::Matrix& getBias() const { return bias; } 00059 00060 /// damps the weights and the biases by multiplying (1-damping) 00061 virtual void damp(double damping){ 00062 weights *= (1-damping); 00063 bias *= (1-damping); 00064 } 00065 00066 /************** STOREABLE **********************************/ 00067 /// stores the layer binary into file stream 00068 bool store(FILE* f) const; 00069 /// restores the layer binary from file stream 00070 bool restore(FILE* f); 00071 00072 /************** CONFIGURABLE INTERFACE ************************/ 00073 virtual paramkey getName() const { 00074 return paramkey("onelayerffnn"); 00075 } 00076 00077 virtual paramval getParam(const paramkey key) const { 00078 if(key == "eps") return eps; 00079 else return 0.0; 00080 } 00081 00082 virtual bool setParam(const paramkey key, paramval val){ 00083 if( key == "eps") { 00084 eps = val; 00085 return true; 00086 } else return false; 00087 } 00088 00089 virtual paramlist getParamList() const{ 00090 paramlist l; 00091 l.push_back(std::pair<paramkey, paramval> ("eps", eps)); 00092 return l; 00093 } 00094 00095 00096 private: 00097 double eps; 00098 double factor_bias; 00099 ActivationFunction actfun; ///< callback activation function 00100 ActivationFunction dactfun; ///< first derivative of the activation function 00101 00102 private: 00103 bool initialised; 00104 matrix::Matrix weights; 00105 matrix::Matrix bias; 00106 }; 00107 00108 #endif

Generated on Tue Jan 16 02:14:37 2007 for Robotsystem of the Robot Group Leipzig by doxygen 1.3.8