Created
October 5, 2014 04:11
-
-
Save wanirepo/e1e1944a577d9f102db3 to your computer and use it in GitHub Desktop.
Network modeling, Problem Set #03-4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Data info: | |
% Each of the school .mat files has an A matrix (sparse) and a | |
% "local_info" variable, one row per node: a student/faculty status | |
% flag, gender, major, second major/minor (if applicable), dorm/house, | |
% year, and high school. Missing data is coded 0. | |
% datdir = '/Users/clinpsywoo/Documents/2011-2016yr/2014_2015_4th_GS/Network_modeling/Problem_sets/facebook100'; | |
datdir = '/Volumes/engram/Users/wani/Documents/Network_modeling/Problem_sets/facebook100'; | |
fnames = filenames(fullfile(datdir, '*mat')); | |
% the assortativity patterns for: | |
% 1) student/faculty status (row:1) | |
% 2) major (row:3) | |
% 3) vertex degree | |
% x axis: network size n | |
% y axis-1: modularity q for each | |
% y axis-2: relative gender modularity, q/q_rand | |
for i = 1:numel(fnames) | |
t = tic; | |
load(fnames{i}); | |
[~, res.name{i}] = fileparts(fnames{i}); | |
fprintf('\nWorking on.. %s (%d/%d).', res.name{i}, i, numel(fnames)); | |
% calculate the modularity for ***student/faculty status*** | |
fprintf('\n\t1) student/faculty... '); | |
stu_fac = local_info(:,1); | |
missing = find(stu_fac==0); | |
if ~isempty(missing) | |
A = A'; A(:,missing) = []; | |
A = A'; A(:,missing) = []; | |
stu_fac(missing) = []; | |
end | |
n = length(stu_fac); | |
res.stu_fac{i} = modularity_wani(A,stu_fac); | |
% random permutation | |
for iter = 1:100 | |
fprintf('\b\b\b\b%04d', iter); | |
res.rand_stu_fac{i}(iter) = modularity_wani(A, stu_fac(randperm(n))); | |
end | |
load(fnames{i}); | |
% calculate the modularity for ***major*** | |
fprintf('\n\t2) major... '); | |
major = local_info(:,3); | |
missing = find(major==0); | |
if ~isempty(missing) | |
A = A'; A(:,missing) = []; | |
A = A'; A(:,missing) = []; | |
major(missing) = []; | |
end | |
n = length(major); | |
res.major{i} = modularity_wani(A,major); | |
% random permutation | |
for iter = 1:100 | |
fprintf('\b\b\b\b%04d', iter); | |
res.rand_major{i}(iter)= modularity_wani(A,major(randperm(n))); | |
end | |
load(fnames{i}); | |
% calculate the assortativity coefficient for ***vertex degree*** | |
fprintf('\n\t3) vertex degree... '); | |
degree_k = sum(A,1); | |
res.degree{i} = modularity_wani(A, [], 'degree'); | |
for iter = 1:100 | |
fprintf('\b\b\b\b%04d', iter); | |
A = configuration_model(degree_k, 'sparse'); | |
res.rand_degree{i}(iter) = modularity_wani(A, [], 'degree'); | |
end | |
fprintf('\n'); | |
toc(t); | |
end | |
savedir = '/Volumes/engram/Users/wani/Documents/Network_modeling/Problem_sets/PS03'; | |
savename = fullfile(savedir, 'PS03_results.mat'); | |
save(savename, 'res'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment