Skip to content

Implement periodic kernel for HSGP #6877

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 26 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fe795f9
implement periodic psd and pass test
theorashid Aug 24, 2023
788faee
simplify hsgp test, set up for mark other cov_func
theorashid Aug 24, 2023
ee76703
attempt at if-else logic in HSGP class API
theorashid Aug 25, 2023
9134d37
np.pi in w0
theorashid Sep 15, 2023
00071bd
check arguments for period and nonperiod case
theorashid Oct 7, 2023
7203892
tests run but failing
theorashid Oct 9, 2023
1e87c67
fix one of the mypy errors
theorashid Oct 9, 2023
82d317d
periodic cov pytest uses J not m because mpyp
theorashid Oct 9, 2023
2105976
avoid AttributeError by init parameterization
theorashid Oct 10, 2023
11d79e1
get rid of mypy "None" error
theorashid Oct 12, 2023
c57d17b
self.prior_linearized inside if avoids double call
theorashid Oct 12, 2023
5e1599c
need to add the mean function in prior
theorashid Oct 12, 2023
4e51b06
Merge branch 'main' into hsgp-periodic
theorashid Oct 16, 2023
abab45b
run pre-commit locally
theorashid Oct 16, 2023
51391b9
add docs to test about why test_prior fails
theorashid Oct 16, 2023
c9db47b
freshen up the docs
theorashid Oct 16, 2023
6ffd9da
improve coverage of args
theorashid Oct 16, 2023
3bfccd3
mypy ignore type
theorashid Oct 16, 2023
7aa87e2
fix parameterization test
theorashid Oct 16, 2023
15c09bc
use power_spectral_density_approx because cant sum
theorashid Oct 18, 2023
0681ca2
tbe -> the typo docs
theorashid Oct 19, 2023
36eced3
expand warning and change the triggering clause
theorashid Oct 19, 2023
56759ce
separate into HSGP and HSGPPeriodic
theorashid Nov 9, 2023
227584f
remove commented periodic in HSGP test
theorashid Nov 9, 2023
32d9e86
appease mypy
theorashid Nov 9, 2023
56963e0
add scale parameter for HSGP
theorashid Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pymc/gp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
MarginalKron,
MarginalSparse,
)
from pymc.gp.hsgp_approx import HSGP
from pymc.gp.hsgp_approx import HSGP, HSGPPeriodic
22 changes: 22 additions & 0 deletions pymc/gp/cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,28 @@ def full_from_distance(self, dist: TensorLike, squared: bool = False) -> TensorV
r2 = dist if squared else dist**2
return pt.exp(-0.5 * r2)

def power_spectral_density_approx(self, J: TensorLike) -> TensorVariable:
"""
Technically, this is not a spectral density but these are the first `m` coefficients of
the low rank approximation for the periodic kernel, which are used in the same way.
`J` is a vector of `np.arange(m)`.

The coefficients of the HSGP approximation for the `Periodic` kernel are given by:

.. math::

\tilde{q}_j^2 = \frac{2 \text{I}_j (\\ell^{-2})}{\\exp(\\ell^{-2})} \\
\tilde{q}_0^2 = \frac{\text{I}_0 (\\ell^{-2})}{\\exp(\\ell^{-2})}

where $\text{I}_j$ is the modified Bessel function of the first kind.
"""
a = 1 / pt.square(self.ls)
c = pt.where(J > 0, 2, 1)

q2 = c * pt.iv(J, a) / pt.exp(a)

return q2


class Linear(Covariance):
r"""
Expand Down
Loading