Skip to content

Commit 800a1d5

Browse files
author
andre_ramos
committed
blue format
1 parent 483666a commit 800a1d5

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

ext/PlotsExt.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function StateSpaceLearning.plot_point_forecast(y::Vector, prediction::Vector)
88
T = length(y)
99
steps_ahead = length(prediction)
1010
p = plot(collect(1:T), y; w=2, color="Black", lab="Historical", legend=:outerbottom)
11-
plot!(collect(T+1:T+steps_ahead), prediction; lab="Forecast", w=2, color="blue")
11+
plot!(collect((T + 1):(T + steps_ahead)), prediction; lab="Forecast", w=2, color="blue")
1212
return p
1313
end
1414

@@ -17,10 +17,18 @@ function StateSpaceLearning.plot_scenarios(y::Vector, simulation::Matrix)
1717
steps_ahead, n_scenarios = size(simulation)
1818
p = plot(collect(1:T), y; w=2, color="Black", lab="Historical", legend=:outerbottom)
1919
for s in 1:(n_scenarios - 1)
20-
plot!(collect(T+1:T+steps_ahead), simulation[:, s]; lab="", α=0.1, color="red")
20+
plot!(
21+
collect((T + 1):(T + steps_ahead)), simulation[:, s]; lab="", α=0.1, color="red"
22+
)
2123
end
22-
plot!(collect(T+1:T+steps_ahead), simulation[:, n_scenarios]; lab="Scenarios Paths", α=0.1, color="red")
24+
plot!(
25+
collect((T + 1):(T + steps_ahead)),
26+
simulation[:, n_scenarios];
27+
lab="Scenarios Paths",
28+
α=0.1,
29+
color="red",
30+
)
2331
return p
2432
end
2533

26-
end
34+
end

src/estimation_procedure.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ function estimation_procedure(
326326
for key in keys(components_indexes)
327327
if key != "initial_states" && key != "μ1"
328328
component = components_indexes[key]
329-
if key != "Exogenous_X" && key != "o" && !(key in ["ν1"]) && !(occursin("γ", key))
329+
if key != "Exogenous_X" &&
330+
key != "o" &&
331+
!(key in ["ν1"]) &&
332+
!(occursin("γ", key))
330333
κ = count(i -> i != 0, coefs[component]) < 1 ? 0 : std(coefs[component])
331334
if hasintercept
332335
ts_penalty_factor[component .- 1] .= (1 /+ ϵ))

src/models/structural_model.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mutable struct StructuralModel <: StateSpaceLearningModel
5858
stochastic_trend::Bool
5959
seasonal::Bool
6060
stochastic_seasonal::Bool
61-
freq_seasonal::Union{Int, Vector{Int}}
61+
freq_seasonal::Union{Int,Vector{Int}}
6262
outlier::Bool
6363
ζ_ω_threshold::Int
6464
n_exogenous::Int
@@ -72,7 +72,7 @@ mutable struct StructuralModel <: StateSpaceLearningModel
7272
stochastic_trend::Bool=true,
7373
seasonal::Bool=true,
7474
stochastic_seasonal::Bool=true,
75-
freq_seasonal::Union{Int, Vector{Int}}=12,
75+
freq_seasonal::Union{Int,Vector{Int}}=12,
7676
outlier::Bool=true,
7777
ζ_ω_threshold::Int=12,
7878
Exogenous_X::Matrix=if typeof(y) <: Vector
@@ -261,7 +261,12 @@ end
261261
262262
"""
263263
function create_initial_states_Matrix(
264-
T::Int, freq_seasonal::Union{Int, Vector{Int}}, steps_ahead::Int, level::Bool, trend::Bool, seasonal::Bool
264+
T::Int,
265+
freq_seasonal::Union{Int,Vector{Int}},
266+
steps_ahead::Int,
267+
level::Bool,
268+
trend::Bool,
269+
seasonal::Bool,
265270
)::Matrix
266271
initial_states_matrix = zeros(T + steps_ahead, 0)
267272
if level
@@ -332,7 +337,7 @@ function create_X(
332337
stochastic_trend::Bool,
333338
seasonal::Bool,
334339
stochastic_seasonal::Bool,
335-
freq_seasonal::Union{Int, Vector{Int}},
340+
freq_seasonal::Union{Int,Vector{Int}},
336341
outlier::Bool,
337342
ζ_ω_threshold::Int,
338343
Exogenous_X::Matrix{Fl},
@@ -435,9 +440,7 @@ function get_components_indexes(model::StructuralModel)::Dict
435440
if model.stochastic_seasonal
436441
for s in model.freq_seasonal
437442
ω_s_indexes = collect(
438-
(FINAL_INDEX + 1):(FINAL_INDEX + ω_size(
439-
T, s, model.ζ_ω_threshold
440-
)),
443+
(FINAL_INDEX + 1):(FINAL_INDEX + ω_size(T, s, model.ζ_ω_threshold))
441444
)
442445
FINAL_INDEX += length(ω_s_indexes)
443446
push!(ω_indexes, ω_s_indexes)

test/models/structural_model.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ end
360360
stochastic_trend=true,
361361
seasonal=true,
362362
stochastic_seasonal=true,
363-
freq_seasonal=[2,5],
363+
freq_seasonal=[2, 5],
364364
outlier=true,
365365
ζ_ω_threshold=0,
366366
Exogenous_X=Exogenous_X2,
@@ -394,7 +394,9 @@ end
394394

395395
models = [Basic_Structural, Basic_Structural2, Local_Level, Local_Linear_Trend]
396396

397-
params_vec = [["ξ", "ζ", "ω_2", "ε"], ["ξ", "ζ", "ω_2", "ω_5", "ε"], ["ξ", "ε"], ["ξ", "ζ", "ε"]]
397+
params_vec = [
398+
["ξ", "ζ", "ω_2", "ε"], ["ξ", "ζ", "ω_2", "ω_5", "ε"], ["ξ", "ε"], ["ξ", "ζ", "ε"]
399+
]
398400

399401
for idx in eachindex(models)
400402
model = models[idx]
@@ -467,15 +469,17 @@ end
467469
stochastic_trend=false,
468470
seasonal=true,
469471
stochastic_seasonal=true,
470-
freq_seasonal=[2,5],
472+
freq_seasonal=[2, 5],
471473
outlier=true,
472474
ζ_ω_threshold=0,
473475
Exogenous_X=zeros(10, 0),
474476
)
475477

476478
models = [model1, model2, model3, model4]
477479

478-
keys_vec = [["ξ", "ζ", "ω_2"], ["ζ", "ω_2"], ["ξ", "ω_2"], ["ξ", "ζ"], ["ξ", "ω_2", "ω_5"]]
480+
keys_vec = [
481+
["ξ", "ζ", "ω_2"], ["ζ", "ω_2"], ["ξ", "ω_2"], ["ξ", "ζ"], ["ξ", "ω_2", "ω_5"]
482+
]
479483

480484
for idx in eachindex(models)
481485
model = models[idx]

0 commit comments

Comments
 (0)