DistanceMatrix
- class DistanceMatrix(snapshots, times, distance_metric)[source]
Base class for matrix of pairwise distance/similarity between snapshots of a temporal network.
- Variables
times (list of (int or float)) – Times corresponding to each of the T snapshots
snapshots (numpy array) – Array of dim (T, N, N) representing instantaneous adjacency matrices. Snapshots can also be inputed as vectors of dim (T, N).
snapshots_flat (numpy array) – Snapshots (flattened into vectors if originals are matrices) from which the distance matrix is computed
distance_metric (str) – Distance metric used to compute the distance between snapshots, e.g. ‘euclidean’ with sklearn.metrics.pairwise.paired_distances. It must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter (e.g. ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘euclidean’, ‘hamming’, ‘jaccard’, etc.), or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
distance_matrix (numpy array) – Array of dim (T, T)
distance_matrix_flat (numpy array) – Flattened distance matrix of dim (T,)
Base class for a distance matrix, i.e. a matrix where each entry is the distance/similarity between two snapshots in ‘snapshots’.
- Parameters
snapshots (numpy array) – Array of dim (T, N, N) representing instantaneous adjacency matrices. Snapshots can also be inputed as vectors of dim (T, N).
times (list of (float or int)) – Times corresponding to each snapshot
distance_metric (str) – Distance metric used to compute the distance between snapshots, e.g. ‘euclidean’, with sklearn.metrics.pairwise.paired_distances. It must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter (e.g. ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘euclidean’, ‘hamming’, ‘jaccard’, etc.), or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
- property distance_matrix
Returns the distance matrix as a numpy array
- property distance_matrix_flat
Returns the distance matrix flattened for easier use in clustering
- property distance_metric
Returns the distance metric used to compute the distance matrix
- classmethod from_temporal_network(temporal_network, distance_metric)[source]
Generates a distance matrix from a temporal network
Each entry of the matrix is the distance between two snapshots of the temporal network.
- Parameters
temporal_network (TemporalNetwork) – Temporal network from which to compute the distance matrix
distance_metric (str) – Distance metric used to compute the distance between snapshots, e.g. ‘euclidean’, with sklearn.metrics.pairwise.paired_distances. It must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter (e.g. ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘euclidean’, ‘hamming’, ‘jaccard’, etc.), or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
- Return type
- classmethod from_timeseries(timeseries, distance_metric)[source]
Generates a distance matrix from time series
Each entry of the matrix is the distance between two ‘snapshots’ of the timeseries, i.e. the vector with instantaneous values of the N timeseries at time t.
- Parameters
timeseries (pandas.Dataframe) – Timeseries relative to nodes, edges, or both. Each row is a timeseries, with index as series name and columns as times.
distance_metric (str) – Distance metric used to compute the distance between snapshots, e.g. ‘euclidean’, with sklearn.metrics.pairwise.paired_distances. It must be one of the options allowed by scipy.spatial.distance.pdist for its metric parameter (e.g. ‘chebyshev’, ‘cityblock’, ‘correlation’, ‘cosine’, ‘euclidean’, ‘hamming’, ‘jaccard’, etc.), or a metric listed in pairwise.PAIRWISE_DISTANCE_FUNCTIONS.
- Return type
- property snapshots
Returns the snapshots (matrix or vectors) from which the distance matrix is computed
- property snapshots_flat
Returns the snapshots (flattened into vectors if original are matrices) from which the distance matrix is computed
- property times
Returns the sorted list of times corresponding to the snapshots