Skip to content

Commit

Permalink
add finally block for restoring original model in profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Dec 9, 2024
1 parent 2f92408 commit 9250d2b
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/profile/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,28 @@ value of ζ exceeds `threshold`.
function profile(m::LinearMixedModel; threshold=4)
isfitted(m) || refit!(m)
final = copy(m.optsum.final)
tc = TableColumns(m)
val = profileσ(m, tc; threshold) # FIXME: defer creating the splines until the whole table is constructed
objective!(m, final) # restore the parameter estimates
for s in filter(s -> startswith(string(s), 'β'), keys(first(val.tbl)))
profileβj!(val, tc, s; threshold)
end
copyto!(m.optsum.final, final)
m.optsum.fmin = objective!(m, final)
for s in filter(s -> startswith(string(s), 'θ'), keys(first(val.tbl)))
profileθj!(val, s, tc; threshold)
try
tc = TableColumns(m)
val = profileσ(m, tc; threshold) # FIXME: defer creating the splines until the whole table is constructed
objective!(m, final) # restore the parameter estimates
for s in filter(s -> startswith(string(s), 'β'), keys(first(val.tbl)))
profileβj!(val, tc, s; threshold)
end
copyto!(m.optsum.final, final)
m.optsum.fmin = objective!(m, final)
for s in filter(s -> startswith(string(s), 'θ'), keys(first(val.tbl)))
profileθj!(val, s, tc; threshold)
end
profileσs!(val, tc)
catch ex
@error "Exception occurred in profiling; aborting..."
rethrow(ex)
finally
objective!(m, final) # restore the parameter estimates
copyto!(m.optsum.final, final)
m.optsum.fmin = objective(m)
m.optsum.sigma = nothing
end
profileσs!(val, tc)
objective!(m, final) # restore the parameter estimates
copyto!(m.optsum.final, final)
m.optsum.fmin = objective(m)
m.optsum.sigma = nothing
return MixedModelProfile(m, Table(val.tbl), val.fwd, val.rev)
end

Expand Down

0 comments on commit 9250d2b

Please sign in to comment.