-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtime_step_RBF_new.m
94 lines (75 loc) · 2.11 KB
/
time_step_RBF_new.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function [x, L]= time_step_RBF_new(W,x,lambda,timestep,time_step_value)
% build the degree function ( d_i = sum_j w_ij)
W=sparse(W);
D=sum(W,2);
laplacian = 1;
[dim num] = size(x);
if nargin<5
time_step_value=0.25;
time_step_value=0.1;
time_step_value=0.25;
time_step_value=0.1;
time_step_value=0.2;%% for depth
time_step_value=0.1;
end
% checks if elements of the degree function are zero and correct this
if(sum(D==0)>0)
disp('Warning, Elements of d are zero');
for i=1:num
if(D(i)==0), D(i)=1; end
end
end
% type of Laplacian (normalized, unnormalized)
% build the final weight matrix - reweighted by some power of the degree
% function \tilde{k}_ij = k_ij / pow(d_i d_j, lambda)
if(lambda~=0)
f=spdiags(1./(D.^lambda), 0, num, num);
W=1/(num)*f*W*f;
clear f;
end
clear d
% final degree function of weights \tilde{k}
e=sum(W,2);
if(sum(e==0)>0)
disp('Warning, Elements of e are zero');
for i=1:num
if(e(i)==0), e(i)=1/(num); end
end
end
% for the time step it is easier to have the transpose of x
x=x';
tic
if(timestep==0)
% explicit timestep
D=spdiags(e,0,num,num);
L=D-W;
step=-0.1*L*x;
x = x + step;
else
% implicit timestep
D=spdiags(e,0,num,num);
L=sparse(D-W);
%L=sparse(L);
switch laplacian
case 0,
%normalized, solve L*x_new =x_old, where L=Id - E^{-1}W
z=(D+0.25*L)\(D*x);
% z=(D+0.1*L)\(D*x);
diff = z - x;
for i=1:num
x(i,:) = x(i,:) + diff(i,:);
end
case 1,
%unnormalized
% z=cholmod(speye(num) + 0.5*L,x);
z = (speye(num) + time_step_value*L)\x;
diff = z - x;
parfor i=1:num
x(i,:) = x(i,:) + diff(i,:);
end
end
end
x=x'; % transform the data back in column format (one data point=one column in x)
t=toc;
% disp(['Time for time step: ', num2str(t),' seconds']);
% time_step_value