Inheritance diagram for nipy.neurospin.spatial_models.structural_bfls:
The main routine of this module aims at performing the extraction of ROIs from multisubject dataset using the localization.
This has been published in Thirion et al. Structural Analysis of fMRI Data Revisited: Improving the Sensitivity and Reliability of fMRI Group Studies. IEEE TMI 2007
Author : Bertrand Thirion, 2006-2008
Bases: nipy.neurospin.spatial_models.hroi.NROI
This class is intended to represent a set of inter-subject regions besides the standard multiple ROI features, its has features ‘subjects_ids’ and ‘individual_positions’ to describe from which subjects at which position it is found.
Methods
Sample the postreior density of being in k on a grid defined by cs, assuming that the roi is an ellipsoid
| Parameters: | cs array of shape(n,dim): a set of input coordinates : pval=0.95: cutoff for the CR : dmax=1.0: an upper bound for the spatial variance :
|
|---|
Creates the Minimum Spanning Tree self using Kruskal’s algo. efficient is self is sparse
| Returns: | K: WeightedGraph instance :
|
|---|
Creates the Minimum Spanning Tree self using Kruskal’s algo. efficient is self is sparse
| Returns: | K: WeightedGraph instance :
|
|---|
label = self.Voronoi_Labelling(seed) 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 fixme: how is dealt the case of diconnected graph ? : |
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) : |
|---|
returns the sum of weighted degree of graph self
| Parameters: | c (int): side selection :
|
|---|---|
| Returns: | wd : array of shape (self.V),
|
Create the adjacency matrix of self
| Returns: | A : an ((self.V*self.V),np.double) array
|
|---|
returns all the distances of the graph as a tree
| Parameters: | seed=None array of shape(nbseed) with valuesin [0..self.V-1] :
|
|---|---|
| Returns: | dg: array of shape(nseed, self.V): the resulting distance : |
self.as_multiple_balls(position, radius) Given a set of positions and radii, defines one roi at each (position/radius) couple
| Parameters: | position: array of shape (k,3): the set of positions : radius: array of shape (k): the set of radii : |
|---|
Returns an array of labels corresponding to the different connex components of the graph.
| Returns: | label: array of shape(self.V), labelling of the vertices : |
|---|
Check that the proposed is indeed a graph, i.e. contains no loop
| Returns: | a boolean b=0 iff there are loops, 1 otherwise : |
|---|
Check the consistency of the input values: affine should be a (4,4) array
all values of xyz should be in the range [0,d1]*[0,d2]*[0,d3] where self.shape = (d1,d2,d3), if shape is defined
check that self.roi_features have the coorect size i.e. f.shape[0]=self.k for f in self.roi_features and that self.discrete features have the correct size i.e. for f in self.roi_features: f is a list of length self.k f[i] is an array with dimensions consistent with xyz
Note: features that are not found consistent are removed
checks that the image is in the header of self
| Parameters: | image_path: (string) the path of an image : |
|---|
Extraction of the graphe cliques these are defined using replicator dynamics equations
| Returns: | - cliques: array of shape (self.V), type (np.int) :
|
|---|
self.compute_children() define the children list
| Returns: | children: a list of self.V lists, :
|
|---|
Create a ‘position’ feature based on self.affine and self.indexes, which is simply an affine transform from self.xyz to the space of self
fixme : if a position is already available it does not need to be computed
the computed position is returned
self.cut_redudancies() Remove possibly redundant edges: if an edge (ab) is present twice in the edge matrix, only the first instance in kept. The weights are processed accordingly
| Returns: | - E(int): the number of edges, self.E : |
|---|
returns the degree of the graph vertices
| Returns: | rdegree: array of shape self.V, the right degree : ldegree: array of shape self.V, the left degree : |
|---|
compute a labelling of the nodes which is 0 for the leaves, 1 for their parents etc and maximal for the roots
| Returns: | depth: array of shape (self.V): the depth values of the vertices : |
|---|
returns all the [graph] geodesic distances starting from seed it is mandatory that the graph weights are non-negative
| Parameters: | seed (int, >-1,<self.V) or array of shape(p) :
|
|---|---|
| Returns: | dg: array of shape (self.V) , :
|
Compute an ROI-level feature given the discrete features
| Parameters: | fid(string) the discrete feature under consideration : method=’average’ the assessment method : Results : —— : the computed roi-feature is returned : |
|---|
set the graph to be the eps-nearest-neighbours graph of the data
| Parameters: | X array of shape (self.V) or (self.V,p) :
eps=1. (float), the neighborhood width : |
|---|---|
| Returns: | self.E the number of edges of the resulting graph : |
Given a set of feature values, produce a feature map, assuming that one feature corresponds to one region
| Parameters: | feature, array of shape (self.k) : the information to map imPath=None, string yielding the output image path :
pw=0.95: volume of the Gaussian ellipsoid associated with the ROIs : |
|---|---|
| Returns: | The image object : |
Compute all the geodesic distances starting from seeds it is mandatory that the graph weights are non-negative
| Parameters: | seed= None: array of shape (nbseed), type np.int :
|
|---|---|
| Returns: | dg array of shape (nbseed,self.V) :
|
set the graph to be the topological neighbours graph of the thre-dimensional coordinate 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 : |
sets the edges of self according to the adjacency matrix M
| Parameters: | M: array of shape(sef.V,self.V) : |
|---|
All the voxels of the image that have non-zero-value self.k becomes the number of values of the (discrete) image
| Parameters: | image_path: string :
labels=None : array of shape (nlabels)
|
|---|
Generate the set of coordinates that is canonically associated with the referential of self
| Returns: | cs, array of shape (nvox, 3) the coordinates set : |
|---|
E = knn(X,k) set the graph to be the k-nearest-neighbours graph of the data
| Parameters: | X array of shape (self.V) or (self.V,p) :
k=1 : is the number of neighbours considered |
|---|---|
| Returns: | - self.E (int): the number of edges of the resulting graph : |
tests whether the given nodes within ids represent all the leaves of a certain subtree of self
| Parameters: | idds: array of shape (n) that takes values in [0..self.V-1] : custom == False, boolean :
|
|---|
| Returns: | the left incidence matrix of self :
|
|---|
Returns the indexes of the vertices within the main cc
| Returns: | idx: array of shape (sizeof main cc) : |
|---|
write a int image where the nonzero values are the ROIs
| Parameters: | path: string, optional :
|
|---|---|
| Returns: | brifti image instance : |
Sample the set of landmark regions on the proposed coordiante set cs, assuming a Gaussian shape
| Parameters: | cs: array of shape(n,dim) a set of input coordinates : pval=0.95 (float in [0,1]): cutoff for the CR :
dmax=1. : an upper bound for the spatial variance
|
|---|
Remove the non-valid items by including them in their parents when it exists methods indicates the way possible features are dealt with. (not implemented yet)
| Parameters: | valid array of shape(self.k) : |
|---|
self.merge_descending() Remove the items with only one son by including them in their son
| Parameters: | methods indicates the way possible features are dealt with : (not implemented yet) : |
|---|
makes self the MST of the array X
| Parameters: | X: an array of shape (self.V,dim) :
|
|---|---|
| Returns: | tl (float) the total length of the mst : |
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 :
|
|---|
boxplot the distribution of features within ROIs Note that this assumes 1-d features
| Parameters: | fid: string, :
ax: axis handle, optional : |
|---|
boxplot the feature within the ROI Note that this assumes a 1-d feature
| Parameters: | fid string, :
|
|---|
Particular feature map where feature self.roi_prevalence()
| Parameters: | imPath=None, string yielding the output image path :
pw=0.95: volume of the Gaussian ellipsoid associated with the ROIs : |
|---|---|
| Returns: | The image object : |
label = self.propagate_upward(label) Assuming that label is a certain positive integer field (i.e. labels) that is defined at the leaves of the tree and can be compared, this propagates these labels to the parents whenever the children nodes have coherent properties otherwise the parent value is unchanged
| Parameters: | label: array of shape(self.V) : |
|---|---|
| Returns: | label: array of shape(self.V) : |
propagates some binary property in the forest that is defined in the leaves so that prop[parents] = logical_and(prop[children])
| Parameters: | prop, array of shape(self.V), the input property : |
|---|---|
| Returns: | prop, array of shape(self.V), the output property field : |
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 : |
|---|
Reorder the graph according to the index c
| Parameters: | c=0 in {0,1,2}, index that designates the array :
|
|---|
reorder the tree so that the leaves come first then their parents and so on, and the roots are last the permutation necessary to apply to all vertex-based information
| Returns: | order: array of shape(self.V) :
|
|---|
| Returns: | the right incidence matrix of self :
|
|---|
assuming that fid=’confidence’ field has been set as a discrete feature, this creates an approximate p-value that states how confident one might that the LR is defined in at least ths individuals if conficence is not defined as a discrete_feature, it is assumed to be 1.
| Parameters: | ths: integer that yields the representativity threshold : |
|---|
l = self.subtree(k) returns an array of the nodes included in the subtree rooted in k
| Parameters: | k (int): the vertex from which the subtree is searched : |
|---|---|
| Returns: | idx : array of shape>=1 the index of the nodes beneath k |
| Parameters: | fid (string): feature identifier : data: list of self.k arrays with shape(nk,p),with p>0 :
|
|---|
extract some discrete information from an image
| Parameters: | fid: string, feature id : image_path, string, optional :
image, brfiti image path, :
Note that either image_path or image has to be provided : |
|---|
Assuming that self.discrete_feature[‘index’] exists this extracts the values from data corresponding to the index and sets these are self.discrete_feature[fid]
| Parameters: | fid (string): feature id : data: array of shape(nbitem,k) where nbitem is supposed :
|
|---|
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 dinstance 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 |
|---|
this function simply stores data
| Parameters: | fid (string): feature identifier, e.g. : data: array of shape(self.k,p),with p>0 : |
|---|
extract some roi-related information from an image
| Parameters: | fid: feature id : image_path(string): path of the feature-defining image : method=’average’ (string) : take the roi feature as
|
|---|
| Parameters: | weights : an array of shape(self.V), edges weights |
|---|
creates a subforest with the vertices for which valid>0 and with the correponding set of edges the children of deleted vertices become their own parent
| Parameters: | valid: array of shape (self.V) : |
|---|---|
| Returns: | a new forest 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 : |
converts the graph to a neighboring system The neighboring system is nothing but a (sparser) representation of the edge matrix
| Returns: | ci, ne, we: arrays of shape (self.V+1), (self.E), (self.E) :
|
|---|
This is the main function for building the BFLs
| Parameters: | Fbeta : nipy.neurospin.graph.field.Field instance
Beta: an array of shape (nbnodes, subjects): :
xyz array of shape (nnodes,3): :
affine=np.eye(4), array of shape(4,4) :
shape=None, tuple of length 3 defining the size of the grid :
coord array of shape (nnodes,3): :
dmax=10.: spatial relaxation allowed in the preocedure : thr = 3.0: thrshold at the first-level : ths = 0, number of subjects to validate a BFL : pval = 0.2 : significance p-value for the spatial inference |
|---|
Replicator dynamics graph segmentation: python implementation
| Parameters: | Gc: graph to be segmented : bstochastic=1 stochastic initialization of the graph : |
|---|
Given a list of hierarchical ROIs, and an associated labelling, this creates an Amer structure wuch groups ROIs with the same label.
| Parameters: | BF list of nipy.neurospin.spatial_models.hroi.Nroi instances :
ths=0 defines the condition (c): :
|
|---|
Given a first labelling of the graph Gc, this function builds a reduced graph by merging the vertices according to the labelling
| Parameters: | Gc nipy.neurospin.graph.graph.WeightedGraph instance : labels array of shape V, the number of vertices of Gc :
|
|---|
Hard segmentation of the graph Gc using a replicator dynamics approach. The clusters obtained in the first pass are further merged during a second pass, based on a reduced graph
| Parameters: | Gc : nipy.neurospin.graph.graph.WeightedGraph instance
|
|---|