Skip to content

Commit 80185f9

Browse files
committed
1st commit of rdpg. Steps 1 and 2 as outlined in email (see analysis.m)
1 parent 4078c39 commit 80185f9

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

rdpg/analysis.m

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
% %% Pipeline as outlined below by Jovo (via e-mail)
2+
%
3+
% 1) for each graph, compute the scaled sign positive graph laplacian of
4+
% each graph (call it L_i). one obtains this by filling in the diagonal of
5+
% each adjacency matrix by the degree of that vertex, divided by n-1 (this
6+
% is the expected weight of the self loop).
7+
%
8+
% 2) compute an svd of L_i for all i. look at the scree plots.
9+
% presumably, a relatively small number of eigenvalues should suffice to
10+
% capture most of the variance.
11+
%
12+
% 3) build a classifier using only the first d singular vectors. we
13+
% haven't really thought much about this, but svd implicitly assumes
14+
% gaussian noise, so, the optimal classifier under this assumption is a
15+
% discriminant classifier. the code i have in the repo for discriminant
16+
% classifiers is still in progress, but if you want to fix it up, that'd be
17+
% fine. report results for the discriminant classifiers (LDA and QDA, but
18+
% with diagonal covariance matrices and whitened covariance matrices).
19+
%
20+
% 4) cluster the singular vectors. do this by initializing with a
21+
% hierarchical clustering algorithm, and then use that to seed a k-means
22+
% algorithm. you can do this for a variety of values of k and d. choose
23+
% the one with the best BIC. marchette will send details for computing BIC
24+
% values here, and for implementing the "k-means" algorithm, which is, in
25+
% fact, more like a constrained finite gaussian mixture model algorithm.
26+
%
27+
% 5) given a particular choice of k and d, build a classifier. here, each
28+
% class is a mixture of gaussians, so a naive discriminant classifier is
29+
% insufficient. instead, one can implement a bayes plugin classifier. so,
30+
% given the fit of the mixture distributions for the two classes, compute
31+
% whether a test graph is closer to class 0 or class 1 distribution.
32+
33+
%% Setup - Change to fit your desires
34+
35+
% this is just where i load stuff from my computer
36+
load /users/dsussman/documents/MATLAB/Brain_graphs/BLSA79_data.mat;
37+
38+
% you can set up stuff however you want here
39+
40+
%% Step 1 - Compute Laplacians
41+
Ls = graph_laplacian(As);
42+
43+
%% Step 2 - Compute SVDs and make scree plots
44+
[Us, Ss, Vs] = graph_svd(Ls);
45+
sz = size(Ss);
46+
singVals = zeros(sz(1),sz(3)); % col vectors of singular vals
47+
for k=1:sz(3)
48+
singVals(:,k) = diag(squeeze(Ss(:,:,k)));
49+
end
50+
51+
52+
% show scree plots of for all the graphs, red is targs is true blue is
53+
% targs is false
54+
figure(401);
55+
hold all;
56+
plot( singVals(:,targs==1), 'r');
57+
plot( singVals(:,targs==0), 'b');
58+
59+
%%

rdpg/graph_laplacian.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function [ L ] = graph_laplacian( A )
2+
%graph_laplacian Comput scaled sign positive graph laplacian
3+
% compute the scaled sign positive graph laplacian of each graph (call it
4+
% L_i). one obtains this by filling in the diagonal of each adjacency
5+
% matrix by the degree of that vertex, divided by n-1 (this is the
6+
% expected weight of the self loop).
7+
d = size(A);
8+
L=A;
9+
if numel(d)==2
10+
for k=1:d(1)
11+
L(k,k) = sum(A(k,:))/(d(1)-1);
12+
end
13+
end
14+
if numel(d) == 3
15+
for g=1:d(3)
16+
for k=1:d(1)
17+
L(k,k,g) = sum(A(k,:,g))/(d(1)-1);
18+
end
19+
end
20+
end
21+
end
22+

rdpg/graph_svd.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function [ U, S, V ] = graph_svd( L )
2+
%graph_svd Computes the SVD of the Laplacian of an adjacancy matrix or
3+
%matrices
4+
% Returns the standard U,S,V matrix or matrices for each Laplacian matrix
5+
% in L. Ie L can be either a 2d square matrix or a 3d array of square
6+
% matrices.
7+
% Q: Do we need to keep U or V or should we just return a vector of
8+
% singular values?
9+
d = size(L);
10+
if numel(d) == 2
11+
[U,S,V] = svd(L);
12+
return;
13+
end
14+
U = zeros(d);
15+
S = U;
16+
V = U;
17+
for k=1:d(3)
18+
[U(:,:,k),S(:,:,k),V(:,:,k)] = svd(L(:,:,k));
19+
end
20+
21+
end
22+

0 commit comments

Comments
 (0)