Skip to content
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

Non-isotropic length scales for graph-based Gaussian processes #23

Merged
merged 11 commits into from
Dec 11, 2024
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ env:
# Our tests may contain a number of stochastic elements. Setting a seed will make sure they are
# not flaky (but also hide potential issues).
SEED: "0"
cmdstanVersion: "2.31.0"
cmdstanVersion: "2.36.0"

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion stan/docs/interface/fft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Utility Functions
The following functions, and their two-dimensional analogues, primarily exist as utility functions but may be useful for more complex models.

- :stan:func:`gp_rfft` transforms Gaussian process realizations to the Fourier domain and scales the coefficients such that they are white noise under the Gaussian process prior.
- :stan:func:`gp_rfft_log_abs_det_jacobian` evaluates the log absolute determinant of the Jacobian associated with the transformations :stan:func:`gp_rfft`.
- :stan:func:`gp_rfft_log_abs_det_jac` evaluates the log absolute determinant of the Jacobian associated with the transformations :stan:func:`gp_rfft`.

Together, these two functions are used by :stan:func:`gp_rfft_lpdf` to evaluate the likelihood.

Expand Down
11 changes: 11 additions & 0 deletions stan/gptools/stan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ def get_include() -> str:
"""
Get the include directory for the library.
"""
version = cmdstanpy.cmdstan_version()
if version and version < (2, 36): # pragma: no cover
logging.warning(
"cmdstan<2.36.0 had a bug in the evaluation of Matern 3/2 kernels "
"with different length scales for different dimensions; see "
"https://github.com/stan-dev/math/pull/3084 for details. Your "
"model may yield unexpected results or crash if you use "
"nearest-neighbor Gaussian processes with Matern 3/2 kernels. Your "
"cmdstan version is %d.%d; consider upgrading.",
*version,
)
return os.path.dirname(__file__)


Expand Down
4 changes: 2 additions & 2 deletions stan/gptools/stan/gptools/fft1.stan
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Evaluate the log absolute determinant of the Jacobian associated with
:param n: Size of the real signal. Necessary because the size cannot be inferred from :code:`rfft`.
:returns: Log absolute determinant of the Jacobian.
*/
real gp_rfft_log_abs_det_jacobian(vector cov_rfft, int n) {
real gp_rfft_log_abs_det_jac(vector cov_rfft, int n) {
vector[n %/% 2 + 1] rfft_scale = gp_evaluate_rfft_scale(cov_rfft, n);
return - sum(log(rfft_scale[1:n %/% 2 + 1])) -sum(log(rfft_scale[2:(n + 1) %/% 2]))
- log(2) * ((n - 1) %/% 2) + n * log(n) / 2;
Expand All @@ -94,7 +94,7 @@ real gp_rfft_lpdf(vector y, vector loc, vector cov_rfft) {
int n = size(y);
int nrfft = n %/% 2 + 1;
vector[n] z = gp_rfft(y, loc, cov_rfft);
return std_normal_lpdf(z) + gp_rfft_log_abs_det_jacobian(cov_rfft, n);
return std_normal_lpdf(z) + gp_rfft_log_abs_det_jac(cov_rfft, n);
}


Expand Down
4 changes: 2 additions & 2 deletions stan/gptools/stan/gptools/fft2.stan
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Evaluate the log absolute determinant of the Jacobian associated with
Fourier transform :code:`cov_rfft2`).
:returns: Log absolute determinant of the Jacobian.
*/
real gp_rfft2_log_abs_det_jacobian(matrix cov_rfft2, int width) {
real gp_rfft2_log_abs_det_jac(matrix cov_rfft2, int width) {
int height = rows(cov_rfft2);
int n = width * height;
int fftwidth = width %/% 2 + 1;
Expand Down Expand Up @@ -185,7 +185,7 @@ Evaluate the log probability of a two-dimensional Gaussian process realization i
*/
real gp_rfft2_lpdf(matrix y, matrix loc, matrix cov_rfft2) {
return std_normal_lpdf(to_vector(gp_rfft2(y, loc, cov_rfft2)))
+ gp_rfft2_log_abs_det_jacobian(cov_rfft2, cols(y));
+ gp_rfft2_log_abs_det_jac(cov_rfft2, cols(y));
}


Expand Down
Loading
Loading