****************************************
Minimizer is Minuit2 / Migrad
MinFCN = 1.687e-08
NDf = 0
Edm = 1.68896e-08
NCalls = 146
Par_0 = 0.999952 +/- 1.00372
Par_1 = 0.999892 +/- 2.00986
****************************************
Minimizer is Minuit2 / Migrad
MinFCN = 2.72222e-08
NDf = 0
Edm = 2.72448e-08
NCalls = 76
Par_0 = 0.999954 +/- 1.00444
Par_1 = 0.999892 +/- 2.01131
Use Functor1D for wrapping one-dimensional function and compute integral of f(x) = x^2-1
integral-1D value = 5.999999999999999
Use Functor for wrapping a multi-dimensional function, the Rosenbrock Function r(x,y) and find its minimum
Use GradFunctor1D for making a function object implementing f(x) and f'(x)
Found root value x0 : f(x0) = 0 : 1.0
Use GradFunctor for making a function object implementing f(x,y) and df(x,y)/dx and df(x,y)/dy
import array
import ROOT
try:
import numpy as np
except Exception as e:
print("Failed to import numpy:", e)
exit()
return x*x -1
print("Use Functor1D for wrapping one-dimensional function and compute integral of f(x) = x^2-1")
ig.SetFunction(func)
value = ig.Integral(0, 3)
print("integral-1D value = ", value)
expValue = 6
if (not ROOT.TMath.AreEqualRel(value, expValue, 1.E-15)) :
print("Error computing integral - computed value - different than expected, diff = ", value - expValue)
print("\n\nUse Functor for wrapping a multi-dimensional function, the Rosenbrock Function r(x,y) and find its minimum")
def RosenbrockFunction(xx):
x = xx[0]
y = xx[1]
tmp1 = y-x*x
tmp2 = 1-x
return 100*tmp1*tmp1+tmp2*tmp2
initialParams = np.array([0.,0.], dtype='d')
fitter.FitFCN(func2D, initialParams)
fitter.Result().Print(ROOT.std.cout)
if (
not ROOT.TMath.AreEqualRel(fitter.Result().
Parameter(0), 1, 1.E-3)
or not ROOT.TMath.AreEqualRel(fitter.Result().
Parameter(1), 1, 1.E-3)) :
print("Error minimizing Rosenbrock function ")
print("\n\nUse GradFunctor1D for making a function object implementing f(x) and f'(x)")
try:
rf.SetFunction(gradFunc, 3)
rf.Solve()
value = rf.Root()
print("Found root value x0 : f(x0) = 0 : ", value)
if value != 1:
print("Error finding a ROOT of function f(x)=x^2-1")
except Exception as e:
print(e)
print("\n\nUse GradFunctor for making a function object implementing f(x,y) and df(x,y)/dx and df(x,y)/dy")
def RosenbrockDerivatives(xx, icoord):
x = xx[0]
y = xx[1]
if (icoord == 0) :
return 2*(200*x*x*x-200*x*y+x-1)
else :
return 200 * (y - x * x)
initialParams = array.array('d',[0.,0.])
fitter.FitFCN(gradFunc2d, initialParams)
fitter.Result().Print(ROOT.std.cout)
if (
not ROOT.TMath.AreEqualRel(fitter.Result().
Parameter(0), 1, 1.E-3)
or not ROOT.TMath.AreEqualRel(fitter.Result().
Parameter(1), 1, 1.E-3)) :
print("Error minimizing Rosenbrock function ")
Fitter class, entry point for performing all type of fits.
Functor1D class for one-dimensional functions.
Documentation for class Functor class.
GradFunctor1D class for one-dimensional gradient functions.
GradFunctor class for Multidimensional gradient functions.
User Class for performing numerical integration of a function in one dimension.
User Class to find the Root of one dimensional functions.