We could add a gaussian_process_sq_exp_log() function
that takes a parameterization of a squared exponential.
Something like this for the prior:
real gaussian_process_sq_exp_log(vector y, vector x,
real eta_sq, real rho_sq, real sigma_sq);
and this for the posterior:
real gaussian_process_sq_exp_log(vector y_tilde, vector x_tilde,
vector y, vector x,
real eta_sq, real rho_sq, real sigma_sq);
I just added a 10-page chapter to the manual on coding
Gaussian processes. I start with a simple Stan model that
samples from the prior, discuss a Cholesky transform for
efficient multivariate Gaussian generation, extend it to obvious joint model
that can compute the posterior, then to hyperparameter estimation,
then I unfold it with the analytical posterior. I also do logistic
regression. So it's quite a few models. I tested them all
on simulated data.
lp__ <- lp__ - 0.5 * dot_self(tL_inv * (y - mu));
- Bob
--
I spend all my time using gaussian processes with MCMC.
It is quite surprising where the time is spent. Constructing K and C can be a bottleneck in some cases.
Realising what is dependent and independent on x (the current position) is vital, and storing intermediate vectors of things which are independent of x.
I don;t have time to understand Bob's notation, but my guess is that K is dependent on x and inv(C) * y is independent. So most of the work will be spent in repeatedly contsructing K, little work is done in cholesky factorisation or back substitution, at least for the mean. The variance does need repeated back substitutions.
Of course, to calculate
K' * inv(C) * K
one should calculate
P = L \ K
and then construct
P' * P
There are as many varieties of gaussian processes as there are names. Surrogate, proxy, linear bayes, estimator, radial basis function, etc etc.
There are many flavours of the algorithms. I come more from a linear bayes perspective. I also pay significant attention to a linear regreassion model as a starting point, with second order terms. I use sophisticated techniques to determine the efficient terms in the polynomial.
There are issues such as whether one should include the variance of the regression beta coefficients on the variance.
I actually use Matern correlation functions rather than gaussian. They are more flexible but more time consuming, unless (as i do) you use approximate methods. Taking the derivatives of matern adds extra complexity...
There is another range of choices in the hyperparameters, you can go from one global correlation length to adapting every term in the correlation matrix - but rasmussen discusses these alternatives quite well.
As a point of note, I caculate all the derivatives and use NUTS very successfully.
A lot (all?) of the computation can be easily vectorised. This is where R is excellent, at things like matrix * matrix calculations. I don;t know exactly what underlying libraries they use, but some version of BLAS must be there. A C implementation should use similar libraries.
More commonly I have 50 dimensions and 400 data points. Hence constructing K is a bottleneck.
I also use not just one gaussian process, but up to 500 independent gaussian processes, all of which contribute to a likelihood function which is used in MCMC.
I repeat this MCMC calculation maybe 50 times, it takes a few days for the whole process!
Maybe we are talking with different ssumptions, but....
I am talking about sampling a single Gaussian process using MCMC.
So if we have nS samples, for the mean we do cholesky factorisation 1 time, we construct the k matrix nS times, and we multiply the K matrix by the stored constant vector nS times.
The K matrix takes nData x dimension operations.
So in total the K matrix contruction dominates, it take O(S x dimension x data points) operations.
That is for the mean. The variance is different, of course, you have to do a lot of back substitutions, but again factorisation is only done once for all samples.
Maybe you are talking about optimising the hyper parameters, where of course you have to factorise each time they change.
It is late and i am tired so I may be wrong, I have not checked against my code, but more likely we are talking about different things. If in doubt I can send some profiling results.
Hyperarameter estimation is a subject in itself, there are papers giving the complcated formulae for the derivative of the likelihood function (if doing maximum likelihood evaluation), and other papers taking a bayesian approach to estimation.
Take a look at the www.mucm.ac.uk web site. Technical papers 09/05 and 11/03 may be of interest.