forked from lawrennd/gp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
demGpSample.m
57 lines (51 loc) · 1.23 KB
/
demGpSample.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
% DEMGPSAMPLE Simple demonstration of sampling from a covariance function.
% GP
randn('seed', 1e5)
rand('seed', 1e5)
bw = false;
x = linspace(-1, 1, 25)';
kern = kernCreate(x, 'rbf');
kern.inverseWidth = 10;
figure(1)
clf
K = kernCompute(kern, x);
imagesc(K);
if bw
colormap gray
else
colormap jet
end
colorbar
t = [];
t = [t xlabel('n')];
t = [t ylabel('m')];
set(gca, 'fontname', 'times')
set(gca, 'fontsize', 24)
if exist('printDiagram', 'var') && printDiagram
printPlot('gpCovariance', '../tex/diagrams/', '../html');
end
% need to take the real part of the sample as the kernel is numerically less than full rank
f = real(gsamp(zeros(1, size(x, 1)), K, 1))';
figure(2)
clf
a = plot(f, 'k.');
t = [t text(12.5, -.5, 'n')];
t = [t text(-5, .5, 'f_n')];
set(t, 'fontname', 'times')
set(t, 'fontsize', 24)
set(t, 'fontangle', 'italic')
set(gca, 'fontname', 'times')
set(gca, 'fontsize', 18)
set(a,'markersize', 20)
set(a, 'linewidth', 2)
zeroAxes(gca)
if exist('printDiagram', 'var') && printDiagram
printPlot('gpSample', '../tex/diagrams/', '../html');
end
% if bw
% set(a, 'color', [0 0 0])
% print('-deps', '../tex/diagrams/gpSamplebw.eps');
% else
% print('-depsc', '../tex/diagrams/gpSample.eps');
% end
save demGpSample K x f