|
epinowcast
|
Go to the source code of this file.
Functions | |
| vector | diagSPD_EQ (real alpha, real rho, real L, int M) |
| vector | matern_indices (int M, real L) |
| vector | diagSPD_Matern12 (real alpha, real rho, real L, int M) |
| vector | diagSPD_Matern32 (real alpha, real rho, real L, int M) |
| vector | diagSPD_Matern52 (real alpha, real rho, real L, int M) |
| vector | diagSPD_Periodic (real alpha, real rho, int M) |
| vector | update_gp (matrix PHI, int M, real L, real alpha, real rho, vector eta, int type, real nu) |
| vector | apply_gp_term (vector base, int present, int T, int G, int M, real L, int type, real nu, int d, matrix PHI, matrix eta, array[] real rho, array[] real alpha, array[] int flat_idx) |
| vector apply_gp_term | ( | vector | base, |
| int | present, | ||
| int | T, | ||
| int | G, | ||
| int | M, | ||
| real | L, | ||
| int | type, | ||
| real | nu, | ||
| int | d, | ||
| matrix | PHI, | ||
| matrix | eta, | ||
| array[]real | rho, | ||
| array[]real | alpha, | ||
| array[]int | flat_idx ) |
Add an approximate Gaussian process latent term to a per-observation predictor, with optional integer-order differencing.
Encapsulates the spectral update, per-group evaluation, optional integration, and per-observation gather so module call sites are a single line. When present is 0 the input is returned unchanged. Each group shares the length scale rho and magnitude alpha; per-group spectral coefficients are stacked column-wise in eta.
The differencing order d integrates each group's realisation d times before it enters the predictor:
d = 0: stationary deviations of length T (the basis matrix is T x M). This is the original behaviour.d >= 1: the basis matrix has T - d rows, so the spectral update yields T - d free values. These fill positions (d + 1):T of a length-T vector whose first d entries are zero; applying cumulative_sum() d times then integrates the series. Because the leading d entries start at zero, they stay zero through every integration pass, anchoring the first d values of the realisation to zero. This leaves the free level (for d = 1) and additionally the free slope (for d >= 2) to the module's fixed effects rather than the GP, which is the identifiability fix. d = 1 matches EpiNow2's non-stationary reproduction-number GP (gp[2:(gp_n + 1)] = noise; cumulative_sum).| base | Predictor to which the latent process is added. |
| present | 0 = inert, 1 = active. |
| T | Number of time points in the integrated series. |
| G | Number of groups. |
| M | Number of basis functions. |
| L | Boundary factor. |
| type | Kernel type (0 SE, 1 periodic, 2 Matern). |
| nu | Matern smoothness. |
| d | Differencing (integration) order, d >= 0. |
| PHI | Basis matrix ((T - d) x M, or (T - d) x 2M periodic). |
| eta | Spectral coefficients ((2M or M) x G matrix; empty when not present). |
| rho | Length scale (length-1 array, empty when inert). |
| alpha | Magnitude (length-1 array, empty when inert). |
| flat_idx | Per-observation column-major index into the (T x G) latent matrix. |
Definition at line 161 of file gaussian_process.stan.
| vector diagSPD_EQ | ( | real | alpha, |
| real | rho, | ||
| real | L, | ||
| int | M ) |
Hilbert-space reduced-rank (spectral) approximate Gaussian process.
Adapted from EpiNow2 (https://github.com/epiforecasts/EpiNow2, inst/stan/functions/gaussian_process.stan, MIT licensed, copyright EpiForecasts). Lightly modified for epinowcast: array syntax, naming, and an apply_gp_term() wrapper that matches the apply_arima_residual() per-observation gather used elsewhere in this package.
The approximation follows:
A latent series f over T time points is approximated as f = PHI * (sqrt(S(rho, alpha)) .* eta), where PHI is a fixed (data) matrix of basis functions, S is the spectral density of the chosen kernel evaluated at the basis eigenvalues, and eta are unit-normal spectral coefficients. The per-observation contribution is gathered from the (T x G) latent matrix with a flat column-major index, mirroring the ARIMA path. Spectral density for the squared exponential kernel.
Definition at line 28 of file gaussian_process.stan.
| vector diagSPD_Matern12 | ( | real | alpha, |
| real | rho, | ||
| real | L, | ||
| int | M ) |
Spectral density for the 1/2 Matern (Ornstein-Uhlenbeck) kernel.
Definition at line 46 of file gaussian_process.stan.
| vector diagSPD_Matern32 | ( | real | alpha, |
| real | rho, | ||
| real | L, | ||
| int | M ) |
Spectral density for the 3/2 Matern kernel.
Definition at line 54 of file gaussian_process.stan.
| vector diagSPD_Matern52 | ( | real | alpha, |
| real | rho, | ||
| real | L, | ||
| int | M ) |
Spectral density for the 5/2 Matern kernel.
Definition at line 63 of file gaussian_process.stan.
| vector diagSPD_Periodic | ( | real | alpha, |
| real | rho, | ||
| int | M ) |
Spectral density for the periodic kernel.
Definition at line 72 of file gaussian_process.stan.
| vector matern_indices | ( | int | M, |
| real | L ) |
Squared spectral indices shared by the Matern kernels.
Definition at line 38 of file gaussian_process.stan.
| vector update_gp | ( | matrix | PHI, |
| int | M, | ||
| real | L, | ||
| real | alpha, | ||
| real | rho, | ||
| vector | eta, | ||
| int | type, | ||
| real | nu ) |
Update a Gaussian process using the spectral densities.
| PHI | Basis function matrix (T x M, or T x 2M for periodic). |
| M | Number of basis functions. |
| L | Boundary factor. |
| alpha | Magnitude (marginal standard deviation). |
| rho | Length scale. |
| eta | Spectral coefficients (M, or 2M for periodic). |
| type | 0 = squared exponential, 1 = periodic, 2 = Matern. |
| nu | Matern smoothness; one of 0.5, 1.5, 2.5. |
Definition at line 95 of file gaussian_process.stan.