julia lang - How to pass parameters and data to objective function for optimization with NLopt -
in julia v0.3.10 on ubuntu 14.04, need pass parameters , data objective function use in optimisation routine using nlopt in julia. following example code demonstrates how this:
function estimate(mymodel, mydata, myinitialvalue, nloptalgorithm, numberofparameters) opt = opt(nloptalgorithm, numberofparameters) localobjectivefunction = ((param, grad) -> generic_objective_function(param, grad, mymodel, mydata)) min_objective!(opt, localobjectivefunction) (objfuncopt, paramopt, flag) = optimize(opt, myinitialvalue) end function generic_objective_function(param, grad, mymodel, mydata) #some code end this works, although suffers issue localobjectivefunction anonymous compiler not able determine output type of function @ run-time, in turn has performance implications.
i'm wondering if there better way deal problem? should using fastanonymous? or there form of magic gets around issue?
from julia v0.5, question superfluous. this pull request on github fixes performance issues anonymous functions, v0.5 onwards, use anonymous functions!
Comments
Post a Comment