Mark-Kramer / dppm

Matlab pipeline for simulating dynamical networks and evaluating dynamic community tracking methods, including CPM, MMM and DPPM
1 stars 6 forks source link

Dynanets

The purpose of this code is to track communities in dynamic networks.

Dependices

Download the following software packages, required to track dynamic communities and analyze the networks.

Initial MATLAB setup

Rename the file dynanets_defaults_local_example.m --> dynanets_defaults_local.m

You can enter information for a second system in Lines 13-18, if useful.

Code organization

The central file of the pipeline is main_dynanets.m, which calls all other routines. The code is organized into subfolders according to the tasks being done:

This pipeline configurations is based on the use of a structure called cfg where all the settings are stored (inspired by the approach implemented in Fieldtrip toolbox). Here are the options of the configuration:

% Build simulation data
cfg.data.run = true;
cfg.data.patients = {'P1', 'P2'}; % list of the patients to be analyzed (used to search in folders)
cfg.data.seizures = {{'S1', 'S2'}, {'S1', 'S2', 'S3'}}; % list of seizures for each patients
cfg.data.build_fun = @my_build_fun; % function called to build the data segment to be analyzed (e.g., will create P1_S1.mat file)
cfg.data.padding = [0 0]; % how much data to include pre- and post-seizure

% Preprocessing settings
cfg.preprocess.run = true; % runs the preprocessing step
cfg.preprocess.ref = ''; % Choose the reference for re-referencing: '' (do nothing), 'cavg' (common average), 'bipolar' (only for simulations)
cfg.preprocess.filt = 'firls'; % choice for the filter function
cfg.preprocess.band = [4 50]; % Frequency band to keep

% Inference settings
cfg.infer.run = true; % runs the inference step
cfg.infer.method = 'corr_0_lag'; % Choose the inference method: 'corr', 'corr_0_lag'
cfg.infer.windowsize = 1; % Window size for net inference (s).
cfg.infer.windowstep = 0.5;  % Window overlap (s)
cfg.infer.smooth = false; % Use vote to smooth networks in time
cfg.infer.scale  = true; % Scale variance of correlation using all time.

% Network tracking through time
cfg.track.run = true; % runs the tracking step
cfg.track.method = { % list of methods to apply with their parameters (can add as many as wanted)
    struct('name', 'dpp', 'k', 2, 'm', 4);
    struct('name', 'mmm', 'gamma', 1, 'omega', 0.1);
    struct('name', 'cpm', 'min_clique', 4);
    };

% Settings for figures
cfg.fig.run = true; % runs the analysis step
cfg.fig.type = '-djpeg'; % Choose the output format: '-djpeg', '-depsc', '-dpdf'
cfg.fig.plotpadding = [0 0]; % Used in xlim in some figs, e.g. [0 0], PADDING
cfg.fig.mmmthresh = 4; % used to clean the MMM plots (minimum com size, 0 = all)
cfg.fig.analyze_seizures = true; % runs the seizure by seizure analysis step
cfg.fig.custom_node_sort = @my_order; % define a different order for the nodes in the plots [optional]
cfg.fig.custom_stats = @my_additional_stats; % run another function for additional analyses [optional]
cfg.fig.analyze_population_fun = @population_results; % analyze patient by patient results [optional]
cfg.fig.usetitle = true; % choose to use titles in plots
cfg.fig.fontsize = 12; % font size used in plots

To run and analyze multiple scenarios, each multiple times, see the example cfg description in the simulation folder, dynanets_sim_all.m.

To run and analyze a single simulation scenario a single time, see the example cfg description in the simulation folder, dynanets_sim_individual.m

Simulations

The simulation folder contains the code to run the simulations from the paper. More specifically:

Example simulation and network tracking analysis

To run an example simulation and analysis, first define dynanets_defaults_local.m as described above. Then, from the root dppm folder, run the following commands at the MATLAB prompt:

>> dynanets_defaults_local
>> run simulation/dynanets_sim_individual