-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 helper functions to calculate required M for hsgp #7058
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
from collections import Counter | ||
from functools import reduce | ||
from math import ceil | ||
from operator import add, mul | ||
from typing import Any, Callable, List, Optional, Sequence, Union | ||
|
||
|
@@ -564,6 +565,10 @@ | |
def power_spectral_density(self, omega: TensorLike) -> TensorVariable: | ||
raise NotImplementedError | ||
|
||
@staticmethod | ||
def required_num_eigenvectors(L: float, ls: float) -> int: | ||
raise NotImplementedError | ||
|
||
|
||
class ExpQuad(Stationary): | ||
r""" | ||
|
@@ -595,6 +600,28 @@ | |
exp = pt.exp(-0.5 * pt.dot(pt.square(omega), pt.square(ls))) | ||
return c * pt.prod(ls) * exp | ||
|
||
@staticmethod | ||
def required_num_eigenvectors(L: float, ls: float) -> int: | ||
r"""Number of eigenvectors in Hilbert space that approximate the GP well. | ||
|
||
.. math:: | ||
|
||
m \ge 1.75 \frac{L}{ls} | ||
|
||
Parameters | ||
---------- | ||
L : float | ||
Approximation bound | ||
ls : float | ||
lengthscale | ||
|
||
Returns | ||
------- | ||
int | ||
Number of eigenvectors | ||
""" | ||
return ceil(1.75 * L / ls) | ||
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. Can you link the source of these numbers in the docstring? 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, you can rebase on |
||
|
||
|
||
class RatQuad(Stationary): | ||
r""" | ||
|
@@ -663,6 +690,28 @@ | |
pow = pt.power(5.0 + pt.dot(pt.square(omega), pt.square(ls)), -1 * D52) | ||
return (num / den) * pt.prod(ls) * pow | ||
|
||
@staticmethod | ||
def required_num_eigenvectors(L: float, ls: float) -> int: | ||
r"""Number of eigenvectors in Hilbert space that approximate the GP well. | ||
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. Probably should add some more detail in the docstrings here? Would be kind of mysterious to see this if you're not using HSGPs, or know how to choose L. Another idea (take it or leave it) would be to have this put into a single function in def required_num_eigenvectors(cov_func, L, ls):
if cov_func.__class__.__name__ == "ExpQuad":
return ceil(1.75 * L / ls)
elif ...:
... which maybe is better because the docstring can be in one place and the logic and purpose is isolated in one spot instead of spread out. I wonder if the recommendations may evolve too, since in the paper they didn't try for higher than 1D inputs. 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. Even more convenient would be to have this function called automatically if 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. and 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. Yeah, I'll do this |
||
|
||
.. math:: | ||
|
||
m \ge 2.65 \frac{L}{ls} | ||
|
||
Parameters | ||
---------- | ||
L : float | ||
Approximation bound | ||
ls : float | ||
lengthscale | ||
|
||
Returns | ||
------- | ||
int | ||
Number of eigenvectors | ||
""" | ||
return ceil(2.65 * L / ls) | ||
|
||
|
||
class Matern32(Stationary): | ||
r""" | ||
|
@@ -702,6 +751,28 @@ | |
pow = pt.power(3.0 + pt.dot(pt.square(omega), pt.square(ls)), -1 * D32) | ||
return (num / den) * pt.prod(ls) * pow | ||
|
||
@staticmethod | ||
def required_num_eigenvectors(L: float, ls: float) -> int: | ||
r"""Number of eigenvectors in Hilbert space that approximate the GP well. | ||
|
||
.. math:: | ||
|
||
m \ge 3.42 \frac{L}{ls} | ||
|
||
Parameters | ||
---------- | ||
L : float | ||
Approximation bound | ||
ls : float | ||
lengthscale | ||
|
||
Returns | ||
------- | ||
int | ||
Number of eigenvectors | ||
""" | ||
return ceil(3.42 * L / ls) | ||
|
||
|
||
class Matern12(Stationary): | ||
r""" | ||
|
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.
Could we add the paper (and maybe an equation reference) to understand where to learn more about the factors (for us, the newbies?)