som.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __SOM_H
00025 #define __SOM_H
00026
00027 #include "abstractmodel.h"
00028 #include "controller_misc.h"
00029
00030 #include <vector>
00031
00032
00033
00034
00035
00036 class SOM : public AbstractModel {
00037 public:
00038 typedef std::list< std::pair<int,double> > Neighbours;
00039 typedef std::vector<std::pair<matrix::Matrix,double> > Neighbourhood;
00040
00041 SOM(const std::string& name="SOM",
00042 const std::string& revision = "$Id$");
00043
00044
00045
00046
00047 SOM(unsigned int dimensions, double sigma, double eps, double rbfsize,
00048 const std::string& name="SOM",
00049 const std::string& revision = "$Id$");
00050 virtual ~SOM(){};
00051
00052
00053
00054
00055
00056
00057
00058 virtual void init(unsigned int inputDim, unsigned int outputDim,
00059 double unit_map = 0.0, RandGen* randGen = 0);
00060
00061 virtual const matrix::Matrix process (const matrix::Matrix& input);
00062
00063
00064
00065
00066
00067
00068 virtual const matrix::Matrix learn (const matrix::Matrix& input,
00069 const matrix::Matrix& nom_output,
00070 double learnRateFactor = 1);
00071
00072 virtual void damp(double damping) { return;}
00073
00074 virtual unsigned int getInputDim() const { return weights[0].getM();}
00075 virtual unsigned int getOutputDim() const { return weights.size();}
00076
00077
00078 virtual bool store(FILE* f) const;
00079 virtual bool restore(FILE* f);
00080
00081 virtual void printWeights(FILE* f) const;
00082
00083 const Neighbourhood& getNeighbourhood(){return neighbourhood;}
00084
00085 protected:
00086
00087
00088 static double activationfunction(void* rdfsize, double d);
00089
00090
00091 static bool validCoord(const matrix::Matrix& m, int size);
00092
00093 static int coordToIndex(const matrix::Matrix& m, int size);
00094
00095 static matrix::Matrix indexToCoord(int index, int size, int dimensions);
00096
00097
00098
00099 void initNeighbourhood(double sigma);
00100
00101
00102
00103 Neighbours getNeighbours(int winner);
00104
00105
00106 public:
00107 double eps;
00108 private:
00109
00110 std::vector<matrix::Matrix> weights;
00111 std::vector<matrix::Matrix> diffvectors;
00112 matrix::Matrix distances;
00113 int dimensions;
00114 double sigma;
00115 double rbfsize;
00116 int size;
00117
00118
00119
00120 Neighbourhood neighbourhood;
00121
00122
00123 bool initialised;
00124 };
00125
00126
00127 #endif