Inheritance diagram for nipy.algorithms.graph.field:
This module implements the Field class, which simply a WeightedGraph (see the graph.py) module, plus an arrray that yields (possibly multi-dimnesional) features associated with graph vertices. This allows some kinds of computations (all thoses relating to mathematical morphology, diffusion etc.)
Certain functions are provided to Instantiate Fields easily, given a WeightedGraph and feature data.
Author:Bertrand Thirion, 2006–2011
Bases: nipy.algorithms.graph.graph.WeightedGraph
Methods
adjacency() | returns the adjacency matrix of the graph as a sparse coo matrix |
anti_symmeterize() | anti-symmeterize self, i.e. produces the graph |
cc() | Compte the different connected components of the graph. |
cliques() | Extraction of the graphe cliques |
closing([nbiter]) | Morphological closing of the field data. |
compact_neighb() | returns a compact representation of self |
constrained_voronoi(seed) | Voronoi parcellation of the field starting from the input seed |
copy() | copy function |
custom_watershed([refdim, th]) | customized watershed analysis of the field. |
cut_redundancies() | Returns a graph with redundant edges removed: ecah edge (ab) is present ony once in the edge matrix: the correspondng weights are added. |
degrees() | Returns the degree of the graph vertices. |
diffusion([nbiter]) | diffusion of the field data in the weighted graph structure |
dijkstra([seed]) | Returns all the [graph] geodesic distances starting from seed |
dilation([nbiter, fast]) | Morphological dimlation of the field data. |
erosion([nbiter]) | Morphological openeing of the field |
floyd([seed]) | Compute all the geodesic distances starting from seeds |
from_3d_grid(xyz[, k]) | Sets the graph to be the topological neighbours graph |
geodesic_kmeans([seeds, label, maxiter, ...]) | Geodesic k-means algorithm i.e. |
get_E() | To get the number of edges in the graph |
get_V() | To get the number of vertices in the graph |
get_edges() | To get the graph’s edges |
get_field() | |
get_local_maxima([refdim, th]) | Look for the local maxima of one dimension (refdim) of self.field |
get_vertices() | To get the graph’s vertices (as id) |
get_weights() | |
highest_neighbor([refdim]) | Computes the neighbor with highest field value along refdim |
is_connected() | States whether self is connected or not |
kruskal() | Creates the Minimum Spanning Tree of self using Kruskal’s algo. |
left_incidence() | Return left incidence matrix |
list_of_neighbors() | returns the set of neighbors of self as a list of arrays |
local_maxima([refdim, th]) | Returns all the local maxima of a field |
main_cc() | Returns the indexes of the vertices within the main cc |
normalize([c]) | Normalize the graph according to the index c |
opening([nbiter]) | Morphological opening of the field data. |
remove_edges(valid) | Removes all the edges for which valid==0 |
remove_trivial_edges() | Removes trivial edges, i.e. |
right_incidence() | Return right incidence matrix |
set_edges(edges) | Sets the graph’s edges |
set_euclidian(X) | Compute the weights of the graph as the distances between the |
set_field(field) | |
set_gaussian(X[, sigma]) | Compute the weights of the graph as a gaussian function |
set_weights(weights) | Set edge weights |
show([X, ax]) | plots the current graph in 2D |
subfield(valid) | Returns a subfield of self, with only vertices such that valid > 0 |
subgraph(valid) | Creates a subgraph with the vertices for which valid>0 |
symmeterize() | Symmeterize self, modify edges and weights so that |
threshold_bifurcations([refdim, th]) | Analysis of the level sets of the field: |
to_coo_matrix() | Return adjacency matrix as coo sparse |
voronoi_diagram(seeds, samples) | Defines the graph as the Voronoi diagram (VD) |
voronoi_labelling(seed) | Performs a voronoi labelling of the graph |
ward(nbcluster) | Ward’s clustering of self |
Parameters : | V (int > 0) the number of vertices of the graph : edges=None: the edge array of the graph : weights=None: the asociated weights array : field=None: the field data itself : |
---|
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) :
|
---|
Morphological closing of the field data. self.field is changed inplace
Parameters : | nbiter=1 : the number of iterations required |
---|
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 : |
---|
Voronoi parcellation of the field starting from the input seed
Parameters : | seed: int array of shape(p), the input seeds : |
---|---|
Returns : | label: The resulting labelling of the data : |
copy function
customized watershed analysis of the field. Note that bassins are found around each maximum (and not minimum as conventionally)
Parameters : | refdim: int, optional : th: float optional, threshold of the field : |
---|---|
Returns : | idx: array of shape (nbassins) :
label : array of shape (self.V)
|
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 : |
---|
diffusion of the field data in the weighted graph structure self.field is changed inplace
Parameters : | nbiter: int, optional the number of iterations required : |
---|
Returns all the [graph] geodesic distances starting from seed x Parameters ———- 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), :
|
---|
Morphological dimlation of the field data. self.field is changed
Parameters : | nbiter: int, optional, the number of iterations required : |
---|
Morphological openeing of the field
Parameters : | nbiter: int, optional, the number of iterations required : |
---|
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 : |
Geodesic k-means algorithm i.e. obtention of clusters that are topologically connected and minimally variable concerning the information of self.field
Parameters : | seeds: array of shape(p), optional, :
labels: array of shape(self.V) initial labels, optional, :
maxiter: int, optional, :
eps: float, optional, :
|
---|---|
Returns : | seeds: array of shape (p), the final seeds : label : array of shape (self.V), the resulting field label J: float, inertia value : |
To get the number of edges in the graph
To get the number of vertices in the graph
To get the graph’s edges
Look for the local maxima of one dimension (refdim) of self.field
Parameters : | refdim (int) the field dimension over which the maxima are looked after : th = float, optional :
|
---|---|
Returns : | idx: array of shape (nmax) :
depth: array of shape (nmax) :
|
To get the graph’s vertices (as id)
Computes the neighbor with highest field value along refdim
Parameters : | refdim: int optiontal, the dimension to consider : |
---|---|
Returns : | hneighb: array of shape(self.V), index of the neighbor with highest :
|
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 all the local maxima of a field
Parameters : | refdim (int) field dimension over which the maxima are looked after : th: float, optional :
|
---|---|
Returns : | depth: array of shape (nmax) :
|
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 :
|
---|
Morphological opening of the field data. self.field is changed inplace
Parameters : | nbiter: int, optional, the number of iterations required : |
---|
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 : |
Returns a subfield of self, with only vertices such that valid > 0
Parameters : | valid: array of shape (self.V), :
|
---|---|
Returns : | F: Field instance, :
|
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.
Analysis of the level sets of the field: Bifurcations are defined as changes in the topology in the level sets when the level (threshold) is varied This can been thought of as a kind of Morse analysis
Parameters : | th: float, optional, :
|
---|---|
Returns : | idx: array of shape (nlsets) :
height: array of shape (nlsets) :
parents: array of shape (nlsets) :
label: array of shape (self.V) :
|
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 : |
Ward’s clustering of self
Parameters : | nbcluster: int, :
|
---|---|
Returns : | label: array of shape (self.V) :
J (float): the resulting inertia : |
Instantiates a weighted graph from a (sparse) coo_matrix
Parameters : | x: (V, V) scipy.sparse.coo_matrix instance, :
data: array of shape (V, dim), :
|
---|---|
Returns : | ifield: resulting Field instance : |
Instantiate a Fieldfrom a WeightedGraph plus some feature data Parameters ———- x: (V, V) scipy.sparse.coo_matrix instance,
the input matrix
Returns : | ifield: resulting field instance : |
---|