@@ -130,7 +130,7 @@ def _assert_params_info_correct(param_info, coords, param_dims):
130130 else :
131131 inferred_dims = None
132132
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 ()
134134
135135 assert info ["shape" ] == shape
136136 assert dims == inferred_dims
@@ -196,9 +196,9 @@ def create_structural_model_and_equivalent_statsmodel(
196196 components = []
197197
198198 if irregular :
199- sigma2 = np .abs (rng .normal ()).astype (floatX )
199+ sigma2 = np .abs (rng .normal ()).astype (floatX ). item ()
200200 params ["sigma_irregular" ] = np .sqrt (sigma2 )
201- sm_params ["sigma2.irregular" ] = sigma2 . item ()
201+ sm_params ["sigma2.irregular" ] = sigma2
202202 expected_param_dims ["sigma_irregular" ] += ("observed_state" ,)
203203
204204 comp = st .MeasurementError ("irregular" )
@@ -298,7 +298,7 @@ def create_structural_model_and_equivalent_statsmodel(
298298 sm_init .update (seasonal_dict )
299299
300300 if stochastic_seasonal :
301- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
301+ sigma2 = np .abs (rng .normal ()).astype (floatX )
302302 params ["sigma_seasonal" ] = np .sqrt (sigma2 )
303303 sm_params ["sigma2.seasonal" ] = sigma2
304304 expected_coords [SHOCK_DIM ] += [
@@ -322,9 +322,6 @@ def create_structural_model_and_equivalent_statsmodel(
322322 n_states = 2 * n - int (last_state_not_identified )
323323 state_names = [f"seasonal_{ s } _{ f } _{ i } " for i in range (n ) for f in ["Cos" , "Sin" ]]
324324
325- # if last_state_not_identified:
326- # state_names.pop(-1)
327-
328325 seasonal_params = rng .normal (size = n_states ).astype (floatX )
329326
330327 params [f"seasonal_{ s } " ] = seasonal_params
@@ -343,7 +340,7 @@ def create_structural_model_and_equivalent_statsmodel(
343340 state_count += 1
344341
345342 if has_innov :
346- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
343+ sigma2 = np .abs (rng .normal ()).astype (floatX )
347344 params [f"sigma_seasonal_{ s } " ] = np .sqrt (sigma2 )
348345 sm_params [f"sigma2.freq_seasonal_{ s } ({ n } )" ] = sigma2
349346 expected_coords [SHOCK_DIM ] += state_names
@@ -359,7 +356,7 @@ def create_structural_model_and_equivalent_statsmodel(
359356
360357 # Statsmodels takes the frequency not the cycle length, so convert it.
361358 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
363360
364361 init_cycle = rng .normal (size = (2 ,)).astype (floatX )
365362 params ["cycle" ] = init_cycle
@@ -374,15 +371,15 @@ def create_structural_model_and_equivalent_statsmodel(
374371 sm_init ["cycle.auxilliary" ] = init_cycle [1 ]
375372
376373 if stochastic_cycle :
377- sigma2 = np .abs (rng .normal (size = ( 1 ,) )).astype (floatX )
374+ sigma2 = np .abs (rng .normal ()).astype (floatX )
378375 params ["sigma_cycle" ] = np .sqrt (sigma2 )
379376 expected_coords [SHOCK_DIM ] += state_names
380377 expected_coords [SHOCK_AUX_DIM ] += state_names
381378
382379 sm_params ["sigma2.cycle" ] = sigma2
383380
384381 if damped_cycle :
385- rho = rng .beta (1 , 1 , size = ( 1 ,)). astype ( floatX )
382+ rho = rng .beta (1 , 1 )
386383 params ["cycle_dampening_factor" ] = rho
387384 sm_params ["damping.cycle" ] = rho
388385
@@ -398,7 +395,9 @@ def create_structural_model_and_equivalent_statsmodel(
398395 if autoregressive is not None :
399396 ar_names = [f"L{ i + 1 } .data" for i in range (autoregressive )]
400397 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 )
402401
403402 params ["ar_params" ] = ar_params
404403 params ["sigma_ar" ] = np .sqrt (sigma2 )
@@ -550,8 +549,9 @@ def test_autoregressive_model(order, rng):
550549 ar = st .AutoregressiveComponent (order = order )
551550 params = {
552551 "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 ,
554553 }
554+
555555 x , y = simulate_from_numpy_model (ar , rng , params , steps = 100 )
556556
557557 # Check coords
@@ -578,7 +578,7 @@ def random_word(rng):
578578
579579 params = {"season_coefs" : x0 }
580580 if mod .innovations :
581- params ["sigma_season" ] = np . array ([ 0.0 ], dtype = floatX )
581+ params ["sigma_season" ] = 0.0
582582
583583 x , y = simulate_from_numpy_model (mod , rng , params )
584584 y = y .ravel ()
@@ -604,7 +604,7 @@ def get_shift_factor(s):
604604def test_frequency_seasonality (n , s , rng ):
605605 mod = st .FrequencySeasonality (season_length = s , n = n , name = "season" )
606606 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 }
608608 k = get_shift_factor (s )
609609 T = int (s * k )
610610
@@ -641,10 +641,7 @@ def test_cycle_component_with_dampening(rng):
641641 cycle = st .CycleComponent (
642642 name = "cycle" , cycle_length = 12 , estimate_cycle_length = False , innovations = False , dampen = True
643643 )
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 }
648645 x , y = simulate_from_numpy_model (cycle , rng , params , steps = 100 )
649646
650647 # Check that the cycle dampens to zero over time
@@ -657,9 +654,9 @@ def test_cycle_component_with_innovations_and_cycle_length(rng):
657654 )
658655 params = {
659656 "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 ,
663660 }
664661
665662 x , y = simulate_from_numpy_model (cycle , rng , params )
@@ -707,7 +704,7 @@ def test_add_components():
707704 }
708705 se_params = {
709706 "seasonal_coefs" : np .ones (11 , dtype = floatX ),
710- "sigma_seasonal" : np . ones ( 1 , dtype = floatX ) ,
707+ "sigma_seasonal" : 1.0 ,
711708 }
712709 all_params = ll_params .copy ()
713710 all_params .update (se_params )
0 commit comments