PartitionModeState#
- class graph_tool.inference.PartitionModeState(bs, relabel=True, nested=False, converge=False, **kwargs)[source]#
Bases:
object
The random label model state for a set of labelled partitions, which attempts to align them with a common group labelling.
- Parameters:
- bslist of iterables
List of partitions to be aligned. If
nested=True
, these should be hierarchical partitions, composed each as a list of partitions.- relabel
bool
(optional, default:True
) If
True
, an initial alignment of the partitions will be attempted during instantiation, otherwise they will be incorporated as they are.- nested
bool
(optional, default:False
) If
True
, the partitions will be assumed to be hierarchical.- converge
bool
(optional, default:False
) If
True
, the label alignment will be iterated until convergence upon initialization (otherwisereplace_partitions()
needs to be called repeatedly).
References
[peixoto-revealing-2021]Tiago P. Peixoto, “Revealing consensus and dissensus between network partitions”, Phys. Rev. X 11 021003 (2021) DOI: 10.1103/PhysRevX.11.021003 [sci-hub, @tor], arXiv: 2005.13977
Methods
add_partition
(b[, relabel])Adds partition
b
to the ensemble, after relabelling it ifrelabel=True
, and returns its index in the population.align_mode
(mode)Relabel entire ensemble to align with another ensemble given by
mode
, which should be an instance ofPartitionModeState
.copy
([bs])Copies the state.
get_B
()Return the total number of labels used.
get_M
()Return the number of partitions
Return the instance of
PartitionModeState
representing the model at the upper hierarchical level.get_marginal
(g)Return a
VertexPropertyMap
forGraph
g
, withvector<int>
values containing the marginal group membership counts for each node.get_max
(g)Return a
VertexPropertyMap
forGraph
g
, withint
values containing the maximum marginal group membership for each node.Return a hierarchical partition as a list of
numpy.ndarray
objects, containing the maximum marginal group membership for each node in every level.Returns nested partition with index
i
.Returns all nested partitions.
Returns partition with index
i
.Returns all partitions.
posterior_cdev
([MLE])Return the uncertainty of the mode in the range \([0,1]\), using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.posterior_entropy
([MLE])Return the entropy of the random label model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.posterior_lprob
(b[, MLE])Return the log-probability of partition
b
, using maximum likelihood estimates for the marginal node probabilities if`MLE=True`
, otherwise using posterior mean estimates.relabel
()Re-order group labels according to group sizes.
Returns a relabelled copy of partition
b
, according to its alignment with the ensemble.Removes partition with index
i
from the ensemble.Removes and re-adds every partition, after relabelling, and returns the entropy difference (negative log probability).
sample_nested_partition
([MLE, fix_empty])Sampled a nested partition from the inferred model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.sample_partition
([MLE])Sampled a partition from the inferred model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.virtual_add_partition
(b[, relabel])Computes the entropy difference (negative log probability) if partition
b
were inserted the ensemble, after relabelling it ifrelabel=True
.virtual_remove_partition
(b[, relabel])Computes the entropy difference (negative log probability) if partition
b
were removed from the ensemble, after relabelling it ifrelabel=True
.- add_partition(b, relabel=True)[source]#
Adds partition
b
to the ensemble, after relabelling it ifrelabel=True
, and returns its index in the population.
- align_mode(mode)[source]#
Relabel entire ensemble to align with another ensemble given by
mode
, which should be an instance ofPartitionModeState
.
- copy(bs=None)[source]#
Copies the state. The parameters override the state properties, and have the same meaning as in the constructor.
- get_coupled_state()[source]#
Return the instance of
PartitionModeState
representing the model at the upper hierarchical level.
- get_marginal(g)[source]#
Return a
VertexPropertyMap
forGraph
g
, withvector<int>
values containing the marginal group membership counts for each node.
- get_max(g)[source]#
Return a
VertexPropertyMap
forGraph
g
, withint
values containing the maximum marginal group membership for each node.
- get_max_nested()[source]#
Return a hierarchical partition as a list of
numpy.ndarray
objects, containing the maximum marginal group membership for each node in every level.
- posterior_cdev(MLE=True)[source]#
Return the uncertainty of the mode in the range \([0,1]\), using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.
- posterior_entropy(MLE=True)[source]#
Return the entropy of the random label model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.
- posterior_lprob(b, MLE=True)[source]#
Return the log-probability of partition
b
, using maximum likelihood estimates for the marginal node probabilities if`MLE=True`
, otherwise using posterior mean estimates.
- relabel_partition(b)[source]#
Returns a relabelled copy of partition
b
, according to its alignment with the ensemble.
- replace_partitions()[source]#
Removes and re-adds every partition, after relabelling, and returns the entropy difference (negative log probability).
- sample_nested_partition(MLE=True, fix_empty=True)[source]#
Sampled a nested partition from the inferred model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.
- sample_partition(MLE=True)[source]#
Sampled a partition from the inferred model, using maximum likelihood estimates for the marginal node probabilities if
`MLE=True`
, otherwise using posterior mean estimates.