On Aug 10, 2012, at 8:46 PM, Philipp Eisenhauer wrote:
> 
> best from Chicago, I am currently working with the NLopt Python Interface for 
> my economics thesis. I want to check the sensitivity of my results to 
> alternative numerical optimization algorithms. Thank you very much for this 
> great piece of software!
> 
> Is there any explicit way to feed additional arguments to the maximization 
> function besides the starting values? 
> 
> Of course, I can work around this issue by using shared namespaces, but for 
> an easy and safe integration into the existing structure of my program this 
> would be very helpful. I studied the online documentation carefully, so I 
> hope I am not missing something obvious.

Yes, you can use Python's lexical scoping to do this without global variables.  
There is an example of this in the NLopt tutorial.

For example, suppose, your objective function takes an additional parameter "p" 
as a third argument:

        def myfunc(x, grad, p):
                ....

and you want to pass p = 0.3 in your code.  You would do:

        opt.set_max_objective(lambda x,grad: myfunc(x,grad,0.3))

Steven
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to