Image Component Library (ICL)
LLM.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/LLM.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/Configurable.h>
36 #include <vector>
37 
38 namespace icl{
39  namespace math{
41 
108  public:
112  Kernel();
114  Kernel(unsigned int inputDim, unsigned int outputDim);
116  Kernel(const Kernel &k);
118  ~Kernel();
120  Kernel &operator=(const Kernel &k);
121 
123  float *w_in;
124 
126  float *w_out;
127 
129  float *A;
130 
132  float *dw_in;
133 
135  float *var;
136 
138  unsigned int inputDim;
139 
141  unsigned int outputDim;
142 
144  void show(unsigned int idx=0) const;
145 
147 
155  void set(const float *w_in, const float *w_out, const float *A);
156  };
157 
158 
159  static const int TRAIN_CENTERS = 1;
160  static const int TRAIN_SIGMAS = 2;
161  static const int TRAIN_OUTPUTS = 4;
162  static const int TRAIN_MATRICES = 8;
163  static const int TRAIN_ALL = TRAIN_CENTERS | TRAIN_SIGMAS | TRAIN_OUTPUTS | TRAIN_MATRICES;
165  private:
166  void init_private(unsigned int inputDim,unsigned int outputDim);
167 
168  public:
169 
171  LLM(unsigned int inputDim, unsigned int outputDim);
172 
173  LLM(unsigned int inputDim, unsigned int outputDim, unsigned int numCenters,
174  const std::vector<utils::Range<icl32f> > &ranges,
175  const std::vector<float> &var=std::vector<float>(1,1));
176 
178 
190  void init(unsigned int numCenters, const std::vector<utils::Range<icl32f> > &ranges,
191  const std::vector<float> &var=std::vector<float>(1,1));
192 
194 
197  void init(const std::vector<float*> &centers,
198  const std::vector<float> &var=std::vector<float>(1,1));
199 
201 
203  const float *apply(const float *x);
204 
206 
208  void train(const float *x,const float *y, int trainflags = TRAIN_ALL);
209 
211  void trainCenters(const float *x);
212 
214  void trainSigmas(const float *x);
215 
217  void trainOutputs(const float *x,const float *y);
218 
220  void trainMatrices(const float *x,const float *y);
221 
222  private:
224 
226  const float *updateGs(const float *x);
227 
228  public:
230  const float *getErrorVec(const float *x, const float *y);
231 
232 
234  void setEpsilonIn(float val) { setPropertyValue("epsilon In",val); }
235 
237  void setEpsilonOut(float val) { setPropertyValue("epsilon Out",val); }
238 
240  void setEpsilonA(float val) { setPropertyValue("epsilon A",val); }
241 
243 
244  void setEpsilonSigma(float val) { setPropertyValue("epsilon Sigma",val); }
245 
247  void showKernels() const;
248 
250  unsigned int numKernels() const { return m_kernels.size(); }
251 
253  const Kernel &operator[](unsigned int i) const { return m_kernels[i]; }
254 
256 
260  Kernel &operator[](unsigned int i) { return m_kernels[i]; }
261 
263  bool isSoftMaxUsed() const { return const_cast<Configurable*>(static_cast<const Configurable*>(this))->getPropertyValue("soft max enabled").as<bool>(); }
264 
266  void setSoftMaxEnabled(bool enabled) { setPropertyValue("soft max enabled",enabled); }
267 
268  private:
269 
271  void trainCentersIntern(const float *x,const float *g);
272 
274  void trainSigmasIntern(const float *x,const float *g);
275 
277  void trainOutputsIntern(const float *x,const float *y,const float *g, const float *dy, bool useDeltaWin);
278 
280  void trainMatricesIntern(const float *x,const float *y,const float *g, const float *dy);
281 
283  const float *applyIntern(const float *x,const float *g);
284 
286  const float *getErrorVecIntern(const float *y, const float *ynet);
287 
289  unsigned int m_inputDim;
290 
292  unsigned int m_outputDim;
293 
294  #if 0
295  float m_epsilonIn;
297 
299  float m_epsilonOut;
300 
302  float m_epsilonA;
303 
305  float m_epsilonSigma;
306  #endif
307  std::vector<Kernel> m_kernels;
309 
311  std::vector<float> m_outBuf;
312 
314  std::vector<float> m_gBuf;
315 
317  std::vector<float> m_errorBuf;
318 
319  #if 0
320  bool m_bUseSoftMax;
322  #endif
323  };
324 
325  } // namespace math
326 }
class representing a range defined by min and max value
Definition: Range.h:49
std::vector< float > m_outBuf
internal output value buffer
Definition: LLM.h:311
undocument this line if you encounter any issues!
Definition: Any.h:37
#define ICLMath_API
Definition: CompatMacros.h:173
const Kernel & operator[](unsigned int i) const
returns a specifice kernel at given index (const)
Definition: LLM.h:253
unsigned int numKernels() const
returns the current internal kernel count
Definition: LLM.h:250
float * w_in
input weight (prototype vector) of this kernel
Definition: LLM.h:123
unsigned int m_inputDim
input dimension
Definition: LLM.h:289
Kernel & operator[](unsigned int i)
returns a specifice kernel (unconst version)
Definition: LLM.h:260
unsigned int outputDim
output dimension
Definition: LLM.h:141
void setEpsilonIn(float val)
sets up learning rate for input weights to a new value (about 0..1)
Definition: LLM.h:234
void setEpsilonA(float val)
sets up learning rate for slope matrices to a new value (about 0..1)
Definition: LLM.h:240
float * A
matrix for the linear map
Definition: LLM.h:129
Internally used Kernel structure.
Definition: LLM.h:110
std::vector< float > m_gBuf
internal buffer for the g_i[x]
Definition: LLM.h:314
unsigned int inputDim
input dimension
Definition: LLM.h:138
void setEpsilonSigma(float val)
sets up learning rate for sigmas to a new value (about 0..1)
Definition: LLM.h:244
float * var
variance-vector of the Gaussian kernel (trace(Cxx))
Definition: LLM.h:135
float * dw_in
buffer for last input weight update
Definition: LLM.h:132
Interface for classes that can be configured from configuration-files and GUI-Components.
Definition: Configurable.h:194
bool isSoftMaxUsed() const
returns whether the softmax function for calculation for g_i[x] is used
Definition: LLM.h:263
void setSoftMaxEnabled(bool enabled)
sets whether the softmax function for calculation for g_i[x] is used
Definition: LLM.h:266
Local Linear Map implementation (LLM)
Definition: LLM.h:107
std::vector< float > m_errorBuf
internal buffer for the current error vector
Definition: LLM.h:317
ICLQt_API void show(const icl::core::ImgBase &image)
shows an image using TestImages::show
void setEpsilonOut(float val)
sets up learning rate for output weights to a new value (about 0..1)
Definition: LLM.h:237
float * w_out
output weight of this kernel
Definition: LLM.h:126
unsigned int m_outputDim
output dimension
Definition: LLM.h:292