Skip to content

Commit e250d9c

Browse files
committed
more cleanup
1 parent 095ef33 commit e250d9c

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

ext/MixedModelsPRIMAExt.jl

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function MixedModels.optimize!(m::LinearMixedModel, ::PRIMABackend; progress::Bo
3030
fitlog = optsum.fitlog
3131

3232
function obj(x)
33-
isempty(g) || throw(ArgumentError("g should be empty for this objective"))
3433
iter += 1
3534
val = if isone(iter) && x == optsum.initial
3635
optsum.finitial
@@ -52,25 +51,11 @@ function MixedModels.optimize!(m::LinearMixedModel, ::PRIMABackend; progress::Bo
5251
return val
5352
end
5453

55-
try
56-
# use explicit evaluation w/o calling opt to avoid confusing iteration count
57-
optsum.finitial = objective!(m, optsum.initial)
58-
catch ex
59-
ex isa PosDefException || rethrow()
60-
# give it one more try with a massive change in scaling
61-
@info "Initial objective evaluation failed, rescaling initial guess and trying again."
62-
@warn """Failure of the initial evaluation is often indicative of a model specification
63-
that is not well supported by the data and/or a poorly scaled model.
64-
"""
65-
optsum.initial ./=
66-
(isempty(m.sqrtwts) ? 1.0 : maximum(m.sqrtwts)^2) *
67-
maximum(response(m))
68-
optsum.finitial = objective!(m, optsum.initial)
69-
end
7054
empty!(fitlog)
7155
push!(fitlog, (copy(optsum.initial), optsum.finitial))
56+
maxfun = optsum.maxfeval > 0 ? optsum.maxfeval : 500 * length(optsum.initial)
7257
info = prima_optimizer!(Val(optsum.optimizer), obj, optsum.final;
73-
xl=optsum.lowerbd, maxfun=optsum.maxfeval,
58+
xl=optsum.lowerbd, maxfun,
7459
optsum.rhoend, optsum.rhobeg)
7560
ProgressMeter.finish!(prog)
7661
optsum.feval = info.nf

src/linearmixedmodel.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,23 @@ function StatsAPI.fit!(
460460
end
461461
optsum.REML = REML
462462
optsum.sigma = σ
463+
464+
try
465+
# use explicit evaluation w/o calling opt to avoid confusing iteration count
466+
optsum.finitial = objective!(m, optsum.initial)
467+
catch ex
468+
ex isa PosDefException || rethrow()
469+
# give it one more try with a massive change in scaling
470+
@info "Initial objective evaluation failed, rescaling initial guess and trying again."
471+
@warn """Failure of the initial evaluation is often indicative of a model specification
472+
that is not well supported by the data and/or a poorly scaled model.
473+
"""
474+
optsum.initial ./=
475+
(isempty(m.sqrtwts) ? 1.0 : maximum(m.sqrtwts)^2) *
476+
maximum(response(m))
477+
optsum.finitial = objective!(m, optsum.initial)
478+
end
479+
463480
xmin, fmin = optimize!(m; progress, thin)
464481
fitlog = optsum.fitlog
465482
## check if small non-negative parameter values can be set to zero

src/nlopt.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,6 @@ function optimize!(m::LinearMixedModel, ::NLoptBackend; progress::Bool=true, thi
3434
iter = 0
3535
fitlog = optsum.fitlog
3636

37-
try
38-
# use explicit evaluation w/o calling opt to avoid confusing iteration count
39-
optsum.finitial = objective!(m, optsum.initial)
40-
catch ex
41-
ex isa PosDefException || rethrow()
42-
# give it one more try with a massive change in scaling
43-
@info "Initial objective evaluation failed, rescaling initial guess and trying again."
44-
@warn """Failure of the initial evaluation is often indicative of a model specification
45-
that is not well supported by the data and/or a poorly scaled model.
46-
"""
47-
optsum.initial ./=
48-
(isempty(m.sqrtwts) ? 1.0 : maximum(m.sqrtwts)^2) *
49-
maximum(response(m))
50-
optsum.finitial = objective!(m, optsum.initial)
51-
end
5237
empty!(fitlog)
5338
push!(fitlog, (copy(optsum.initial), optsum.finitial))
5439
fmin, xmin, ret = NLopt.optimize!(opt, copyto!(optsum.final, optsum.initial))

0 commit comments

Comments
 (0)