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
% In this simulation we examined how reliable peak distance and pattern correlation | |
% by comparing two simulated data with the same ground truth patterns of signal. | |
% define SNR levels | |
snr_all = [.1 .3 .5 .7 .9 1.1]; | |
% create ground truth pattern | |
pattern = [0.4 1.7 0.5 0.7 0.2 |
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
poscm = colormap_tor([0.96 0.41 0], [1 1 0]); % warm | |
negcm = colormap_tor([0.11 0.46 1], [.23 1 1]); % cools | |
cluster_surf(cl ,which('surf_BrainMesh_ICBM152Right_smoothed.mat'), 2, 'heatmap', 'colormaps', poscm, negcm) | |
axis vis3d; |
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
cd('/Users/clinpsywoo/github/fastRPCA'); | |
setup_fastRPCA; | |
% load an example data | |
load('/Users/clinpsywoo/github/SAS2015_PatRec/data.mat'); | |
X = dat.dat; | |
SS = svd(X, 'econ'); % can decompose x or x', but faster when rows >> cols | |
% 3 solvers (5 variants) | |
% 1) constrained |
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
function [bestL, bestP, info] = KL_heuristic_k2(A, varargin) | |
% usage: [bestL, bestP, info] = KL_heuristic_k2(A, varargin) | |
% | |
% feature: use the Kernighan-Lin (KL) heuristic to optimize any partition | |
% score function, e.g., modularity Q or stochastic block model's | |
% likelihood function. This works only for 2 partitioning problem. | |
% | |
% input: A adjacency matrix | |
% |
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
function L = SBM_likelihood(A, z, varargin) | |
% usage: L = SBM_likelihood(A, z) | |
% | |
% feature: log-likelihood estimation for simple Stochastic Block Model (SBM) | |
% (undirected, unweighted) based on Maximum Likelihood estimation. | |
% | |
% input: A adjacency matrix (simple graph) | |
% z group membership | |
% |
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')); |
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
function nmi = norm_mutual_info(za, zb) | |
% function nmi = norm_mutual_info(za, zb) | |
% | |
% feature: This function calculates the normalized mutual information, | |
% which tells us how much information we learn about Community | |
% structure A (or B) if we know B (or A). If A and B are | |
% identical, we learn everything about A from B (or B from A). | |
% In this case, nmi returns 1. If they are entirely uncorrelated, | |
% we learn nothing. In this case, nmi returns 0. |
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
function [max_z, max_q, outinfo] = community_modularity(A, varargin) | |
% function [z, q, outinfo] = community_modularity(A, optional_inputs) | |
% | |
% feature: This function conduct the greedy agglomerative algorithm to find | |
% community structure that maximizes the network's modularity (Q). | |
% | |
% input: A adjacency matrix | |
% | |
% output: max_z a vector of community membership that maximize Q |
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
function q = modularity_wani(A,z,varargin) | |
% function q = modularity_wani(A,z, [optional 'scalar' or 'degree']) | |
% | |
% feature: This function calculates the modularity (same with | |
% assortativity), q. It works for categorical and continuous | |
% (needs optional input, 'scalar') attributes. | |
% | |
% input: z attributes or category membership | |
% A adjacency matrix |
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
function A = build_adjacency_from_list(ij) | |
% function A = build_adjacency_from_list(ij) | |
% | |
% ij: row, column | |
A = zeros(max(max(ij)),max(max(ij))); | |
for i = 1:length(ij) | |
A(ij(i,1), ij(i,2)) = 1; |
NewerOlder