Inheritance diagram for nipy.algorithms.graph.graph:
This module implements two graph classes:
Graph: basic topological graph, i.e. vertices and edges. This kind of object only has topological properties
WeightedGraph (Graph): also has a value associated with edges, called weights, that are used in some computational procedures (e.g. path length computation). Importantly these objects are equivalent to square sparse matrices, which is used to perform certain computations.
This module also provides several functions to instantiate WeightedGraphs from data: - k nearest neighbours (where samples are rows of a 2D-array) - epsilon-neighbors (where sample rows of a 2D-array) - representation of the neighbors on a 3d grid (6-, 18- and 26-neighbors) - Minimum Spanning Tree (where samples are rows of a 2D-array)
Author: Bertrand Thirion, 2006–2011
Bases: object
Basic topological (non-weighted) directed Graph class
Methods
adjacency | |
cc | |
degrees | |
get_E | |
get_V | |
get_edges | |
get_vertices | |
main_cc | |
set_edges | |
show | |
to_coo_matrix |
Constructor
Parameters : | - V (int): the number of vertices : - E (int): the number of edges : |
---|
returns the adjacency matrix of the graph as a sparse coo matrix
Returns : | adj: scipy.sparse matrix instance, :
|
---|
Compte the different connected components of the graph.
Returns : | label: array of shape(self.V), labelling of the vertices : |
---|
Returns the degree of the graph vertices.
Returns : | rdegree: (array, type=int, shape=(self.V,)), the right degrees : ldegree: (array, type=int, shape=(self.V,)), the left degrees : |
---|
To get the number of edges in the graph
To get the number of vertices in the graph
To get the graph’s edges
To get the graph’s vertices (as id)
Returns the indexes of the vertices within the main cc
Returns : | idx: array of shape (sizeof main cc) : |
---|
Sets the graph’s edges
Shows the graph as a planar one.
Parameters : | ax, axis handle : |
---|---|
Returns : | ax, axis handle : |
Return adjacency matrix as coo sparse
Returns : | sp: scipy.sparse matrix instance, :
|
---|
Bases: nipy.algorithms.graph.graph.Graph
Basic weighted, directed graph class
Methods
Constructor
Parameters : | - V (int > 0): the number of vertices : - edges (array, type=int, shape=(E,2)): edges of the graph : - weights (array, type=int, shape=(E,)): weights/lenghts of the edges : |
---|
returns the adjacency matrix of the graph as a sparse coo matrix
Returns : | adj: scipy.sparse matrix instance, :
|
---|
anti-symmeterize self, i.e. produces the graph whose adjacency matrix would be the antisymmetric part of its current adjacency matrix
Compte the different connected components of the graph.
Returns : | label: array of shape(self.V), labelling of the vertices : |
---|
Extraction of the graphe cliques these are defined using replicator dynamics equations
Returns : | cliques: array of shape (self.V), type (np.int) :
|
---|
returns a compact representation of self
Returns : | idx: array of of shape(self.V + 1): :
neighb: array of shape(self.E), concatenated list of neighbors : weights: array of shape(self.E), concatenated list of weights : |
---|
returns a copy of self
Returns a graph with redundant edges removed: ecah edge (ab) is present ony once in the edge matrix: the correspondng weights are added.
Returns : | the resulting WeightedGraph : |
---|
Returns the degree of the graph vertices.
Returns : | rdegree: (array, type=int, shape=(self.V,)), the right degrees : ldegree: (array, type=int, shape=(self.V,)), the left degrees : |
---|
Returns all the [graph] geodesic distances starting from seed x
- seed (int, >-1, <self.V) or array of shape(p)
- edge(s) from which the distances are computed
Returns : | dg: array of shape (self.V), :
|
---|
Compute all the geodesic distances starting from seeds
Parameters : | seed= None: array of shape (nbseed), type np.int :
|
---|---|
Returns : | dg array of shape (nbseed, self.V) :
|
Sets the graph to be the topological neighbours graph of the three-dimensional coordinates set xyz, in the k-connectivity scheme
Parameters : | xyz: array of shape (self.V, 3) and type np.int, : k = 18: the number of neighbours considered. (6, 18 or 26) : |
---|---|
Returns : | E(int): the number of edges of self : |
To get the number of edges in the graph
To get the number of vertices in the graph
To get the graph’s edges
To get the graph’s vertices (as id)
States whether self is connected or not
Creates the Minimum Spanning Tree of self using Kruskal’s algo. efficient is self is sparse
Returns : | K, WeightedGraph instance: the resulting MST : |
---|
Return left incidence matrix
Returns : | left_incid: list :
|
---|
returns the set of neighbors of self as a list of arrays
Returns the indexes of the vertices within the main cc
Returns : | idx: array of shape (sizeof main cc) : |
---|
Normalize the graph according to the index c Normalization means that the sum of the edges values that go into or out each vertex must sum to 1
Parameters : | c=0 in {0, 1, 2}, optional: index that designates the way :
|
---|
Removes all the edges for which valid==0
Parameters : | valid, an array of shape (self.E) : |
---|
Removes trivial edges, i.e. edges that are (vv)-like self.weights and self.E are corrected accordingly
Returns : | self.E (int): The number of edges : |
---|
Return right incidence matrix
Returns : | right_incid: list :
|
---|
Sets the graph’s edges
Compute the weights of the graph as the distances between the corresponding rows of X, which represents an embdedding of self
Parameters : | X array of shape (self.V, edim), :
|
---|
Compute the weights of the graph as a gaussian function of the distance between the corresponding rows of X, which represents an embdedding of self
Parameters : | X array of shape (self.V, dim) :
sigma=0, float: the parameter of the gaussian function : |
---|
Set edge weights
Parameters : | weights: array :
|
---|
plots the current graph in 2D
Parameters : | X=None, array of shape (self.V, 2) :
ax: ax handle, optional : |
---|---|
Returns : | ax: axis handle : |
Creates a subgraph with the vertices for which valid>0 and with the correponding set of edges
Parameters : | valid, array of shape (self.V): nonzero for vertices to be retained : |
---|---|
Returns : | G, WeightedGraph instance, the desired subgraph of self : |
Symmeterize self, modify edges and weights so that self.adjacency becomes the symmetric part of the current self.adjacency.
Return adjacency matrix as coo sparse
Returns : | sp: scipy.sparse matrix instance :
|
---|
Defines the graph as the Voronoi diagram (VD) that links the seeds. The VD is defined using the sample points.
Parameters : | seeds: array of shape (self.V, dim) : samples: array of shape (nsamples, dim) : |
---|
Performs a voronoi labelling of the graph
Parameters : | seed: array of shape (nseeds), type (np.int), :
|
---|---|
Returns : | labels: array of shape (self.V) the labelling of the vertices : |
returns a complete graph with n vertices
Returns the concatenation of the graphs G1 and G2 It is thus assumed that the vertices of G1 and G2 represent disjoint sets
Parameters : | G1, G2: the two WeightedGraph instances to be concatenated : |
---|---|
Returns : | G, WeightedGraph, the concatenated graph : |
Returns the eps-nearest-neighbours graph of the data
Parameters : | X, array of shape (n_samples, n_features), input data : eps, float, optional: the neighborhood width : |
---|---|
Returns : | the resulting graph instance : |
Utility that computes the six neighbors on a 3d grid
Parameters : | xyz: array of shape (n_samples, 3); grid coordinates of the points : k: neighboring system, equal to 6, 18, or 26 : |
---|---|
Returns : | i, j, d 3 arrays of shape (E), :
|
returns the k-nearest-neighbours graph of the data
Parameters : | X, array of shape (n_samples, n_features): the input data : k, int, optional: is the number of neighbours considered : |
---|---|
Returns : | the corresponding WeightedGraph instance : |
Returns the connected comonents of a graph represented as a list of lists
Parameters : | lil: a list of list representing the graph neighbors : |
---|---|
Returns : | label a vector of shape len(lil): connected components labelling : |
Returns the WeightedGraph that is the minimum Spanning Tree of X
Parameters : | X: data array, of shape(n_samples, n_features) : |
---|---|
Returns : | the corresponding WeightedGraph instance : |
Create graph as the set of topological neighbours of the three-dimensional coordinates set xyz, in the k-connectivity scheme
Parameters : | xyz: array of shape (nsamples, 3) and type np.int, : k = 18: the number of neighbours considered. (6, 18 or 26) : |
---|---|
Returns : | the WeightedGraph instance : |
Instantiates a weighted graph from a square 2D array
Parameters : | x: 2D array instance, the input array : |
---|---|
Returns : | wg: WeightedGraph instance : |
Instantiates a weighted graph from a (sparse) coo_matrix
Parameters : | x: scipy.sparse.coo_matrix instance, the input matrix : |
---|---|
Returns : | wg: WeightedGraph instance : |