Copyright (C) 2012- Joseph T. Lizier
The linsync
toolkit provides Matlab tools for analysing synchronization in networks of linearly coupled nodes.
Specifically, it provides implementations of the maths to measure and explore
the expected mean square deviation from synchronization
J.T. Lizier, F. Bauer, F.M. Atay, and J. Jost, "Analytic relationship of relative synchronizability to network structure and motifs", arXiv:2305.10509, 2023
The tools compute
- Continuous-time Ornstein-Uhlenbeck dynamics:
$$dX(t) = -X(t)(I-C)\theta dt + \zeta dw(t),$$ where$C$ is the update matrix,$w(t)$ is a multivariate Wiener process (uncorrelated) with covariance matrix$I$ ,$\theta$ is the reversion rate and$\zeta^2$ is noise strength, and - Discrete-time auto-regressive processes:
$$X(t+1) = X(t)C + \zeta R(t),$$ where where$C$ is the update matrix,$R(t)$ is uncorrelated mean-zero unit-variance Gaussian noise and$\zeta^2$ is noise strength.
In both cases the
Note that the toolkit fixes
Please cite your use of the toolkit via the above paper.
In this readme, we describe:
- the use cases of the code and how to thread them together
- how to recreate results from our papers
- the contents of this top-level folder (the primary analysis scripts).
In this section we briefly outline the primary use cases here, being:
-
Generating sample network structures
$C$ to investigate, and -
Computing the deviation from sync
$\left\langle \sigma^2 \right\rangle$ for a given network structure$C$ .
Then building on those we discuss more involved use cases for:
-
Batch experiments involving parameter sweeps and repeat runs, or
Finally, with the results generated you can:
- plot the results from these runs.
In order to compute
- Erdos-Renyi random graphs --
generateNewRandomMatrix.m
- Fixed in-degree random graphs --
generateNewRandomMatrixFixedD.m
- Watts-Strogatz ring networks with fixed in-degree --
generateNewRandomRingMatrix.m
These scripts generate unweighted adjacency matrices, then the user should weight the edges.
A sample generating a weighted, directed Watts-Strogatz ring network of
% First generate the unweighted adjacency matrix without self-edges:
A = generateNewRandomRingMatrix(N, d, p, false, true, false, true);
% Then compute the in-degrees (should be all d in this example):
D = diag(sum(A));
% and weight the edges as c/d each and insert self-edges with weight b - c:
% (note that using b=1 ensures \psi_0 is an eigenvector of C with \lambda_0 = 1)
C = (b - c) .* I + c .* A * inv(D);
Computing the expected deviation
As such, there are two steps involved here:
- Calculating the projected covariance matrix
$\Omega_U$ , and - Computing
$\left\langle \sigma^2 \right\rangle$ from that.
% First compute the projected covariance matrix. The two latter arguments are:
% discreteTime is a boolean for whether we consider discrete-time (true) or continuous-time process (false).
% MaxK is the number of iterations of the power series to compute \Omega_U.
[sortedLambdasCU, Omega_U, err] = covarianceUGaussianNet(C, false, 100000);
% Then compute sigma^2:
exp_sigma_sqr = synchronizability(Omega_U);
The call to covarianceUGaussianNet
will throw an error if the matrix does not meet synchronisation conditions,
or will not ensure guaranteed convergence of
In order to experiment with sweeping over many different parameters,
with many different sample networks, you can use (or build on) the
computeSyncResults.m
script, which incorporates the above use cases
into an experimental framework.
First, set up a parameters file, using parametersTemplate.m
as a template.
This will tell the compute script, for example, what size of network,
what type of network, the weights to use on coupled nodes, how many
repeat runs or samples for each parameter set to use, etc.
The sample parameters template is currently set up to recreate the results
for Fig 4b of the paper (i.e. N=100
, d=4
, c=0.5
, p=[0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1]
, directed network, continuous time,
no empirical runs (S=0
), motif approximations up to 50.), except for only 2 repeat
runs per set (to make your first run go fast!).
Then call computeSyncResults.m
, passing in the parameters file you have set up
(this can be supplied either as a filename, or running the script first
and then passing in parameters
object it creates):
computeSyncResults('parametersTemplate.m'); % using our template file
This call will run experiments across all of the specified parameters,
with multiple network samples for each parameter set, and then
save the experimental results into a .mat
file, in the
folder specified by parameters.folder
, formatted with a filename composed
from the parameters themselves. Running the above from our parametersTemplate.m
file will create a results file named N100-randRing-d4-b1.00-c0.50-dir-k50-cont-S0-repeats2.mat
.
We show how to generate such batch results recreating the plots from our 2023 paper in 2023-AnalyticRelationshipPaper.
For small number of repeats or no empirical simulations, the scripts run fairly fast. To investigate large numbers or repeats or empirical simulations, particularly for large numbers of samples, you'll likely be better served running the simulations on a compute cluster, splitting out repeat runs over multiple compute processes.
See folder cluster for suggestions on how to do this.
After having generated results files, you can post-process these results to make plots.
To plot plotSyncResults.m
, passing in the same parameters object / filename:
plotSyncResults('parametersTemplate.m'); % using our template file
Alternatively, plot the error between emprical and analytic calculations
for plotErrorInEmpiricalSyncResults.m
:
plotErrorInEmpiricalSyncResults('parametersTemplate.m'); % using our template file
This specifically requires having set the parameter S
(number of empirical
samples) to be computeSyncResults
one time for each of the values of S
that you
wish to plot for (specified by parameters.SRangeToPlot
).
We show how to generate such batch results on a cluster recreating the Figure 1 and 4 plots from the 2023 paper in cluster.
- For Lizier et al., "Analytic relationship of relative synchronizability to network structure and motifs", 2023, the folder 2023-AnalyticRelationshipPaper contains scripts / parameters files to recreate these results, as well as a README documenting how to run them.
Primary experimental scripts to run:
-
computeSyncResults.m
- main script to sample$\left\langle \sigma^2 \right\rangle$ for many networks with given parameters; saves results to .mat files for later processing.
Plotting scripts once results are ready:
-
plotSyncResults.m
- plot$\left\langle \sigma^2 \right\rangle$ versus$p$ or$c$ (like Figure 4). -
plotErrorInEmpiricalSyncResults.m
- plot difference between analytic and empirical results for$\left\langle \sigma^2 \right\rangle$ (like Figure 1).
User-level scripts for analytical computation of projected covariance matrices and
-
covarianceUGaussianNet.m
- computes the projected covariance matrix ($\Omega_U$ ) and eigenvalues of a given connectivity matrix$C$ . -
synchronizability.m
- computes$\left\langle \sigma^2 \right\rangle$ from the output ($\Omega_U$ ) ofcovarianceUGaussianNet.m
.
Underlying scripts involved in analytical computation of projected covariance matrices and
contCon2CovProjected.m
* - computes the projected covariance matrix for the continuous-time casediscreteCon2CovProjected.m
* - computes the projected covariance matrix for the discrete-time case
Underlying scripts to run numerical simulations of dynamics for empirical calculation of
empiricalCovariancesProjected.m
- runs numerical simulations to return an empirical measurement of the projected covariance matrix, for a given number of time samplesS
.contCon2LaggedCovProjected.m
* - computes covariance between nodes, starting from zero covariance at time 0; used in the simulations of continuous time dynamics.
Scripts to generate new adjacency matrices:
generateNewRandomMatrix.m
- generate new Erdos-Renyi graphgenerateNewRandomMatrixFixedD.m
- generate network with a fixed in-degree for each node, sources selected at randomgenerateNewRandomRingMatrix.m
- generate new Watts-Strogatz ring network, starting with fixed in-degree and then randomising edges (for directed graphs the in-degree is maintained)
Sample parameters file:
parametersTemplate.m
- set parameters for batch experimental runs.
Utility files:
adjMatrixToList.m
- converts an adjacency matrix to a list, required for some of the network generators.parseParameters.m
- used by experimental scripts to convert varargin to pull out all required parameters.maxrelerr.m
* - used in convergence checks for the power series calculation of the projected covariance matrixnegligible.m
* - used in convergence checks for the power series calculation of the projected covariance matrixrunDfs.m
- runs a depth first search, used to ensure generated networks are (undirectionally) connected.
Files marked * are adapted from the ncomp toolkit of Barnett et al., originally distributed at http://www.secse.net/ncomp/ncomp_tools.zip (though no longer available at that address), with the paper L. Barnett, C. L. Buckley and S. Bullock (2009), "On Neural Complexity and Structural Connectivity", Physical Review E, 79, 051914, under a license to "use as you wish".
3/3/2023 - Initial code version uploaded (repo currently private)
JL was supported through the Australian Research Council DECRA grant DE160100630, and The University of Sydney SOAR award.
As above, several files were adapted from the ncomp toolkit of Barnett et al.