@@ -88,14 +88,36 @@ function get_standard_innovations(fo::FilterOutput)
88
88
return v[:, 1 ] ./ sqrt .(F[1 , 1 , :])
89
89
end
90
90
91
+ function vector_of_vector_to_matrix (vov:: Vector{Vector{T}} ) where T
92
+ n = length (vov)
93
+ p = length (vov[1 ])
94
+ mat = Matrix {T} (undef, n, p)
95
+ for i in 1 : n, j in 1 : p
96
+ mat[i, j] = vov[i][j]
97
+ end
98
+ return mat
99
+ end
100
+
101
+ function vector_of_matrix_to_array (vom:: Vector{Matrix{T}} ) where T
102
+ n = length (vom)
103
+ p = length (vom[1 ])
104
+ arr = Array {T, 3} (undef, n, p, p)
105
+ for i in 1 : n, j in 1 : p, k in 1 : p
106
+ arr[i, j, k] = vom[i][j, k]
107
+ end
108
+ return arr
109
+ end
110
+
91
111
"""
92
112
get_innovations
93
113
94
114
Returns the innovations `v` obtained with the Kalman filter.
95
115
"""
96
116
function get_innovations end
97
117
98
- get_innovations (filter:: FilterOutput ) = permutedims (cat (filter. v... ; dims= 2 ))
118
+ function get_innovations (filter:: FilterOutput )
119
+ return vector_of_vector_to_matrix (filter. v)
120
+ end
99
121
100
122
function get_innovations (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
101
123
assert_possible_to_filter (model)
@@ -109,7 +131,9 @@ Returns the variance `F` of innovations obtained with the Kalman filter.
109
131
"""
110
132
function get_innovations_variance end
111
133
112
- get_innovations_variance (filter_output:: FilterOutput ) = cat (filter_output. F... ; dims= 3 )
134
+ function get_innovations_variance (filter:: FilterOutput )
135
+ return vector_of_matrix_to_array (filter. F)
136
+ end
113
137
114
138
function get_innovations_variance (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
115
139
assert_possible_to_filter (model)
@@ -123,7 +147,9 @@ Returns the filtered state `att` obtained with the Kalman filter.
123
147
"""
124
148
function get_filtered_state end
125
149
126
- get_filtered_state (filter:: FilterOutput ) = permutedims (cat (filter. att... ; dims= 2 ))
150
+ function get_filtered_state (filter:: FilterOutput )
151
+ return vector_of_vector_to_matrix (filter. att)
152
+ end
127
153
128
154
function get_filtered_state (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
129
155
assert_possible_to_filter (model)
@@ -137,7 +163,7 @@ Returns the variance `Ptt` of the filtered state obtained with the Kalman filter
137
163
"""
138
164
function get_filtered_state_variance end
139
165
140
- get_filtered_state_variance (filter:: FilterOutput ) = cat (filter. Ptt... ; dims = 3 )
166
+ get_filtered_state_variance (filter:: FilterOutput ) = vector_of_matrix_to_array (filter. Ptt)
141
167
142
168
function get_filtered_state_variance (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
143
169
assert_possible_to_filter (model)
@@ -151,7 +177,7 @@ Returns the predictive state `a` obtained with the Kalman filter.
151
177
"""
152
178
function get_predictive_state end
153
179
154
- get_predictive_state (filter:: FilterOutput ) = permutedims ( cat ( filter. a... ; dims = 2 ) )
180
+ get_predictive_state (filter:: FilterOutput ) = vector_of_vector_to_matrix ( filter. a)
155
181
156
182
function get_predictive_state (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
157
183
assert_possible_to_filter (model)
@@ -165,7 +191,7 @@ Returns the variance `P` of the predictive state obtained with the Kalman filter
165
191
"""
166
192
function get_predictive_state_variance end
167
193
168
- get_predictive_state_variance (filter:: FilterOutput ) = cat (filter. P... ; dims = 3 )
194
+ get_predictive_state_variance (filter:: FilterOutput ) = vector_of_matrix_to_array (filter. P)
169
195
170
196
function get_predictive_state_variance (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
171
197
assert_possible_to_filter (model)
@@ -229,7 +255,7 @@ Returns the smoothed state `alpha` obtained with the smoother.
229
255
"""
230
256
function get_smoothed_state end
231
257
232
- get_smoothed_state (smoother:: SmootherOutput ) = permutedims ( cat ( smoother. alpha... ; dims = 2 ) )
258
+ get_smoothed_state (smoother:: SmootherOutput ) = vector_of_vector_to_matrix ( smoother. alpha)
233
259
234
260
function get_smoothed_state (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
235
261
assert_possible_to_filter (model)
@@ -243,9 +269,9 @@ Returns the variance `V` of the smoothed state obtained with the smoother.
243
269
"""
244
270
function get_smoothed_state_variance end
245
271
246
- get_smoothed_state_variance (smoother:: SmootherOutput ) = cat (smoother. V... ; dims = 3 )
272
+ get_smoothed_state_variance (smoother:: SmootherOutput ) = vector_of_matrix_to_array (smoother. V)
247
273
248
274
function get_smoothed_state_variance (model:: StateSpaceModel ; filter:: KalmanFilter = default_filter (model))
249
275
assert_possible_to_filter (model)
250
276
return get_smoothed_state_variance (kalman_smoother (model; filter= filter))
251
- end
277
+ end
0 commit comments