-
-
Notifications
You must be signed in to change notification settings - Fork 65
Add num_steps_per_season parameter in TimeSeasonality #509
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
Draft
gdeleva
wants to merge
1
commit into
pymc-devs:main
Choose a base branch
from
gdeleva:num_steps_per_season
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1068,7 +1068,11 @@ class TimeSeasonality(Component): | |
---------- | ||
season_length: int | ||
The number of periods in a single seasonal cycle, e.g. 12 for monthly data with annual seasonal pattern, 7 for | ||
daily data with weekly seasonal pattern, etc. | ||
daily data with weekly seasonal pattern, etc. It must be greater than one. | ||
|
||
num_steps_per_season: int, default 1 | ||
Number of time steps between successive applications of the same seasonal position (state). | ||
This determines how long each seasonal effect is held constant before moving to the next. | ||
|
||
innovations: bool, default True | ||
Whether to include stochastic innovations in the strength of the seasonal effect | ||
|
@@ -1094,14 +1098,24 @@ class TimeSeasonality(Component): | |
----- | ||
A seasonal effect is any pattern that repeats every fixed interval. Although there are many possible ways to | ||
model seasonal effects, the implementation used here is the one described by [1] as the "canonical" time domain | ||
representation. The seasonal component can be expressed: | ||
representation. Indexing the seasonal component as | ||
|
||
.. math:: | ||
\underbrace{\gamma_0, \gamma_0, \ldots, \gamma_0}_{r\ \text{times}}, | ||
\underbrace{\gamma_1, \gamma_1, \ldots, \gamma_1}_{r\ \text{times}}, | ||
\ldots, | ||
\underbrace{\gamma_{s-1}, \gamma_{s-1}, \ldots, \gamma_{s-1}}_{r\ \text{times}}, | ||
\ldots, | ||
|
||
where :math:`s` is the ``seasonal_length`` parameter and :math:`r` is the ``num_steps_per_season`` parameter, | ||
the seasonal component can be then expressed: | ||
|
||
.. math:: | ||
\gamma_t = -\sum_{i=1}^{s-1} \gamma_{t-i} + \omega_t, \quad \omega_t \sim N(0, \sigma_\gamma) | ||
|
||
Where :math:`s` is the ``seasonal_length`` parameter and :math:`\omega_t` is the (optional) stochastic innovation. | ||
where :math:`\omega_t` is the (optional) stochastic innovation. | ||
To give interpretation to the :math:`\gamma` terms, it is helpful to work through the algebra for a simple | ||
example. Let :math:`s=4`, and omit the shock term. Define initial conditions :math:`\gamma_0, \gamma_{-1}, | ||
example. Let :math:`s=4`, :math:`r=1`, and omit the shock term. Define initial conditions :math:`\gamma_0, \gamma_{-1}, | ||
\gamma_{-2}`. The value of the seasonal component for the first 5 timesteps will be: | ||
|
||
.. math:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also update this block with a second example that has |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is correct, but this can be written more nicely using a floor operator on the index:
$
\gamma_t = -\sum_{i=1}^{s-1} \gamma_{\left\lfloor \frac{t}{d} \right\rfloor - i} + \omega_{\left\lfloor \frac{t}{d} \right\rfloor}, \quad \omega_j \sim \mathcal{N}(0, \sigma_\gamma)
$
I suggest to use
d
for "duration" instead ofr
for the number of steps, but I'm fine with being overruled if you have a strong opinion.