-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathivmUpdateM.m
78 lines (73 loc) · 2.6 KB
/
ivmUpdateM.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
77
78
function model = ivmUpdateM(model, index)
% IVMUPDATEM Update matrix M, L, v and mu.
% FORMAT
% DESC updates the stored representations in the IVM (M, L,
% v and mu) given a new data point.
% ARG model : the model for which the represenations are to be
% updated.
% ARG index : the index of the data point that is being included.
% RETURN model : the returned model with all the representations up
% to date.
%
% SEEALSO : ivmCreate, ivmAddPoint, kernCompute
%
% COPYRIGHT : Neil D. Lawrence, 2005
% IVM
activePoint = length(model.I)+1;
% Compute the kernel(s) at the new point.
model.kern.Kstore(:, activePoint) = kernCompute(model.kern, model.X, ...
model.X(index, :));
if isfield(model.kern, 'whiteVariance')
model.kern.Kstore(index, activePoint) = model.kern.Kstore(index, activePoint) ...
+ model.kern.whiteVariance;
end
% Compute the values of M for the new point
for c = 1:length(model.Sigma)
if length(model.I) > 0
a = model.Sigma(c).M(:, index);
s = model.kern.Kstore(:, activePoint)' - a'*model.Sigma(c).M;
lValInv = sqrt(model.nu(index, c));
%/~
% If Nu is so low then the included data-point isn't really useful.
if lValInv < 1e-16
warning(['Square root of nu is ' num2str(lValInv)])
end
%~/
model.Sigma(c).M = [model.Sigma(c).M; lValInv*s];
ainv = (-a*lValInv)'/model.Sigma(c).L;
model.Sigma(c).L = [[model.Sigma(c).L; a'] [zeros(length(model.I),1); 1/lValInv]];
model.Sigma(c).Linv = [[model.Sigma(c).Linv; ainv] [zeros(length(model.I),1); lValInv]];
else
s = model.kern.Kstore(:, 1)';
lValInv = sqrt(model.nu(index, c));
model.Sigma(c).M = [lValInv*s];
model.Sigma(c).L = 1/lValInv;
model.Sigma(c).Linv = lValInv;
end
%/~
oldVarSigma = model.varSigma(:, c);
%~/
model.varSigma(:, c) = model.varSigma(:, c) - ((model.nu(index, c)*s).*s)';
%/~
if any(model.varSigma(:, c)<0)
minVar = min(model.varSigma(:, c));
warning(['Minimum variance ' num2str(minVar)])
model.varSigma(find(model.varSigma(:, c) < 0), c) = 0;
end
% Seems like this variance can go as low as 1e-13 in, for example, demRegression1.m
%~/
model.mu(:, c) = model.mu(:, c) + model.g(index, c)*s';
end
if length(model.Sigma)==1 & size(model.y, 2)>1
for c = 2:size(model.y, 2)
model.varSigma(:, c) = model.varSigma(:, c) ...
- ((model.nu(index, c)*s).*s)';
model.mu(:, c) = model.mu(:, c) + model.g(index, c)*s';
%/~
if any(model.varSigma(:, c)<0)
minVar = min(model.varSigma(:, c));
warning(['Minimum variance ' num2str(minVar)])
end
%~/
end
end