Skip to content

Commit 95e16c6

Browse files
committed
initial commit
1 parent d9fcf06 commit 95e16c6

35 files changed

+1389
-0
lines changed

Figure1.m

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
clear all
2+
close all
3+
clc
4+
5+
G1 = [1 0; 0 1];
6+
G2 = [0 1; 1 0];
7+
G3 = 0.5;
8+
9+
G1 = imresize(G1,50,'nearest');
10+
G2 = imresize(G2,50,'nearest');
11+
G3 = imresize(G3,100,'nearest');
12+
13+
Fig = figure(1);
14+
G1(:,1) = 0;
15+
G1(1,:) = 0;
16+
G1(:,end) = 0;
17+
G1(end,:) = 0;
18+
imshow(G1);
19+
20+
text(22,25,'0','color',[0 0 0], 'fontsize',20);
21+
text(72,25,'1','color',[0.99 0.99 0.99],'backgroundcolor','k', 'fontsize',20);
22+
text(22,75,'1','color',[0.99 0.99 0.99],'backgroundcolor','k', 'fontsize',20);
23+
text(72,75,'0','color',[0 0 0], 'fontsize',20);
24+
25+
Fig_prop = get(gcf);
26+
boundbox = Fig_prop.PaperPosition;
27+
width = boundbox(3);
28+
height = boundbox(4);
29+
set(gcf, 'PaperPosition', [0, 0, width, height]);
30+
set(gcf, 'PaperSize', [width height]);
31+
% saveas(Fig, 'twin_eg_w.eps','epsc');
32+
33+
34+
Fig = figure(2);
35+
G2(:,1) = 0;
36+
G2(1,:) = 0;
37+
G2(:,end) = 0;
38+
G2(end,:) = 0;
39+
40+
imshow(G2);
41+
text(22,25,'1','color',[0.99 0.99 0.99],'backgroundcolor','k', 'fontsize',20);
42+
text(72,25,'0','color',[0 0 0], 'fontsize',20);
43+
text(22,75,'0','color',[0 0 0], 'fontsize',20);
44+
text(72,75,'1','color',[0.99 0.99 0.99],'backgroundcolor','k', 'fontsize',20);
45+
46+
Fig_prop = get(gcf);
47+
boundbox = Fig_prop.PaperPosition;
48+
width = boundbox(3);
49+
height = boundbox(4);
50+
set(gcf, 'PaperPosition', [0, 0, width, height]);
51+
set(gcf, 'PaperSize', [width height]);
52+
% saveas(Fig, 'twin_eg_w1.eps','epsc');
53+
54+

Figure2.m

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
clear all
2+
close all
3+
clc
4+
5+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6+
% This routine reproduces the results of Figure 2
7+
%
8+
% Stanley Chan
9+
% Harvard University
10+
% Dec 28, 2013
11+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12+
13+
%========= Load Package ===========%
14+
addpath(genpath('./deconvtv_v1/'));
15+
16+
17+
18+
%========= Experiment Setup =======%
19+
n = 500; % Number of nodes
20+
caseid = 4; % Graphon ID
21+
wtrue = gen_graphon(n,caseid); % Generate a graphon
22+
G = construct_a_graph_from_P(wtrue,n,1); % Sample a random graph
23+
pidx = randperm(n); % Randomly permute col/row
24+
G = G(pidx,pidx);
25+
26+
27+
%========= Sort and Smooth ========%
28+
[M0 N0] = size(G);
29+
n = M0;
30+
h = round(log(n));
31+
32+
% Empirical Degree Sorting
33+
d = mean(G);
34+
[~, pos] = sort(d,'ascend');
35+
A = G(pos,pos);
36+
37+
% Histogram
38+
H = imfilter(A, ones(h)/h^2, 'symmetric');
39+
H = H(1:h:end, 1:h:end);
40+
41+
% TV
42+
opts.beta = [1 1 0];
43+
opts.print = false;
44+
opts.method = 'l2';
45+
[M N] = size(H);
46+
M2 = round(M/2);
47+
N2 = round(N/2);
48+
Hpad = padarray(H, [M2 N2], 'symmetric');
49+
50+
out = deconvtv(Hpad,1,7.5,opts);
51+
what = out.f;
52+
wtv = what(M2+1:end-M2, N2+1:end-N2);
53+
54+
west = imresize(wtv,[M0,N0],'nearest');
55+
56+
57+
58+
59+
60+
%========= Display Results ========%
61+
Fig = figure(1);
62+
imagesc(G); axis image; colormap(gray);
63+
export_fig Illustration_G.eps -transparent
64+
65+
Fig = figure(2);
66+
imagesc(A); axis image; colormap(gray);
67+
export_fig Illustration_A.eps -transparent
68+
69+
70+
Fig = figure(3);
71+
imagesc(H); axis image;
72+
export_fig Illustration_H.eps -transparent
73+
74+
Fig = figure(4);
75+
imagesc(wtv); axis image;
76+
export_fig Illustration_wtv.eps -transparent
77+
78+
79+

Figure3.m

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
clear all
2+
close all
3+
clc
4+
5+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6+
% This routine reproduces the results of Figure 3
7+
%
8+
% Stanley Chan
9+
% Harvard University
10+
% Dec 28, 2013
11+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12+
13+
%========= Load Package ===========%
14+
addpath(genpath('./deconvtv_v1/'));
15+
16+
17+
%========= Experiment Setup =======%
18+
n = 1000; % Number of nodes
19+
caseid = 1; % Graphon ID
20+
wtrue = gen_graphon(n,caseid); % Generate a graphon
21+
G = construct_a_graph_from_P(wtrue,n,1); % Sample a random graph
22+
pidx = randperm(n); % Randomly permute col/row
23+
G = G(pidx,pidx);
24+
25+
26+
27+
28+
29+
%========= Sort and Smooth (Proposed) ====%
30+
t0 = tic;
31+
wsas = sort_and_smooth(G);
32+
t_sas = toc(t0);
33+
34+
%========= USVT (Chatterjee 2012) ========%
35+
t1 = tic;
36+
wusvt = usvt(G);
37+
t_usvt = toc(t1);
38+
39+
%========= SBA (Airoldi et al. 2013) =====%
40+
t2 = tic;
41+
h_opt = oracle_h(G,wtrue);
42+
wsba = stochastic_block(G,h_opt);
43+
t_sba = toc(t2);
44+
45+
46+
47+
48+
49+
%========= Display Result =====%
50+
Fig = figure(1);
51+
imagesc(wtrue); axis image; axis off;
52+
export_fig wtrue_1.eps -transparent
53+
54+
Fig = figure(2);
55+
imagesc(wsas); axis image; axis off;
56+
export_fig wsas_1.eps -transparent
57+
58+
Fig = figure(3);
59+
imagesc(wusvt); axis image; axis off;
60+
export_fig wusvt_1.eps -transparent
61+
62+
Fig = figure(4);
63+
imagesc(wsba); axis image; axis off;
64+
export_fig wsba_1.eps -transparent
65+
66+

Figure4.m

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
clear all
2+
close all
3+
clc
4+
5+
addpath(genpath('./deconvtv_v1/'));
6+
n_set = round(logspace(log10(100),log10(2500),50));
7+
8+
mse_sas = zeros(10,length(n_set));
9+
mse_usvt = zeros(10,length(n_set));
10+
mse_sba = zeros(10,length(n_set));
11+
12+
t_sas = zeros(10,length(n_set));
13+
t_usvt = zeros(10,length(n_set));
14+
t_sba = zeros(10,length(n_set));
15+
16+
17+
% Main Loop
18+
for cidx = 1:1
19+
caseid = cidx;
20+
fprintf('cidx = %3g, \n', cidx);
21+
22+
for nidx=1:length(n_set)
23+
fprintf('nidx = %3g, \n', nidx);
24+
25+
% Generate a graphon
26+
n = n_set(nidx);
27+
wtrue = gen_graphon(n,caseid);
28+
29+
% Sample a random graph from the graphon
30+
G = construct_a_graph_from_P(wtrue,n,1);
31+
pidx = randperm(n);
32+
G = G(pidx,pidx);
33+
34+
% Apply Sort and Smooth
35+
t0 = tic;
36+
wsas = sort_and_smooth(G);
37+
t_sas(cidx,nidx) = toc(t0);
38+
39+
% Apply USVT
40+
t1 = tic;
41+
wusvt = usvt(G);
42+
t_usvt(cidx,nidx) = toc(t1);
43+
44+
% Apply Stochastic Blockmodel Approximation
45+
t2 = tic;
46+
wsba = stochastic_block(G,round(log(n)));
47+
t_sba(cidx,nidx) = toc(t2);
48+
49+
% Record MSE
50+
mse_sas(cidx,nidx) = mean((wsas(:) -wtrue(:)).^2);
51+
mse_usvt(cidx,nidx) = mean((wusvt(:)-wtrue(:)).^2);
52+
mse_sba(cidx,nidx) = mean((wsba(:) -wtrue(:)).^2);
53+
end
54+
end
55+
56+
Fig = figure(1);
57+
plot(n_set(1:2:end), mean(t_sas(:,1:2:end)), '-x', 'LineWidth',2); hold on;
58+
plot(n_set(1:2:end), mean(t_usvt(:,1:2:end)), 'r-o', 'LineWidth',2);
59+
plot(n_set(1:2:end), mean(t_sba(:,1:2:end)), 'k-^', 'LineWidth',2);
60+
grid on;
61+
xlabel('n');
62+
ylabel('Runtime (Seconds)');
63+
legend('SAS (proposed)','USVT','SBA','Location','NW');
64+
% export_fig runtime.eps -transparent

Figure5.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
clear all
2+
close all
3+
clc
4+
5+
%%%%%%%%%%%%%%%%%%%%%%%%%%%
6+
% This program tests the Stanford Network Data
7+
%%%%%%%%%%%%%%%%%%%%%%%%%%%
8+
9+
addpath(genpath('./deconvtv_v1/'));
10+
11+
load('./data/ca-AstroPh.mat');
12+
G = Problem.A;
13+
clear Problem;
14+
15+
% Reduce data size and symmetrize data
16+
% G = G(1:10:end,1:10:end);
17+
G = G - diag(diag(G)); % remove diagonal
18+
G = (G + G')/2>0;
19+
20+
21+
% tic
22+
% Empirical Degree Sorting and rearrangement
23+
d = mean(G);
24+
[~, pos] = sort(d,'descend');
25+
A = G(pos,pos);
26+
d = mean(A);
27+
28+
29+
% Parameter
30+
n = size(A,1);
31+
h = 20; % h = 20 for ca-Astroph, h = 30 for soc-Epinion
32+
k = round(n/h); % number of bins
33+
34+
binwidth = h*ones(1,k);
35+
cum = cumsum(binwidth); % cumulative sum of bin widths
36+
binwidth(cum>n) = []; % remove oversized bins
37+
binwidth = [binwidth n-sum(binwidth)]; % compensate the last bin
38+
binstart = cumsum(binwidth); % record the starting bin ID
39+
40+
% Histogram
41+
H = zeros(k,k);
42+
for i=1:length(binstart)-1
43+
fprintf('i = %3g / %3g \n', i,k);
44+
for j=1:length(binstart)-1
45+
H(i,j) = (nnz(A(binstart(i):binstart(i+1), binstart(j):binstart(j+1)))>0);
46+
end
47+
end
48+
49+
% TV minimization
50+
opts.beta = [1 1 0];
51+
opts.print = true;
52+
opts.method = 'l2';
53+
[M N] = size(H);
54+
M2 = 10;
55+
N2 = 10;
56+
Hpad = padarray(H, [M2 N2], 'symmetric');
57+
out = deconvtv(Hpad,1,2.5,opts);
58+
wtv = out.f;
59+
wtv = wtv(M2+1:end-M2, N2+1:end-N2);
60+
61+
imagesc(wtv); axis image; axis off;
62+
% export_fig Graphon_soc_Epinions1.eps -transparent

Readme.txt

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
================================================
2+
Sort and Smooth (SAS) Algorithm for Consistent Graphon Estimation
3+
4+
5+
================================================
6+
This MATLAB package is a supplement to the paper
7+
8+
S. H. Chan and E. M. Airoldi, "A Consistent Histogram Estimator for Exchangeable Graph Models", in Proceedings of International Conference on Machine Learning, 2014.
9+
10+
11+
================================================
12+
Content:
13+
14+
1. Construct Graphs from a Graphon
15+
Method 1: [G P u] = construct_a_graph(w,n,T)
16+
Input: w - a Graphon
17+
n - number of nodes
18+
T - number of observations
19+
Output: G - graph (size nxnxT)
20+
P - probability of each node
21+
u - label indices
22+
23+
Method 2: G = construct_a_graph_from_P(P,n,T)
24+
Input: P - probability of each node
25+
n - number of nodes
26+
T - number of observations
27+
Output: G - graph (size nxnxT)
28+
29+
2. Sorting and Smoothing (sort_and_smooth.m)
30+
Input: G - a graph
31+
Output: west - estimated graphon
32+
33+
Algorithm dependency: ./deconvtv_v1/
34+
35+
36+
3. Results reported in the paper
37+
Figure1.m - plot a twin graphon
38+
Figure2.m - display an example of the SAS algorithm
39+
Figure3.m - results of SAS, USVT and SBA for graphons no. 5 and no. 10
40+
Figure4.m - runtime plot
41+
Figure5.m - graphon estimation of soc-Epinion1 and ca-astroph network
42+
Table2.m - mean squared error (average and standard deviation) of SAS, USVT and SBA.
43+
44+
4. Compared Methods
45+
(i) stochastic_block.m (Stochastic Blockmodel Approximation, Airoldi et al. 2013)
46+
(ii) usvt.m (Universal Singular Value Thresholding, Chatterjee 2012)
47+
48+
49+
50+
References
51+
[1] E. M. Airoldi, T. B. Costa, and S. H. Chan, "Stochastic blockmodel approximation of a graphon: Theory and consistent estimation", Advances in Neural Information Processing Systems. ArXiv: 1311.1731. 2013.
52+
53+
[2] S. Chatterjee. Matrix estimation by universal singular value thresholding. ArXiv:1212.1247. 2012.
54+
55+
56+
57+
58+
================================================
59+
Please report bugs to Stanley Chan [email protected]
60+
61+
Last update: January 10, 2014

0 commit comments

Comments
 (0)