14 RosenBrockFunction() : fNCalls(0) {}
15 virtual ~RosenBrockFunction() {}
17 unsigned int NDim()
const {
return 2; }
20 return new RosenBrockFunction();
23 unsigned int getNCalls() {
return fNCalls; }
26 mutable unsigned int fNCalls;
28 inline double DoEval (
const double *
x)
const {
35 return 100*tmp1*tmp1+tmp2*tmp2;
41 virtual ~Parabole() {}
43 unsigned int NDim()
const {
return 1; }
46 return new Parabole();
51 inline double DoEval (
const double *
x)
const {
58 inline double DoEval (
const double *
x)
const {
63 virtual ~MultiMin() {}
65 unsigned int NDim()
const {
return 1; }
68 return new MultiMin();
76 cout <<
"****************************************************\n";
77 cout <<
"Parabola Function Minimization \n";
85 cout <<
"Parabole min:" << gaParabole.
MinValue() <<
" x = [" << gaParabole.
X()[0] <<
"]" << endl;
86 bool ok = (std::abs(gaParabole.
MinValue() ) < 1.
E-3 );
87 if (!ok)
Error(
"testGAMinimizer",
"Test failed for parabola");
91 cout <<
"****************************************************\n";
92 cout <<
"Rosenbrock Function Minimization \n";
103 const double *
xmin = gaRosenBrock.
X();
104 cout <<
"RosenBrock min: " << gaRosenBrock.
MinValue() <<
" x = [" << xmin[0] <<
"] [" << xmin[1] <<
"]" << endl;
105 ok = (std::abs(gaRosenBrock.
MinValue() ) < 5.
E-2 );
106 if (!ok)
Error(
"testGAMinimizer",
"Test failed for RosenBrock");
110 cout <<
"****************************************************\n";
111 cout <<
"MultiMinima Function Minimization \n";
119 cout <<
"MultiMin min:" << gaMultiMin.
MinValue() <<
" x = [" << gaMultiMin.
X()[0] <<
"]" << endl;
120 ok = (std::abs(gaMultiMin.
MinValue() + 0.8982) < 1.E-3 );
121 if (!ok)
Error(
"testGAMinimizer",
"Test failed for MultiMin");
124 if (status) cout <<
"Test Failed !" << endl;
125 else cout <<
"Done!" << endl;
130 int main(
int argc,
char **argv)
136 for (
Int_t i=1 ; i<argc ; i++) {
137 std::string arg = argv[i] ;
145 std::cout <<
"Usage: " << argv[0] <<
" [-v] [-vv]\n";
146 std::cout <<
" where:\n";
147 std::cout <<
" -v : verbose mode\n";
148 std::cout <<
" -vv : very verbose mode\n";
149 std::cout << std::endl;
void RosenBrock(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t)
void SetMaxIterations(unsigned int maxiter)
set maximum iterations (one iteration can have many function calls)
virtual bool Minimize()
method to perform the minimization
virtual double MinValue() const
return minimum function value
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
Clone a function.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
int main(int argc, char **argv)
int testGAMinimizer(int verbose=0)
void SetRandomSeed(int seed)
void Error(const char *location, const char *msgfmt,...)
Documentation for the abstract class IBaseFunctionMultiDim.
virtual const double * X() const
return pointer to X values at the minimum
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)
set the function to minimize
virtual T DoEval(const T *x) const =0
Implementation of the evaluation function.
void SetPrintLevel(int level)
set print level
virtual bool SetLimitedVariable(unsigned int, const std::string &, double, double, double, double)
set a new upper/lower limited variable (override if minimizer supports them ) otherwise as default se...
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.