From 6a09838fa9f42fbad0e49a4a00ad3721b132b45a Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 16 Nov 2023 04:43:55 -0600 Subject: [PATCH 1/2] Add `rtol` convergence criterion Converging based on an absolute tolerance implies that you know something about what to expect for the range of log-likelihoods. In cases where the ground truth may not be known, it can be useful to allow termination based on improvement that is small *relative* to the log-likelihood. --- src/classic_em.jl | 11 +++++++---- src/fit_em.jl | 9 ++++++--- src/stochastic_em.jl | 24 ++++++++++++++---------- test/runtests.jl | 30 ++++++++++++++++++++++++++++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/classic_em.jl b/src/classic_em.jl index 9a02929..ffe5aee 100644 --- a/src/classic_em.jl +++ b/src/classic_em.jl @@ -5,10 +5,11 @@ The EM algorithm was introduced by A. P. Dempster, N. M. Laird and D. B. Rubin i struct ClassicEM <: AbstractEM end """ - fit_mle!(α::AbstractVector, dists::AbstractVector{F} where {F<:Distribution}, y::AbstractVecOrMat, method::ClassicEM; display=:none, maxiter=1000, atol=1e-3, robust=false) + fit_mle!(α::AbstractVector, dists::AbstractVector{F} where {F<:Distribution}, y::AbstractVecOrMat, method::ClassicEM; display=:none, maxiter=1000, atol=1e-3, rtol=nothing, robust=false) Use the EM algorithm to update the Distribution `dists` and weights `α` composing a mixture distribution. - `robust = true` will prevent the (log)likelihood to overflow to `-∞` or `∞`. -- `atol` criteria determining the convergence of the algorithm. If the Loglikelihood difference between two iteration `i` and `i+1` is smaller than `atol` i.e. `|ℓ⁽ⁱ⁺¹⁾ - ℓ⁽ⁱ⁾| Date: Thu, 16 Nov 2023 05:05:25 -0600 Subject: [PATCH 2/2] Add a couple missing rtols in docstrings --- src/fit_em.jl | 7 +++++-- src/stochastic_em.jl | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/fit_em.jl b/src/fit_em.jl index 861a068..53aecb7 100644 --- a/src/fit_em.jl +++ b/src/fit_em.jl @@ -1,5 +1,5 @@ """ - fit_mle(mix::MixtureModel, y::AbstractVecOrMat, weights...; method = ClassicEM(), display=:none, maxiter=1000, atol=1e-3, robust=false, infos=false) + fit_mle(mix::MixtureModel, y::AbstractVecOrMat, weights...; method = ClassicEM(), display=:none, maxiter=1000, atol=1e-3, rtol=nothing, robust=false, infos=false) Use the an Expectation Maximization (EM) algorithm to maximize the Loglikelihood (fit) the mixture with an i.i.d sample `y`. The `mix` input is a mixture that is used to initilize the EM algorithm. - `weights` when provided, it will compute a weighted version of the EM. (Useful for fitting mixture of mixtures) @@ -7,6 +7,7 @@ The `mix` input is a mixture that is used to initilize the EM algorithm. - `infos = true` returns a `Dict` with informations on the algorithm (converged, iteration number, loglikelihood). - `robust = true` will prevent the (log)likelihood to overflow to `-∞` or `∞`. - `atol` criteria determining the convergence of the algorithm. If the Loglikelihood difference between two iteration `i` and `i+1` is smaller than `atol` i.e. `|ℓ⁽ⁱ⁺¹⁾ - ℓ⁽ⁱ⁾|