Skip to content

Commit ff14616

Browse files
Rename cycle parameters from {name} to params_{name}
1 parent 414017e commit ff14616

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

pymc_extras/statespace/models/structural/components/cycle.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def make_symbolic_graph(self) -> None:
204204
self.ssm["selection", :, :] = pt.as_tensor_variable(selection_matrix)
205205

206206
init_state = self.make_and_register_variable(
207-
f"{self.name}", shape=(self.k_endog, 2) if self.k_endog > 1 else (self.k_states,)
207+
f"params_{self.name}", shape=(self.k_endog, 2) if self.k_endog > 1 else (self.k_states,)
208208
)
209209
self.ssm["initial_state", :] = init_state.ravel()
210210

@@ -245,13 +245,13 @@ def populate_component_properties(self):
245245
for f in ["Cos", "Sin"]
246246
]
247247

248-
self.param_names = [f"{self.name}"]
248+
self.param_names = [f"params_{self.name}"]
249249

250250
if self.k_endog == 1:
251-
self.param_dims = {self.name: (f"state_{self.name}",)}
251+
self.param_dims = {f"params_{self.name}": (f"state_{self.name}",)}
252252
self.coords = {f"state_{self.name}": self.state_names}
253253
self.param_info = {
254-
f"{self.name}": {
254+
f"params_{self.name}": {
255255
"shape": (2,),
256256
"constraints": None,
257257
"dims": (f"state_{self.name}",),
@@ -264,7 +264,7 @@ def populate_component_properties(self):
264264
f"endog_{self.name}": self.observed_state_names,
265265
}
266266
self.param_info = {
267-
f"{self.name}": {
267+
f"params_{self.name}": {
268268
"shape": (self.k_endog, 2),
269269
"constraints": None,
270270
"dims": (f"endog_{self.name}", f"state_{self.name}"),

tests/statespace/models/structural/components/test_cycle.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_cycle_component_deterministic(rng):
2020
cycle = st.CycleComponent(
2121
name="cycle", cycle_length=12, estimate_cycle_length=False, innovations=False
2222
)
23-
params = {"cycle": np.array([1.0, 1.0], dtype=config.floatX)}
23+
params = {"params_cycle": np.array([1.0, 1.0], dtype=config.floatX)}
2424
x, y = simulate_from_numpy_model(cycle, rng, params, steps=12 * 12)
2525

2626
assert_pattern_repeats(y, 12, atol=ATOL, rtol=RTOL)
@@ -30,7 +30,10 @@ def test_cycle_component_with_dampening(rng):
3030
cycle = st.CycleComponent(
3131
name="cycle", cycle_length=12, estimate_cycle_length=False, innovations=False, dampen=True
3232
)
33-
params = {"cycle": np.array([10.0, 10.0], dtype=config.floatX), "dampening_factor_cycle": 0.75}
33+
params = {
34+
"params_cycle": np.array([10.0, 10.0], dtype=config.floatX),
35+
"dampening_factor_cycle": 0.75,
36+
}
3437
x, y = simulate_from_numpy_model(cycle, rng, params, steps=100)
3538

3639
# check that cycle dampens to zero over time
@@ -42,7 +45,7 @@ def test_cycle_component_with_innovations_and_cycle_length(rng):
4245
name="cycle", estimate_cycle_length=True, innovations=True, dampen=True
4346
)
4447
params = {
45-
"cycle": np.array([1.0, 1.0], dtype=config.floatX),
48+
"params_cycle": np.array([1.0, 1.0], dtype=config.floatX),
4649
"length_cycle": 12.0,
4750
"dampening_factor_cycle": 0.95,
4851
"sigma_cycle": 1.0,
@@ -62,7 +65,7 @@ def test_cycle_multivariate_deterministic(rng):
6265
innovations=False,
6366
observed_state_names=["data_1", "data_2", "data_3"],
6467
)
65-
params = {"cycle": np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]], dtype=config.floatX)}
68+
params = {"params_cycle": np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]], dtype=config.floatX)}
6669
x, y = simulate_from_numpy_model(cycle, rng, params, steps=12 * 12)
6770

6871
# Check that each variable has a cyclical pattern with the expected period
@@ -116,7 +119,7 @@ def test_cycle_multivariate_with_dampening(rng):
116119
observed_state_names=["data_1", "data_2", "data_3"],
117120
)
118121
params = {
119-
"cycle": np.array([[10.0, 10.0], [20.0, 20.0], [30.0, 30.0]], dtype=config.floatX),
122+
"params_cycle": np.array([[10.0, 10.0], [20.0, 20.0], [30.0, 30.0]], dtype=config.floatX),
120123
"dampening_factor_cycle": 0.75,
121124
}
122125
x, y = simulate_from_numpy_model(cycle, rng, params, steps=100)
@@ -144,7 +147,7 @@ def test_cycle_multivariate_with_innovations_and_cycle_length(rng):
144147
observed_state_names=["data_1", "data_2", "data_3"],
145148
)
146149
params = {
147-
"cycle": np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]], dtype=config.floatX),
150+
"params_cycle": np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]], dtype=config.floatX),
148151
"length_cycle": 12.0,
149152
"dampening_factor_cycle": 0.95,
150153
"sigma_cycle": np.array([0.5, 1.0, 1.5]), # different innov variances per var

tests/statespace/models/structural/test_against_statsmodels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,8 @@ def create_structural_model_and_equivalent_statsmodel(
370370
params["length_cycle"] = cycle_length
371371

372372
init_cycle = rng.normal(size=(2,)).astype(floatX)
373-
params["cycle"] = init_cycle
374-
expected_param_dims["cycle"] += ("state_cycle",)
373+
params["params_cycle"] = init_cycle
374+
expected_param_dims["params_cycle"] += ("state_cycle",)
375375

376376
state_names = ["Cos_cycle", "Sin_cycle"]
377377
expected_coords["state_cycle"] += state_names

0 commit comments

Comments
 (0)