@@ -79,14 +79,9 @@ function update_loadings!(F::AbstractUnrestrictedFactorProcess, y::AbstractMatri
7979
8080 return (0.5 * dot (ΩΛ, Λ * Eff) - dot (ΩΛ, Eyf)) / length (V)
8181 end
82- function gradient! (∇:: AbstractMatrix , Λ:: AbstractMatrix )
83- ∇ .= Σ \ (Λ * Eff - Eyf)
84- ∇ ./= length (V)
85-
86- return nothing
87- end
88- f = ObjectiveGradientWrapper (objective, gradient!)
89- ffb = FastForwardBackward (maxit = 100 , tol = 1e-2 )
82+ gradient (Λ:: AbstractMatrix ) = (Σ \ (Λ * Eff - Eyf)) ./ length (V)
83+ f = ObjectiveGradientWrapper (objective, gradient)
84+ ffb = ProximalAlgorithms. FastForwardBackward (maxit = 1000 , tol = 1e-4 )
9085 (solution, _) = ffb (x0 = loadings (F), f = f, g = regularizer)
9186 loadings (F) .= solution
9287
@@ -220,14 +215,9 @@ function update!(μ::Exogenous, y::AbstractMatrix, Σ::AbstractMatrix, regulariz
220215
221216 return (0.5 * dot (Ωβ, β * XX) - dot (Ωβ, yX)) / size (regressors (μ), 2 )
222217 end
223- function gradient! (∇:: AbstractMatrix , β:: AbstractMatrix )
224- ∇ .= Σ \ (β * XX - yX)
225- ∇ ./= size (regressors (μ), 2 )
226-
227- return nothing
228- end
229- f = ObjectiveGradientWrapper (objective, gradient!)
230- ffb = FastForwardBackward (maxit = 100 , tol = 1e-2 )
218+ gradient (β:: AbstractMatrix ) = (Σ \ (β * XX - yX)) ./ size (regressors (μ), 2 )
219+ f = ObjectiveGradientWrapper (objective, gradient)
220+ ffb = ProximalAlgorithms. FastForwardBackward (maxit = 1000 , tol = 1e-4 )
231221 (solution, _) = ffb (x0 = slopes (μ), f = f, g = regularizer)
232222 slopes (μ) .= solution
233223
@@ -274,7 +264,7 @@ function update!(ε::SpatialAutoregression, e::AbstractMatrix, Λ::AbstractMatri
274264
275265 return - logdet (G) + 0.5 * dot (Ω, Eee) / size (e, 2 )
276266 end
277- opt = optimize (objective, logit .((spatial (ε) .+ offset) ./ scale), ConjugateGradient (),
267+ opt = optimize (objective, logit .((spatial (ε) .+ offset) ./ scale), LBFGS (),
278268 Optim. Options (g_tol = 1e-4 ))
279269 spatial (ε) .= scale .* logistic .(Optim. minimizer (opt)) .- offset
280270
@@ -302,9 +292,8 @@ function update!(ε::SpatialAutoregression, e::AbstractMatrix, Λ::AbstractMatri
302292
303293 return - logdet (G) + 0.5 * dot (Ω, Eee) / size (e, 2 )
304294 end
305- cache = FiniteDiff. GradientCache (copy (spatial (ε)), copy (spatial (ε)))
306- f = ObjectiveWrapper (objective, cache)
307- ffb = FastForwardBackward (maxit = 100 , tol = 1e-2 )
295+ f = ProximalAlgorithms. AutoDifferentiable (objective, AutoFiniteDiff ())
296+ ffb = ProximalAlgorithms. FastForwardBackward (maxit = 1000 , tol = 1e-4 )
308297 (solution, _) = ffb (x0 = logit .((spatial (ε) .+ offset) ./ scale), f = f,
309298 g = regularizer)
310299 spatial (ε) .= scale .* logistic .(solution) .- offset
@@ -333,7 +322,7 @@ function update!(ε::SpatialMovingAverage, e::AbstractMatrix, Λ::AbstractMatrix
333322
334323 return logdet (G) + 0.5 * tr (Σ \ Eee) / size (e, 2 )
335324 end
336- opt = optimize (objective, logit .((spatial (ε) .+ offset) ./ scale), ConjugateGradient (),
325+ opt = optimize (objective, logit .((spatial (ε) .+ offset) ./ scale), LBFGS (),
337326 Optim. Options (g_tol = 1e-4 ))
338327 spatial (ε) .= scale .* logistic .(Optim. minimizer (opt)) .- offset
339328
@@ -361,9 +350,8 @@ function update!(ε::SpatialMovingAverage, e::AbstractMatrix, Λ::AbstractMatrix
361350
362351 return logdet (G) + 0.5 * tr (Σ \ Eee) / size (e, 2 )
363352 end
364- cache = FiniteDiff. GradientCache (copy (spatial (ε)), copy (spatial (ε)))
365- f = ObjectiveWrapper (objective, cache)
366- ffb = FastForwardBackward (maxit = 100 , tol = 1e-2 )
353+ f = ProximalAlgorithms. AutoDifferentiable (objective, AutoFiniteDiff ())
354+ ffb = ProximalAlgorithms. FastForwardBackward (maxit = 1000 , tol = 1e-4 )
367355 (solution, _) = ffb (x0 = logit .((spatial (ε) .+ offset) ./ scale), f = f,
368356 g = regularizer)
369357 spatial (ε) .= scale .* logistic .(solution) .- offset
0 commit comments