@@ -547,33 +547,11 @@ of $x_1$ is higher [@RasmussenWilliams:2006, page 80].
547547The collection of $\rho_d$ (or $1/\rho_d$) parameters can also be
548548modeled hierarchically.
549549
550- The implementation of automatic relevance determination in Stan is
551- straightforward, though it currently requires the user to directly code the
552- covariance matrix. We'll write a function to generate the Cholesky of the
553- covariance matrix called ` L_gp_exp_quad_cov_ARD ` .
550+ The implementation of automatic relevance determination is a straightforward
551+ extension of the one-dimensional case by modifying ` rho ` to be an array.
554552
555553
556554``` stan
557- functions {
558- matrix L_gp_exp_quad_cov_ARD(array[] vector x,
559- real alpha,
560- vector rho,
561- real delta) {
562- int N = size(x);
563- matrix[N, N] K;
564- real sq_alpha = square(alpha);
565- for (i in 1:(N-1)) {
566- K[i, i] = sq_alpha + delta;
567- for (j in (i + 1):N) {
568- K[i, j] = sq_alpha
569- * exp(-0.5 * dot_self((x[i] - x[j]) ./ rho));
570- K[j, i] = K[i, j];
571- }
572- }
573- K[N, N] = sq_alpha + delta;
574- return cholesky_decompose(K);
575- }
576- }
577555data {
578556 int<lower=1> N;
579557 int<lower=1> D;
@@ -584,15 +562,20 @@ transformed data {
584562 real delta = 1e-9;
585563}
586564parameters {
587- vector <lower=0>[D] rho;
565+ array[D] real <lower=0> rho;
588566 real<lower=0> alpha;
589567 real<lower=0> sigma;
590568 vector[N] eta;
591569}
592570model {
593571 vector[N] f;
594572 {
595- matrix[N, N] L_K = L_gp_exp_quad_cov_ARD(x, alpha, rho, delta);
573+ matrix[N, N] L_K;
574+ matrix[N, N] K = gp_exp_quad_cov(x, alpha, rho);
575+ for (n in 1:N) {
576+ K[n, n] = K[n, n] + delta;
577+ }
578+ L_K = cholesky_decompose(K);
596579 f = L_K * eta;
597580 }
598581
0 commit comments