Hi all,
I am an R user now beginning with Julia. As a start I’m trying to figure out how I can optimize a likelihood function in Julia. However, i cannot get my first try to work. Could anyone help me figuring out what it is that I do wrong?
Thank you!
using NLopt
using Distributions
y = [1, 2, 1, 2, 3]
function loglnorm(par)
ll = 0.0
for i = 1:length(y)
ll -= logpdf(Normal(par[1], par[2]), y[i])
end
return ll
end
opt = Opt(:LN_BOBYQA, 2)
opt.lower_bounds = [-Inf, 0.0]
opt.xtol_rel = 1e-4
opt.min_objective = loglnorm
(minf,minx,ret) = optimize!(opt, [2.0, 1.0])
numevals = opt.numevals
println("obj: $minf, par: $minx, evals: $numevals, return: $ret)")
The return value from optimize always return: “FORCED_STOP”.