brainconn.utils.visualization.reorder_matrix

reorder_matrix(m1, cost='line', verbose=False, H=10000.0, Texp=10, T0=0.001, Hbrk=10)[source]

This function rearranges the nodes in matrix M1 such that the matrix elements are squeezed along the main diagonal. The function uses a version of simulated annealing.

Parameters:
  • M1 (NxN numpy.ndarray) – connection matrix weighted/binary directed/undirected
  • cost (str) – ‘line’ or ‘circ’ for shape of lattice (linear or ring lattice). Default is linear lattice.
  • verbose (bool) – print out cost at each iteration. Default False.
  • H (int) – annealing parameter, default value 1e6
  • Texp (int) – annealing parameter, default value 1. Coefficient of H s.t. Texp0=1-Texp/H
  • T0 (float) – annealing parameter, default value 1e-3
  • Hbrk (int) – annealing parameter, default value = 10. Coefficient of H s.t. Hbrk0 = H/Hkbr
Returns:

  • Mreordered (NxN numpy.ndarray) – reordered connection matrix
  • Mindices (Nx1 numpy.ndarray) – reordered indices
  • Mcost (float) – objective function cost of reordered matrix

Notes

Note that in general, the outcome will depend on the initial condition (the setting of the random number seed). Also, there is no good way to determine optimal annealing parameters in advance - these paramters will need to be adjusted “by hand” (particularly H, Texp, and T0). For large and/or dense matrices, it is highly recommended to perform exploratory runs varying the settings of ‘H’ and ‘Texp’ and then select the best values.

Based on extensive testing, it appears that T0 and Hbrk can remain unchanged in most cases. Texp may be varied from 1-1/H to 1-10/H, for example. H is the most important parameter - set to larger values as the problem size increases. It is advisable to run this function multiple times and select the solution(s) with the lowest ‘cost’.

Setting ‘Texp’ to zero cancels annealing and uses a greedy algorithm instead.