-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdemo9.m
More file actions
116 lines (80 loc) · 1.99 KB
/
demo9.m
File metadata and controls
116 lines (80 loc) · 1.99 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
clear all
close all
clc
% load predefined W matrix for 100 nodes
load mydata
% calculate combinatorial Laplacian Matrix
d = sum(W,2);
L = diag(d)-W;
% find eigenvector and eigenvalues of combinatorial Laplacian
[u v]=eig(L);
% make eignevalue as vector
v=diag(v);
% get maximum eigenvalue
lmax=max(v);
v(v<0)=0;
% create signal where first node is 1 rest of them zero
s=zeros(size(W,1),1);
s(1)=1;
% determine filter
flt =exp(-20*v);
% apply that filter on to graph signal
sf=u*(flt.*(u'*s));
U=zeros(10000,100);
S=zeros(100,10000);
it=0;
for i=1:100:10000
it=it+1;
for j=1:100
U(i:i+100-1,j)=u(:,j)*u(it,j);
end
S(it,i:i+100-1)=s';
end
K=50;
nv=linspace(0,8,K);
basis=bspline_basis(K, nv,v, 3);
A=S*U*basis;
alpha=pinv(A)*sf;
figure;plot(alpha);
xlabel('coeff id');
title('learned filter coeffs \alpha from first graph');
flt2=basis*alpha;
sf2=u*(flt2.*(u'*s));
figure;plot(sf2);hold on;plot(sf,'r-')
% visualize input and result
run gspbox/gsp_start
G=gsp_graph(W,coord);
figure;gsp_plot_signal(G,sf2)
title('Filtered signal on first Graph');
load data2
% calculate combinatorial Laplacian Matrix
d = sum(WW,2);
L = diag(d)-WW;
% calculate Laplacian Matrix
% find eigenvector and eigenvalues of combinatorial Laplacian
[u v]=eig(L);
% make eignevalue as vector
v=diag(v);
% get maximum eigenvalue
lmax=max(v);
v(v<0)=0;
% create signal where first node is 1 rest of them zero
s=zeros(size(WW,1),1);
s(1)=1;
% determine filter
flt =exp(-20*v);
% apply that filter on to graph signal
sf=u*(flt.*(u'*s));
% determine filter
basis=bspline_basis(K, nv,v, 3);
flt=basis*alpha;
% apply that filter on to graph signal
sf2=u*diag(flt)*u'*s;
G=gsp_graph(WW,coord2);
figure;gsp_plot_signal(G,sf2)
title('Filtered signal on second graph by learned coeff');
figure;gsp_plot_signal(G,sf)
title('Filtered signal on second graph by standart filter');
figure;plot(sf2);hold on;plot(sf,'r-')
xlabel('node id')
legend({'filter result by learned coeff','filter result by standart filter'})