20 vector[M] indices = linspaced_vector(M, 1, M);
21 real factor = alpha * sqrt(sqrt(2 * pi()) * rho);
22 real exponent = -0.25 * (rho * pi() / 2 / L)^2;
23 return factor * exp(exponent * square(indices));
42 vector[M] indices = linspaced_vector(M, 1, M);
43 return square(pi() / (2 * L) * indices);
59 return alpha * sqrt(2 ./ denom);
74 real factor = 2 * alpha * (sqrt(3) / rho)^1.5;
76 return factor ./ denom;
91 real factor = 16 * pow(sqrt(5) / rho, 5);
92 vector[M] denom = 3 * pow(5 / square(rho) +
matern_indices(M, L), 3);
93 return alpha * sqrt(factor ./ denom);
107 real a = inv_square(rho);
108 vector[M] indices = linspaced_vector(M, 1, M);
111 (log(2) - a + to_vector(log_modified_bessel_first_kind(indices, a)))
113 return append_row(q, q);
127matrix
PHI(
int N,
int M, real L, vector x) {
128 row_vector[M] k = linspaced_row_vector(M, 1, M);
129 matrix[N, M] phi = sin((pi() / (2 * L) * (x + L)) * k) / sqrt(L);
145 row_vector[M] k = linspaced_row_vector(M, 1, M);
146 matrix[N, M] w0xk = (w0 * x) * k;
147 return append_col(cos(w0xk), sin(w0xk));
165 int stationary,
int future_fixed,
int fixed_from) {
166 int noise_time = estimate_r > 0 ? (stationary > 0 ? ot_h : ot_h - 1) : t;
168 future_fixed > 0 ? (noise_time - horizon + fixed_from) : noise_time;
184matrix
setup_gp(
int M, real L,
int dimension,
int is_periodic, real w0) {
185 vector[dimension] x = linspaced_vector(dimension, 1, dimension);
186 x = 2 * (x - mean(x)) / (max(x) - 1);
190 return PHI(dimension, M, L, x);
208 real rho, vector eta,
int type, real nu) {
209 vector[type == 1 ? 2 * M : M] diagSPD;
214 }
else if (type == 1) {
216 }
else if (type == 2) {
219 }
else if (nu == 1.5) {
221 }
else if (nu == 2.5) {
224 reject(
"nu must be one of 0.5, 1.5, or 2.5; found nu=", nu);
227 return PHI * (diagSPD .* eta);
vector update_gp(matrix PHI, int M, real L, real alpha, real rho, vector eta, int type, real nu)
matrix PHI_periodic(int N, int M, real w0, vector x)
vector diagSPD_EQ(real alpha, real rho, real L, int M)
vector diagSPD_Periodic(real alpha, real rho, int M)
vector diagSPD_Matern12(real alpha, real rho, real L, int M)
int setup_noise(int ot_h, int t, int horizon, int estimate_r, int stationary, int future_fixed, int fixed_from)
matrix setup_gp(int M, real L, int dimension, int is_periodic, real w0)
matrix PHI(int N, int M, real L, vector x)
vector diagSPD_Matern52(real alpha, real rho, real L, int M)
vector diagSPD_Matern32(real alpha, real rho, real L, int M)
vector matern_indices(int M, real L)
void gaussian_process_lp(vector eta)