Finding minimum in a function using JMinuit
Code: "func_jmunuit_minimum.py". Programming language: Python
DMelt Version 1.4. Last modified: 07/23/2017. License: Pro
https://datamelt.org/code/cache/func_jmunuit_minimum_169.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from jhplot.shapes import Line
from java.lang import *
from java.awt import *
from jhplot import *
class Func(FNon):
def value(self, x):
a=self.p[0]; b=self.p[1];
return a*Math.sqrt(x[0])*(x[0]-2)**2+b*x[0]*x[0]
c1=HPlot()
c1.visible(); c1.setAutoRange()
pl=Func("a(x-2)^{2}#sqrt{x}+bx^2",1,2) # 1 var, 2 pars
pl.setParameter("par0", 5) # define two parameters
pl.setParameter("par1",-6)
print pl.parameters()
from hep.aida.ref.optimizer.jminuit import *
op=JMinuitOptimizerFactory().create()
op.setFunction(pl)
op.variableSettings("x0").setValue(10) # set initial value
op.optimize() # optimization
res=op.result()
ff=F1D(pl,0,10) # show the function and min value
xmin=res.parameters()[0]
ymin=ff.eval(xmin)
p1=Line(xmin,ymin-10,xmin,ymin+10,BasicStroke(4),Color.red)
c1.add(p1)
c1.draw(ff)
print res.parameters()," status=",res.optimizationStatus()
You see the box below because you did not login.