From d33ffaaa98cec40655f1cb918cf126cbc133954c Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 20 Jun 2024 20:59:22 -0500 Subject: [PATCH 01/13] minor tweaks to improve type inference --- src/linearmixedmodel.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 875b54c92..34f146b9e 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -36,8 +36,8 @@ struct LinearMixedModel{T<:AbstractFloat} <: MixedModel{T} sqrtwts::Vector{T} parmap::Vector{NTuple{3,Int}} dims::NamedTuple{(:n, :p, :nretrms),NTuple{3,Int}} - A::Vector{AbstractMatrix{T}} # cross-product blocks - L::Vector{AbstractMatrix{T}} + A::Vector{<:AbstractMatrix{T}} # cross-product blocks + L::Vector{<:AbstractMatrix{T}} optsum::OptSummary{T} end @@ -408,7 +408,7 @@ function createAL(reterms::Vector{<:AbstractReMat{T}}, Xy::FeMat{T}) where {T} end end end - return A, L + return identity.(A), identity.(L) end StatsAPI.deviance(m::LinearMixedModel) = objective(m) From 1bab6e7288bbc096e4fafc362b1e101e4940a7de Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Thu, 20 Jun 2024 21:10:40 -0500 Subject: [PATCH 02/13] remove unused kwarg --- src/linearmixedmodel.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 34f146b9e..8c02f982a 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -432,7 +432,6 @@ end """ fit!(m::LinearMixedModel; progress::Bool=true, REML::Bool=false, - σ::Union{Real, Nothing}=nothing, thin::Int=typemax(Int)) Optimize the objective of a `LinearMixedModel`. When `progress` is `true` a @@ -446,7 +445,6 @@ function StatsAPI.fit!( m::LinearMixedModel{T}; progress::Bool=true, REML::Bool=false, - σ::Union{Real,Nothing}=nothing, thin::Int=typemax(Int), ) where {T} optsum = m.optsum From 2a190e31ad0ace793229589d5c70789c2dd1cc13 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 12:41:42 -0500 Subject: [PATCH 03/13] another type restriction --- src/linearmixedmodel.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 8c02f982a..cd3ae8a61 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -1339,7 +1339,7 @@ function varest(m::LinearMixedModel) return isnothing(m.optsum.sigma) ? pwrss(m) / ssqdenom(m) : m.optsum.sigma end -function StatsAPI.weights(m::LinearMixedModel) +function StatsAPI.weights(m::LinearMixedModel{T}) where {T} rtwts = m.sqrtwts - return isempty(rtwts) ? ones(eltype(rtwts), nobs(m)) : abs2.(rtwts) + return isempty(rtwts) ? ones(T, nobs(m)) : abs2.(rtwts) end From ed9f06bb6ebc55103d74c908a218528e8647329e Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 12:43:45 -0500 Subject: [PATCH 04/13] fix NEWS and version number --- NEWS.md | 7 ++++++- Project.toml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index ece040c1a..f4e196ce0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ +MixedModels v4.24.2 Release Notes +============================== +- Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773] + MixedModels v4.24.1 Release Notes ============================== -Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773] +- Re-export accidentally dropped export `lrtest`. [#769] MixedModels v4.24.0 Release Notes ============================== @@ -525,4 +529,5 @@ Package dependencies [#755]: https://github.com/JuliaStats/MixedModels.jl/issues/755 [#756]: https://github.com/JuliaStats/MixedModels.jl/issues/756 [#767]: https://github.com/JuliaStats/MixedModels.jl/issues/767 +[#769]: https://github.com/JuliaStats/MixedModels.jl/issues/769 [#773]: https://github.com/JuliaStats/MixedModels.jl/issues/773 diff --git a/Project.toml b/Project.toml index 6d31df627..a602cbffb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MixedModels" uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316" author = ["Phillip Alday ", "Douglas Bates ", "Jose Bayoan Santiago Calderon "] -version = "4.24.1" +version = "4.24.2" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" From 9f4a72b38a799424388f8838a81df462ae3599aa Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 12:49:40 -0500 Subject: [PATCH 05/13] Revert "remove unused kwarg" This reverts commit 1bab6e7288bbc096e4fafc362b1e101e4940a7de. --- src/linearmixedmodel.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index cd3ae8a61..24d85fa83 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -432,6 +432,7 @@ end """ fit!(m::LinearMixedModel; progress::Bool=true, REML::Bool=false, + σ::Union{Real, Nothing}=nothing, thin::Int=typemax(Int)) Optimize the objective of a `LinearMixedModel`. When `progress` is `true` a @@ -445,6 +446,7 @@ function StatsAPI.fit!( m::LinearMixedModel{T}; progress::Bool=true, REML::Bool=false, + σ::Union{Real,Nothing}=nothing, thin::Int=typemax(Int), ) where {T} optsum = m.optsum From 294cd152084d7c15ff2dbe30fd9320d300e449b3 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 12:55:11 -0500 Subject: [PATCH 06/13] fixes --- NEWS.md | 4 ++++ src/linearmixedmodel.jl | 13 +++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index f4e196ce0..ab1d3f430 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,10 @@ MixedModels v4.24.2 Release Notes ============================== - Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773] +- Take advantage of type parameter for `StatsAPI.weights(::LinearMixedModel{T})`. [#772] +- Fix use of kwargs in `fit!((::LinearMixedModel)`: [#772] + - user-specified `σ` is actually used, defaulting to existing value + - `REML` defaults to model's already specified REML value. MixedModels v4.24.1 Release Notes ============================== diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 24d85fa83..3555ff90d 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -431,8 +431,8 @@ function feL(m::LinearMixedModel) end """ - fit!(m::LinearMixedModel; progress::Bool=true, REML::Bool=false, - σ::Union{Real, Nothing}=nothing, + fit!(m::LinearMixedModel; progress::Bool=true, REML::Bool=m.optsum.REML, + σ::Union{Real, Nothing}=m.optsum.sigma, thin::Int=typemax(Int)) Optimize the objective of a `LinearMixedModel`. When `progress` is `true` a @@ -445,8 +445,8 @@ saved in `m.optsum.fitlog`. function StatsAPI.fit!( m::LinearMixedModel{T}; progress::Bool=true, - REML::Bool=false, - σ::Union{Real,Nothing}=nothing, + REML::Bool=m.optsum.REML, + σ::Union{Real,Nothing}=m.optsum.sigma, thin::Int=typemax(Int), ) where {T} optsum = m.optsum @@ -461,6 +461,7 @@ function StatsAPI.fit!( end opt = Opt(optsum) optsum.REML = REML + optsum.sigma = σ prog = ProgressUnknown(; desc="Minimizing", showspeed=true) # start from zero for the initial call to obj before optimization iter = 0 @@ -1341,7 +1342,7 @@ function varest(m::LinearMixedModel) return isnothing(m.optsum.sigma) ? pwrss(m) / ssqdenom(m) : m.optsum.sigma end -function StatsAPI.weights(m::LinearMixedModel{T}) where {T} +function StatsAPI.weights(m::LinearMixedModel) rtwts = m.sqrtwts - return isempty(rtwts) ? ones(T, nobs(m)) : abs2.(rtwts) + return isempty(rtwts) ? ones(eltype(rtwts), nobs(m)) : abs2.(rtwts) end From d22927828112b8f18155670ea0831253e6d3e387 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 13:42:22 -0500 Subject: [PATCH 07/13] simplify convenience constructors for OptSummary --- src/MixedModels.jl | 2 +- src/optsummary.jl | 72 +++++++++++++++------------------------------- 2 files changed, 24 insertions(+), 50 deletions(-) diff --git a/src/MixedModels.jl b/src/MixedModels.jl index 735b18581..231fdfcc5 100644 --- a/src/MixedModels.jl +++ b/src/MixedModels.jl @@ -19,7 +19,7 @@ using LinearAlgebra: ldiv!, lmul!, logdet, mul!, norm, normalize, normalize!, qr using LinearAlgebra: rank, rdiv!, rmul!, svd, tril! using Markdown: Markdown using MixedModelsDatasets: dataset, datasets -using NLopt: NLopt, Opt, ftol_abs, ftol_rel, initial_step, xtol_abs, xtol_rel +using NLopt: NLopt, Opt using PooledArrays: PooledArrays, PooledArray using PrecompileTools: PrecompileTools, @setup_workload, @compile_workload using ProgressMeter: ProgressMeter, Progress, ProgressUnknown, finish!, next! diff --git a/src/optsummary.jl b/src/optsummary.jl index e79fb4557..3f2c7b29f 100644 --- a/src/optsummary.jl +++ b/src/optsummary.jl @@ -31,63 +31,37 @@ The latter four fields are MixedModels functionality and not related directly to the future to use a different subtype of `AbstractVector` (e.g., `StaticArrays.SVector`) for each snapshot without being considered a breaking change. """ -mutable struct OptSummary{T<:AbstractFloat} +Base.@kwdef mutable struct OptSummary{T<:AbstractFloat} initial::Vector{T} lowerbd::Vector{T} - finitial::T - ftol_rel::T - ftol_abs::T - xtol_rel::T - xtol_abs::Vector{T} - initial_step::Vector{T} - maxfeval::Int - maxtime::T - feval::Int - final::Vector{T} - fmin::T - optimizer::Symbol - returnvalue::Symbol - nAGQ::Integer # don't really belong here but I needed a place to store them - REML::Bool - sigma::Union{T,Nothing} - fitlog::Vector{Tuple{Vector{T},T}} # not SVector because we would need to parameterize on size (which breaks GLMM) + finitial::T = T(Inf) + ftol_rel::T = zero(T) + ftol_abs::T = zero(T) + xtol_rel::T = zero(T) + xtol_abs::Vector{T} = zero(initial) .+ 1e-10 + initial_step::Vector{T} = T[] + maxfeval::Int = -1 + maxtime::T = T(-1) + feval::Int = -1 + final::Vector{T} = copy(initial) + fmin::T = T(Inf) + optimizer::Symbol = :LN_BOBYQA + returnvalue::Symbol = :FAILURE + ftol_zero_abs::T = T(0.001) + # not SVector because we would need to parameterize on size (which breaks GLMM) + fitlog::Vector{Tuple{Vector{T},T}} = [(initial, T(Inf))] + # don't really belong here but I needed a place to store them + nAGQ::Integer = 1 + REML::Bool = false + sigma::Union{T,Nothing} = nothing end function OptSummary( initial::Vector{T}, lowerbd::Vector{T}, - optimizer::Symbol; - ftol_rel::T=zero(T), - ftol_abs::T=zero(T), - xtol_rel::T=zero(T), - xtol_abs::Vector{T}=zero(initial) .+ 1e-10, - initial_step::Vector{T}=T[], - maxfeval=-1, - maxtime=T(-1), + optimizer::Symbol=:LN_BOBYQA; kwargs... ) where {T<:AbstractFloat} - fitlog = [(initial, T(Inf))] - - return OptSummary( - initial, - lowerbd, - T(Inf), - ftol_rel, - ftol_abs, - xtol_rel, - xtol_abs, - initial_step, - maxfeval, - maxtime, - -1, - copy(initial), - T(Inf), - optimizer, - :FAILURE, - 1, - false, - nothing, - fitlog, - ) + return OptSummary( ; initial, lowerbd, optimizer, kwargs...) end """ From f47fb4a2b292213c49d14f65e86ec43f14539008 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 14:54:02 -0500 Subject: [PATCH 08/13] fix use of type parameters in defaults --- NEWS.md | 1 + src/optsummary.jl | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/NEWS.md b/NEWS.md index ab1d3f430..186d8d556 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ MixedModels v4.24.2 Release Notes - Fix use of kwargs in `fit!((::LinearMixedModel)`: [#772] - 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] MixedModels v4.24.1 Release Notes ============================== diff --git a/src/optsummary.jl b/src/optsummary.jl index 3f2c7b29f..dc3c7bfe8 100644 --- a/src/optsummary.jl +++ b/src/optsummary.jl @@ -34,34 +34,37 @@ The latter four fields are MixedModels functionality and not related directly to Base.@kwdef mutable struct OptSummary{T<:AbstractFloat} initial::Vector{T} lowerbd::Vector{T} - finitial::T = T(Inf) - ftol_rel::T = zero(T) - ftol_abs::T = zero(T) - xtol_rel::T = zero(T) + # the @kwdef macro isn't quite smart enough for us to use the type parameter + # for the default values, but we can fake it + finitial::T = Inf * one(eltype(initial)) + ftol_rel::T = zero(eltype(initial)) + ftol_abs::T = zero(eltype(initial)) + xtol_rel::T = zero(eltype(initial)) xtol_abs::Vector{T} = zero(initial) .+ 1e-10 - initial_step::Vector{T} = T[] + initial_step::Vector{T} = empty(initial) maxfeval::Int = -1 - maxtime::T = T(-1) + maxtime::T = -one(eltype(initial)) feval::Int = -1 final::Vector{T} = copy(initial) - fmin::T = T(Inf) + fmin::T = Inf * one(eltype(initial)) optimizer::Symbol = :LN_BOBYQA returnvalue::Symbol = :FAILURE - ftol_zero_abs::T = T(0.001) + ftol_zero_abs::T = one(eltype(initial)) / 1000 # not SVector because we would need to parameterize on size (which breaks GLMM) - fitlog::Vector{Tuple{Vector{T},T}} = [(initial, T(Inf))] + fitlog::Vector{Tuple{Vector{T},T}} = [(initial, fmin)] # don't really belong here but I needed a place to store them - nAGQ::Integer = 1 + nAGQ::Int = 1 REML::Bool = false sigma::Union{T,Nothing} = nothing end function OptSummary( initial::Vector{T}, - lowerbd::Vector{T}, + lowerbd::Vector{S}, optimizer::Symbol=:LN_BOBYQA; kwargs... -) where {T<:AbstractFloat} - return OptSummary( ; initial, lowerbd, optimizer, kwargs...) +) where {T<:AbstractFloat, S<:AbstractFloat} + TS = promote_type(T, S) + return OptSummary{TS}( ; initial, lowerbd, optimizer, kwargs...) end """ From 822be0f6d6499f257614245604b309d098037111 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 14:56:28 -0500 Subject: [PATCH 09/13] NEWS --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 186d8d556..8e218aeef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -535,4 +535,5 @@ Package dependencies [#756]: https://github.com/JuliaStats/MixedModels.jl/issues/756 [#767]: https://github.com/JuliaStats/MixedModels.jl/issues/767 [#769]: https://github.com/JuliaStats/MixedModels.jl/issues/769 +[#772]: https://github.com/JuliaStats/MixedModels.jl/issues/772 [#773]: https://github.com/JuliaStats/MixedModels.jl/issues/773 From de68714bd7eda5a78ad2ea6008d6a3056860b05f Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 15:04:56 -0500 Subject: [PATCH 10/13] tweaks --- src/linearmixedmodel.jl | 2 +- src/optsummary.jl | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 3555ff90d..2b1951570 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -175,7 +175,7 @@ function LinearMixedModel( A, L = createAL(reterms, Xy) lbd = foldl(vcat, lowerbd(c) for c in reterms) θ = foldl(vcat, getθ(c) for c in reterms) - optsum = OptSummary(θ, lbd, :LN_BOBYQA; ftol_rel=T(1.0e-12), ftol_abs=T(1.0e-8)) + optsum = OptSummary(θ, lbd) optsum.sigma = isnothing(σ) ? nothing : T(σ) fill!(optsum.xtol_abs, 1.0e-10) return LinearMixedModel( diff --git a/src/optsummary.jl b/src/optsummary.jl index dc3c7bfe8..6f5065350 100644 --- a/src/optsummary.jl +++ b/src/optsummary.jl @@ -19,12 +19,13 @@ 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` +* `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 * `REML`: use the REML criterion for LMM fits * `sigma`: a priori value for the residual standard deviation for LMM -* `fitlog`: A vector of tuples of parameter and objectives values from steps in the optimization -The latter four fields are MixedModels functionality and not related directly to the `NLopt` package or algorithms. +The last three fields are MixedModels functionality and not related directly to the `NLopt` package or algorithms. !!! note The internal storage of the parameter values within `fitlog` may change in @@ -37,8 +38,8 @@ Base.@kwdef mutable struct OptSummary{T<:AbstractFloat} # the @kwdef macro isn't quite smart enough for us to use the type parameter # for the default values, but we can fake it finitial::T = Inf * one(eltype(initial)) - ftol_rel::T = zero(eltype(initial)) - ftol_abs::T = zero(eltype(initial)) + ftol_rel::T = eltype(initial)(1.0e-12) + ftol_abs::T = eltype(initial)(1.0e-8) xtol_rel::T = zero(eltype(initial)) xtol_abs::Vector{T} = zero(initial) .+ 1e-10 initial_step::Vector{T} = empty(initial) From 60cbed73b69cba4d3dcf17e87adee77f05b8a404 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 15:05:26 -0500 Subject: [PATCH 11/13] JuliaFormatter Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/optsummary.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/optsummary.jl b/src/optsummary.jl index dc3c7bfe8..74ab05e89 100644 --- a/src/optsummary.jl +++ b/src/optsummary.jl @@ -61,10 +61,10 @@ end function OptSummary( initial::Vector{T}, lowerbd::Vector{S}, - optimizer::Symbol=:LN_BOBYQA; kwargs... -) where {T<:AbstractFloat, S<:AbstractFloat} + optimizer::Symbol=:LN_BOBYQA; kwargs..., +) where {T<:AbstractFloat,S<:AbstractFloat} TS = promote_type(T, S) - return OptSummary{TS}( ; initial, lowerbd, optimizer, kwargs...) + return OptSummary{TS}(; initial, lowerbd, optimizer, kwargs...) end """ From 63264fe024a3b00245c39a5675b2679b64321ba9 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 15:15:37 -0500 Subject: [PATCH 12/13] abstract near-zero checks into configurable params --- NEWS.md | 1 + src/generalizedlinearmixedmodel.jl | 4 ++-- src/linearmixedmodel.jl | 4 ++-- src/optsummary.jl | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8e218aeef..964886040 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ============================== diff --git a/src/generalizedlinearmixedmodel.jl b/src/generalizedlinearmixedmodel.jl index 3e2125499..cfc06a778 100644 --- a/src/generalizedlinearmixedmodel.jl +++ b/src/generalizedlinearmixedmodel.jl @@ -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 diff --git a/src/linearmixedmodel.jl b/src/linearmixedmodel.jl index 2b1951570..14f297835 100644 --- a/src/linearmixedmodel.jl +++ b/src/linearmixedmodel.jl @@ -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 diff --git a/src/optsummary.jl b/src/optsummary.jl index 89a2b5f89..2ee69144c 100644 --- a/src/optsummary.jl +++ b/src/optsummary.jl @@ -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 @@ -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 From 33211b6ba23119d2254c33c3ac7a98edfdc6b988 Mon Sep 17 00:00:00 2001 From: Phillip Alday Date: Mon, 24 Jun 2024 15:17:53 -0500 Subject: [PATCH 13/13] technically we've added a feature.... --- NEWS.md | 2 +- Project.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 964886040..728e40fd7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -MixedModels v4.24.2 Release Notes +MixedModels v4.25 Release Notes ============================== - Add type notations in `pwrss(::LinearMixedModel)` and `logdet(::LinearMixedModel)` to enhance type inference. [#773] - Take advantage of type parameter for `StatsAPI.weights(::LinearMixedModel{T})`. [#772] diff --git a/Project.toml b/Project.toml index a602cbffb..9e02e7138 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "MixedModels" uuid = "ff71e718-51f3-5ec2-a782-8ffcbfa3c316" author = ["Phillip Alday ", "Douglas Bates ", "Jose Bayoan Santiago Calderon "] -version = "4.24.2" +version = "4.25.0" [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"