Skip to content

Commit

Permalink
abstract near-zero checks into configurable params
Browse files Browse the repository at this point in the history
  • Loading branch information
palday committed Jun 24, 2024
1 parent dff11dd commit 63264fe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MixedModels v4.24.2 Release Notes
- user-specified `σ` is actually used, defaulting to existing value
- `REML` defaults to model's already specified REML value.
- Clean up code of keyword convenience constructor for `OptSummary`. [#772]
- Refactor thresholding parameters for forcing near-zero parameter values into `OptSummary`. [#772]

MixedModels v4.24.1 Release Notes
==============================
Expand Down
4 changes: 2 additions & 2 deletions src/generalizedlinearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,13 @@ function StatsAPI.fit!(
## check if very small parameter values bounded below by zero can be set to zero
xmin_ = copy(xmin)
for i in eachindex(xmin_)
if iszero(optsum.lowerbd[i]) && zero(T) < xmin_[i] < T(0.001)
if iszero(optsum.lowerbd[i]) && zero(T) < xmin_[i] < optsum.xtol_zero_abs
xmin_[i] = zero(T)
end
end
loglength = length(fitlog)
if xmin xmin_
if (zeroobj = obj(xmin_, T[])) (fmin + 1.e-5)
if (zeroobj = obj(xmin_, T[])) (fmin + optsum.ftol_zero_abs)
fmin = zeroobj
copyto!(xmin, xmin_)
elseif length(fitlog) > loglength
Expand Down
4 changes: 2 additions & 2 deletions src/linearmixedmodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ function StatsAPI.fit!(
xmin_ = copy(xmin)
lb = optsum.lowerbd
for i in eachindex(xmin_)
if iszero(lb[i]) && zero(T) < xmin_[i] < T(0.001)
if iszero(lb[i]) && zero(T) < xmin_[i] < optsum.xtol_zero_abs
xmin_[i] = zero(T)
end
end
loglength = length(fitlog)
if xmin xmin_
if (zeroobj = obj(xmin_, T[])) (fmin + 1.e-5)
if (zeroobj = obj(xmin_, T[])) (fmin + optsum.ftol_zero_abs)
fmin = zeroobj
copyto!(xmin, xmin_)
elseif length(fitlog) > loglength
Expand Down
4 changes: 3 additions & 1 deletion src/optsummary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Summary of an `NLopt` optimization
* `feval`: the number of function evaluations
* `optimizer`: the name of the optimizer used, as a `Symbol`
* `returnvalue`: the return value, as a `Symbol`
* `xtol_zero_abs`: the tolerance for a near zero parameter to be considered practically zero
* `ftol_zero_abs`: the tolerance for change in the objective for setting a near zero parameter to zero
* `fitlog`: A vector of tuples of parameter and objectives values from steps in the optimization
* `nAGQ`: number of adaptive Gauss-Hermite quadrature points in deviance evaluation for GLMMs
Expand Down Expand Up @@ -50,7 +51,8 @@ Base.@kwdef mutable struct OptSummary{T<:AbstractFloat}
fmin::T = Inf * one(eltype(initial))
optimizer::Symbol = :LN_BOBYQA
returnvalue::Symbol = :FAILURE
ftol_zero_abs::T = one(eltype(initial)) / 1000
xtol_zero_abs::T = eltype(initial)(0.001)
ftol_zero_abs::T = eltype(initial)(1.e-5)
# not SVector because we would need to parameterize on size (which breaks GLMM)
fitlog::Vector{Tuple{Vector{T},T}} = [(initial, fmin)]
# don't really belong here but I needed a place to store them
Expand Down

0 comments on commit 63264fe

Please sign in to comment.