Your last line in the objective function creates an Array{Float64,1} and 
returns that, but you need to return just a Float64. Probably easiest to just 
write:

 

(result’*target)[1]

 

Instead. Also, in the code sent you seem to miss setting the objective for 
NLopt, but given that something ran I assume that was just an oversight in your 
email.

 

From: [email protected] [mailto:[email protected]] On 
Behalf Of Nils Gudat
Sent: Thursday, September 17, 2015 10:24 AM
To: julia-users <[email protected]>
Subject: [julia-users] Debugging help with NLopt

 

Just putting this out here in the hope that someone has an idea:
I'm trying to fit a model to some targets using a minimum distance estimator 
with NLopt. The objective function basically computes the distance between 
model output given two parameters and the targets I set. 
The structure is:

objective(parameters::Vector{Float64}, grad)
  result = solvemodel(parameters)
  result'*target  
end

opt = Opt(:GN_CRS2_LM, 2)
lower_bounds!(opt, [numbers])
upper_bounds!(opt, [numbers])
xtol_rel!(opt,0.005)
(minf, minx, ret) = optimize(opt, [numbers])

When running this code, it stays busy for a while (which is expected, given 
that one evaluation of the model takes about 3 minutes) before throwing a 
MethodError, complaining `convert` has no method convert(::Type{Float64}, 
::Array{Float64,1}). I do get a `in callback catch` after every model 
evaluation, but I'm not sure where this is coming from, as when I simply 
evaluate objective() myself using some numbers, a value is returned without 
error. 

Reply via email to