-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFilterAdjMatFacebook.m
56 lines (48 loc) · 1.88 KB
/
FilterAdjMatFacebook.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
% Script to filter out inactive nodes and nodes with low degrees from
% Viswanath et al. (2009)'s Facebook data
% Author: Ruthwik Junuthula & Kevin S. Xu
binSize = 90; % Size of time bins in days
minDegfrnd = 120; % Minimum degree over the entire friendship adj matrix
minOutInDeg = 0; % Minimum out or in-degree over the entire interactions adj matrix
matFilePath = '';
dataFile = [matFilePath 'FacebookBothAdj' int2str(binSize) 'Days.mat'];
%% Load adjacency matrices
load(dataFile)
tMax = length(adj);
%% Compute minimum degree over friendships
adjAllTimes = frndadj{1};
for t = 2:tMax
adjAllTimes = adjAllTimes + frndadj{t};
end
adjAllTimes(adjAllTimes>0) = 1;
% Identify nodes with at least the minimum degree and remove all other nodes
degfrnd = sum(adjAllTimes)';
minDegNodesfrnd = (degfrnd>=minDegfrnd);
%% Compute minimum degree over interactions (wall posts)
adjAllTimes = adj{1};
for t = 2:tMax
adjAllTimes = adjAllTimes + adj{t};
end
adjAllTimes(adjAllTimes>0) = 1;
% Identify nodes with at least the minimum out or in-degree and remove all
% other nodes
outDeg = sum(adjAllTimes,2);
inDeg = sum(adjAllTimes)';
minDegNodes = (outDeg>=minOutInDeg) | (inDeg>=minOutInDeg);
minDegNodes = minDegNodes & minDegNodesfrnd;
for t = 1:tMax
adj{t} = adj{t}(minDegNodes,minDegNodes); %#ok<SAGROW>
frndadj{t}=frndadj{t}(minDegNodes,minDegNodes); %#ok<SAGROW>
end
%% Convert to full 3-D adjacency matrix form
adj = full(cell2mat(adj));
n = size(adj,1);
adj = reshape(adj,[n n tMax]);
frndadj=full(cell2mat(frndadj));
n=size(adj,1);
frndadj=reshape(frndadj,[n n tMax]);
%% Save filtered and reshaped adjacency matrix
filtFile = [matFilePath 'FacebookFilteredAdj_' int2str(binSize) 'Days_' ...
int2str(minDegfrnd) 'Degfrnd_' int2str(minOutInDeg) 'OutInDeg.mat'];
save(filtFile,'binSize','minDegfrnd','minOutInDeg','frndadj','adj', ...
'endDate','startDate','traceEndDate','traceStartDate')