Skip to content

Commit

Permalink
Update stopping criteria of the solver
Browse files Browse the repository at this point in the history
  • Loading branch information
qntwrsm committed May 13, 2024
1 parent 1ac5d51 commit 3f51d81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions src/fit/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down

0 comments on commit 3f51d81

Please sign in to comment.