diff --git a/Project.toml b/Project.toml index 422a93d..22b9080 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "StateSpaceLearning" uuid = "971c4b7c-2c4e-4bac-8525-e842df3cde7b" authors = ["andreramosfc "] -version = "2.0.1" +version = "2.0.2" [deps] Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" diff --git a/src/models/structural_model.jl b/src/models/structural_model.jl index 4fe890c..3abb8ed 100644 --- a/src/models/structural_model.jl +++ b/src/models/structural_model.jl @@ -1226,13 +1226,17 @@ function get_cycle_decomposition( end for t in 2:T - ϕ_indexes = - max(2, model.stochastic_start):min(t, (T - max(1, model.ϕ_threshold))) - cycle[t] = - dot(c1, [cos(λ[t]), sin(λ[t])]) + sum( - ϕ_cos[i] * cos(λ[t]) + ϕ_sin[i] * sin(λ[t]) for - i in eachindex(ϕ_indexes) - ) + if max(2, model.stochastic_start) <= min(t, (T - max(1, model.ϕ_threshold))) + ϕ_indexes = + max(2, model.stochastic_start):min(t, (T - max(1, model.ϕ_threshold))) + cycle[t] = + dot(c1, [cos(λ[t]), sin(λ[t])]) + sum( + ϕ_cos[i] * cos(λ[t]) + ϕ_sin[i] * sin(λ[t]) for + i in eachindex(ϕ_indexes) + ) + else + cycle[t] = dot(c1, [cos(λ[t]), sin(λ[t])]) + end end else diff --git a/test/models/structural_model.jl b/test/models/structural_model.jl index becdbe4..9b7278c 100644 --- a/test/models/structural_model.jl +++ b/test/models/structural_model.jl @@ -508,6 +508,23 @@ end model, model.output.components, slope ) @test length(trend) == 10 + + model = StateSpaceLearning.StructuralModel( + rand(100); + cycle="stochastic", + cycle_period=3, + outlier=false, + slope="stochastic", + ζ_threshold=0, + freq_seasonal=3, + ω_threshold=0, + ϕ_threshold=0, + stochastic_start=30, + ) + StateSpaceLearning.fit!(model) + @test length( + StateSpaceLearning.get_cycle_decomposition(model, model.output.components, 3) + ) == 100 end @testset "Function: simulate_states" begin