Skip to content

Commit

Permalink
change GLMM objective to use NLopt's tracking of function calls (like…
Browse files Browse the repository at this point in the history
… in LMM)
  • Loading branch information
palday committed Apr 13, 2020
1 parent ebe7906 commit ef8e380
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/generalizedlinearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,15 @@ function fit!(
optsum.final = copy(optsum.initial)
end
setpar! = fast ? setθ! : setβθ!
feval = 0
function obj(x, g)
isempty(g) || error("gradient not defined for this model")
feval += 1
isempty(g) || throw(ArgumentError("g should be empty for this objective"))
val = deviance(pirls!(setpar!(m, x), fast, verbose), nAGQ)
feval == 1 && (optsum.finitial = val)
if verbose
println("f_", feval, ": ", val, " ", x)
end
verbose && println(round(val, digits = 5), " ", x)
val
end
opt = Opt(optsum)
NLopt.min_objective!(opt, obj)
optsum.finitial = obj(optsum.initial, T[])
fmin, xmin, ret = NLopt.optimize(opt, copyto!(optsum.final, optsum.initial))
## check if very small parameter values bounded below by zero can be set to zero
xmin_ = copy(xmin)
Expand All @@ -274,6 +270,7 @@ function fit!(
## ensure that the parameter values saved in m are xmin
pirls!(setpar!(m, xmin), fast, verbose)
optsum.nAGQ = nAGQ
optsum.feval = opt.numevals
optsum.feval = feval
optsum.final = xmin
optsum.fmin = fmin
Expand Down

0 comments on commit ef8e380

Please sign in to comment.