Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LLM.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLMath/src/ICLMath/LLM.h                              **
00010 ** Module : ICLMath                                                **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/Range.h>
00035 #include <ICLUtils/Configurable.h>
00036 #include <vector>
00037 
00038 namespace icl{
00039   namespace math{
00041 
00107     class ICLMath_API LLM : public utils::Configurable{
00108       public:
00110       struct ICLMath_API Kernel{
00112         Kernel();
00114         Kernel(unsigned int inputDim, unsigned int outputDim);
00116         Kernel(const Kernel &k);
00118         ~Kernel();
00120         Kernel &operator=(const Kernel &k);
00121   
00123         float *w_in;
00124         
00126         float *w_out;
00127         
00129         float *A;
00130         
00132         float *dw_in;
00133         
00135         float *var; 
00136         
00138         unsigned int inputDim;
00139         
00141         unsigned int outputDim;
00142   
00144         void show(unsigned int idx=0) const;
00145   
00147 
00155         void set(const float *w_in, const float *w_out, const float *A);
00156       };
00157       
00158   
00159       static const int TRAIN_CENTERS = 1; 
00160       static const int TRAIN_SIGMAS = 2;  
00161       static const int TRAIN_OUTPUTS = 4; 
00162       static const int TRAIN_MATRICES = 8;
00163       static const int TRAIN_ALL = TRAIN_CENTERS | TRAIN_SIGMAS | TRAIN_OUTPUTS | TRAIN_MATRICES; 
00165       private:
00166       void init_private(unsigned int inputDim,unsigned int outputDim);
00167   
00168       public:
00169   
00171       LLM(unsigned int inputDim, unsigned int outputDim);
00172   
00173       LLM(unsigned int inputDim, unsigned int outputDim, unsigned int numCenters, 
00174           const std::vector<utils::Range<icl32f> > &ranges, 
00175           const std::vector<float> &var=std::vector<float>(1,1));
00176   
00178 
00190       void init(unsigned int numCenters, const std::vector<utils::Range<icl32f> > &ranges, 
00191                 const std::vector<float> &var=std::vector<float>(1,1));
00192       
00194 
00197       void init(const std::vector<float*> &centers, 
00198                 const std::vector<float> &var=std::vector<float>(1,1));
00199   
00201 
00203       const float *apply(const float *x);
00204       
00206 
00208       void train(const float *x,const float *y, int trainflags = TRAIN_ALL);
00209   
00211       void trainCenters(const float *x);
00212   
00214       void trainSigmas(const float *x);
00215   
00217       void trainOutputs(const float *x,const float *y);
00218       
00220       void trainMatrices(const float *x,const float *y);
00221   
00222       private:
00224 
00226       const float *updateGs(const float *x);
00227       
00228       public:
00230       const float *getErrorVec(const float *x, const float *y);
00231       
00232   
00234       void setEpsilonIn(float val) { setPropertyValue("epsilon In",val); }
00235   
00237       void setEpsilonOut(float val) { setPropertyValue("epsilon Out",val); }
00238   
00240       void setEpsilonA(float val) { setPropertyValue("epsilon A",val); }
00241       
00243 
00244       void setEpsilonSigma(float val) { setPropertyValue("epsilon Sigma",val); }
00245       
00247       void showKernels() const;
00248       
00250       unsigned int numKernels() const { return m_kernels.size(); }
00251       
00253       const Kernel &operator[](unsigned int i) const { return m_kernels[i]; }
00254   
00256 
00260       Kernel &operator[](unsigned int i) { return m_kernels[i]; }
00261       
00263       bool isSoftMaxUsed() const { return const_cast<Configurable*>(static_cast<const Configurable*>(this))->getPropertyValue("soft max enabled").as<bool>(); }
00264       
00266       void setSoftMaxEnabled(bool enabled) { setPropertyValue("soft max enabled",enabled); }
00267   
00268       private:
00269   
00271       void trainCentersIntern(const float *x,const float *g);
00272       
00274       void trainSigmasIntern(const float *x,const float *g);
00275   
00277       void trainOutputsIntern(const float *x,const float *y,const float *g, const float *dy, bool useDeltaWin);
00278       
00280       void trainMatricesIntern(const float *x,const float *y,const float *g, const float *dy);
00281       
00283       const float *applyIntern(const float *x,const  float *g);
00284   
00286       const float *getErrorVecIntern(const float *y, const float *ynet);
00287   
00289       unsigned int m_inputDim;
00290   
00292       unsigned int m_outputDim;
00293   
00294   #if 0    
00295 
00296       float m_epsilonIn;
00297       
00299       float m_epsilonOut;
00300       
00302       float m_epsilonA;
00303       
00305       float m_epsilonSigma;
00306   #endif
00307 
00308       std::vector<Kernel> m_kernels;
00309   
00311       std::vector<float> m_outBuf;
00312       
00314       std::vector<float> m_gBuf;
00315   
00317       std::vector<float> m_errorBuf;
00318   
00319   #if 0
00320 
00321       bool m_bUseSoftMax;
00322   #endif
00323     };
00324   
00325   } // namespace math
00326 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines