The utils module

The utils module mainly contains functions that are used elsewhere in the package. It also contains the function objscore calculating the value of an arbitrary objective function on a given graph partition.

utils.cut(elemlist, matrix, numbers, dc, mini)

Cuts clusters by separately normalised PCA.

Parameters:
  • elemlist (list of lists of int) – Specifies the members of each cluster in the current clustering
  • matrix (csc matrix) – Matrix objective with which to cut.
  • numbers (list of int) – Marks previous clustering to use as starting vector.
  • dc (boolean) – Whether to skip cutting last cluster
  • mini (boolean) – Whether to minimise (instead of maximise) matrix objective.
Returns:

new cluster constituents

Return type:

list of lists of int

utils.invdiag(M)

Inverts a positive diagonal matrix.

Parameters:M (csc matrix) – matrix to invert
Returns:scipy sparse matrix of inverted diagonal
utils.merge(elemlist)

Merges pairs of clusters randomly.

Parameters:elemlist (list of lists of int) – Specifies the members of each cluster in the current clustering
Returns:New cluster constituents boolean: Whether last cluster was unable to merge list of int: List of markers for current clustering, to use as starting vectors.
Return type:list of lists of int
utils.objscore(labels, k, mat1, mat2=None)

Scores a clustering using the objective matrix given

Parameters:
  • labels (list of int) – Clustering assignment.
  • k (int) – Number of clusters.
  • mat1 (csc matrix) – Numerator matrix of objective score.
  • mat2 (csc matrix) – Denominator matrix of objective score. Default is no denominator.
Returns:

Score.

Return type:

float

utils.sqrtinvdiag(M)

Inverts and square-roots a positive diagonal matrix.

Parameters:M (csc matrix) – matrix to invert
Returns:scipy sparse matrix of inverted square-root of diagonal