|
| 1 | +# Copyright 2024 The PyMC Labs Developers |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +"""Class to store and validate keyword argument for the Hilbert Space Gaussian Process (HSGP) components.""" |
| 15 | + |
| 16 | +from typing import Annotated |
| 17 | + |
| 18 | +import pymc as pm |
| 19 | +from pydantic import BaseModel, Field, InstanceOf |
| 20 | + |
| 21 | + |
| 22 | +class HSGPKwargs(BaseModel): |
| 23 | + """HSGP keyword arguments for the time-varying prior. |
| 24 | +
|
| 25 | + See [1]_ and [2]_ for the theoretical background on the Hilbert Space Gaussian Process (HSGP). |
| 26 | + See , [6]_ for a practical guide through the method using code examples. |
| 27 | + See the :class:`~pymc.gp.HSGP` class for more information on the Hilbert Space Gaussian Process in PyMC. |
| 28 | + We also recommend the following resources for a more practical introduction to HSGP: [3]_, [4]_, [5]_. |
| 29 | +
|
| 30 | + References |
| 31 | + ---------- |
| 32 | + .. [1] Solin, A., Sarkka, S. (2019) Hilbert Space Methods for Reduced-Rank Gaussian Process Regression. |
| 33 | + .. [2] Ruitort-Mayol, G., and Anderson, M., and Solin, A., and Vehtari, A. (2022). Practical Hilbert Space Approximate Bayesian Gaussian Processes for Probabilistic Programming. |
| 34 | + .. [3] PyMC Example Gallery: `"Gaussian Processes: HSGP Reference & First Steps" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/HSGP-Basic.html>`_. |
| 35 | + .. [4] PyMC Example Gallery: `"Gaussian Processes: HSGP Advanced Usage" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/HSGP-Advanced.html>`_. |
| 36 | + .. [5] PyMC Example Gallery: `"Baby Births Modelling with HSGPs" <https://www.pymc.io/projects/examples/en/latest/gaussian_processes/GP-Births.html>`_. |
| 37 | + .. [6] Orduz, J. `"A Conceptual and Practical Introduction to Hilbert Space GPs Approximation Methods" <https://juanitorduz.github.io/hsgp_intro/>`_. |
| 38 | +
|
| 39 | + Parameters |
| 40 | + ---------- |
| 41 | + m : int |
| 42 | + Number of basis functions. Default is 200. |
| 43 | + L : float, optional |
| 44 | + Extent of basis functions. Set this to reflect the expected range of in+out-of-sample data |
| 45 | + (considering that time-indices are zero-centered).Default is `X_mid * 2` (identical to `c=2` in HSGP). |
| 46 | + By default it is None. |
| 47 | + eta_lam : float |
| 48 | + Exponential prior for the variance. Default is 1. |
| 49 | + ls_mu : float |
| 50 | + Mean of the inverse gamma prior for the lengthscale. Default is 5. |
| 51 | + ls_sigma : float |
| 52 | + Standard deviation of the inverse gamma prior for the lengthscale. Default is 5. |
| 53 | + cov_func : ~pymc.gp.cov.Covariance, optional |
| 54 | + Gaussian process Covariance function. By default it is None. |
| 55 | + """ # noqa E501 |
| 56 | + |
| 57 | + m: int = Field(200, description="Number of basis functions") |
| 58 | + L: ( |
| 59 | + Annotated[ |
| 60 | + float, |
| 61 | + Field( |
| 62 | + gt=0, |
| 63 | + description=""" |
| 64 | + Extent of basis functions. Set this to reflect the expected range of in+out-of-sample data |
| 65 | + (considering that time-indices are zero-centered).Default is `X_mid * 2` (identical to `c=2` in HSGP) |
| 66 | + """, |
| 67 | + ), |
| 68 | + ] |
| 69 | + | None |
| 70 | + ) = None |
| 71 | + eta_lam: float = Field(1, gt=0, description="Exponential prior for the variance") |
| 72 | + ls_mu: float = Field( |
| 73 | + 5, gt=0, description="Mean of the inverse gamma prior for the lengthscale" |
| 74 | + ) |
| 75 | + ls_sigma: float = Field( |
| 76 | + 5, |
| 77 | + gt=0, |
| 78 | + description="Standard deviation of the inverse gamma prior for the lengthscale", |
| 79 | + ) |
| 80 | + cov_func: InstanceOf[pm.gp.cov.Covariance] | None = Field( |
| 81 | + None, description="Gaussian process Covariance function" |
| 82 | + ) |
0 commit comments