Minuit (MnMigrad) minimization of P1D function
Code: "func_minuit.py". Programming language: Python
DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/func_minuit_3727.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 org.freehep.math.minuit import FCNBase,MnMigrad,MnUserParameters
from java.lang.Math import *
class func(FCNBase): # define user functions
def valueOf(self, par):
return 10+par[0]*par[0]+exp(par[0])
def getPlot(self,min,max):
f=P1D("function")
step=(max-min)/100.0 # define step
for i in range(100):
x=min+step*i
y=self.valueOf([x])
f.add(x,y)
return f
Par = MnUserParameters()
Par.add("x", 1., 0.1)
migrad = MnMigrad(func(), Par)
vmin = migrad.minimize()
state=vmin.userState()
print "Min value=:",vmin.fval(), "function calls=",vmin.nfcn()
par=state.params()
from jhplot import * # plotting part
from jhplot.shapes import *
from java.awt import Color
c1 = HPlot()
c1.visible()
min=-10; max=10 # min and max values for plotting
c1.setRangeX(min,max)
c1.setRangeY(0,200)
f=func()
p=f.getPlot(min,max)
p.setStyle('l'); p.setPenWidth(3); p.setColor(Color.blue)
c1.draw(p)
# now show min and max values
center=P1D("min value")
center.add(par[0],vmin.fval())
center.setColor(Color.red)
c1.draw(center)
You see the box below because you did not login.