-
Notifications
You must be signed in to change notification settings - Fork 230
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
Add WeeklyFourier #1443
Add WeeklyFourier #1443
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1443 +/- ##
==========================================
- Coverage 94.61% 94.61% -0.01%
==========================================
Files 50 50
Lines 5423 5441 +18
==========================================
+ Hits 5131 5148 +17
- Misses 292 293 +1 ☔ View full report in Codecov by Sentry. |
pymc_marketing/mmm/fourier.py
Outdated
@@ -833,6 +833,63 @@ def _get_default_start_date(self) -> datetime.datetime: | |||
return datetime.datetime(year=now.year, month=now.month, day=1) | |||
|
|||
|
|||
class WeeklyFourier(FourierBase): | |||
"""Monthly fourier seasonality. |
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.
Weekly *
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.
My bad, missed this one
"""Monthly fourier seasonality. | ||
|
||
.. plot:: | ||
:context: close-figs |
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.
Think a space is needed here. It is not rendering in the docs for some reason
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.
Wrong import + missing from __init__.py
. Should be fixed now (tested locally)
pymc_marketing/mmm/fourier.py
Outdated
days_in_period: float = DAYS_IN_WEEK | ||
|
||
def _get_default_start_date(self) -> datetime.datetime: | ||
"""Get the default start date for monthly seasonality. |
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.
Docstring change
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.
Fixed
@wd60622 Anything else on this PR? |
Is the doc rendering correctly? |
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.
Looks good. Just a request to deduplicate tests
tests/mmm/test_fourier.py
Outdated
@pytest.mark.parametrize( | ||
argnames="seasonality", | ||
argvalues=[YearlyFourier, MonthlyFourier, WeeklyFourier], | ||
ids=[ | ||
"yearly", | ||
"monthly", | ||
"weekly", | ||
], | ||
) | ||
def test_sample_curve_same_size(seasonality) -> None: | ||
n_order = 2 | ||
periodicity = seasonality(n_order=n_order) | ||
prior = periodicity.sample_prior(samples=10) | ||
curve_without_dates = periodicity.sample_curve(prior, use_dates=False) | ||
curve_with_dates = periodicity.sample_curve(prior, use_dates=False) | ||
|
||
assert curve_without_dates.sizes == curve_with_dates.sizes |
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.
Not needed the tests as above are same
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 to test that the changes I made to apply
make sense. This test was not passing before.
tests/mmm/test_fourier.py
Outdated
periodicity = seasonality(n_order=n_order) | ||
prior = periodicity.sample_prior(samples=10) | ||
curve_without_dates = periodicity.sample_curve(prior, use_dates=False) | ||
curve_with_dates = periodicity.sample_curve(prior, use_dates=False) |
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.
Why is this false as well? Or is the variable name wrong?
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.
doh!
The sample_curve(..., use_dates)
param took both values in my mind. Fixed now
The introduction of np.ceil
in sample_curve
still holds
Yes. See docs build |
def test_sample_curve_same_size(seasonality) -> None: | ||
n_order = 2 | ||
periodicity = seasonality(n_order=n_order) | ||
prior = periodicity.sample_prior(samples=10) | ||
curve_without_dates = periodicity.sample_curve(prior, use_dates=False) | ||
curve_with_dates = periodicity.sample_curve(prior, use_dates=True) | ||
|
||
assert curve_without_dates.shape == curve_with_dates.shape |
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.
Still dont understand how this is not duplicate but thats fine
Description
WeeklyFourier
sample_curve
. Now returns same sizes when called withuse_dates: bool = True | False
[seetest_sample_curve_same_size
]Related Issue
Checklist
pre-commit.ci autofix
to auto-fix.📚 Documentation preview 📚: https://pymc-marketing--1443.org.readthedocs.build/en/1443/