-
Notifications
You must be signed in to change notification settings - Fork 332
PoC: Use Pydantic as data validator #809
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
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
bf2d621
prior with pydantic
d51331c
dependencies
e4aefbc
validate adstock
6014c5e
make mypy happy
11848af
add validation sample curve
20982cb
Merge branch 'main' into pydantic1
juanitorduz 2138235
Merge branch 'main' into pydantic1
juanitorduz 07a8cd5
make the prior type tighter
56e033e
add test type
828df9b
add validation init mmm
cd8f20a
mmm
cba5b2a
start with Fourier
921730f
fix type
0427e5d
fix test and imprtove docstrings
409f935
docstrings
f628ccb
types
5ca2de3
self type
cfe8021
init validator
c610046
types model builder
1104298
improve docstrings
b75e3c9
more input validations mmm init
62a5be3
validation budget optimizer
63ed4fc
fix dummy example types
9866b40
hsgp kwargs class
6d91790
add kwargs
7416728
undo type hint in dict
36ef9f3
fix fourier names
1cd86fe
better docs
bd8ce8a
fix tests
7f1b944
add type hint
4b83f1b
undo
79c2cc3
fix type error
32d9118
feedback2
39ad8ce
restrict signature
1bd9627
serialize fourier
b69d2ce
docs and tests
5a14589
fix docs
49599b5
Merge branch 'main' into pydantic1
juanitorduz 7df75af
Merge branch 'main' into pydantic1
juanitorduz 101d861
work on parsing
a3201a6
add hsgp to parsing config
650e507
add tests
2d96a71
uncomment
327f880
undo changes
b1c7c84
undo model config parser
7f88be6
Merge branch 'main' into pydantic1
juanitorduz 93f6106
handle hsgp_kwargs
7d88913
add hsgp flag
e650a49
docs
b90e742
undo type hint
08ed78c
improve hints
3fd1329
add more sections to docs
3eb8446
Update pymc_marketing/mmm/tvp.py
juanitorduz 86e4d7a
feedback 4
47851cc
fix test
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 |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ | |
| :toctree: generated/ | ||
|
|
||
| clv | ||
| hsgp_kwargs | ||
| mmm | ||
| model_config | ||
| model_builder | ||
| prior | ||
| ``` | ||
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
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
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Copyright 2024 The PyMC Labs Developers | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
juanitorduz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Class to store and validate keyword argument for the Hilbert Space Gaussian Process (HSGP) components.""" | ||
|
|
||
| from typing import Annotated | ||
|
|
||
| import pymc as pm | ||
| from pydantic import BaseModel, Field, InstanceOf | ||
|
|
||
|
|
||
| class HSGPKwargs(BaseModel): | ||
| """HSGP keyword arguments for the time-varying prior. | ||
|
|
||
| See [1]_ and [2]_ for the theoretical background on the Hilbert Space Gaussian Process (HSGP). | ||
| See , [6]_ for a practical guide through the method using code examples. | ||
| See the :class:`~pymc.gp.HSGP` class for more information on the Hilbert Space Gaussian Process in PyMC. | ||
| We also recommend the following resources for a more practical introduction to HSGP: [3]_, [4]_, [5]_. | ||
|
|
||
| References | ||
| ---------- | ||
| .. [1] Solin, A., Sarkka, S. (2019) Hilbert Space Methods for Reduced-Rank Gaussian Process Regression. | ||
| .. [2] Ruitort-Mayol, G., and Anderson, M., and Solin, A., and Vehtari, A. (2022). Practical Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming. | ||
| .. [3] PyMC Example Gallery: `"Gaussian Processes: HSGP Reference & First Steps" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/HSGP-Basic.html>`_. | ||
| .. [4] PyMC Example Gallery: `"Gaussian Processes: HSGP Advanced Usage" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/HSGP-Advanced.html>`_. | ||
| .. [5] PyMC Example Gallery: `"Baby Births Modelling with HSGPs" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/GP-Births.html>`_. | ||
| .. [6] Orduz, J. `"A Conceptual and Practical Introduction to Hilbert Space GPs Approximation Methods" <https://juanitorduz.github.io/hsgp_intro/>`_. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| m : int | ||
| Number of basis functions. Default is 200. | ||
| L : float, optional | ||
| Extent of basis functions. Set this to reflect the expected range of in+out-of-sample data | ||
| (considering that time-indices are zero-centered).Default is `X_mid * 2` (identical to `c=2` in HSGP). | ||
| By default it is None. | ||
| eta_lam : float | ||
| Exponential prior for the variance. Default is 1. | ||
| ls_mu : float | ||
| Mean of the inverse gamma prior for the lengthscale. Default is 5. | ||
| ls_sigma : float | ||
| Standard deviation of the inverse gamma prior for the lengthscale. Default is 5. | ||
| cov_func : ~pymc.gp.cov.Covariance, optional | ||
| Gaussian process Covariance function. By default it is None. | ||
| """ # noqa E501 | ||
|
|
||
| m: int = Field(200, description="Number of basis functions") | ||
| L: ( | ||
| Annotated[ | ||
| float, | ||
| Field( | ||
| gt=0, | ||
| description=""" | ||
| Extent of basis functions. Set this to reflect the expected range of in+out-of-sample data | ||
| (considering that time-indices are zero-centered).Default is `X_mid * 2` (identical to `c=2` in HSGP) | ||
| """, | ||
| ), | ||
| ] | ||
| | None | ||
| ) = None | ||
| eta_lam: float = Field(1, gt=0, description="Exponential prior for the variance") | ||
| ls_mu: float = Field( | ||
| 5, gt=0, description="Mean of the inverse gamma prior for the lengthscale" | ||
| ) | ||
| ls_sigma: float = Field( | ||
| 5, | ||
| gt=0, | ||
| description="Standard deviation of the inverse gamma prior for the lengthscale", | ||
| ) | ||
| cov_func: InstanceOf[pm.gp.cov.Covariance] | None = Field( | ||
| None, description="Gaussian process Covariance function" | ||
| ) | ||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.