Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StateSpaceLearning"
uuid = "971c4b7c-2c4e-4bac-8525-e842df3cde7b"
authors = ["andreramosfc <[email protected]>"]
version = "2.0.3"
version = "2.0.4"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
35 changes: 21 additions & 14 deletions src/models/structural_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ function create_deterministic_cycle(
)::Matrix where {Fl<:AbstractFloat}
λ = 2 * pi * (1:T) / c_period
cycle1_matrix = hcat(cos.(λ), sin.(λ))
return cycle1_matrix
return round.(cycle1_matrix, digits=5)
end

"""
Expand Down Expand Up @@ -1500,24 +1500,31 @@ function simulate_states(
if model.cycle_period != 0
cycles_t = zeros(AbstractFloat, length(model.cycle_period))
for i in eachindex(model.cycle_period)
ϕ_cos = model.output.components["ϕ_$(model.cycle_period[i])"]["Coefs"][1:2:end]
ϕ_sin = model.output.components["ϕ_$(model.cycle_period[i])"]["Coefs"][2:2:end]
λ = 2 * pi * (1:(T + steps_ahead)) / model.cycle_period[i]

cycle_t =
dot(
if model.stochastic_cycle
ϕ_cos = model.output.components["ϕ_$(model.cycle_period[i])"]["Coefs"][1:2:end]
ϕ_sin = model.output.components["ϕ_$(model.cycle_period[i])"]["Coefs"][2:2:end]
cycle_t =
dot(
model.output.components["c1_$(model.cycle_period[i])"]["Coefs"],
[cos(λ[t]), sin(λ[t])],
) +
sum(
ϕ_cos[j] * cos(λ[t]) + ϕ_sin[j] * sin(λ[t]) for
j in eachindex(ϕ_cos)
) +
sum(
stochastic_cycles_cos_set[i][j] * cos(λ[t]) +
stochastic_cycles_sin_set[i][j] * sin(λ[t]) for
j in eachindex(stochastic_cycles_cos_set[i][1:(t - T)])
)
else
cycle_t = dot(
model.output.components["c1_$(model.cycle_period[i])"]["Coefs"],
[cos(λ[t]), sin(λ[t])],
) +
sum(
ϕ_cos[j] * cos(λ[t]) + ϕ_sin[j] * sin(λ[t]) for
j in eachindex(ϕ_cos)
) +
sum(
stochastic_cycles_cos_set[i][j] * cos(λ[t]) +
stochastic_cycles_sin_set[i][j] * sin(λ[t]) for
j in eachindex(stochastic_cycles_cos_set[i][1:(t - T)])
)
end
cycles_t[i] = cycle_t
end
else
Expand Down
14 changes: 14 additions & 0 deletions test/models/structural_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,20 @@ end
model6, 10, forecast_dynamic_exog_coefs
),
) == 10

model7 = StateSpaceLearning.StructuralModel(
y3; seasonal="none", cycle="deterministic", cycle_period=[12, 6, 4, 3, 12 / 5, 2]
)
StateSpaceLearning.fit!(model7)
forecast7 = trunc.(StateSpaceLearning.forecast(model7, 18); digits=3)
@test length(forecast7) == 18

model8 = StateSpaceLearning.StructuralModel(
y3; seasonal="none", cycle="stochastic", cycle_period=[12, 6, 4, 3, 12 / 5, 2]
)
StateSpaceLearning.fit!(model8)
forecast8 = trunc.(StateSpaceLearning.forecast(model8, 18); digits=3)
@test length(forecast8) == 18
end

@testset "Function: simulate" begin
Expand Down
Loading