Skip to content

Commit b3560d7

Browse files
author
andre_ramos
committed
add simulate outliers parameter
1 parent 9168747 commit b3560d7

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
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.14"
4+
version = "2.0.15"
55

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

src/models/structural_model.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,8 @@ end
13761376
- `steps_ahead::Int`: Steps ahead.
13771377
- `punctual::Bool`: Flag for considering punctual forecast.
13781378
- `seasonal_innovation_simulation::Int`: Flag for considering seasonal innovation simulation.
1379+
- `N_scenarios::Int`: Number of scenarios to simulate.
1380+
- `simulate_outliers::Bool`: Flag for considering outliers simulation.
13791381
13801382
# Returns
13811383
- `Vector{AbstractFloat}`: Vector of states.
@@ -1386,6 +1388,7 @@ function simulate_states(
13861388
punctual::Bool,
13871389
seasonal_innovation_simulation::Int,
13881390
N_scenarios::Int,
1391+
simulate_outliers::Bool,
13891392
)::Matrix{AbstractFloat}
13901393
T = length(model.y)
13911394

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

1662-
outlier_t = if (model.outlier && !punctual)
1665+
outlier_t = if (simulate_outliers && model.outlier && !punctual)
16631666
stochastic_outliers_set[t - T, :]
16641667
else
16651668
zeros(N_scenarios)
@@ -1764,7 +1767,7 @@ function forecast(
17641767
Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, 0),
17651768
dynamic_exog_coefs_forecasts::Vector{<:Vector}=Vector{Vector}(undef, 0),
17661769
)::Vector{AbstractFloat} where {Fl<:AbstractFloat}
1767-
states_prediction = simulate_states(model, steps_ahead, true, 0, 1)[:, 1]
1770+
states_prediction = simulate_states(model, steps_ahead, true, 0, 1, false)[:, 1]
17681771

17691772
@assert size(Exogenous_Forecast, 1) == steps_ahead
17701773
@assert all(
@@ -1807,6 +1810,7 @@ end
18071810
- `Exogenous_Forecast::Matrix{Fl}`: Matrix of forecasts of exogenous variables.
18081811
- `dynamic_exog_coefs_forecasts::Vector{<:Vector}`: Vector of vectors of combination components forecasts.
18091812
- `seasonal_innovation_simulation::Int`: Number of seasonal innovation simulation.
1813+
- `simulate_outliers::Bool`: Flag to indicate whether to simulate outliers.
18101814
- `seed::Int`: Seed for the random number generator.
18111815
18121816
# Returns
@@ -1819,11 +1823,12 @@ function simulate(
18191823
Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, 0),
18201824
dynamic_exog_coefs_forecasts::Vector{<:Vector}=Vector{Vector}(undef, 0),
18211825
seasonal_innovation_simulation::Int=0,
1826+
simulate_outliers::Bool=true,
18221827
seed::Int=1234,
18231828
)::Matrix{AbstractFloat} where {Fl<:AbstractFloat}
18241829
Random.seed!(seed)
18251830
scenarios = simulate_states(
1826-
model, steps_ahead, false, seasonal_innovation_simulation, N_scenarios
1831+
model, steps_ahead, false, seasonal_innovation_simulation, N_scenarios, simulate_outliers
18271832
)
18281833

18291834
dynamic_exog_coefs_prediction = forecast_dynamic_exog_coefs(

test/models/structural_model.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -552,17 +552,17 @@ end
552552
@testset "Function: simulate_states" begin
553553
model = StateSpaceLearning.StructuralModel(rand(100))
554554
StateSpaceLearning.fit!(model)
555-
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1)) == 10
556-
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1)) == 8
557-
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1)) == 10
555+
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1, true)) == 10
556+
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1, true)) == 8
557+
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1, true)) == 10
558558

559559
model = StateSpaceLearning.StructuralModel(
560560
rand(100); seasonal="none", cycle="stochastic", cycle_period=3, outlier=false
561561
)
562562
StateSpaceLearning.fit!(model)
563-
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1)) == 10
564-
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1)) == 8
565-
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1)) == 10
563+
@test length(StateSpaceLearning.simulate_states(model, 10, true, 12, 1, true)) == 10
564+
@test length(StateSpaceLearning.simulate_states(model, 8, false, 12, 1, true)) == 8
565+
@test length(StateSpaceLearning.simulate_states(model, 10, false, 0, 1, true)) == 10
566566
end
567567

568568
@testset "Function: forecast_dynamic_exog_coefs" begin

0 commit comments

Comments
 (0)