From 3f51d8159065a646098b438c43b5130fd2c64425 Mon Sep 17 00:00:00 2001 From: Quint Wiersma Date: Mon, 13 May 2024 11:36:43 +0200 Subject: [PATCH] Update stopping criteria of the solver --- src/fit/solver.jl | 18 +++++------------- src/interface.jl | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/fit/solver.jl b/src/fit/solver.jl index 2ad47a3..361041c 100644 --- a/src/fit/solver.jl +++ b/src/fit/solver.jl @@ -10,7 +10,7 @@ solver.jl =# """ - update!(model) + update!(model, regularizer) Update parameters of dynamic factor model `model` using an expectation-maximization (EM) solve w/ regularization term given by @@ -89,9 +89,7 @@ function update_loadings!( return (0.5 * dot(ΩΛ, Λ * Eff) - dot(ΩΛ, Eyf)) / length(V) end - ffb = FastForwardBackward( - stop=(iter, state) -> norm(state.res, Inf) < 1e-4 - ) + ffb = FastForwardBackward(maxit=1_000, tol=1e-4) (solution, _) = ffb(x0=loadings(F), f=objective, g=regularizer) loadings(F) .= solution @@ -224,9 +222,7 @@ function update!(μ::Exogenous, y::AbstractMatrix, Σ::AbstractMatrix, regulariz return (0.5 * dot(Ωβ, β * XX) - dot(Ωβ, yX)) / size(regressors(μ), 2) end - ffb = FastForwardBackward( - stop=(iter, state) -> norm(state.res, Inf) < 1e-4 - ) + ffb = FastForwardBackward(maxit=1_000, tol=1e-4) (solution, _) = ffb(x0=slopes(μ), f=objective, g=regularizer) slopes(μ) .= solution @@ -305,9 +301,7 @@ function update!(ε::SpatialAutoregression, Λ::AbstractMatrix, V::AbstractVecto return -logdet(G) + 0.5 * dot(Ω, Eee) / size(resid(ε), 2) end - ffb = FastForwardBackward( - stop=(iter, state) -> norm(state.res, Inf) < 1e-4 - ) + ffb = FastForwardBackward(maxit=1_000, tol=1e-4) (solution, _) = ffb(x0=logit.((spatial(ε) .+ offset) ./ scale), f=objective, g=regularizer) spatial(ε) .= scale .* logistic.(solution) .- offset @@ -370,9 +364,7 @@ function update!(ε::SpatialMovingAverage, Λ::AbstractMatrix, V::AbstractVector return logdet(G) + 0.5 * tr(Σ \ Eee) / size(resid(ε), 2) end - ffb = FastForwardBackward( - stop=(iter, state) -> norm(state.res, Inf) < 1e-4 - ) + ffb = FastForwardBackward(maxit=1_000, tol=1e-4) (solution, _) = ffb(x0=logit.((spatial(ε) .+ offset) ./ scale), f=objective, g=regularizer) spatial(ε) .= scale .* logistic.(solution) .- offset diff --git a/src/interface.jl b/src/interface.jl index 789e8e0..b1604f7 100644 --- a/src/interface.jl +++ b/src/interface.jl @@ -200,7 +200,7 @@ function fit!( regularizer::NamedTuple=(factors=nothing, mean=nothing, error=nothing), init_method::NamedTuple=(factors=:data, mean=:data, error=:data), ϵ::AbstractFloat=1e-4, - max_iter::Integer=1000, + max_iter::Integer=1_000, verbose::Bool=false ) keys(regularizer) ⊇ (:factors, :mean, :error) || error("regularizer must be a NamedTuple with keys :factors, :mean, and :error.")