Image Component Library (ICL)
SOM.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLMath/src/ICLMath/SOM.h **
10 ** Module : ICLMath **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Range.h>
35 #include <ICLUtils/SmartPtr.h>
36 #include <vector>
37 
38 namespace icl{
39  namespace math{
40 
42 
71  public:
73 
78 
80  Neuron(){}
82 
86  Neuron(vector_type gridpos,vector_type prototype,unsigned int griddim, unsigned int datadim);
87 
90 
93 
95  unsigned int griddim;
96 
98  unsigned int datadim;
99 
101  void *meta;
102 
104  inline bool isNull() const { return !!gridpos; }
105  };
106 
108 
119  SOM(unsigned int dataDim, const std::vector<unsigned int> &dims,
120  const std::vector<utils::Range<float> > &prototypeBounds,
121  float epsilon=0.1, float sigma=1);
122 
124  ~SOM();
125 
127  void train(const float *input);
128 
130  const Neuron &getWinner(const float *input) const;
131 
133  Neuron &getWinner(const float *input);
134 
136  const std::vector<Neuron> &getNeurons() const;
137 
139  std::vector<Neuron> &getNeurons();
140 
142  const Neuron &getNeuron(const std::vector<int> &dims) const;
143 
145  Neuron &getNeuron(const std::vector<int> &dims);
146 
148  unsigned int getDataDim() const { return m_uiDataDim; }
149 
151  unsigned int getSomDim() const { return m_uiSomDim; }
152 
154  const std::vector<unsigned int> getDimensions() const { return m_vecDimensions; }
155 
157  void setEpsilon(float epsilon);
158 
160  void setSigma(float sigma);
161 
162  protected:
163 
165  unsigned int m_uiDataDim;
166 
168  unsigned int m_uiSomDim;
169 
171  std::vector<unsigned int> m_vecDimensions;
172 
174  std::vector<utils::Range<float> > m_vecPrototypeBounds;
175 
177  std::vector<Neuron> m_vecNeurons;
178 
180  std::vector<unsigned int> m_vecDimOffsets;
181 
183  float m_fEpsilon;
184 
186  float m_fSigma;
187  };
188 
189 
190  } // namespace math
191 }
192 
193 
float m_fEpsilon
learning rate
Definition: SOM.h:183
undocument this line if you encounter any issues!
Definition: Any.h:37
#define ICLMath_API
Definition: CompatMacros.h:173
unsigned int getSomDim() const
returns the SOM dimension (e.g. 2D, 3D ..)
Definition: SOM.h:151
std::vector< unsigned int > m_vecDimensions
internal grid dimensions
Definition: SOM.h:171
unsigned int m_uiSomDim
internal SOM dimension variable ( = m_vecPrototypeBounds.size() = m_vecDimensions....
Definition: SOM.h:168
unsigned int griddim
grid dimension
Definition: SOM.h:95
std::vector< Neuron > m_vecNeurons
set of neurons
Definition: SOM.h:177
unsigned int getDataDim() const
returns the data dimension
Definition: SOM.h:148
Generic implementation of D to K dim Self Organizing Map (SOM)
Definition: SOM.h:70
vector_type prototype
prototype vector of dim "datadim"
Definition: SOM.h:92
std::vector< utils::Range< float > > m_vecPrototypeBounds
internal bounds for prototype ranges (todo: is it necessary to store them ?)
Definition: SOM.h:174
float m_fSigma
standard deviation for the grid distance function
Definition: SOM.h:186
vector_type gridpos
grid position vector of dim "griddim"
Definition: SOM.h:89
Neuron()
create a null neuron
Definition: SOM.h:80
void * meta
meta-data storage pointer
Definition: SOM.h:101
std::vector< unsigned int > m_vecDimOffsets
internal utility offset vector for each dimension
Definition: SOM.h:180
utils::SmartPtr< float > vector_type
Definition: SOM.h:77
unsigned int m_uiDataDim
internal data dimension variable
Definition: SOM.h:165
const std::vector< unsigned int > getDimensions() const
returns the SOM's grid dimension (e.g. 20x40 for a 2D SOM)
Definition: SOM.h:154
unsigned int datadim
prototype dimension
Definition: SOM.h:98
bool isNull() const
returns whether this neuron is already initialized (i.e. has valid pointers)
Definition: SOM.h:104
SOM internal Neuron struct.
Definition: SOM.h:76