forked from lawrennd/gp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpComputeAlpha.m
76 lines (71 loc) · 2.12 KB
/
gpComputeAlpha.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function model = gpComputeAlpha(model, m)
% GPCOMPUTEALPHA Update the vector `alpha' for computing posterior mean quickly.
% FORMAT
% DESC updates the vectors that are known as `alpha' in the support
% vector machine, in other words invK*y, where y is the target values.
% ARG model : the model for which the alphas are going to be
% updated.
% ARG m : the values of m for which the updates will be made.
% RETURN model : the model with the updated alphas.
%
% SEEALSO : gpCreate, gpUpdateAD, gpUpdateKernels
%
% COPYRIGHT : Neil D. Lawrence, 2006, 2009
% GP
if nargin < 2
m = model.m;
end
switch model.approx
case 'ftc'
model.alpha = zeros(model.N, model.d);
if ~isfield(model, 'isSpherical') | model.isSpherical
model.alpha = model.invK_uu*m;
else
for i = 1:model.d
ind = gpDataIndices(model, i);
model.alpha(ind, i) = model.invK_uu{i}* ...
m(ind, i);
end
end
case {'dtc', 'dtcvar'}
model.alpha = zeros(model.k, model.d);
if ~isfield(model, 'isSpherical') | model.isSpherical
model.alpha = model.Ainv*model.K_uf*m;
else
for i = 1:model.d
ind = gpDataIndices(model, i);
model.alpha(:, i) = model.Ainv{i} ...
*model.K_uf(:, ind) ...
*m(ind, i);
end
end
case 'fitc'
model.alpha = zeros(model.k, model.d);
if ~isfield(model, 'isSpherical') | model.isSpherical
model.alpha = model.Ainv*model.K_uf*model.Dinv*m;
else
for i = 1:model.d
ind = gpDataIndices(model, i);
model.alpha(:, i) = model.Ainv{i} ...
*model.K_uf(:, ind) ...
*model.Dinv{i}*m(ind, i);
end
end
case 'pitc'
model.alpha = zeros(model.k, model.d);
if ~isfield(model, 'isSpherical') | model.isSpherical
for i = 1:length(model.blockEnd)
ind = gpBlockIndices(model, i);
model.alpha = model.alpha+model.Ainv*model.K_uf(:, ind)* ...
model.Dinv{i}*m(ind, :);
end
else
for i = 1:length(model.blockEnd)
for j = 1:model.d
ind = gpDataIndices(model, j, i);
model.alpha(:, j) = model.alpha(:, j)+model.Ainv{j}*model.K_uf(:, ind)* ...
model.Dinv{i, j}*m(ind, j);
end
end
end
end