netneurotools.networks.strength_preserving_rand_sa_dir
- netneurotools.networks.strength_preserving_rand_sa_dir(A, rewiring_iter=10, nstage=100, niter=10000, temp=1000, frac=0.5, energy_type='sse', energy_func=None, connected=True, verbose=False, seed=None)[source]
Strength-preserving network randomization using simulated annealing.
Randomize a directed weighted network, while preserving the in- and out-degree and strength sequences using simulated annealing.
- Parameters:
A ((N, N) array-like) – Directed weighted connectivity matrix
rewiring_iter (int, optional) – Rewiring parameter. Default = 10. Each edge is rewired approximately rewiring_iter times.
nstage (int, optional) – Number of annealing stages. Default = 100.
niter (int, optional) – Number of iterations per stage. Default = 10000.
temp (float, optional) – Initial temperature. Default = 1000.
frac (float, optional) – Fractional decrease in temperature per stage. Default = 0.5.
energy_type (str, optional) –
- Energy function to minimize. Can be either:
- ‘sse’: Sum of squared errors between strength sequence vectors
of the original network and the randomized network
‘max’: Maximum absolute error ‘mae’: Mean absolute error ‘mse’: Mean squared error ‘rmse’: Root mean squared error
Default = ‘sse’.
energy_func (callable, optional) – Callable with two positional arguments corresponding to two strength sequence numpy arrays that returns an energy value. Overwrites “energy_type”. See “energy_type” for specifying a predefined energy type instead.
connected (bool, optional) – Whether to ensure connectedness of the randomized network. Default = True.
verbose (bool, optional) – Whether to print status to screen at the end of every stage. Default = False.
seed (float, optional) – Random seed. Default = None.
- Returns:
B ((N, N) array-like) – Randomized connectivity matrix
min_energy (float) – Minimum energy obtained by annealing
Notes
Uses Maslov & Sneppen rewiring model to produce a surrogate connectivity matrix, B, with the same size, density, and in- and out-degree sequences as A. The weights are then permuted to optimize the match between the strength sequences of A and B using simulated annealing. Both in- and out-strengths are preserved.
This function is adapted from a function written in MATLAB by Richard Betzel.
References
Misic, B. et al. (2015) Cooperative and Competitive Spreading Dynamics on the Human Connectome. Neuron. Rubinov, M. (2016) Constraints and spandrels of interareal connectomes. Nature Communications. Milisav, F. et al. (2024) A simulated annealing algorithm for randomizing weighted networks.