from java.lang import Math
from jhplot import *
class MyFunc(FNon): # define a function a*(x-2)^2 + (y+1)^2
def value(self, x):
return (x[0]-2)*(x[0]-2)*self.p[0]+(x[1]+1)*(x[1]+1)
c1 = HPlot3D() # plot data and the fit function
c1.visible()
c1.setAutoRange()
pl = MyFunc("2D function",2,1) # 2 variables, 1 parameter
print pl.numberOfParameters()
print pl.dimension()
print pl.parameterNames().tolist()
pl.setParameter("par0",2)
print pl.parameters()
c1.draw( F2D(pl,-10,10,-10,10) ) # create plottable function and show it
from hep.aida.ref.optimizer.jminuit import *
op=JMinuitOptimizerFactory().create()
op.setFunction(pl) # set function
op.variableSettings("x0").setValue(10) # set initial value
op.variableSettings("x1").setValue(-10) # set initial value
op.optimize() # perform optimization
res =op.result()
print "Minimization results=",res.parameters(), " status=",res.optimizationStatus()