Neuron: neural networks


kohonen.h
Go to the documentation of this file.
1
2
3#ifndef _KOHONEN_HH_
4#define _KOHONEN_HH_
5
6
7#include <vector>
8#include <iostream>
9
10
11class Kohonen;
12
13
16
17std::ostream & operator << ( std::ostream & fich, const Kohonen & koh );
19std::istream & operator >> ( std::istream & fich, Kohonen & koh );
21
22
23
26{
27 public:
29 VectCode() { cla = 0; }
31 std::vector<double> coord;
33 std::vector<double> vect;
35 int cla;
36};
37
38
42{
45
46 friend std::ostream & operator << ( std::ostream &, const Kohonen & );
48 friend std::istream & operator >> ( std::istream &, Kohonen & );
50
51 public:
54
57 std::vector<double> UserData;
59
62
63 Kohonen( int ndim=1, int ncdim=2 );
65 Kohonen( const Kohonen & koh );
67 virtual ~Kohonen();
69
72
73 Kohonen & operator = ( const Kohonen & koh );
75
78
79 int WinIndex() const { return( _winIndex ); }
81 double SqDistWinner() const { return( _sqDistWinner ); }
83 int NDim() const { return( _nDim ); }
85 int NCDim() const { return( _nCDim ); }
87 int NVCode() const { return( _vCode.size() ); }
89 VectCode* VCode( unsigned i ) const { return( _vCode[i] ); }
91 VectCode VCWinner() const { return( *_vCWinner ); }
93 double LearnRay() const { return( _learnRay ); }
95 void SetLearnRay( double lr ) { _learnRay = lr; }
97 double LearnFactor() const { return( _learnFactor ); }
99 void SetLearnFactor( double lf ) { _learnFactor = lf; }
101 double DensityRay() const { return( _densityRay ); }
103 void SetDensityRay( double dr ) { _densityRay = dr; }
105 void ChangeDims( unsigned ndim, unsigned ncdim );
107
110
111 void CopyVC( const std::vector<VectCode*> &vcl );
115 int RemoveVectCode( const VectCode *vc );
119 void Empty();
124 void CreateUniformVC( unsigned nvd, double cmin=-1., double cmax=1. );
126 void CreateUniformVCFromComp( unsigned c, double *comp, unsigned nvd,
127 double cmin, double cmax );
129 void RandVC( double cmin=-1., double cmax=1. );
131
134
135 static void PrintVC( const VectCode *vc );
137 static void PrintVect( const std::vector<double> *vect );
139 static double SqVectDist( const std::vector<double> *v1,
140 const std::vector<double> *v2 );
142
145
146 int Save( const char *nom ) const;
148 int Load( const char *nom );
150 int ByteSize() const;
152
155
156 VectCode *FindWinner( const std::vector<double> *vec );
157 //VectCode *FindWinner( void *toto );
159 int Learn( const std::vector<double> *vect );
161 void PrintMap() const;
163 double MapDist( int i1, int i2 ) const;
165 double MapDist( const VectCode *vc1, const VectCode *vc2 ) const;
167 double DistFact( double d ) const;
169 int Density( const std::vector<double> *vect ) const;
171
172
173 protected:
175 unsigned _nDim;
177 unsigned _nCDim;
179 std::vector<VectCode*> _vCode;
183 unsigned _winIndex;
187 double _learnRay;
192
193
194 private:
195
196};
197
198
199#endif
Classe Kohonen.
Definition kohonen.h:42
unsigned _nDim
Nombre de dimensions de la carte (1 ou 2 normalement)
Definition kohonen.h:175
void CreateUniformVCFromComp(unsigned c, double *comp, unsigned nvd, double cmin, double cmax)
Ajoute uniformément des VC sur les composantes à partir de la c-ème.
int DelVectCode(VectCode *vc)
double SqDistWinner() const
Carré de la distance au vecteur-code gagnant.
Definition kohonen.h:81
void SetLearnFactor(double lf)
Definition kohonen.h:99
double MapDist(const VectCode *vc1, const VectCode *vc2) const
virtual ~Kohonen()
int WinIndex() const
Indice du vecteur-code élu.
Definition kohonen.h:79
void PrintMap() const
static void PrintVC(const VectCode *vc)
static double SqVectDist(const std::vector< double > *v1, const std::vector< double > *v2)
double MapDist(int i1, int i2) const
int AddVectCode(VectCode *vc)
int NCDim() const
Nombre de dimensions des vecteurs-code.
Definition kohonen.h:85
double _learnRay
Rayon d'apprentisasge.
Definition kohonen.h:187
int Save(const char *nom) const
double DensityRay() const
Rayon de recherche pour un comptage de densité.
Definition kohonen.h:101
friend std::ostream & operator<<(std::ostream &, const Kohonen &)
VectCode * FindWinner(const std::vector< double > *vec)
double LearnFactor() const
Facteur d'apprentissage.
Definition kohonen.h:97
unsigned _nCDim
Nombre de dimensions des vecteurs-code.
Definition kohonen.h:177
void CreateUniformVC(unsigned nvd, double cmin=-1., double cmax=1.)
Crée des vecteurs-code uniformément répartis.
double LearnRay() const
Rayon d'apprentisasge.
Definition kohonen.h:93
int NVCode() const
Nombre de vecteurs-code.
Definition kohonen.h:87
void Empty()
void SetDensityRay(double dr)
Definition kohonen.h:103
int ByteSize() const
void ChangeDims(unsigned ndim, unsigned ncdim)
int Density(const std::vector< double > *vect) const
double _sqDistWinner
Distance au vecteur-code élu.
Definition kohonen.h:185
double _learnFactor
Facteur d'apprentissage.
Definition kohonen.h:189
Kohonen(const Kohonen &koh)
double DistFact(double d) const
friend std::istream & operator>>(std::istream &, Kohonen &)
int RemoveVectCode(const VectCode *vc)
int Load(const char *nom)
std::vector< double > UserData
Données utilisateur.
Definition kohonen.h:57
void SetLearnRay(double lr)
Definition kohonen.h:95
double _densityRay
Rayon de recherche pour un comptage de densité.
Definition kohonen.h:191
Kohonen(int ndim=1, int ncdim=2)
VectCode VCWinner() const
Vecteur-code élu.
Definition kohonen.h:91
std::vector< VectCode * > _vCode
Vecteurs-code.
Definition kohonen.h:179
void CopyVC(const std::vector< VectCode * > &vcl)
Recopie tous les vecteurs-code à partir de vcl.
unsigned _winIndex
Index du vecteur-code élu.
Definition kohonen.h:183
int NDim() const
Nombre de dimensions de la carte (1 ou 2 normalement)
Definition kohonen.h:83
int Learn(const std::vector< double > *vect)
VectCode * _vCWinner
Vecteur-code élu.
Definition kohonen.h:181
VectCode * VCode(unsigned i) const
Vecteur code numéro i.
Definition kohonen.h:89
Kohonen & operator=(const Kohonen &koh)
static void PrintVect(const std::vector< double > *vect)
void RandVC(double cmin=-1., double cmax=1.)
type Vecteur-code
Definition kohonen.h:26
std::vector< double > coord
Coordonnées dans la carte.
Definition kohonen.h:31
int cla
Classe représentée par ce vecteur.
Definition kohonen.h:35
VectCode()
Constructeur.
Definition kohonen.h:29
std::vector< double > vect
Vecteur lui-même.
Definition kohonen.h:33
std::ostream & operator<<(std::ostream &fich, const Kohonen &koh)
std::istream & operator>>(std::istream &fich, Kohonen &koh)