@@ -130,7 +130,7 @@ def _assert_params_info_correct(param_info, coords, param_dims):
130
130
else :
131
131
inferred_dims = None
132
132
133
- shape = tuple (len (label ) for label in labels ) if labels is not None else (1 , )
133
+ shape = tuple (len (label ) for label in labels ) if labels is not None else ()
134
134
135
135
assert info ["shape" ] == shape
136
136
assert dims == inferred_dims
@@ -196,9 +196,9 @@ def create_structural_model_and_equivalent_statsmodel(
196
196
components = []
197
197
198
198
if irregular :
199
- sigma2 = np .abs (rng .normal ()).astype (floatX )
199
+ sigma2 = np .abs (rng .normal ()).astype (floatX ). item ()
200
200
params ["sigma_irregular" ] = np .sqrt (sigma2 )
201
- sm_params ["sigma2.irregular" ] = sigma2 . item ()
201
+ sm_params ["sigma2.irregular" ] = sigma2
202
202
expected_param_dims ["sigma_irregular" ] += ("observed_state" ,)
203
203
204
204
comp = st .MeasurementError ("irregular" )
@@ -298,7 +298,7 @@ def create_structural_model_and_equivalent_statsmodel(
298
298
sm_init .update (seasonal_dict )
299
299
300
300
if stochastic_seasonal :
301
- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
301
+ sigma2 = np .abs (rng .normal ()).astype (floatX )
302
302
params ["sigma_seasonal" ] = np .sqrt (sigma2 )
303
303
sm_params ["sigma2.seasonal" ] = sigma2
304
304
expected_coords [SHOCK_DIM ] += [
@@ -322,9 +322,6 @@ def create_structural_model_and_equivalent_statsmodel(
322
322
n_states = 2 * n - int (last_state_not_identified )
323
323
state_names = [f"seasonal_{ s } _{ f } _{ i } " for i in range (n ) for f in ["Cos" , "Sin" ]]
324
324
325
- # if last_state_not_identified:
326
- # state_names.pop(-1)
327
-
328
325
seasonal_params = rng .normal (size = n_states ).astype (floatX )
329
326
330
327
params [f"seasonal_{ s } " ] = seasonal_params
@@ -343,7 +340,7 @@ def create_structural_model_and_equivalent_statsmodel(
343
340
state_count += 1
344
341
345
342
if has_innov :
346
- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
343
+ sigma2 = np .abs (rng .normal ()).astype (floatX )
347
344
params [f"sigma_seasonal_{ s } " ] = np .sqrt (sigma2 )
348
345
sm_params [f"sigma2.freq_seasonal_{ s } ({ n } )" ] = sigma2
349
346
expected_coords [SHOCK_DIM ] += state_names
@@ -359,7 +356,7 @@ def create_structural_model_and_equivalent_statsmodel(
359
356
360
357
# Statsmodels takes the frequency not the cycle length, so convert it.
361
358
sm_params ["frequency.cycle" ] = 2.0 * np .pi / cycle_length
362
- params ["cycle_length" ] = np . atleast_1d ( cycle_length )
359
+ params ["cycle_length" ] = cycle_length
363
360
364
361
init_cycle = rng .normal (size = (2 ,)).astype (floatX )
365
362
params ["cycle" ] = init_cycle
@@ -374,15 +371,15 @@ def create_structural_model_and_equivalent_statsmodel(
374
371
sm_init ["cycle.auxilliary" ] = init_cycle [1 ]
375
372
376
373
if stochastic_cycle :
377
- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
374
+ sigma2 = np .abs (rng .normal ()).astype (floatX )
378
375
params ["sigma_cycle" ] = np .sqrt (sigma2 )
379
376
expected_coords [SHOCK_DIM ] += state_names
380
377
expected_coords [SHOCK_AUX_DIM ] += state_names
381
378
382
379
sm_params ["sigma2.cycle" ] = sigma2
383
380
384
381
if damped_cycle :
385
- rho = rng .beta (1 , 1 , size = ( 1 ,)). astype ( floatX )
382
+ rho = rng .beta (1 , 1 )
386
383
params ["cycle_dampening_factor" ] = rho
387
384
sm_params ["damping.cycle" ] = rho
388
385
@@ -398,7 +395,9 @@ def create_structural_model_and_equivalent_statsmodel(
398
395
if autoregressive is not None :
399
396
ar_names = [f"L{ i + 1 } .data" for i in range (autoregressive )]
400
397
ar_params = rng .normal (size = (autoregressive ,)).astype (floatX )
401
- sigma2 = np .abs (rng .normal (size = (1 ,))).astype (floatX )
398
+ if autoregressive == 1 :
399
+ ar_params = ar_params .item ()
400
+ sigma2 = np .abs (rng .normal ()).astype (floatX )
402
401
403
402
params ["ar_params" ] = ar_params
404
403
params ["sigma_ar" ] = np .sqrt (sigma2 )
@@ -550,8 +549,9 @@ def test_autoregressive_model(order, rng):
550
549
ar = st .AutoregressiveComponent (order = order )
551
550
params = {
552
551
"ar_params" : np .full ((sum (ar .order ),), 0.5 , dtype = floatX ),
553
- "sigma_ar" : np . array ([ 0.0 ], dtype = floatX ) ,
552
+ "sigma_ar" : 0.0 ,
554
553
}
554
+
555
555
x , y = simulate_from_numpy_model (ar , rng , params , steps = 100 )
556
556
557
557
# Check coords
@@ -578,7 +578,7 @@ def random_word(rng):
578
578
579
579
params = {"season_coefs" : x0 }
580
580
if mod .innovations :
581
- params ["sigma_season" ] = np . array ([ 0.0 ], dtype = floatX )
581
+ params ["sigma_season" ] = 0.0
582
582
583
583
x , y = simulate_from_numpy_model (mod , rng , params )
584
584
y = y .ravel ()
@@ -604,7 +604,7 @@ def get_shift_factor(s):
604
604
def test_frequency_seasonality (n , s , rng ):
605
605
mod = st .FrequencySeasonality (season_length = s , n = n , name = "season" )
606
606
x0 = rng .normal (size = mod .n_coefs ).astype (floatX )
607
- params = {"season" : x0 , "sigma_season" : np . array ([ 0.0 ], dtype = floatX ) }
607
+ params = {"season" : x0 , "sigma_season" : 0.0 }
608
608
k = get_shift_factor (s )
609
609
T = int (s * k )
610
610
@@ -641,10 +641,7 @@ def test_cycle_component_with_dampening(rng):
641
641
cycle = st .CycleComponent (
642
642
name = "cycle" , cycle_length = 12 , estimate_cycle_length = False , innovations = False , dampen = True
643
643
)
644
- params = {
645
- "cycle" : np .array ([10.0 , 10.0 ], dtype = floatX ),
646
- "cycle_dampening_factor" : np .array ([0.75 ], dtype = floatX ),
647
- }
644
+ params = {"cycle" : np .array ([10.0 , 10.0 ], dtype = floatX ), "cycle_dampening_factor" : 0.75 }
648
645
x , y = simulate_from_numpy_model (cycle , rng , params , steps = 100 )
649
646
650
647
# Check that the cycle dampens to zero over time
@@ -657,9 +654,9 @@ def test_cycle_component_with_innovations_and_cycle_length(rng):
657
654
)
658
655
params = {
659
656
"cycle" : np .array ([1.0 , 1.0 ], dtype = floatX ),
660
- "cycle_length" : np . array ([ 12 ], dtype = floatX ) ,
661
- "cycle_dampening_factor" : np . array ([ 0.95 ], dtype = floatX ) ,
662
- "sigma_cycle" : np . array ([ 1.0 ], dtype = floatX ) ,
657
+ "cycle_length" : 12.0 ,
658
+ "cycle_dampening_factor" : 0.95 ,
659
+ "sigma_cycle" : 1.0 ,
663
660
}
664
661
665
662
x , y = simulate_from_numpy_model (cycle , rng , params )
@@ -707,7 +704,7 @@ def test_add_components():
707
704
}
708
705
se_params = {
709
706
"seasonal_coefs" : np .ones (11 , dtype = floatX ),
710
- "sigma_seasonal" : np . ones ( 1 , dtype = floatX ) ,
707
+ "sigma_seasonal" : 1.0 ,
711
708
}
712
709
all_params = ll_params .copy ()
713
710
all_params .update (se_params )
0 commit comments