Image Component Library (ICL)
|
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/SimplexOptimizer.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/Function.h> 00035 #include <ICLUtils/Uncopyable.h> 00036 #include <ICLMath/DynVector.h> 00037 #include <ICLMath/FixedVector.h> 00038 00039 namespace icl{ 00040 namespace math{ 00041 00043 template<class T, class Vector=DynColVector<T> > 00044 struct SimplexOptimizationResult{ 00045 const Vector &x; 00046 const T fx; 00047 const int iterations; 00048 const std::vector<Vector> &vertices; 00049 }; 00050 00051 00053 00144 template<class T, class Vector=DynColVector<T> > 00145 class ICLMath_IMP SimplexOptimizer : public utils::Uncopyable{ 00146 struct Data; 00147 Data *m_data; 00148 00149 public: 00151 typedef utils::Function<T, const Vector&> error_function; 00152 typedef SimplexOptimizationResult<T,Vector> Result; 00153 typedef utils::Function<void,const Result &> iteration_callback; 00154 00155 00157 00168 SimplexOptimizer(error_function f, int dim, 00169 int iterations=1E5, T minError=1.0E-10, 00170 T minDelta=1.0E-10, 00171 T a=1.0, T b=1.0, T g=0.5, T h=0.5); 00172 00174 void setDim(int dim); 00175 00177 void setA(T a); 00178 00180 void setB(T b); 00181 00183 void setG(T g); 00184 00186 void setH(T h); 00187 00189 void setIterations(int iterations); 00190 00192 void setMinError(T minError); 00193 00195 void setMinDelta(T minDelta); 00196 00198 void setErrorFunction(error_function f); 00199 00201 int getDim() const; 00202 00204 T getA() const; 00205 00207 T getB() const; 00208 00210 T getG() const; 00211 00213 T getH() const; 00214 00216 int getIterations() const; 00217 00219 T getMinError() const; 00220 00222 T getMinDelta() const; 00223 00225 error_function getErrorFunction() const; 00226 00228 void setIterationCallback(const iteration_callback &cb); 00229 00231 00234 Result optimize(const Vector &init); 00235 00237 00238 Result optimize(const std::vector<Vector> &init); 00239 00241 00243 static std::vector<Vector> createDefaultSimplex(const Vector &init); 00244 }; 00245 } // namespace math 00246 } 00247 00248