00001 /* PerceptronNetwork.h 00002 * 00003 * Copyright (C) 2002-2003 -- Sebastian Nowozin 00004 */ 00005 00006 #ifndef PERCEPTRONNETWORK_H 00007 #define PERCEPTRONNETWORK_H 00008 00009 #include <vector> 00010 #include <fstream> 00011 00012 #include <neuralnet/ActivationFunction.h> 00013 #include <neuralnet/RandomFunction.h> 00014 #include <neuralnet/PerceptronLayer.h> 00015 00019 class 00020 PerceptronNetwork { 00024 friend class WeightMatrix; 00025 00026 public: 00030 const char * name; 00031 00036 vector<double> input; 00037 00042 vector<double> output; 00043 00064 PerceptronNetwork (vector<unsigned int> desc_layers, 00065 const char *network_name = "unnamed", 00066 const ActivationFunction *fact = 00067 &ActivationFunctions::fact_tanh); 00068 00069 /* Default constructor. (To be used with the load method). 00070 */ 00071 PerceptronNetwork (void); 00072 00077 ~PerceptronNetwork (void); 00078 00083 PerceptronNetwork (PerceptronNetwork& source); 00084 00091 void setActivationFunction (PerceptronLayerType type, 00092 const ActivationFunction *fact); 00093 00094 /* LOAD/SAVE methods */ 00099 void save (fstream& fs) const; 00100 00107 bool load (fstream& fs); 00108 00109 /* NETWORK operation methods */ 00110 00117 void randomizeParameters (const RandomFunction *weight_func, 00118 const RandomFunction *theta_func); 00119 00125 void setInput (vector<double>& in); 00126 00134 void setOptimalOutput (vector<double>& optimal); 00135 00138 vector<double> getOutput (void) const; 00139 00148 double errorTerm (void) const; 00149 00154 void resetDiffs (void); 00155 00156 /* ALGORITHMS */ 00157 00164 void propagate (void); 00165 00172 void backpropagate (void); 00173 00176 void postprocess (void); 00177 00180 void update (void); 00181 00182 /* DEBUG facilities */ 00188 void dumpNetworkGraph (const char *filename) const; 00189 00192 double getLearningParameter (void) const; 00193 00198 void setLearningParameter (double epsilon); 00199 00202 double getOptimalTolerance (void) const; 00203 00208 void setOptimalTolerance (double tolerance); 00209 00212 double getWeightDecayParameter (void) const; 00213 00218 void setWeightDecayParameter (double factor); 00219 00222 double getMomentumTermParameter (void) const; 00223 00228 void setMomentumTermParameter (double factor); 00229 00230 protected: 00234 vector<double> output_optimal; 00235 00241 vector<PerceptronLayer *> layers; 00242 00245 double epsilon; 00246 00249 double opt_tolerance; 00250 00253 double weight_decay; 00254 00257 double momentum_term; 00258 }; 00259 00260 #endif 00261