-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathKrigingVariance.m
44 lines (41 loc) · 1.76 KB
/
KrigingVariance.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
% Kriging Variance
% Computes and plots the kriging variance for 2D covariance kernels
% Also produces some plots of optimal kriging weights
% Calls on: DistanceMatrix
K = @(e,r) exp(-(e*r).^2); % Define the Gaussian RBF
%K = @(epsilon,r) exp(-epsilon*r); % basic Matern
%K = @(epsilon,r) exp(-epsilon*r).*(3+3*epsilon*r+(epsilon*r).^2); % Matern quadratic
ep = 5;
N = 225; gridtype = 'u';
dsites = CreatePoints(N,2,gridtype);
ctrs = dsites;
neval = 40; M = neval^2;
epoints = CreatePoints(M,2,'u');
DM_data = DistanceMatrix(dsites,ctrs);
Kmatrix = K(ep,DM_data);
DM_basis = DistanceMatrix(ctrs,epoints); % note that this is a matrix evaluating all
% of the basis functions at epoints; one per row
kvectors = K(ep,DM_basis);
Kxx = K(ep,0);
weights = Kmatrix\kvectors;
krigingvariance = Kxx-sum(kvectors.*weights,1);
% Plot kriging variance
figure
xe = reshape(epoints(:,1),neval,neval);
ye = reshape(epoints(:,2),neval,neval);
Kvplot = surf(xe,ye,reshape(krigingvariance,neval,neval));
set(Kvplot,'FaceColor','interp','EdgeColor','none')
set(gca,'ZScale','log')
% Plot a kriging weight
figure
Kwplot = surf(xe,ye,reshape(weights(1,:),neval,neval));
set(Kwplot,'FaceColor','interp','EdgeColor','none')
colormap autumn; view([145 45]); camlight; lighting gouraud
figure
Kwplot = surf(xe,ye,reshape(weights(ceil(N/2),:),neval,neval));
set(Kwplot,'FaceColor','interp','EdgeColor','none')
colormap autumn; view([145 45]); camlight; lighting gouraud
figure
Kwplot = surf(xe,ye,reshape(weights(ceil(sqrt(N)/2),:),neval,neval));
set(Kwplot,'FaceColor','interp','EdgeColor','none')
colormap autumn; view([145 45]); camlight; lighting gouraud