Skip to content

Commit f35505d

Browse files
Merge pull request #63 from LAMPSPUC/fix_cycle_decomposition
fix cycle decomposition for stochastic start > 0
2 parents 5e69ff9 + bd10714 commit f35505d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StateSpaceLearning"
22
uuid = "971c4b7c-2c4e-4bac-8525-e842df3cde7b"
33
authors = ["andreramosfc <[email protected]>"]
4-
version = "2.0.1"
4+
version = "2.0.2"
55

66
[deps]
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"

src/models/structural_model.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,13 +1226,17 @@ function get_cycle_decomposition(
12261226
end
12271227

12281228
for t in 2:T
1229-
ϕ_indexes =
1230-
max(2, model.stochastic_start):min(t, (T - max(1, model.ϕ_threshold)))
1231-
cycle[t] =
1232-
dot(c1, [cos(λ[t]), sin(λ[t])]) + sum(
1233-
ϕ_cos[i] * cos(λ[t]) + ϕ_sin[i] * sin(λ[t]) for
1234-
i in eachindex(ϕ_indexes)
1235-
)
1229+
if max(2, model.stochastic_start) <= min(t, (T - max(1, model.ϕ_threshold)))
1230+
ϕ_indexes =
1231+
max(2, model.stochastic_start):min(t, (T - max(1, model.ϕ_threshold)))
1232+
cycle[t] =
1233+
dot(c1, [cos(λ[t]), sin(λ[t])]) + sum(
1234+
ϕ_cos[i] * cos(λ[t]) + ϕ_sin[i] * sin(λ[t]) for
1235+
i in eachindex(ϕ_indexes)
1236+
)
1237+
else
1238+
cycle[t] = dot(c1, [cos(λ[t]), sin(λ[t])])
1239+
end
12361240
end
12371241

12381242
else

test/models/structural_model.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,23 @@ end
508508
model, model.output.components, slope
509509
)
510510
@test length(trend) == 10
511+
512+
model = StateSpaceLearning.StructuralModel(
513+
rand(100);
514+
cycle="stochastic",
515+
cycle_period=3,
516+
outlier=false,
517+
slope="stochastic",
518+
ζ_threshold=0,
519+
freq_seasonal=3,
520+
ω_threshold=0,
521+
ϕ_threshold=0,
522+
stochastic_start=30,
523+
)
524+
StateSpaceLearning.fit!(model)
525+
@test length(
526+
StateSpaceLearning.get_cycle_decomposition(model, model.output.components, 3)
527+
) == 100
511528
end
512529

513530
@testset "Function: simulate_states" begin

0 commit comments

Comments
 (0)