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.14"
version = "2.0.15"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
11 changes: 8 additions & 3 deletions src/models/structural_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,8 @@ end
- `steps_ahead::Int`: Steps ahead.
- `punctual::Bool`: Flag for considering punctual forecast.
- `seasonal_innovation_simulation::Int`: Flag for considering seasonal innovation simulation.
- `N_scenarios::Int`: Number of scenarios to simulate.
- `simulate_outliers::Bool`: Flag for considering outliers simulation.

# Returns
- `Vector{AbstractFloat}`: Vector of states.
Expand All @@ -1386,6 +1388,7 @@ function simulate_states(
punctual::Bool,
seasonal_innovation_simulation::Int,
N_scenarios::Int,
simulate_outliers::Bool,
)::Matrix{AbstractFloat}
T = length(model.y)

Expand Down Expand Up @@ -1659,7 +1662,7 @@ function simulate_states(
cycles_t = [zeros(N_scenarios) for _ in eachindex(model.cycle_period)]
end

outlier_t = if (model.outlier && !punctual)
outlier_t = if (simulate_outliers && model.outlier && !punctual)
stochastic_outliers_set[t - T, :]
else
zeros(N_scenarios)
Expand Down Expand Up @@ -1764,7 +1767,7 @@ function forecast(
Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, 0),
dynamic_exog_coefs_forecasts::Vector{<:Vector}=Vector{Vector}(undef, 0),
)::Vector{AbstractFloat} where {Fl<:AbstractFloat}
states_prediction = simulate_states(model, steps_ahead, true, 0, 1)[:, 1]
states_prediction = simulate_states(model, steps_ahead, true, 0, 1, false)[:, 1]

@assert size(Exogenous_Forecast, 1) == steps_ahead
@assert all(
Expand Down Expand Up @@ -1807,6 +1810,7 @@ end
- `Exogenous_Forecast::Matrix{Fl}`: Matrix of forecasts of exogenous variables.
- `dynamic_exog_coefs_forecasts::Vector{<:Vector}`: Vector of vectors of combination components forecasts.
- `seasonal_innovation_simulation::Int`: Number of seasonal innovation simulation.
- `simulate_outliers::Bool`: Flag to indicate whether to simulate outliers.
- `seed::Int`: Seed for the random number generator.

# Returns
Expand All @@ -1819,11 +1823,12 @@ function simulate(
Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, 0),
dynamic_exog_coefs_forecasts::Vector{<:Vector}=Vector{Vector}(undef, 0),
seasonal_innovation_simulation::Int=0,
simulate_outliers::Bool=true,
seed::Int=1234,
)::Matrix{AbstractFloat} where {Fl<:AbstractFloat}
Random.seed!(seed)
scenarios = simulate_states(
model, steps_ahead, false, seasonal_innovation_simulation, N_scenarios
model, steps_ahead, false, seasonal_innovation_simulation, N_scenarios, simulate_outliers
)

dynamic_exog_coefs_prediction = forecast_dynamic_exog_coefs(
Expand Down
12 changes: 6 additions & 6 deletions test/models/structural_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,17 @@ end
@testset "Function: simulate_states" begin
model = StateSpaceLearning.StructuralModel(rand(100))
StateSpaceLearning.fit!(model)
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1)) == 10
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1)) == 8
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1)) == 10
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1, true)) == 10
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1, true)) == 8
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1, true)) == 10

model = StateSpaceLearning.StructuralModel(
rand(100); seasonal="none", cycle="stochastic", cycle_period=3, outlier=false
)
StateSpaceLearning.fit!(model)
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1)) == 10
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1)) == 8
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1)) == 10
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1, true)) == 10
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1, true)) == 8
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1, true)) == 10
end

@testset "Function: forecast_dynamic_exog_coefs" begin
Expand Down
Loading