Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PolynomialRegression.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/PolynomialRegression.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.GPL  **
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 <ICLMath/DynMatrix.h>
00034 #include <vector>
00035 #include <string>
00036 
00037 namespace icl{
00038   
00039   namespace math{
00040     
00043 
00044     template<class T>
00045     struct PolynomialRegressionAttrib{ 
00046       virtual T compute(const T *row) const = 0; 
00047       virtual std::string toString() const = 0;
00048     };
00052 
00053 
00081     template<class T>
00082     class PolynomialRegression{
00083       
00085       typedef DynMatrix<T> Matrix;
00086       
00088       typedef PolynomialRegressionAttrib<T> Attrib;
00089       
00090       public:
00091       
00093       class Result{
00095         friend class PolynomialRegression;
00096 
00098         std::vector<const Attrib*> m_attribs;
00099         
00101         std::string m_function;
00102         
00104         mutable Matrix m_params; 
00105         
00107         mutable Matrix m_xbuf, m_resultBuf;
00108         
00110         mutable int m_attribMaxIndex;
00111         
00113         void setup(const std::string &function);
00114         
00115         public:
00116         
00118         inline Result(){}
00119         
00121         Result(const std::string &xmlfilename);
00122         
00124         const Matrix &getParams() const { return m_params; }
00125         
00127 
00137         const Matrix &operator()(const Matrix &xs) const;
00138         
00140         std::vector<const Attrib*> getAttribs() const { return m_attribs; }
00141         
00143         std::string toString(const std::vector<std::string> &rowLabels=std::vector<std::string> ()) const;
00144         
00146         void save(const std::string &xmlFileName) const;
00147       };
00148       
00149       protected:
00150       
00152       mutable Matrix m_buf;
00153       
00155       Result m_result;
00156       
00157 
00158       public:
00159 
00161       PolynomialRegression(const std::string &function);
00162       
00163       
00165 
00176       const Result &apply(const Matrix &xs, const Matrix &ys, bool useSVD=false);
00177       
00179       std::string getFunctionString() const;
00180     };
00181 
00182   }
00183 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines