ROOT logo
// @(#)root/mathmore:$Id: GSLMinimizer.h 37448 2010-12-09 20:20:56Z moneta $
// Author: L. Moneta Wed Oct 18 11:48:00 2006

 /**********************************************************************
  *                                                                    *
  * Copyright (c) 2006  LCG ROOT Math Team, CERN/PH-SFT                *
  *                                                                    *
  * This library is free software; you can redistribute it and/or      *
  * modify it under the terms of the GNU General Public License        *
  * as published by the Free Software Foundation; either version 2     *
  * of the License, or (at your option) any later version.             *
  *                                                                    *
  * This library is distributed in the hope that it will be useful,    *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
  * General Public License for more details.                           *
  *                                                                    *
  * You should have received a copy of the GNU General Public License  *
  * along with this library (see file COPYING); if not, write          *
  * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
  * 330, Boston, MA 02111-1307 USA, or contact the author.             *
  *                                                                    *
  **********************************************************************/


// Header file for class GSLMinimizer

#ifndef ROOT_Math_GSLMinimizer
#define ROOT_Math_GSLMinimizer

#ifndef ROOT_Math_Minimizer
#include "Math/Minimizer.h"
#endif


#ifndef ROOT_Math_IFunctionfwd
#include "Math/IFunctionfwd.h"
#endif

#ifndef ROOT_Math_IParamFunctionfwd
#include "Math/IParamFunctionfwd.h"
#endif

#ifndef ROOT_Math_MinimizerVariable
#include "Math/MinimizerVariable.h"
#endif


#include <vector>
#include <map>
#include <string> 



namespace ROOT { 

namespace Math { 


   /**
      enumeration specifying the types of GSL minimizers
      @ingroup MultiMin
   */
   enum EGSLMinimizerType { 
      kConjugateFR, 
      kConjugatePR, 
      kVectorBFGS, 
      kVectorBFGS2, 
      kSteepestDescent
   };


   class GSLMultiMinimizer; 

   class MinimTransformFunction;


//_____________________________________________________________________________________
/** 
   GSLMinimizer class. 
   Implementation of the ROOT::Math::Minimizer interface using the GSL multi-dimensional 
   minimization algorithms.

   See <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html">GSL doc</A> 
   from more info on the GSL minimization algorithms. 

   The class implements the ROOT::Math::Minimizer interface and can be instantiated using the 
   ROOT plugin manager (plugin name is "GSLMultiMin"). The varius minimization algorithms 
   (conjugatefr, conjugatepr, bfgs, etc..) can be passed as enumerations and also as a string. 
   The default algorithm is conjugatefr (Fletcher-Reeves conjugate gradient algorithm).  

   @ingroup MultiMin
*/ 
class GSLMinimizer : public ROOT::Math::Minimizer {

public: 

   /** 
      Default constructor
   */ 
   GSLMinimizer (ROOT::Math::EGSLMinimizerType type = ROOT::Math::kConjugateFR  ); 

   /**
      Constructor with a string giving name of algorithm 
    */
   GSLMinimizer (const char *  type  ); 

   /** 
      Destructor 
   */ 
   virtual ~GSLMinimizer (); 

private:
   // usually copying is non trivial, so we make this unaccessible

   /** 
      Copy constructor
   */ 
   GSLMinimizer(const GSLMinimizer &) : Minimizer() {}

   /** 
      Assignment operator
   */ 
   GSLMinimizer & operator = (const GSLMinimizer & rhs) { 
      if (this == &rhs) return *this;  // time saving self-test
      return *this;
   }

public: 

   /// set the function to minimize
   virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 

   /// set gradient the function to minimize
   virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 

   /// set free variable 
   virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 


   /// set lower limit variable  (override if minimizer supports them )
   virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
   /// set upper limit variable (override if minimizer supports them )
   virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ); 
   /// set upper/lower limited variable (override if minimizer supports them )
   virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double /* lower */, double /* upper */); 
   /// set fixed variable (override if minimizer supports them )
   virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */);  
   /// set the value of an existing variable 
   virtual bool SetVariableValue(unsigned int ivar, double val );
   /// set the values of all existing variables (array must be dimensioned to the size of existing parameters)
   virtual bool SetVariableValues(const double * x);

   /// method to perform the minimization
   virtual  bool Minimize(); 

   /// return minimum function value
   virtual double MinValue() const { return fMinVal; } 

   /// return expected distance reached from the minimum
   virtual double Edm() const { return 0; } // not impl. }

   /// return  pointer to X values at the minimum 
   virtual const double *  X() const { return &fValues.front(); } 

   /// return pointer to gradient values at the minimum 
   virtual const double *  MinGradient() const; 

   /// number of function calls to reach the minimum 
   virtual unsigned int NCalls() const;  

   /// this is <= Function().NDim() which is the total 
   /// number of variables (free+ constrained ones) 
   virtual unsigned int NDim() const { return fValues.size(); }   

   /// number of free variables (real dimension of the problem) 
   /// this is <= Function().NDim() which is the total number of free parameters
   virtual unsigned int NFree() const { return fObjFunc->NDim(); }  

   /// minimizer provides error and error matrix
   virtual bool ProvidesError() const { return false; } 

   /// return errors at the minimum 
   virtual const double * Errors() const { 
      return 0;
   }

   /** return covariance matrices elements 
       if the variable is fixed the matrix is zero
       The ordering of the variables is the same as in errors
   */ 
   virtual double CovMatrix(unsigned int , unsigned int ) const { return 0; }


   // method of only GSL  minimizer (not inherited from interface)
 
   /// return pointer to used objective gradient function 
   const ROOT::Math::IMultiGradFunction * ObjFunction() const { return fObjFunc; }

   /// return transformation function (NULL if not having a transformation) 
   const ROOT::Math::MinimTransformFunction * TransformFunction() const; 


protected: 

private: 
   
   // dimension of the function to be minimized 
   unsigned int fDim; 

   ROOT::Math::GSLMultiMinimizer * fGSLMultiMin; 
   const ROOT::Math::IMultiGradFunction * fObjFunc; 
   
   double fMinVal; 
   double fLSTolerance;  // Line Search Tolerance
   std::vector<double> fValues;
   //mutable std::vector<double> fErrors;
   std::vector<double> fSteps;
   std::vector<std::string> fNames;
   std::vector<ROOT::Math::EMinimVariableType> fVarTypes;  // vector specifyng the type of variables
   std::map< unsigned int, std::pair<double, double> > fBounds; // map specifying the bound using as key the parameter index

}; 

   } // end namespace Fit

} // end namespace ROOT



#endif /* ROOT_Math_GSLMinimizer */
 GSLMinimizer.h:1
 GSLMinimizer.h:2
 GSLMinimizer.h:3
 GSLMinimizer.h:4
 GSLMinimizer.h:5
 GSLMinimizer.h:6
 GSLMinimizer.h:7
 GSLMinimizer.h:8
 GSLMinimizer.h:9
 GSLMinimizer.h:10
 GSLMinimizer.h:11
 GSLMinimizer.h:12
 GSLMinimizer.h:13
 GSLMinimizer.h:14
 GSLMinimizer.h:15
 GSLMinimizer.h:16
 GSLMinimizer.h:17
 GSLMinimizer.h:18
 GSLMinimizer.h:19
 GSLMinimizer.h:20
 GSLMinimizer.h:21
 GSLMinimizer.h:22
 GSLMinimizer.h:23
 GSLMinimizer.h:24
 GSLMinimizer.h:25
 GSLMinimizer.h:26
 GSLMinimizer.h:27
 GSLMinimizer.h:28
 GSLMinimizer.h:29
 GSLMinimizer.h:30
 GSLMinimizer.h:31
 GSLMinimizer.h:32
 GSLMinimizer.h:33
 GSLMinimizer.h:34
 GSLMinimizer.h:35
 GSLMinimizer.h:36
 GSLMinimizer.h:37
 GSLMinimizer.h:38
 GSLMinimizer.h:39
 GSLMinimizer.h:40
 GSLMinimizer.h:41
 GSLMinimizer.h:42
 GSLMinimizer.h:43
 GSLMinimizer.h:44
 GSLMinimizer.h:45
 GSLMinimizer.h:46
 GSLMinimizer.h:47
 GSLMinimizer.h:48
 GSLMinimizer.h:49
 GSLMinimizer.h:50
 GSLMinimizer.h:51
 GSLMinimizer.h:52
 GSLMinimizer.h:53
 GSLMinimizer.h:54
 GSLMinimizer.h:55
 GSLMinimizer.h:56
 GSLMinimizer.h:57
 GSLMinimizer.h:58
 GSLMinimizer.h:59
 GSLMinimizer.h:60
 GSLMinimizer.h:61
 GSLMinimizer.h:62
 GSLMinimizer.h:63
 GSLMinimizer.h:64
 GSLMinimizer.h:65
 GSLMinimizer.h:66
 GSLMinimizer.h:67
 GSLMinimizer.h:68
 GSLMinimizer.h:69
 GSLMinimizer.h:70
 GSLMinimizer.h:71
 GSLMinimizer.h:72
 GSLMinimizer.h:73
 GSLMinimizer.h:74
 GSLMinimizer.h:75
 GSLMinimizer.h:76
 GSLMinimizer.h:77
 GSLMinimizer.h:78
 GSLMinimizer.h:79
 GSLMinimizer.h:80
 GSLMinimizer.h:81
 GSLMinimizer.h:82
 GSLMinimizer.h:83
 GSLMinimizer.h:84
 GSLMinimizer.h:85
 GSLMinimizer.h:86
 GSLMinimizer.h:87
 GSLMinimizer.h:88
 GSLMinimizer.h:89
 GSLMinimizer.h:90
 GSLMinimizer.h:91
 GSLMinimizer.h:92
 GSLMinimizer.h:93
 GSLMinimizer.h:94
 GSLMinimizer.h:95
 GSLMinimizer.h:96
 GSLMinimizer.h:97
 GSLMinimizer.h:98
 GSLMinimizer.h:99
 GSLMinimizer.h:100
 GSLMinimizer.h:101
 GSLMinimizer.h:102
 GSLMinimizer.h:103
 GSLMinimizer.h:104
 GSLMinimizer.h:105
 GSLMinimizer.h:106
 GSLMinimizer.h:107
 GSLMinimizer.h:108
 GSLMinimizer.h:109
 GSLMinimizer.h:110
 GSLMinimizer.h:111
 GSLMinimizer.h:112
 GSLMinimizer.h:113
 GSLMinimizer.h:114
 GSLMinimizer.h:115
 GSLMinimizer.h:116
 GSLMinimizer.h:117
 GSLMinimizer.h:118
 GSLMinimizer.h:119
 GSLMinimizer.h:120
 GSLMinimizer.h:121
 GSLMinimizer.h:122
 GSLMinimizer.h:123
 GSLMinimizer.h:124
 GSLMinimizer.h:125
 GSLMinimizer.h:126
 GSLMinimizer.h:127
 GSLMinimizer.h:128
 GSLMinimizer.h:129
 GSLMinimizer.h:130
 GSLMinimizer.h:131
 GSLMinimizer.h:132
 GSLMinimizer.h:133
 GSLMinimizer.h:134
 GSLMinimizer.h:135
 GSLMinimizer.h:136
 GSLMinimizer.h:137
 GSLMinimizer.h:138
 GSLMinimizer.h:139
 GSLMinimizer.h:140
 GSLMinimizer.h:141
 GSLMinimizer.h:142
 GSLMinimizer.h:143
 GSLMinimizer.h:144
 GSLMinimizer.h:145
 GSLMinimizer.h:146
 GSLMinimizer.h:147
 GSLMinimizer.h:148
 GSLMinimizer.h:149
 GSLMinimizer.h:150
 GSLMinimizer.h:151
 GSLMinimizer.h:152
 GSLMinimizer.h:153
 GSLMinimizer.h:154
 GSLMinimizer.h:155
 GSLMinimizer.h:156
 GSLMinimizer.h:157
 GSLMinimizer.h:158
 GSLMinimizer.h:159
 GSLMinimizer.h:160
 GSLMinimizer.h:161
 GSLMinimizer.h:162
 GSLMinimizer.h:163
 GSLMinimizer.h:164
 GSLMinimizer.h:165
 GSLMinimizer.h:166
 GSLMinimizer.h:167
 GSLMinimizer.h:168
 GSLMinimizer.h:169
 GSLMinimizer.h:170
 GSLMinimizer.h:171
 GSLMinimizer.h:172
 GSLMinimizer.h:173
 GSLMinimizer.h:174
 GSLMinimizer.h:175
 GSLMinimizer.h:176
 GSLMinimizer.h:177
 GSLMinimizer.h:178
 GSLMinimizer.h:179
 GSLMinimizer.h:180
 GSLMinimizer.h:181
 GSLMinimizer.h:182
 GSLMinimizer.h:183
 GSLMinimizer.h:184
 GSLMinimizer.h:185
 GSLMinimizer.h:186
 GSLMinimizer.h:187
 GSLMinimizer.h:188
 GSLMinimizer.h:189
 GSLMinimizer.h:190
 GSLMinimizer.h:191
 GSLMinimizer.h:192
 GSLMinimizer.h:193
 GSLMinimizer.h:194
 GSLMinimizer.h:195
 GSLMinimizer.h:196
 GSLMinimizer.h:197
 GSLMinimizer.h:198
 GSLMinimizer.h:199
 GSLMinimizer.h:200
 GSLMinimizer.h:201
 GSLMinimizer.h:202
 GSLMinimizer.h:203
 GSLMinimizer.h:204
 GSLMinimizer.h:205
 GSLMinimizer.h:206
 GSLMinimizer.h:207
 GSLMinimizer.h:208
 GSLMinimizer.h:209
 GSLMinimizer.h:210
 GSLMinimizer.h:211
 GSLMinimizer.h:212
 GSLMinimizer.h:213
 GSLMinimizer.h:214
 GSLMinimizer.h:215
 GSLMinimizer.h:216
 GSLMinimizer.h:217
 GSLMinimizer.h:218
 GSLMinimizer.h:219
 GSLMinimizer.h:220
 GSLMinimizer.h:221
 GSLMinimizer.h:222
 GSLMinimizer.h:223
 GSLMinimizer.h:224
 GSLMinimizer.h:225
 GSLMinimizer.h:226
 GSLMinimizer.h:227
 GSLMinimizer.h:228
 GSLMinimizer.h:229
 GSLMinimizer.h:230
 GSLMinimizer.h:231