paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 182 forks source link

Add periodic kernel for HSGP #1691

Open avehtari opened 2 days ago

avehtari commented 2 days ago

brms has now all other HSGP kernels from HSGP paper except periodic. The code for the HSGP paper periodic is

matrix PHI_periodic(int N, int M, real w0, vector x) {
  matrix[N,M] mw0x = diag_post_multiply(rep_matrix(w0*x, M), linspaced_vector(M, 1, M));
  return append_col(cos(mw0x), sin(mw0x));
}
vector diagSPD_periodic(real alpha, real rho, int M) {
  real a = 1/rho^2;
  vector[M] q = exp(log(alpha) + 0.5 * (log(2) - a + to_vector(log_modified_bessel_first_kind(linspaced_int_array(M, 1, M), a))));
  return append_row(q,q);
}

where M is the number of basis functions, w0 is the period length (fine to be fixed as part of gp() arguments), and rho is the lengthscale.

paul-buerkner commented 14 hours ago

Thanks! I will implement periodic kernels in the next release. Linking https://github.com/paul-buerkner/brms/issues/234#issuecomment-2381279070 for further references.