Utils¶
Clusters¶
Functions to manipulate and sort clusters
- aggregate_network_by_cluster(temporal_network, clusters, sort_clusters=None, output='averaged')[source]¶
Aggregates the temporal network over eacher cluster in a cluster set
- Parameters
temporal_network (phasik.TemporalNetwork) – Temporal network to aggregate
clusters (array of int) – Cluster labels
sort_clusters (bool) – If True, sort cluster labels basde on ascending times
output ({‘weighted’, ‘averaged’, ‘binary’, ‘normalised’}, optional) – Determines the type of output edge weights
- Returns
aggregates – Dict each key is a cluster label and each value is a tuple of the form (networkx.Graph, list of time indices of cluster).
- Return type
dict
- cluster_sort(clusters, final_labels=None)[source]¶
Return array of cluster labels sorted in order of appearance, with clusters unchanged
Example
>>> clusters = np.array([2, 2, 2, 3, 3, 1, 1, 1]) >>> cluster_sort(clusters) [ 1 1 1 2 2 3 3 3 ]
- convert_cluster_labels_to_dict(clusters)[source]¶
Returns dictionary where each key is a cluster label and each value is list of the time indices composing the cluster
- Parameters
clusters (list of int) – List of cluster labels
- rand_index_over_methods_and_sizes(valid_cluster_sets, reference_method='ward')[source]¶
Compute Rand Index to compare any method to a reference method, for all combinations of methods and number of clusters
- Parameters
valid_cluster_sets (list)
reference_method (str)
- Returns
rand_scores – Array of dimension (n_sizes, n_methods) with rand index scores
- Return type
ndarray
Graphs¶
Utility functions for static graphs
- create_graph_from_interactions(filename, sheet, source, target)[source]¶
Create a networkx.Graph from an excel sheet describing edges
- Parameters
filename (str) – Path to the excel file
sheet (str) – Name of the sheet within the excel file
source (str) – Name of the column containing the source nodes
target (str) – Name of the column containing the target nodes
- Returns
graph
- Return type
networkx.Graph
- weighted_edges_as_df(network)[source]¶
Returns a pandas.Dataframe of weighted edges sorted by weight, from a networkx.Graph.
Columns are [‘i’, ‘j’, ‘weight’] and each row represents a different edge
- Parameters
network (networkx.Graph) – A network from which to get weighted edges
- Returns
- Return type
pandas.DataFrame
Paths¶
Functions to deal with system paths
- slugify(text, keep_characters=None)[source]¶
Turn any text into a string that can be used in a filename
- Parameters
text (str) – text to slugify
keep_characters (list of str) – characters in this iterable will be kept in the final string. Defaults to [‘_’]. Any other non-alphanumeric characters will be removed.
- Returns
slug
- Return type
str