-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinterpolate_kernel.m
More file actions
88 lines (66 loc) · 2.04 KB
/
Copy pathinterpolate_kernel.m
File metadata and controls
88 lines (66 loc) · 2.04 KB
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
79
80
81
82
83
84
85
86
87
88
addpath ..
clear all
seed=0;
randn('state',seed);
rand('state',seed);
try
ccc=openfig('interpolate_kernel.fig');
catch
disp('missing figure file')
end
n = 10;
x = rand(n,1)*2-1;
y = abs(x) -1 + randn(n,1)*.1;
y = randn(n,1);
xtest = 2*(0:.001:1)'-1;
% gaussian kernel
alphak = 6;
K = exp( -sq_dist(x',x') * alphak );
Ktest = exp( -sq_dist(xtest',x') * alphak );
alpha = K \ y;
yest1 = Ktest*alpha;
plot(xtest,yest1,'r','linewidth',2); hold on;
plot(x,y,'kx','markersize',8); hold off;
% exponential kernel
alphak = 2;
K = exp( -sqrt(sq_dist(x',x')) * alphak );
Ktest = exp( -sqrt(sq_dist(xtest',x')) * alphak );
alpha = K \ y;
yest2 = Ktest*alpha;
plot(xtest,yest1,'r','linewidth',2); hold on;
plot(xtest,yest2,'b','linewidth',2); hold on;
plot(x,y,'kx','markersize',8); hold off;
% exponential kernel - 2
alphak = 2;
temp = sqrt(sq_dist(x',x'));
K = (1 + sqrt(sq_dist(x',x')) * alphak ).* exp( -sqrt(sq_dist(x',x')) * alphak );
Ktest = (1 +sqrt(sq_dist(xtest',x')) * alphak ).* exp( -sqrt(sq_dist(xtest',x')) * alphak );
alpha = K \ y;
yest3 = Ktest*alpha;
plot(xtest,yest1,'r','linewidth',2); hold on;
plot(xtest,yest2,'b','linewidth',2); hold on;
plot(xtest,yest3,'k','linewidth',2); hold on;
plot(x,y,'kx','markersize',16); hold off;
% exponential kernel - 3
alphak = 2;
temp = sqrt(sq_dist(x',x'));
K = (1 + sqrt(sq_dist(x',x')) * alphak + sq_dist(x',x') * alphak^2 / 3 ).* exp( -sqrt(sq_dist(x',x')) * alphak );
Ktest = (1 + sqrt(sq_dist(xtest',x')) * alphak + sq_dist(xtest',x') * alphak^2 / 3 ).* exp( -sqrt(sq_dist(xtest',x')) * alphak );
alpha = K \ y;
yest4 = Ktest*alpha;
plot(xtest,yest2,'m','linewidth',2); hold on;
plot(xtest,yest3,'k','linewidth',2); hold on;
plot(xtest,yest4,'r','linewidth',2); hold on;
plot(xtest,yest1,'b','linewidth',2); hold on;
plot(x,y,'g.','markersize',30); hold off;
legend('Exponential (s=1)','Matern (s=2)','Matern (s=3)','Gaussian')
set(gca,'fontsize',24)
axis([-1 1 -10 10])
xlabel('x');
ylabel('y');
try
print('-depsc', 'interpolate_kernel.eps');
close(ccc)
catch
disp('missing figure file')
end