Skip to content

TimeSeasonality component of statespace module lists wrong dimensions #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kforeman opened this issue Nov 7, 2023 · 1 comment · Fixed by #287
Closed

TimeSeasonality component of statespace module lists wrong dimensions #262

kforeman opened this issue Nov 7, 2023 · 1 comment · Fixed by #287

Comments

@kforeman
Copy link

kforeman commented Nov 7, 2023

If you create a structural timeseries model with a TimeSeasonality component, it says the corresponding coefficients should have dim {name}_state, but should actually be {name}_periods.

ws = st.TimeSeasonality(
    season_length=7,  # day of week
    name="weekly",
    innovations=True,
    state_names=["Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"],
)
sts_mod = (ws).build()

says:

The following parameters should be assigned priors inside a PyMC model block: 
	weekly_coefs -- shape: (6,), constraints: None, dims: (weekly_state, )
	sigma_weekly -- shape: (1,), constraints: Positive, dims: None
	P0 -- shape: (6, 6), constraints: Positive semi-definite, dims: ('state', 'state_aux')

However, if you use weekly_state as the dim, it throws an error:

with pm.Model(coords=sts_mod.coords) as mod:
    weekly_coefs = pm.Normal("weekly-coefs", mu=0, sigma=1, dims=("weekly_state",))

returns

KeyError: "Dimensions {'weekly_state'} are unknown to the model and cannot be used to specify a `shape`."

Changing instead to weekly_periods fixes it:

with pm.Model(coords=sts_mod.coords) as mod:
    weekly_coefs = pm.Normal("weekly-coefs", mu=0, sigma=1, dims=("weekly_periods",))

I thought maybe this was arising from this line but sts_mod.param_dims correctly returns {'weekly_coefs': ('weekly_periods',), 'P0': ('state', 'state_aux')} in this case, so I suppose I'm not quite sure exactly how the recordkeeping for dims works.

@jessegrabowski
Copy link
Member

Ah yes there's a typo somewhere in the codebase. I have actually run into this myself, but I will push a fix ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants