-
Notifications
You must be signed in to change notification settings - Fork 92
/
gpPosteriorMeanCovarTest.m
43 lines (40 loc) · 1.45 KB
/
gpPosteriorMeanCovarTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function [analMu, analCov, diffMu, diffCov] = gpPosteriorMeanCovarTest(model, X)
% GPPOSTERIORMEANCOVARTEST Test the gradients of the mean and covariance.
% FORMAT
% DESC tests the gpPosteriorMeanCovar and gpPosteriorGradMeanCovar
% functions.
% ARG model : the model to test the gradients for.
% ARG X : the input locations to test the gradients for.
% RETURN analMu : the analytical gradients of the mean with respect
% to X.
% RETURN analCov : the analytical gradients of the covariance with respect
% to X.
% RETURN diffMu : the numerical gradients of the mean with respect
% to X.
% RETURN diffCov : the numerical gradients of the covariance with respect
% to X.
% RETURN delta : erros between the numerical and analytical
% gradients.
%
% SEEALSO : gpPosteriorMeanCovar, gpPosteriorGradMeanCovar
%
% COPYRIGHT : Neil D. Lawrence, 2006
% GP
[analMu, analCov] = gpPosteriorGradMeanCovar(model, X);
origX = X;
change = 1e-6;
for i = 1:size(X, 1)
for j = 1:size(X, 2)
X(i, j) = origX(i, j) - change;
[muMinus, covMinus] = gpPosteriorMeanCovar(model, X);
X(i, j) = origX(i, j) + change;
[muPlus, covPlus] = gpPosteriorMeanCovar(model, X);
X(i, j) = origX(i, j);
diffMu{j}(i, :) = (muPlus(i, :) - muMinus(i, :))/(2*change);
for k = 1:model.d
% Not sure why the transpose is need here ... hope it isn't
% two wrongs making a right ...
diffCov{j, k}(:, i) = (covPlus{k}(i, :) - covMinus{k}(i, :))'/(2*change);
end
end
end