Utility Functions
Utility functions support the implementation of Gaussian Processes on Graphs and Likelihood Evaluations Based on Fast Fourier Transforms, such as
rfft
,inv_rfft
,rfft2
, andinv_rfft2
to evaluate real fast Fourier transforms in one and two dimensions.gp_conditional_loc_scale
to evaluate the conditional location and scale parameter of a univariate normal random variable given observations of correlated variables.functions to compare values and assertions for debugging.
Function Reference
- void assert_equal(int actual, int desired)
Assert that two integers are equal.
- Parameters
actual – Actual value.
desired – Desired value.
- int is_close(real actual, real desired, real rtol, real atol)
Check whether two values are close.
The actual value
x
and desired valuey
may differ by at mosttol = rtol * y + atol
, wherertol
is the relative tolerance, andatol
is the absolute tolerance. The tolerancetol
is clipped below at \(10^{-15}\) to avoid rejection due to rounding errors.- Parameters
actual – Actual value
x
.desired – Desired value
y
.rtol – Relative tolerance
r
.atol – Absolute tolerance
a
.
- Returns
1
if the values are close,0
otherwise.
- void assert_close(real actual, real desired, real rtol, real atol)
Assert that two values are close. See
is_close(real, real, real, real)
for a description of the parameters.
- void assert_close(real actual, real desired)
Assert that two values are close. See
is_close(real, real, real, real)
for a description of the parameters.
- int is_finite(complex x)
Check whether a possibly complex value is finite.
- Parameters
x – Value to check.
- Returns
1
if the value is finite,0
otherwise.
- void assert_close(vector actual, vector desired, real rtol, real atol)
Assert that two vectors are close. See
is_close(real, real, real, real)
for a description of the parameters.
- void assert_close(vector actual, vector desired)
Assert that two vectors are close. See
is_close
for description of parameters.
- void assert_close(vector actual, real desired, real rtol, real atol)
Assert that two vectors are close. See
is_close
for description of parameters.
- void assert_close(vector actual, real desired)
Assert that two vectors are close. See
is_close
for description of parameters.
- int is_finite(vector x)
Check whether all elements of a vector are finite.
- Parameters
x – Vector to check.
- Returns
1
if all elements of the vector are finite,0
otherwise.
- void assert_finite(vector x)
Assert that all elements of a vector are finite.
- Param
Vector to check.
- int is_finite(matrix x)
Check whether all elements of a matrix are finite.
- Param
Vector to check.
- void print_matrix(complex_matrix x)
Pretty-print a matrix.
- void assert_close(matrix actual, matrix desired, real rtol, real atol)
Assert that two matrices are close. See
is_close
for description of parameters.
- void assert_close(matrix actual, matrix desired)
Assert that two matrices are close. See
is_close
for description of parameters.
- void assert_close(matrix actual, real desired, real rtol, real atol)
Assert that two matrices are close. See
is_close
for description of parameters.
- void assert_close(matrix actual, real desired)
Assert that two matrices are close. See
is_close
for description of parameters.
- void assert_close(complex_vector actual, complex_vector desired, real rtol, real atol)
Assert that two vectors are close. See
is_close
for description of parameters.
- void assert_close(complex_vector actual, complex_vector desired)
Assert that two vectors are close. See
is_close
for description of parameters.
- void assert_close(complex_vector actual, complex desired, real rtol, real atol)
Assert that two vectors are close. See
is_close
for description of parameters.
- void assert_close(complex_vector actual, complex desired)
Assert that two vectors are close. See
is_close
for description of parameters.
- complex_vector rfft(vector y)
Compute the one-dimensional discrete Fourier transform for real input.
- Parameters
y – Real signal with
n
elements to transform.- Returns
Truncated vector of Fourier coefficients with
n %/% 2 + 1
elements.
- complex_vector expand_rfft(complex_vector y, int n)
Expand truncated one-dimensional discrete Fourier transform coefficients for real input to full Fourier coefficients.
- vector inv_rfft(complex_vector z, int n)
Compute the one-dimensional inverse discrete Fourier transform for real output.
- Parameters
z – Truncated vector of Fourier coefficents with
n %/% 2 + 1
elements.n – Length of the signal (required because the length of the signal cannot be determined from
z
alone).
- Returns
Real signal with
n
elements.
- complex_matrix rfft2(matrix y)
Compute the two-dimensional discrete Fourier transform for real input.
- Parameters
y – Real signal with
n
rows andm
columns to transform.- Returns
Truncated vector of Fourier coefficients with
n
rows andm %/% 2 + 1
elements.
- matrix inv_rfft2(complex_matrix z, int m)
Compute the two-dimensional inverse discrete Fourier transform for real output.
- Parameters
z – Truncated vector of Fourier coefficients with
n
rows andm %/% 2 + 1
elements.m – Number of columns of the signal (required because the number of columns cannot be determined from
z
alone).
- Returns
Real signal with
n
rows andm
columns.
- vector gp_conditional_loc_scale(vector y, real cov11, vector cov21, matrix cov22)
Evaluate the conditional location and scale parameter of a univariate normal random variable given correlated observations from a multivariate normal distribution.
- Parameters
y – Observation to condition on.
cov11 – Marginal variance of the target random variable.
cov21 – Covariance between
y
and the target random variable.cov22 – Covariance amongst the elements of
y
.
- Returns
Location and scale as a vector.