Skip to content

Commit 20741ed

Browse files
author
andre_ramos
committed
fix tests and format
1 parent 08f3eb6 commit 20741ed

File tree

7 files changed

+714
-309
lines changed

7 files changed

+714
-309
lines changed

src/StateSpaceLearning.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ include("datasets.jl")
1313
include("fit_forecast.jl")
1414
include("plots.jl")
1515

16-
export fit!, forecast, simulate, StructuralModel, plot_point_forecast, plot_scenarios, simulate_states
16+
export fit!,
17+
forecast,
18+
simulate,
19+
StructuralModel,
20+
plot_point_forecast,
21+
plot_scenarios,
22+
simulate_states
1723

1824
end # module StateSpaceLearning

src/fit_forecast.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function fit!(
6868

6969
decomposition = get_model_decomposition(model, components)
7070

71-
model.output = Output(
71+
return model.output = Output(
7272
coefs, ε, fitted, residuals_variances, valid_indexes, components, decomposition
7373
)
74-
7574
end

src/models/structural_model.jl

Lines changed: 380 additions & 112 deletions
Large diffs are not rendered by default.

src/utils.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ function build_components(
2929
X[:, components_indexes[key]] * coefs[components_indexes[key]]
3030
end
3131
if haskey(components, "exog")
32-
components["exog"]["Selected"] = findall(
33-
i -> i != 0, components["exog"]["Coefs"]
34-
)
32+
components["exog"]["Selected"] = findall(i -> i != 0, components["exog"]["Coefs"])
3533
end
3634
return components
3735
end
@@ -134,14 +132,21 @@ get_stochastic_values(estimated_stochastic::Vector{Fl}, steps_ahead::Int, T::Int
134132
# Returns
135133
- `Vector{AbstractFloat}`: Vector of stochastic seasonal values.
136134
"""
137-
function get_stochastic_values(estimated_stochastic::Vector{Fl}, steps_ahead::Int, T::Int, start_idx::Int, final_idx::Int, seasonal_innovation_simulation::Int)::Vector{AbstractFloat} where {Fl<:AbstractFloat}
138-
135+
function get_stochastic_values(
136+
estimated_stochastic::Vector{Fl},
137+
steps_ahead::Int,
138+
T::Int,
139+
start_idx::Int,
140+
final_idx::Int,
141+
seasonal_innovation_simulation::Int,
142+
)::Vector{AbstractFloat} where {Fl<:AbstractFloat}
139143
if seasonal_innovation_simulation != 0
140144
stochastic_term = Vector{AbstractFloat}(undef, steps_ahead)
141145
for t in 1:steps_ahead
142146

143147
# Generate potential seasonal indices
144-
seasonal_indices = (T + t) % seasonal_innovation_simulation : seasonal_innovation_simulation : T
148+
seasonal_indices =
149+
((T + t) % seasonal_innovation_simulation):seasonal_innovation_simulation:T
145150

146151
# Filter indices to be within the valid range
147152
valid_indices = filter(idx -> start_idx <= idx <= final_idx, seasonal_indices)
@@ -150,9 +155,9 @@ function get_stochastic_values(estimated_stochastic::Vector{Fl}, steps_ahead::In
150155
stochastic_term[t] = rand(estimated_stochastic[valid_indices]) * rand([1, -1])
151156
end
152157
else
153-
stochastic_term = rand(estimated_stochastic, steps_ahead) .* rand([1, -1], steps_ahead)
158+
stochastic_term =
159+
rand(estimated_stochastic, steps_ahead) .* rand([1, -1], steps_ahead)
154160
end
155161

156162
return stochastic_term
157-
158163
end

test/fit_forecast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
@test length(model2.output.residuals_variances) == 4
2525
@test length(keys(model2.output.components)) == 10
2626
@test length(keys(model2.output.decomposition)) == 3
27-
end
27+
end

0 commit comments

Comments
 (0)