Skip to content

Commit

Permalink
Rename _jacobian -> _jac (cf. stan-dev/stanc3#1470).
Browse files Browse the repository at this point in the history
  • Loading branch information
tillahoffmann committed Nov 25, 2024
1 parent c47eb6b commit a4d4487
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
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
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
6 changes: 3 additions & 3 deletions torch/gptools/torch/fft/fft1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gptools.util.fft import transform_rfft, transform_irfft, evaluate_rfft_log_abs_det_jacobian
from gptools.util.fft import transform_rfft, transform_irfft, evaluate_rfft_log_abs_det_jac
from gptools.util.fft.fft1 import _get_rfft_scale
import torch as th
from torch.distributions import constraints
Expand Down Expand Up @@ -43,8 +43,8 @@ def _inv_call(self, y: th.Tensor) -> th.Tensor:
"""
return transform_irfft(y, self.loc, rfft_scale=self.rfft_scale)

def log_abs_det_jacobian(self, x: th.Tensor, y: th.Tensor) -> th.Tensor:
return evaluate_rfft_log_abs_det_jacobian(x.shape[-1], rfft_scale=self.rfft_scale)
def log_abs_det_jac(self, x: th.Tensor, y: th.Tensor) -> th.Tensor:
return evaluate_rfft_log_abs_det_jac(x.shape[-1], rfft_scale=self.rfft_scale)


class FourierGaussianProcess1D(th.distributions.TransformedDistribution):
Expand Down
6 changes: 3 additions & 3 deletions torch/gptools/torch/fft/fft2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gptools.util.fft import transform_rfft2, transform_irfft2, evaluate_rfft2_log_abs_det_jacobian
from gptools.util.fft import transform_rfft2, transform_irfft2, evaluate_rfft2_log_abs_det_jac
from gptools.util.fft.fft2 import _get_rfft2_scale
import torch as th
from .. import OptionalTensor
Expand Down Expand Up @@ -44,8 +44,8 @@ def _inv_call(self, y: th.Tensor) -> th.Tensor:
"""
return transform_irfft2(y, self.loc, rfft2_scale=self.rfft2_scale)

def log_abs_det_jacobian(self, x: th.Tensor, y: th.Tensor) -> th.Tensor:
return evaluate_rfft2_log_abs_det_jacobian(x.shape[-1], rfft2_scale=self.rfft2_scale)
def log_abs_det_jac(self, x: th.Tensor, y: th.Tensor) -> th.Tensor:
return evaluate_rfft2_log_abs_det_jac(x.shape[-1], rfft2_scale=self.rfft2_scale)


class FourierGaussianProcess2D(th.distributions.TransformedDistribution):
Expand Down
8 changes: 4 additions & 4 deletions util/gptools/util/fft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from .fft1 import evaluate_log_prob_rfft, evaluate_rfft_log_abs_det_jacobian, expand_rfft, \
from .fft1 import evaluate_log_prob_rfft, evaluate_rfft_log_abs_det_jac, expand_rfft, \
transform_irfft, transform_rfft
from .fft2 import evaluate_log_prob_rfft2, evaluate_rfft2_log_abs_det_jacobian, transform_irfft2, \
from .fft2 import evaluate_log_prob_rfft2, evaluate_rfft2_log_abs_det_jac, transform_irfft2, \
transform_rfft2
from .util import log_prob_stdnorm


__all__ = [
"evaluate_log_prob_rfft",
"evaluate_log_prob_rfft2",
"evaluate_rfft_log_abs_det_jacobian",
"evaluate_rfft2_log_abs_det_jacobian",
"evaluate_rfft_log_abs_det_jac",
"evaluate_rfft2_log_abs_det_jac",
"expand_rfft",
"log_prob_stdnorm",
"transform_irfft",
Expand Down
6 changes: 3 additions & 3 deletions util/gptools/util/fft/fft1.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ def evaluate_log_prob_rfft(y: ArrayOrTensor, loc: ArrayOrTensor, *,
rfft_scale = _get_rfft_scale(cov_rfft, cov, rfft_scale, y.shape[-1])
rfft = transform_rfft(y, loc, rfft_scale=rfft_scale)
return log_prob_stdnorm(rfft).sum(axis=-1) \
+ evaluate_rfft_log_abs_det_jacobian(y.shape[-1], rfft_scale=rfft_scale)
+ evaluate_rfft_log_abs_det_jac(y.shape[-1], rfft_scale=rfft_scale)


def evaluate_rfft_log_abs_det_jacobian(size: int, *, cov_rfft: OptionalArrayOrTensor = None,
def evaluate_rfft_log_abs_det_jac(size: int, *, cov_rfft: OptionalArrayOrTensor = None,
cov: OptionalArrayOrTensor = None,
rfft_scale: OptionalArrayOrTensor = None) -> ArrayOrTensor:
"""
Expand All @@ -202,7 +202,7 @@ def evaluate_rfft_log_abs_det_jacobian(size: int, *, cov_rfft: OptionalArrayOrTe
:code:`(..., size // 2 + 1)`.
Returns:
log_abs_det_jacobian: Log absolute determinant of the Jacobian.
log_abs_det_jac: Log absolute determinant of the Jacobian.
"""
imagidx = (size + 1) // 2
rfft_scale = _get_rfft_scale(cov_rfft, cov, rfft_scale, size)
Expand Down
6 changes: 3 additions & 3 deletions util/gptools/util/fft/fft2.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def transform_rfft2(y: ArrayOrTensor, loc: ArrayOrTensor, *,
return unpack_rfft2(dispatch[y].fft.rfft2(y - loc) / rfft2_scale, y.shape)


def evaluate_rfft2_log_abs_det_jacobian(width: int, *, cov_rfft2: OptionalArrayOrTensor = None,
def evaluate_rfft2_log_abs_det_jac(width: int, *, cov_rfft2: OptionalArrayOrTensor = None,
cov: OptionalArrayOrTensor = None,
rfft2_scale: OptionalArrayOrTensor = None) -> ArrayOrTensor:
"""
Expand All @@ -194,7 +194,7 @@ def evaluate_rfft2_log_abs_det_jacobian(width: int, *, cov_rfft2: OptionalArrayO
:code:`(..., height, width // 2 + 1)`.
Returns:
log_abs_det_jacobian: Log absolute determinant of the Jacobian.
log_abs_det_jac: Log absolute determinant of the Jacobian.
"""
rfft2_scale = _get_rfft2_scale(cov_rfft2, cov, rfft2_scale, width)
height = rfft2_scale.shape[-2]
Expand Down Expand Up @@ -249,4 +249,4 @@ def evaluate_log_prob_rfft2(y: ArrayOrTensor, loc: ArrayOrTensor, *,
rfft2_scale = _get_rfft2_scale(cov_rfft2, cov, rfft2_scale, y.shape[-1])
rfft2 = transform_rfft2(y, loc, rfft2_scale=rfft2_scale)
return log_prob_stdnorm(rfft2).sum(axis=(-2, -1)) \
+ evaluate_rfft2_log_abs_det_jacobian(y.shape[-1], rfft2_scale=rfft2_scale)
+ evaluate_rfft2_log_abs_det_jac(y.shape[-1], rfft2_scale=rfft2_scale)

0 comments on commit a4d4487

Please sign in to comment.