#ifndef ROOT_Math_Minimizer
#define ROOT_Math_Minimizer
#ifndef ROOT_Math_IFunction
#include "Math/IFunction.h"
#endif
#include <vector>
#include <string>
#include <limits>
#include <cmath>
#ifdef DEBUG
#include <iostream>
#endif
namespace ROOT {
namespace Math {
class Minimizer {
public:
Minimizer () :
fValidError(false),
#ifndef DEBUG
fDebug(0),
#else
fDebug(3),
#endif
fStrategy(1),
fStatus(-1),
fMaxCalls(0),
fMaxIter(0),
fTol(1.E-6),
fUp(1.)
{}
virtual ~Minimizer () {}
private:
Minimizer(const Minimizer &) {}
Minimizer & operator = (const Minimizer & rhs) {
if (this == &rhs) return *this;
return *this;
}
public:
virtual void Clear() {}
virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func) = 0;
virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func)
{
SetFunction(static_cast<const ::ROOT::Math::IMultiGenFunction &> (func));
}
template<class VariableIterator>
int SetVariables(const VariableIterator & begin, const VariableIterator & end) {
unsigned int ivar = 0;
for ( VariableIterator vitr = begin; vitr != end; ++vitr) {
#ifdef DEBUG
std::cout << "adding variable " << ivar << " " << vitr->Name();
if (vitr->IsDoubleBound() ) std::cout << " bounded to [ " << vitr->LowerLimit() << " , " << vitr->UpperLimit() << " ] ";
std::cout << std::endl;
#endif
bool iret = false;
if (vitr->IsFixed() )
iret = SetFixedVariable(ivar, vitr->Name(), vitr->Value() );
else if (vitr->IsDoubleBound() )
iret = SetLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->LowerLimit(), vitr->UpperLimit() );
else if (vitr->HasLowerLimit() )
iret = SetLowerLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->LowerLimit() );
else if (vitr->HasUpperLimit() )
iret = SetUpperLimitedVariable(ivar, vitr->Name(), vitr->Value(), vitr->StepSize(), vitr->UpperLimit() );
else
iret = SetVariable( ivar, vitr->Name(), vitr->Value(), vitr->StepSize() );
if (iret) ivar++;
#ifdef DEBUG
if (iret)
std::cout << "Added variable " << vitr->Name() << " val = " << vitr->Value() << " step " << vitr->StepSize()
<< std::endl;
else
std::cout << "Failed to Add variable " << vitr->Name() << std::endl;
#endif
}
return ivar;
}
virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step) = 0;
virtual bool SetLowerLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double lower ) {
return SetLimitedVariable(ivar, name, val, step, lower, std::numeric_limits<double>::infinity() );
}
virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ) {
return SetLimitedVariable(ivar, name, val, step, - std::numeric_limits<double>::infinity(), upper );
}
virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double , double ) {
return SetVariable(ivar, name, val, step );
}
virtual bool SetFixedVariable(unsigned int ivar , const std::string & name , double val ) {
return SetLimitedVariable(ivar, name, val, 0., val, val);
}
virtual bool SetVariableValue(unsigned int , double ) { return false; }
virtual bool SetVariableValues(const double * x) {
bool ret = true;
unsigned int i = 0;
while ( i <= NDim() && ret) {
SetVariableValue(i,x[i] ); i++;
}
return ret;
}
virtual bool Minimize() = 0;
virtual double MinValue() const = 0;
virtual double Edm() const = 0;
virtual const double * X() const = 0;
virtual const double * MinGradient() const = 0;
virtual unsigned int NCalls() const = 0;
virtual unsigned int NDim() const = 0;
virtual unsigned int NFree() const = 0;
virtual bool ProvidesError() const = 0;
virtual const double * Errors() const = 0;
virtual double CovMatrix(unsigned int i, unsigned int j) const = 0;
virtual double Correlation(unsigned int i, unsigned int j ) const {
double tmp = CovMatrix(i,i) * CovMatrix(j,j);
return ( tmp < 0) ? 0 : CovMatrix(i,j) / std::sqrt( tmp );
}
virtual double GlobalCC(unsigned int ) const { return -1; }
virtual bool GetMinosError(unsigned int , double & errLow, double & errUp) {
errLow = 0; errUp = 0;
return false;
}
virtual bool Scan(unsigned int , unsigned int & , double * , double * ,
double = 0, double = 0) {
return false;
}
virtual bool Contour(unsigned int , unsigned int , unsigned int &,
double * , double * ) {
return false;
}
virtual void PrintResults() {}
int PrintLevel() const { return fDebug; }
unsigned int MaxFunctionCalls() { return fMaxCalls; }
unsigned int MaxIterations() { return fMaxIter; }
double Tolerance() const { return fTol; }
int Strategy() const { return fStrategy; }
int Status() const { return fStatus; }
double ErrorDef() const { return fUp; }
bool IsValidError() const { return fValidError; }
void SetPrintLevel(int level) { fDebug = level; }
void SetMaxFunctionCalls(unsigned int maxfcn) { if (maxfcn > 0) fMaxCalls = maxfcn; }
void SetMaxIterations(unsigned int maxiter) { if (maxiter > 0) fMaxIter = maxiter; }
void SetTolerance(double tol) { fTol = tol; }
void SetStrategy(int strategyLevel) { fStrategy = strategyLevel; }
void SetErrorDef(double up) { fUp = up; }
void SetValidError(bool on) { fValidError = on; }
protected:
bool fValidError;
int fDebug;
int fStrategy;
int fStatus;
unsigned int fMaxCalls;
unsigned int fMaxIter;
double fTol;
double fUp;
};
}
}
#endif /* ROOT_Math_Minimizer */
Last change: Fri Dec 12 12:11:41 2008
Last generated: 2008-12-12 12:11
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.