@@ -64,19 +64,45 @@ def _assert_coord_shapes_match_matrices(mod, params):
64
64
params ["initial_state_cov" ] = np .eye (mod .k_states )
65
65
66
66
x0 , P0 , c , d , T , Z , R , H , Q = unpack_symbolic_matrices_with_params (mod , params )
67
+
67
68
n_states = len (mod .coords [ALL_STATE_DIM ])
68
- n_shocks = len (mod .coords [SHOCK_DIM ])
69
+
70
+ # There will always be one shock dimension -- dummies are inserted into fully deterministic models to avoid errors
71
+ # in the state space representation.
72
+ n_shocks = max (1 , len (mod .coords [SHOCK_DIM ]))
69
73
n_obs = len (mod .coords [OBS_STATE_DIM ])
70
74
71
- assert x0 .shape [- 1 :] == (n_states ,)
72
- assert P0 .shape [- 2 :] == (n_states , n_states )
73
- assert c .shape [- 1 :] == (n_states ,)
74
- assert d .shape [- 1 :] == (n_obs ,)
75
- assert T .shape [- 2 :] == (n_states , n_states )
76
- assert Z .shape [- 2 :] == (n_obs , n_states )
77
- assert R .shape [- 2 :] == (n_states , n_shocks )
78
- assert H .shape [- 2 :] == (n_obs , n_obs )
79
- assert Q .shape [- 2 :] == (n_shocks , n_shocks )
75
+ assert x0 .shape [- 1 :] == (
76
+ n_states ,
77
+ ), f"x0 expected to have shape (n_states, ), found { x0 .shape [- 1 :]} "
78
+ assert P0 .shape [- 2 :] == (
79
+ n_states ,
80
+ n_states ,
81
+ ), f"P0 expected to have shape (n_states, n_states), found { P0 .shape [- 2 :]} "
82
+ assert c .shape [- 1 :] == (
83
+ n_states ,
84
+ ), f"c expected to have shape (n_states, ), found { c .shape [- 1 :]} "
85
+ assert d .shape [- 1 :] == (n_obs ,), f"d expected to have shape (n_obs, ), found { d .shape [- 1 :]} "
86
+ assert T .shape [- 2 :] == (
87
+ n_states ,
88
+ n_states ,
89
+ ), f"T expected to have shape (n_states, n_states), found { T .shape [- 2 :]} "
90
+ assert Z .shape [- 2 :] == (
91
+ n_obs ,
92
+ n_states ,
93
+ ), f"Z expected to have shape (n_obs, n_states), found { Z .shape [- 2 :]} "
94
+ assert R .shape [- 2 :] == (
95
+ n_states ,
96
+ n_shocks ,
97
+ ), f"R expected to have shape (n_states, n_shocks), found { R .shape [- 2 :]} "
98
+ assert H .shape [- 2 :] == (
99
+ n_obs ,
100
+ n_obs ,
101
+ ), f"H expected to have shape (n_obs, n_obs), found { H .shape [- 2 :]} "
102
+ assert Q .shape [- 2 :] == (
103
+ n_shocks ,
104
+ n_shocks ,
105
+ ), f"Q expected to have shape (n_shocks, n_shocks), found { Q .shape [- 2 :]} "
80
106
81
107
82
108
def _assert_basic_coords_correct (mod ):
@@ -514,12 +540,12 @@ def test_structural_model_against_statsmodels(
514
540
515
541
_assert_all_statespace_matrices_match (mod , params , sm_mod )
516
542
517
- mod .build (verbose = False )
543
+ built_model = mod .build (verbose = False )
518
544
519
- _assert_coord_shapes_match_matrices (mod , params )
520
- _assert_param_dims_correct (mod .param_dims , expected_dims )
521
- _assert_coords_correct (mod .coords , expected_coords )
522
- _assert_params_info_correct (mod .param_info , mod .coords , mod .param_dims )
545
+ _assert_coord_shapes_match_matrices (built_model , params )
546
+ _assert_param_dims_correct (built_model .param_dims , expected_dims )
547
+ _assert_coords_correct (built_model .coords , expected_coords )
548
+ _assert_params_info_correct (built_model .param_info , built_model .coords , built_model .param_dims )
523
549
524
550
525
551
def test_level_trend_model (rng ):
0 commit comments