BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
ROOT::Math::GSLMultiMinimizer Class Reference

Description

GSLMultiMinimizer class , for minimizing multi-dimensional function using derivatives

Definition at line 53 of file GSLMultiMinimizer.h.

Collaboration diagram for ROOT::Math::GSLMultiMinimizer:
[legend]

Public Member Functions

 GSLMultiMinimizer (ROOT::Math::EGSLMinimizerType type)
 
 ~GSLMultiMinimizer ()
 
void CreateMinimizer (unsigned int n)
 create the minimizer from the type and size More...
 
double * Gradient () const
 gradient value at the minimum More...
 
int Iterate ()
 
double Minimum () const
 function value at the minimum More...
 
std::string Name () const
 
int Restart ()
 restart minimization from current point More...
 
int Set (const ROOT::Math::IMultiGradFunction &func, const double *x, double stepSize, double tol)
 
int TestGradient (const double *g, double absTol) const
 test gradient (require a vector gradient) More...
 
int TestGradient (double absTol) const
 test gradient (ask from minimizer gradient vector) More...
 
double * X () const
 x values at the minimum More...
 

Private Member Functions

 GSLMultiMinimizer (const GSLMultiMinimizer &)
 
GSLMultiMinimizeroperator= (const GSLMultiMinimizer &rhs)
 

Private Attributes

GSLMultiMinDerivFunctionWrapper fFunc
 
gsl_multimin_fdfminimizer * fMinimizer
 
const gsl_multimin_fdfminimizer_type * fType
 
gsl_vector * fVec
 

Constructor & Destructor Documentation

◆ GSLMultiMinimizer() [1/2]

ROOT::Math::GSLMultiMinimizer::GSLMultiMinimizer ( ROOT::Math::EGSLMinimizerType  type)
inline

Default constructor

Definition at line 60 of file GSLMultiMinimizer.h.

60  :
61  fMinimizer(0),
62  fType(0),
63  fVec(0)
64  {
65  switch(type)
66  {
68  fType = gsl_multimin_fdfminimizer_conjugate_fr;
69  break;
71  fType = gsl_multimin_fdfminimizer_conjugate_pr;
72  break;
74  fType = gsl_multimin_fdfminimizer_vector_bfgs;
75  break;
77 #if (GSL_MAJOR_VERSION > 1) || ((GSL_MAJOR_VERSION == 1) && (GSL_MINOR_VERSION >= 9))
78  // bfgs2 is available only for v>= 1.9
79  fType = gsl_multimin_fdfminimizer_vector_bfgs2;
80 #else
81  MATH_INFO_MSG("GSLMultiMinimizer","minimizer BFSG2 does not exist with this GSL version , use BFGS");
82  fType = gsl_multimin_fdfminimizer_vector_bfgs;
83 #endif
84  break;
86  fType = gsl_multimin_fdfminimizer_steepest_descent;
87  break;
88  default:
89  fType = gsl_multimin_fdfminimizer_conjugate_fr;
90  break;
91  }
92 
93  }
#define MATH_INFO_MSG(loc, str)
Definition: Error.h:44
const gsl_multimin_fdfminimizer_type * fType
gsl_multimin_fdfminimizer * fMinimizer
@ kSteepestDescent
Definition: GSLMinimizer.h:61

References fType, ROOT::Math::kConjugateFR, ROOT::Math::kConjugatePR, ROOT::Math::kSteepestDescent, ROOT::Math::kVectorBFGS, ROOT::Math::kVectorBFGS2, and MATH_INFO_MSG.

◆ ~GSLMultiMinimizer()

ROOT::Math::GSLMultiMinimizer::~GSLMultiMinimizer ( )
inline

Destructor

Definition at line 98 of file GSLMultiMinimizer.h.

98  {
99  if (fMinimizer != 0 ) gsl_multimin_fdfminimizer_free(fMinimizer);
100  // can free vector (is copied inside)
101  if (fVec != 0) gsl_vector_free(fVec);
102  }

References fMinimizer, and fVec.

◆ GSLMultiMinimizer() [2/2]

ROOT::Math::GSLMultiMinimizer::GSLMultiMinimizer ( const GSLMultiMinimizer )
inlineprivate

Copy constructor

Definition at line 110 of file GSLMultiMinimizer.h.

110 {}

Member Function Documentation

◆ CreateMinimizer()

void ROOT::Math::GSLMultiMinimizer::CreateMinimizer ( unsigned int  n)
inline

create the minimizer from the type and size

Definition at line 141 of file GSLMultiMinimizer.h.

141  {
142  if (fMinimizer) gsl_multimin_fdfminimizer_free(fMinimizer);
143  fMinimizer = gsl_multimin_fdfminimizer_alloc(fType, n);
144  }

References fMinimizer, and fType.

Referenced by Set().

◆ Gradient()

double* ROOT::Math::GSLMultiMinimizer::Gradient ( ) const
inline

gradient value at the minimum

Definition at line 170 of file GSLMultiMinimizer.h.

170  {
171  if (fMinimizer == 0) return 0;
172  gsl_vector * g = gsl_multimin_fdfminimizer_gradient(fMinimizer);
173  return g->data;
174  }

References fMinimizer.

◆ Iterate()

int ROOT::Math::GSLMultiMinimizer::Iterate ( )
inline

Definition at line 151 of file GSLMultiMinimizer.h.

151  {
152  if (fMinimizer == 0) return -1;
153  return gsl_multimin_fdfminimizer_iterate(fMinimizer);
154  }

References fMinimizer.

◆ Minimum()

double ROOT::Math::GSLMultiMinimizer::Minimum ( ) const
inline

function value at the minimum

Definition at line 164 of file GSLMultiMinimizer.h.

164  {
165  if (fMinimizer == 0) return 0;
166  return gsl_multimin_fdfminimizer_minimum(fMinimizer);
167  }

References fMinimizer.

◆ Name()

std::string ROOT::Math::GSLMultiMinimizer::Name ( ) const
inline

Definition at line 146 of file GSLMultiMinimizer.h.

146  {
147  if (fMinimizer == 0) return "undefined";
148  return std::string(gsl_multimin_fdfminimizer_name(fMinimizer) );
149  }

References fMinimizer.

◆ operator=()

GSLMultiMinimizer& ROOT::Math::GSLMultiMinimizer::operator= ( const GSLMultiMinimizer rhs)
inlineprivate

Assignment operator

Definition at line 115 of file GSLMultiMinimizer.h.

115  {
116  if (this == &rhs) return *this; // time saving self-test
117  return *this;
118  }

◆ Restart()

int ROOT::Math::GSLMultiMinimizer::Restart ( )
inline

restart minimization from current point

Definition at line 177 of file GSLMultiMinimizer.h.

177  {
178  if (fMinimizer == 0) return -1;
179  return gsl_multimin_fdfminimizer_restart(fMinimizer);
180  }

References fMinimizer.

◆ Set()

int ROOT::Math::GSLMultiMinimizer::Set ( const ROOT::Math::IMultiGradFunction func,
const double *  x,
double  stepSize,
double  tol 
)
inline

set the function to be minimize the initial minimizer parameters, step size and tolerance in the line search

Definition at line 126 of file GSLMultiMinimizer.h.

126  {
127  // create function wrapper
128  fFunc.SetFunction(func);
129  // create minimizer object (free previous one if already existing)
130  unsigned int ndim = func.NDim();
131  CreateMinimizer( ndim );
132  // set initial values
133  if (fVec != 0) gsl_vector_free(fVec);
134  fVec = gsl_vector_alloc( ndim );
135  std::copy(x,x+ndim, fVec->data);
136  assert(fMinimizer != 0);
137  return gsl_multimin_fdfminimizer_set(fMinimizer, fFunc.GetFunc(), fVec, stepSize, tol);
138  }
void SetFunction(const FuncType &f)
Fill gsl function structure from a C++ Function class.
GSLMultiMinDerivFunctionWrapper fFunc
void CreateMinimizer(unsigned int n)
create the minimizer from the type and size
virtual unsigned int NDim() const=0

References CreateMinimizer(), fFunc, fMinimizer, fVec, ROOT::Math::GSLMultiMinDerivFunctionWrapper::GetFunc(), ROOT::Math::IGradientFunctionMultiDimTempl< T >::NDim(), and ROOT::Math::GSLMultiMinDerivFunctionWrapper::SetFunction().

Here is the call graph for this function:

◆ TestGradient() [1/2]

int ROOT::Math::GSLMultiMinimizer::TestGradient ( const double *  g,
double  absTol 
) const
inline

test gradient (require a vector gradient)

Definition at line 190 of file GSLMultiMinimizer.h.

190  {
191  if (fVec == 0 ) return -1;
192  unsigned int n = fVec->size;
193  if (n == 0 ) return -1;
194  std::copy(g,g+n, fVec->data);
195  return gsl_multimin_test_gradient( fVec, absTol);
196  }

References fVec.

◆ TestGradient() [2/2]

int ROOT::Math::GSLMultiMinimizer::TestGradient ( double  absTol) const
inline

test gradient (ask from minimizer gradient vector)

Definition at line 183 of file GSLMultiMinimizer.h.

183  {
184  if (fMinimizer == 0) return -1;
185  gsl_vector * g = gsl_multimin_fdfminimizer_gradient(fMinimizer);
186  return gsl_multimin_test_gradient( g, absTol);
187  }

References fMinimizer.

◆ X()

double* ROOT::Math::GSLMultiMinimizer::X ( ) const
inline

x values at the minimum

Definition at line 157 of file GSLMultiMinimizer.h.

157  {
158  if (fMinimizer == 0) return 0;
159  gsl_vector * x = gsl_multimin_fdfminimizer_x(fMinimizer);
160  return x->data;
161  }

References fMinimizer.

Member Data Documentation

◆ fFunc

GSLMultiMinDerivFunctionWrapper ROOT::Math::GSLMultiMinimizer::fFunc
private

Definition at line 202 of file GSLMultiMinimizer.h.

Referenced by Set().

◆ fMinimizer

gsl_multimin_fdfminimizer* ROOT::Math::GSLMultiMinimizer::fMinimizer
private

◆ fType

const gsl_multimin_fdfminimizer_type* ROOT::Math::GSLMultiMinimizer::fType
private

Definition at line 203 of file GSLMultiMinimizer.h.

Referenced by GSLMultiMinimizer(), and CreateMinimizer().

◆ fVec

gsl_vector* ROOT::Math::GSLMultiMinimizer::fVec
mutableprivate

Definition at line 205 of file GSLMultiMinimizer.h.

Referenced by ~GSLMultiMinimizer(), Set(), and TestGradient().


The documentation for this class was generated from the following file: