1
1
"""
2
- ξ_size(T::Int64 )::Int64
2
+ ξ_size(T::Int )::Int
3
3
4
4
Calculates the size of ξ innovation matrix based on the input T.
5
5
6
6
# Arguments
7
- - `T::Int64 `: Length of the original time series.
7
+ - `T::Int `: Length of the original time series.
8
8
9
9
# Returns
10
- - `Int64 `: Size of ξ calculated from T.
10
+ - `Int `: Size of ξ calculated from T.
11
11
12
12
"""
13
- ξ_size (T:: Int64 ):: Int64 = T - 2
13
+ ξ_size (T:: Int ):: Int = T - 2
14
14
15
15
"""
16
- ζ_size(T::Int64 , ζ_ω_threshold::Int64 )::Int64
16
+ ζ_size(T::Int , ζ_ω_threshold::Int )::Int
17
17
18
18
Calculates the size of ζ innovation matrix based on the input T.
19
19
20
20
# Arguments
21
- - `T::Int64 `: Length of the original time series.
22
- - `ζ_ω_threshold::Int64 `: Stabilize parameter ζ.
21
+ - `T::Int `: Length of the original time series.
22
+ - `ζ_ω_threshold::Int `: Stabilize parameter ζ.
23
23
24
24
# Returns
25
- - `Int64 `: Size of ζ calculated from T.
25
+ - `Int `: Size of ζ calculated from T.
26
26
27
27
"""
28
- ζ_size (T:: Int64 , ζ_ω_threshold:: Int64 ):: Int64 = T- ζ_ω_threshold- 2
28
+ ζ_size (T:: Int , ζ_ω_threshold:: Int ):: Int = T- ζ_ω_threshold- 2
29
29
30
30
"""
31
- ω_size(T::Int64 , s::Int64 )::Int64
31
+ ω_size(T::Int , s::Int )::Int
32
32
33
33
Calculates the size of ω innovation matrix based on the input T.
34
34
35
35
# Arguments
36
- - `T::Int64 `: Length of the original time series.
37
- - `s::Int64 `: Seasonal period.
36
+ - `T::Int `: Length of the original time series.
37
+ - `s::Int `: Seasonal period.
38
38
39
39
# Returns
40
- - `Int64 `: Size of ω calculated from T.
40
+ - `Int `: Size of ω calculated from T.
41
41
42
42
"""
43
- ω_size (T:: Int64 , s:: Int64 , ζ_ω_threshold:: Int64 ):: Int64 = T - ζ_ω_threshold - s + 1
43
+ ω_size (T:: Int , s:: Int , ζ_ω_threshold:: Int ):: Int = T - ζ_ω_threshold - s + 1
44
44
45
45
"""
46
- create_ξ(T::Int64 , steps_ahead::Int64 )::Matrix
46
+ create_ξ(T::Int , steps_ahead::Int )::Matrix
47
47
48
48
Creates a matrix of innovations ξ based on the input sizes, and the desired steps ahead (this is necessary for the forecast function)
49
49
50
50
# Arguments
51
- - `T::Int64 `: Length of the original time series.
52
- - `steps_ahead::Int64 `: Number of steps ahead (for estimation purposes this should be set at 0).
51
+ - `T::Int `: Length of the original time series.
52
+ - `steps_ahead::Int `: Number of steps ahead (for estimation purposes this should be set at 0).
53
53
54
54
# Returns
55
55
- `Matrix`: Matrix of innovations ξ constructed based on the input sizes.
56
56
57
57
"""
58
- function create_ξ (T:: Int64 , steps_ahead:: Int64 ):: Matrix
58
+ function create_ξ (T:: Int , steps_ahead:: Int ):: Matrix
59
59
ξ_matrix = Matrix {Float64} (undef, T+ steps_ahead, T - 1 )
60
60
for t in 1 : T+ steps_ahead
61
61
ξ_matrix[t, :] = t < T ? vcat (ones (t- 1 ), zeros (T- t)) : ones (T- 1 )
@@ -65,20 +65,20 @@ function create_ξ(T::Int64, steps_ahead::Int64)::Matrix
65
65
end
66
66
67
67
"""
68
- create_ζ(T::Int64 , steps_ahead::Int64 , ζ_ω_threshold::Int64 )::Matrix
68
+ create_ζ(T::Int , steps_ahead::Int , ζ_ω_threshold::Int )::Matrix
69
69
70
70
Creates a matrix of innovations ζ based on the input sizes, and the desired steps ahead (this is necessary for the forecast function).
71
71
72
72
# Arguments
73
- - `T::Int64 `: Length of the original time series.
74
- - `steps_ahead::Int64 `: Number of steps ahead (for estimation purposes this should be set at 0).
75
- - `ζ_ω_threshold::Int64 `: Stabilize parameter ζ.
73
+ - `T::Int `: Length of the original time series.
74
+ - `steps_ahead::Int `: Number of steps ahead (for estimation purposes this should be set at 0).
75
+ - `ζ_ω_threshold::Int `: Stabilize parameter ζ.
76
76
77
77
# Returns
78
78
- `Matrix`: Matrix of innovations ζ constructed based on the input sizes.
79
79
80
80
"""
81
- function create_ζ (T:: Int64 , steps_ahead:: Int64 , ζ_ω_threshold:: Int64 ):: Matrix
81
+ function create_ζ (T:: Int , steps_ahead:: Int , ζ_ω_threshold:: Int ):: Matrix
82
82
ζ_matrix = Matrix {Float64} (undef, T+ steps_ahead, T - 2 )
83
83
for t in 1 : T+ steps_ahead
84
84
ζ_matrix[t, :] = t < T ? vcat (collect (t- 2 : - 1 : 1 ), zeros (T- 2 - length (collect (t- 2 : - 1 : 1 )))) : collect (t- 2 : - 1 : t- T+ 1 )
@@ -87,25 +87,25 @@ function create_ζ(T::Int64, steps_ahead::Int64, ζ_ω_threshold::Int64)::Matrix
87
87
end
88
88
89
89
"""
90
- create_ω(T::Int64 , s::Int64 , steps_ahead::Int64 )::Matrix
90
+ create_ω(T::Int , s::Int , steps_ahead::Int )::Matrix
91
91
92
92
Creates a matrix of innovations ω based on the input sizes, and the desired steps ahead (this is necessary for the forecast function).
93
93
94
94
# Arguments
95
- - `T::Int64 `: Length of the original time series.
96
- - `freq_seasonal::Int64 `: Seasonal period.
97
- - `steps_ahead::Int64 `: Number of steps ahead (for estimation purposes this should be set at 0).
95
+ - `T::Int `: Length of the original time series.
96
+ - `freq_seasonal::Int `: Seasonal period.
97
+ - `steps_ahead::Int `: Number of steps ahead (for estimation purposes this should be set at 0).
98
98
99
99
# Returns
100
100
- `Matrix`: Matrix of innovations ω constructed based on the input sizes.
101
101
102
102
"""
103
- function create_ω (T:: Int64 , freq_seasonal:: Int64 , steps_ahead:: Int64 , ζ_ω_threshold:: Int64 ):: Matrix
103
+ function create_ω (T:: Int , freq_seasonal:: Int , steps_ahead:: Int , ζ_ω_threshold:: Int ):: Matrix
104
104
ω_matrix_size = ω_size (T, freq_seasonal, ζ_ω_threshold) + ζ_ω_threshold
105
105
ω_matrix = zeros (T+ steps_ahead, ω_matrix_size)
106
106
for t in freq_seasonal+ 1 : T+ steps_ahead
107
107
ωₜ_coefs = zeros (ω_matrix_size)
108
- Mₜ = Int64 (floor ((t- 1 )/ freq_seasonal))
108
+ Mₜ = Int (floor ((t- 1 )/ freq_seasonal))
109
109
lag₁ = [t - j* freq_seasonal for j in 0 : Mₜ- 1 ]
110
110
lag₂ = [t - j* freq_seasonal - 1 for j in 0 : Mₜ- 1 ]
111
111
ωₜ_coefs[lag₁[lag₁.<= ω_matrix_size+ (freq_seasonal - 1 )] .- (freq_seasonal - 1 )] .= 1
@@ -116,14 +116,14 @@ function create_ω(T::Int64, freq_seasonal::Int64, steps_ahead::Int64, ζ_ω_thr
116
116
end
117
117
118
118
"""
119
- create_initial_states_Matrix(T::Int64 , s::Int64 , steps_ahead::Int64 , level::Bool, trend::Bool, seasonal::Bool)::Matrix
119
+ create_initial_states_Matrix(T::Int , s::Int , steps_ahead::Int , level::Bool, trend::Bool, seasonal::Bool)::Matrix
120
120
121
121
Creates an initial states matrix based on the input parameters.
122
122
123
123
# Arguments
124
- - `T::Int64 `: Length of the original time series.
125
- - `freq_seasonal::Int64 `: Seasonal period.
126
- - `steps_ahead::Int64 `: Number of steps ahead.
124
+ - `T::Int `: Length of the original time series.
125
+ - `freq_seasonal::Int `: Seasonal period.
126
+ - `steps_ahead::Int `: Number of steps ahead.
127
127
- `level::Bool`: Flag for considering level component.
128
128
- `trend::Bool`: Flag for considering trend component.
129
129
- `seasonal::Bool`: Flag for considering seasonal component.
132
132
- `Matrix`: Initial states matrix constructed based on the input parameters.
133
133
134
134
"""
135
- function create_initial_states_Matrix (T:: Int64 , freq_seasonal:: Int64 , steps_ahead:: Int64 , level:: Bool , trend:: Bool , seasonal:: Bool ):: Matrix
135
+ function create_initial_states_Matrix (T:: Int , freq_seasonal:: Int , steps_ahead:: Int , level:: Bool , trend:: Bool , seasonal:: Bool ):: Matrix
136
136
137
137
initial_states_matrix = zeros (T+ steps_ahead, 0 )
138
138
level ? initial_states_matrix = hcat (initial_states_matrix, ones (T+ steps_ahead, 1 )) : nothing
@@ -151,21 +151,21 @@ function create_initial_states_Matrix(T::Int64, freq_seasonal::Int64, steps_ahea
151
151
end
152
152
153
153
"""
154
- create_X(model_input::Dict, Exogenous_X::Matrix{Fl}, steps_ahead::Int64 =0, Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, size(Exogenous_X, 2))) where Fl
154
+ create_X(model_input::Dict, Exogenous_X::Matrix{Fl}, steps_ahead::Int =0, Exogenous_Forecast::Matrix{Fl}=zeros(steps_ahead, size(Exogenous_X, 2))) where Fl
155
155
156
156
Creates the StateSpaceLearning matrix X based on the model type and input parameters.
157
157
158
158
# Arguments
159
159
- `model_type::String`: Type of model.
160
160
- `Exogenous_X::Matrix{Fl}`: Exogenous variables matrix.
161
- - `steps_ahead::Int64 `: Number of steps ahead (default: 0).
161
+ - `steps_ahead::Int `: Number of steps ahead (default: 0).
162
162
- `Exogenous_Forecast::Matrix{Fl}`: Exogenous variables forecast matrix (default: zeros).
163
163
164
164
# Returns
165
165
- `Matrix`: StateSpaceLearning matrix X constructed based on the input parameters.
166
166
"""
167
167
function create_X (model_input:: Dict , Exogenous_X:: Matrix{Fl} ,
168
- steps_ahead:: Int64 = 0 , Exogenous_Forecast:: Matrix{Fl} = zeros (steps_ahead, size (Exogenous_X, 2 ))) where Fl
168
+ steps_ahead:: Int = 0 , Exogenous_Forecast:: Matrix{Fl} = zeros (steps_ahead, size (Exogenous_X, 2 ))) where Fl
169
169
170
170
outlier = model_input[" outlier" ]; ζ_ω_threshold = model_input[" ζ_ω_threshold" ]; T = size (Exogenous_X, 1 )
171
171
@@ -203,52 +203,52 @@ function get_components_indexes(Exogenous_X::Matrix{Fl}, model_input::Dict)::Dic
203
203
initial_states_indexes = [1 ]
204
204
FINAL_INDEX += length (μ1_indexes)
205
205
else
206
- μ1_indexes = Int64 []
207
- initial_states_indexes = Int64 []
206
+ μ1_indexes = Int []
207
+ initial_states_indexes = Int []
208
208
end
209
209
210
210
if model_input[" trend" ]
211
211
ν1_indexes = [2 ]
212
212
initial_states_indexes = vcat (initial_states_indexes, ν1_indexes)
213
213
FINAL_INDEX += length (ν1_indexes)
214
214
else
215
- ν1_indexes = Int64 []
215
+ ν1_indexes = Int []
216
216
end
217
217
218
218
if model_input[" seasonal" ]
219
219
γ1_indexes = collect (FINAL_INDEX+ 1 : FINAL_INDEX+ model_input[" freq_seasonal" ])
220
220
initial_states_indexes = vcat (initial_states_indexes, γ1_indexes)
221
221
FINAL_INDEX += length (γ1_indexes)
222
222
else
223
- γ1_indexes = Int64 []
223
+ γ1_indexes = Int []
224
224
end
225
225
226
226
if model_input[" stochastic_level" ]
227
227
ξ_indexes = collect (FINAL_INDEX+ 1 : FINAL_INDEX+ ξ_size (T))
228
228
FINAL_INDEX += length (ξ_indexes)
229
229
else
230
- ξ_indexes = Int64 []
230
+ ξ_indexes = Int []
231
231
end
232
232
233
233
if model_input[" stochastic_trend" ]
234
234
ζ_indexes = collect (FINAL_INDEX+ 1 : FINAL_INDEX+ ζ_size (T, ζ_ω_threshold))
235
235
FINAL_INDEX += length (ζ_indexes)
236
236
else
237
- ζ_indexes = Int64 []
237
+ ζ_indexes = Int []
238
238
end
239
239
240
240
if model_input[" stochastic_seasonal" ]
241
241
ω_indexes = collect (FINAL_INDEX+ 1 : FINAL_INDEX+ ω_size (T, model_input[" freq_seasonal" ], ζ_ω_threshold))
242
242
FINAL_INDEX += length (ω_indexes)
243
243
else
244
- ω_indexes = Int64 []
244
+ ω_indexes = Int []
245
245
end
246
246
247
247
if outlier
248
248
o_indexes = collect (FINAL_INDEX+ 1 : FINAL_INDEX+ o_size (T))
249
249
FINAL_INDEX += length (o_indexes)
250
250
else
251
- o_indexes = Int64 []
251
+ o_indexes = Int []
252
252
end
253
253
254
254
exogenous_indexes = collect (FINAL_INDEX + 1 : FINAL_INDEX + size (Exogenous_X, 2 ))
@@ -259,20 +259,20 @@ function get_components_indexes(Exogenous_X::Matrix{Fl}, model_input::Dict)::Dic
259
259
end
260
260
261
261
"""
262
- get_variances(ε::Vector{Fl}, coefs::Vector{Fl}, components_indexes::Dict{String, Vector{Int64 }})::Dict where Fl
262
+ get_variances(ε::Vector{Fl}, coefs::Vector{Fl}, components_indexes::Dict{String, Vector{Int }})::Dict where Fl
263
263
264
264
Calculates variances for each innovation component and for the residuals.
265
265
266
266
# Arguments
267
267
- `ε::Vector{Fl}`: Vector of residuals.
268
268
- `coefs::Vector{Fl}`: Vector of coefficients.
269
- - `components_indexes::Dict{String, Vector{Int64 }}`: Dictionary containing indexes for different components.
269
+ - `components_indexes::Dict{String, Vector{Int }}`: Dictionary containing indexes for different components.
270
270
271
271
# Returns
272
272
- `Dict`: Dictionary containing variances for each innovation component.
273
273
274
274
"""
275
- function get_variances (ε:: Vector{Fl} , coefs:: Vector{Fl} , components_indexes:: Dict{String, Vector{Int64 }} ):: Dict where Fl
275
+ function get_variances (ε:: Vector{Fl} , coefs:: Vector{Fl} , components_indexes:: Dict{String, Vector{Int }} ):: Dict where Fl
276
276
277
277
variances = Dict ()
278
278
for component in [" ξ" , " ζ" , " ω" ]
0 commit comments