perturbationx.topo_npa.permutation
Submodules
Package Contents
Functions
|
Permute an adjacency matrix. |
|
Permute an edge list. |
- perturbationx.topo_npa.permutation.permute_adjacency(adj: numpy.ndarray | scipy.sparse.sparray, permutations=('k2',), iterations=500, permutation_rate=1.0, seed=None)
Permute an adjacency matrix.
- Parameters:
adj (np.ndarray | sp.sparray) – The adjacency matrix to permute.
permutations (list, optional) – The permutations to apply. May contain ‘k1’ and ‘k2’ in any order. Defaults to (‘k2’,).
iterations (int, optional) – The number of permutations to generate. Defaults to 500.
permutation_rate (float, optional) – The fraction of edges to permute. Defaults to 1.
seed (int, optional) – The seed for the random number generator.
- Raises:
ValueError – If the adjacency matrix is not square.
- Returns:
A dictionary of lists with permuted adjacency matrices, keyed by the permutation name.
- Return type:
dict
- perturbationx.topo_npa.permutation.permute_edge_list(edge_list: numpy.ndarray, node_list=None, iterations=500, method='k1', permutation_rate=1.0, seed=None)
Permute an edge list.
- Parameters:
edge_list (np.ndarray) – The edge list to permute. Must be a 2D array with shape (n_edges, 4). The first two columns contain the source and target nodes, the third column contains the edge type, and the fourth column contains the confidence weight. Confidence weights are optional.
node_list (list, optional) – The list of nodes to use in the permutation. Only edges that connect nodes in this list are permuted. If None, the list is inferred from the edge list.
iterations (int, optional) – The number of permutations to generate. Defaults to 500.
method (str, optional) – The permutation method to use. Defaults to ‘k1’. May be ‘k1’ or ‘k2’.
permutation_rate (float | str, optional) – The fraction of edges to permute. Defaults to 1. If ‘confidence’, the confidence weights are used to determine the number of edges to permute. For each edge, a random number is drawn from a uniform distribution between 0 and 1. If the confidence weight is larger than this number, the edge is permuted.
seed (int, optional) – The seed for the random number generator.
- Raises:
ValueError – If the permutation method is unknown.
- Returns:
A list of permutations. Each permutation is a list of tuples with the source node, target node, and edge type. If the edge type is None, the edge is removed.