Skip to content
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

Fix bug in TimeSeasonality when pop_state = False #407

Merged

Conversation

jessegrabowski
Copy link
Member

@jessegrabowski jessegrabowski commented Jan 2, 2025

Small bugfix for the TimeSeasonality component.

In the classical definition, the n-th seasonal effect isn't identified, so n-1 effects are defined and the transition matrix is:

$$ T= \begin{bmatrix} -1 & -1 & -1 & -1 \\ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix} $$

It's no obvious, so there's a worked example in the API docs for why this does what you want it to do.

I wanted to add an argument that would allow users to handle this normalization themselves if they wished, but it was implemented incorrectly. Now it should work. If you pinky swear that the seasonal effects are normalized (e.g. with ZeroSumNormal prior), you can get a transition matrix like:

$$ T = \begin{bmatrix} 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \end{bmatrix} $$

Which will just loop the effects around without doing anything fancy. This will be much easier to interpret.

Rename `pop_state` to `remove_first_state` for clarity.

Add test for `remove_first_state = False`
@jessegrabowski jessegrabowski merged commit be77d9d into pymc-devs:main Jan 2, 2025
5 checks passed
@jessegrabowski jessegrabowski deleted the time-seasonality-argfix branch January 2, 2025 08:46
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 this pull request may close these issues.

2 participants