Fork me on GitHub

pyhrf.boldsynth.pottsfield.swendsenwang module

computes a default list GraphLinks from RefGraph

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2

output:

  • GraphLinks: Same shape as RefGraph. Each entry indicates whether the link of the corresponding edge in RefGraph is considered or not in Swensdsen-Wang Sampling (1 -> yes / 0 -> no).
pyhrf.boldsynth.pottsfield.swendsenwang.CptDefaultGraphNodesLabels(RefGraph)

computes a default list GraphNodesLabels from RefGraph

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2

output:

  • GraphNodesLabels: List containing the nodes labels (consiedered for the computation of U). The sampler aims to modify its values in function of beta and NbLabels.
pyhrf.boldsynth.pottsfield.swendsenwang.CptDefaultGraphWeight(RefGraph)

computes a default list GraphWeight from RefGraph. Each edge weight is set to 1.0.

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2

output:

  • GraphWeight: Same shape as RefGraph. Each entry is the weight of the corresponding edge in RefGraph
pyhrf.boldsynth.pottsfield.swendsenwang.CptRefGrphNgbhPosi(RefGraph)

computes the critical list CptRefGrphNgbhPosi from RefGraph

imput:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2

output:

  • RefGrphNgbhPosi: Same shape as RefGraph. RefGrphNgbhPosi[i][j] indicates for which k is the link to i in RefGraph[RefGraph[i][j]][k]. It makes algorithms which run through the graph much faster since it avoids a critical loop.
pyhrf.boldsynth.pottsfield.swendsenwang.Cpt_U_graph(RefGraph, GraphNodesLabels, GraphWeight=None)

Computes an estimation of U(Graph)

inputs:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • GraphNodesLabels: list containing the nodes labels.
  • GraphWeight: Same shape as RefGraph. Each entry is the weight of the corresponding edge in RefGraph. If not defined the weights are set to 1.0.

output:

  • U value
pyhrf.boldsynth.pottsfield.swendsenwang.Cpt_Vec_U_graph(RefGraph, beta, LabelsNb, SamplesNb, GraphWeight=None, GraphNodesLabels=None, GraphLinks=None, RefGrphNgbhPosi=None)

Computes a given number of U for fields generated according to a given normalization constant Beta. Swendsen-Wang sampling is used to generate fields.

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • beta: normalization constant
  • LabelsNb: Labels number
  • SamplesNb: Samples number for the U estimations
  • GraphWeight: Same shape as RefGraph. Each entry is the weight of the corresponding edge in RefGraph. If not defined the weights are set to 1.0.
  • GraphNodesLabels: Optional list containing the nodes labels. The sampler aims to modify its values in function of beta and NbLabels. At this level this variable is seen as temporary and will be modified. Defining it slightly increases the calculation times.
  • GraphLinks: Same shape as RefGraph. Each entry indicates if the link of the corresponding edge in RefGraph is considered (if yes …=1 else …=0). At this level this variable is seen as temporary and will be modified. Defining it slightly increases the calculation times.
  • RefGrphNgbhPosi: Same shape as RefGraph. RefGrphNgbhPosi[i][j] indicates for which k is the link to i in RefGraph[RefGraph[i][j]][k]. This optional list is never modified.

output:

  • VecU: Vector of size SamplesNb containing the U computations
pyhrf.boldsynth.pottsfield.swendsenwang.GraphBetaMix(RefGraph, GraphNodesLabels, beta=0.5, NbLabels=2, NbIt=5, weights=None)

Generate a partition in GraphNodesLabels with respect to beta.

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • GraphNodesLabels: list containing the nodes labels.
  • beta: correlation factor for all conditions
  • NbLabels: number of labels in all site conditions
  • NbIt: number of sampling steps with SwendsenWangSampler_graph

output:

  • GraphNodesLabels: sampled GraphNodesLabels (not returned but modified)
pyhrf.boldsynth.pottsfield.swendsenwang.GraphToImage(GraphNodesCoord, GraphNodesLabels, NBZ, NBY, NBX)

Computes a 3D image from a connectivity graph.

input:

  • GraphNodesCoord: Coordinates of each node in Mask
  • GraphNodesLabels: Nodes labels. For example, GraphNodesLabels[i] is the label of node i.
  • NBZ: image size on Z axis
  • NBY: image size on Y axis
  • NBX: image size on X axis

output:

  • Image
pyhrf.boldsynth.pottsfield.swendsenwang.ImageToGraph(Image, Mask, LabelOI=1, ConnectivityType=6)

Computes the connectivity graph of an image under a 3D mask voxels.

inputs:

  • Image: the 3D image (label field).
  • Mask: corresponding 3D mask.
  • LabelOI: Voxels of Mask containing the label LabelOI are those considered.
  • ConnectivityType: controles the connectivity considered in the graph. ConnectivityType=26 : 26-connectivity ConnectivityType=18 : 18-connectivity ConnectivityType=6 : 6-connectivity

outputs:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • GraphWeight: Same shape as RefGraph. Each entry is the weight of the corresponding edge in RefGraph
  • GraphNodesCoord: Coordinates of each node in Mask
  • GraphNodesLabels: list containing the nodes labels.
pyhrf.boldsynth.pottsfield.swendsenwang.MaskToGraph(Mask, LabelOI=1, ConnectivityType=6)

Computes the connectivity graph of in 3D mask voxels.

inputs:

  • Mask: 3D mask.
  • LabelOI: Voxels of Mask containing the label LabelOI are those considered.
  • ConnectivityType: controles the connectivity considered in the graph. ConnectivityType=26 : 26-connectivity ConnectivityType=18 : 18-connectivity ConnectivityType=6 : 6-connectivity

outputs:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • GraphWeight: Same shape as RefGraph. Each entry is the weight of the corresponding edge in RefGraph
  • GraphNodesCoord: Coordinates of each node in Mask
pyhrf.boldsynth.pottsfield.swendsenwang.SwendsenWangSampler_graph(RefGraph, GraphNodesLabels, beta, NbLabels, GraphLinks=None, RefGrphNgbhPosi=None, method=1, weights=None)

image sampling with Swendsen-Wang algorithm

input:

  • RefGraph: List which contains the connectivity graph. Each entry represents a node of the graph and contains the list of its neighbors entry location in the graph. ex: RefGraph[2][3]=10 means 3rd neighbour of the 2nd node is the 10th node. => There exists i such that RefGraph[10][i]=2
  • GraphNodesLabels: list containing the nodes labels. The sampler aims to modify its values in function of beta and NbLabels.
  • beta: normalization constant
  • NbLabels: number of labels (connected voxel pairs are considered if their labels are equal)
  • GraphLinks: Same shape as RefGraph. Each entry indicates if the link of the corresponding edge in RefGraph is considered (if yes …=1 else …=0). This optional list is used as a temporary variable and will be modified ! Defining it makes the algorithm faster (no memory allocation).
  • RefGrphNgbhPosi: Same shape as RefGraph. RefGrphNgbhPosi[i][j] indicates for which k is the link to i in RefGraph[RefGraph[i][j]][k] This optional list is never modified.

output:

  • GraphNodesLabels: resampled nodes labels. (not returned but modified)
pyhrf.boldsynth.pottsfield.swendsenwang.linkNodes(RefGraph, beta, GraphNodesLabels, GraphLinks, RefGrphNgbhPosi)
pyhrf.boldsynth.pottsfield.swendsenwang.linkNodesSets(RefGraph, beta, GraphNodesLabels, links, weights=None)
pyhrf.boldsynth.pottsfield.swendsenwang.pickLabels(RefGraph, GraphLinks, GraphNodesLabels, NbLabels, TempVec, NextTempVec)
pyhrf.boldsynth.pottsfield.swendsenwang.set_cluster_labels(links, labels, nbClasses)
pyhrf.boldsynth.pottsfield.swendsenwang.walkCluster(i, links, labels, l, remainingIndexes)