Created
November 2, 2011 14:50
-
-
Save alexsparrow/1333817 to your computer and use it in GitHub Desktop.
Example using TPyMultiGenFunction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ROOT as r | |
class Rosenbrock( r.TPyMultiGenFunction ): | |
def __init__( self ): | |
print "CREATED" | |
r.TPyMultiGenFunction.__init__( self, self ) | |
def NDim( self ): | |
print 'PYTHON NDim called' | |
return 1 | |
def DoEval( self, args ): | |
x = args[0] | |
y = args[1]; | |
tmp1 = y-x*x; | |
tmp2 = 1-x; | |
return 100*tmp1*tmp1+tmp2*tmp2; | |
if __name__ == "__main__": | |
min = r.Math.Factory.CreateMinimizer("GSLMultiMin", "BFGS") | |
min.SetMaxFunctionCalls(1000000) | |
min.SetMaxIterations(100000) | |
min.SetTolerance(0.001) | |
min.SetPrintLevel(1) | |
rose = Rosenbrock() | |
step = [0.01,0.01] | |
variable = [-1.0,1.2] | |
min.SetFunction(rose) | |
# Set the free variables to be minimized! | |
min.SetVariable(0,"x",variable[0], step[0]) | |
min.SetVariable(1,"y",variable[1], step[1]) | |
min.Minimize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment