{
"cells": [
{
"cell_type": "markdown",
"id": "24164d4f",
"metadata": {},
"source": [
"# GlobalMinimization\n",
"Example based in\n",
"http://cran.r-project.org/web/packages/DEoptim/DEoptim.pdf\n",
"Please install the R package DEoptim before run this example.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Omar Zapata \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, December 21, 2025 at 02:49 PM."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4eb9832",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%cpp -d\n",
"#include\n",
"#include\n",
"#include\n",
"#include"
]
},
{
"cell_type": "markdown",
"id": "e7d15536",
"metadata": {},
"source": [
" In the next function the *double pointer should be changed by a TVectorD datatype,\n",
"because the pointer has no meaning in R's enviroment.\n",
"This is a generalization of the RosenBrock function, with the min xi=1 and i>0.\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b977e427",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%cpp -d\n",
"Double_t GenRosenBrock(const TVectorD xx )\n",
"{\n",
" int length=xx.GetNoElements();\n",
"\n",
" Double_t result=0;\n",
" for (int i=0;i<(length-1);i++) {\n",
" result+=pow(1-xx[i],2)+100*pow(xx[i+1]-pow(xx[i],2),2);\n",
" }\n",
" return result;\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "de63b091",
"metadata": {},
"source": [
" the min xi=0 i>0\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2c4b03e",
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%%cpp -d\n",
"Double_t Rastrigin(const TVectorD xx)\n",
"{\n",
" int length=xx.GetNoElements();\n",
" Double_t result=10*length;\n",
" for (int i=0;iIsBatch()) {\n",
" r<<\"dev.new(title='RosenBrock Convergence')\";\n",
" r<<\"plot(result1,type='o',pch='.')\";\n",
" r<<\"dev.off()\";\n",
" r<<\"dev.new(title='Rastrigin Convergence')\";\n",
" r<<\"plot(result2,type='o',pch='.')\";\n",
" r<<\"dev.off()\";\n",
"}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}