18 for(
int i=0;i<(length-1);i++)
20 result+=
pow(1-xx[i],2)+100*
pow(xx[i+1]-
pow(xx[i],2),2);
32 result+=xx[i]*xx[i]-10*
cos(6.2831853*xx[i]);
42 Bool_t installed=r.
Eval(
"is.element('DEoptim', installed.packages()[,1])");
45 std::cout<<
"Package DEoptim no installed in R"<<std::endl;
46 std::cout<<
"Run install.packages('DEoptim') in R's environment"<<std::endl;
51 r<<
"suppressMessages(library(DEoptim, quietly = TRUE))";
65 bench.
Start(
"GlobalMinimizationRosenBrock");
67 r<<
"result1<-DEoptim(fn=GenRosenBrock,lower=ll,upper=ul,control=list(NP=10*n,itermax=MaxIter,trace=FALSE))";
68 std::cout<<
"-----------------------------------------"<<std::endl;
69 std::cout<<
"RosenBrock's minimum in: "<<std::endl;
70 r<<
"print(result1$optim$bestmem)";
71 std::cout<<
"Bechmark Times"<<std::endl;
73 bench.
Show(
"GlobalMinimizationRosenBrock");
77 r[
"Rastrigin"]<<ROOT::R::TRFunctionExport(
Rastrigin);
87 bench.
Start(
"GlobalMinimizationRastrigin");
89 r<<
"result2<-DEoptim(fn=Rastrigin,lower=ll,upper=ul,control=list(NP=10*n,itermax=MaxIter,trace=FALSE))";
90 std::cout<<
"-----------------------------------------"<<std::endl;
91 std::cout<<
"Rastrigin's minimum in: "<<std::endl;
92 r<<
"print(result2$optim$bestmem)";
93 std::cout<<
"Bechmark Times"<<std::endl;
95 bench.
Show(
"GlobalMinimizationRastrigin");
97 if (!
gROOT->IsBatch()) {
98 r<<
"dev.new(title='RosenBrock Convergence')";
99 r<<
"plot(result1,type='o',pch='.')";
101 r<<
"dev.new(title='Rastrigin Convergence')";
102 r<<
"plot(result2,type='o',pch='.')";
virtual void Show(const char *name)
Stops Benchmark name and Prints results.
Double_t Rastrigin(const TVectorD xx)
virtual void Start(const char *name)
Starts Benchmark with the specified name.
double pow(double, double)
Double_t GenRosenBrock(const TVectorD xx)
void GlobalMinimization()
Double_t length(const TVector2 &v)
This class is a ROOT utility to help benchmarking applications.
static TRInterface & Instance()
static method to get an TRInterface instance reference
Int_t GetNoElements() const
Int_t Eval(const TString &code, TRObject &ans)
Method to eval R code and you get the result in a reference to TRObject.
This is a class to pass functions from ROOT to R