-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcorrspline.m
67 lines (64 loc) · 1.82 KB
/
corrspline.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
function [r, dr] = corrspline(theta, d)
%CORRSPLINE Cubic spline correlation function,
%
% n
% r_i = prod S(theta_j*d_ij) , i = 1,...,m
% j=1
%
% with
% 1 - 15x^2 + 30x^3 for 0 <= x <= 0.5
% S(x) = 1.25(1 - x)^3 for 0.5 < x < 1
% 0 for x >= 1
% If length(theta) = 1, then the model is isotropic:
% all theta_j = theta.
%
% Call: r = corrspline(theta, d)
% [r, dr] = corrspline(theta, d)
%
% theta : parameters in the correlation function
% d : m*n matrix with differences between given data points
% r : correlation
% dr : m*n matrix with the Jacobian of r at x. It is
% assumed that x is given implicitly by d(i,:) = x - S(i,:),
% where S(i,:) is the i'th design site.
% Last update May 30, 2002
[m n] = size(d); % number of differences and dimension of data
if length(theta) == 1
theta = repmat(theta,1,n);
elseif length(theta) ~= n
error(sprintf('Length of theta must be 1 or %d',n))
else
theta = theta(:).';
end
mn = m*n; ss = zeros(mn,1);
xi = reshape(abs(d) .* repmat(theta,m,1), mn,1);
% Contributions to first and second part of spline
i1 = find(xi <= 0.2);
i2 = find(0.2 < xi & xi < 1);
if ~isempty(i1)
ss(i1) = 1 - xi(i1).^2 .* (15 - 30*xi(i1));
end
if ~isempty(i2)
ss(i2) = 1.25 * (1 - xi(i2)).^3;
end
% Values of correlation
ss = reshape(ss,m,n);
r = prod(ss, 2);
if nargout > 1 % get Jacobian
u = reshape(sign(d) .* repmat(theta,m,1), mn,1);
dr = zeros(mn,1);
if ~isempty(i1)
dr(i1) = u(i1) .* ( (90*xi(i1) - 30) .* xi(i1) );
end
if ~isempty(i2)
dr(i2) = -3.75 * u(i2) .* (1 - xi(i2)).^2;
end
ii = 1 : m;
for j = 1 : n
sj = ss(:,j); ss(:,j) = dr(ii);
dr(ii) = prod(ss,2);
ss(:,j) = sj; ii = ii + m;
end
dr = reshape(dr,m,n);
end % Jacobian