00001 # ifndef NETWORK_H
00002 # define NETWORK_H
00003
00004 # include <layer.h>
00005 # include <axon.h>
00006 # include <qstring.h>
00007 # include <qmessagebox.h>
00008 # include <qfile.h>
00009 # include <qtextstream.h>
00010 # include <iostream>
00011 # include <list>
00012 # include <vector>
00013
00014 # define SEQUENTIAL 1
00015 # define RANDOM_WITH 2
00016 # define RANDOM_WITHOUT 3
00017
00018 using namespace std;
00019
00020 class Network {
00021 private:
00022 Layer *input;
00023 Layer *output;
00024 list<Layer*> *hidden;
00025 list<Axon*> *axons;
00026 int nextFreeId;
00027 vector<int> hiddenLayersId ;
00028 float vstep ;
00029 float neursize ;
00030 float axsize ;
00031 int shiny ;
00032 bool displayneurons_ ;
00033 bool displayaxons_ ;
00034 bool displaylayers_ ;
00035 bool displayvalues_ ;
00036 float k ;
00037 vector<double> *errorEvolution;
00038 int currentEpoch;
00039 double currentAverageError;
00040 int EPS;
00041 int exampleOrder;
00042
00043 public:
00044 Network();
00045
00049 int getnextfreeid(void) { return nextFreeId ; }
00050 void setnextfreeid(int id) { nextFreeId = id ; }
00051 Layer* getInputLayer( void ) ;
00052 Layer* getOutputLayer( void ) ;
00053 list<Layer*>* getHiddenLayers( void ) ;
00054 list<Axon*>* getAxons( void ) ;
00055 int getNbNeurons( int id_layer ) ;
00056 int getHiddenLayerId(int i) ;
00057 int getHiddenLayerPos( int id ) ;
00058 Layer* getLayer(int id_l) ;
00059 Neuron* getNeuronFromId(int id_neur);
00060 int getLayerNumTheNeuronIsOn( int id_neur ) ;
00061 int getLayerNumFromLayerId( int id_layer ) ;
00062 float getK();
00063 void setK(float _k);
00064 int getEPS();
00065 void setEPS(int e);
00066 int getCurrentEpoch();
00067 double getCurrentAverageError();
00068 vector<double>* getErrorEvolution();
00069
00073 int shininess( void ) ;
00074 float neuronsize( void ) ;
00075 float axonsize( void ) ;
00076 float getVStep( void ) ;
00077 bool displayaxons( void ) ;
00078 bool displayneurons( void ) ;
00079 bool displaylayers( void ) ;
00080 bool displayvalues( void ) ;
00081 void setDisplayAxons( bool display ) ;
00082 void setDisplayNeurons( bool display ) ;
00083 void setDisplayLayers( bool display ) ;
00084 void setDisplayValues( bool display ) ;
00085 ManipulatedFrame * frame( int id ) ;
00086 void setShininess( int shiny ) ;
00087 void draw( int selected, const bool names = false ) ;
00088
00092 int nbHiddenLayers();
00093 int nbLayers();
00094 void addHiddenLayer();
00095 void addHiddenLayer(int id);
00096 void addNHiddenLayers( int n ) ;
00097 void removeHiddenLayer(int id_layer);
00098 void clearLayer(int id_layer);
00099 void clearHiddenLayers();
00100 bool existLayer(int id_layer);
00101
00105 void addNeuron(int id_layer);
00106 void addNeuron(int id_layer, int id, float x, float z);
00107 void addNNeurons(int id_layer, int n);
00108 void removeNeuron(int id_neur);
00109 int nbNeurons( void );
00110 bool existNeuron(int id_neur);
00111
00115 int nbAxons( void ) ;
00116 void addAxon(int id_neur1, int id_neur2);
00117 void addAxon(int id, int id_neur1, int id_neur2);
00118 void addAxon(int id, int id_neur1, int id_neur2, double weight);
00119 void removeAxon(int id_ax, bool b);
00120 void removeAxons();
00121 bool existAxon(int id_ax);
00122 bool existAxon(int id_neur_in, int id_neur_out);
00123
00127 void resetAllValues();
00128 void resetTempValues();
00129 void initLayerIn(vector<double> in);
00130 void forwardPropagation();
00131 vector<double>* getOutValues();
00132 vector<double>* computeOut(vector<double> *in);
00133 double computeErrorRate(vector<double> *errors);
00134 vector<double>* computeErrors(vector<double> *computed, vector<double> *expected);
00135 void initLayerOutGradient(vector<double> *errors);
00136 void gradientBackPropagation(vector<double> *errors);
00137 void changeAxonsWeight(double convergenceCoeff);
00138 double learnExample(vector<double> *exampleIn, vector<double> *exampleOut, double convergenceCoeff);
00139 double computeAverage(vector<double> v);
00140 list< vector<double> >* readExampleFile(QTextStream *file, QString mode);
00141 vector<double> readTestFile(QTextStream *file);
00142 void link2Layers(Layer *first, Layer *second);
00143 void constructTopologyMLP();
00144 void constructTopologyCC();
00145 void clearErrorEvolution();
00146 void setExampleOrder(int o);
00147 void learning(QString file, double errorThreshold, int maxNbEpoch, double convergenceCoeff);
00148
00152 list< vector<double> >* copyVectorList(list< vector<double> > *vl);
00153 void description();
00154 };
00155
00156 # endif