graph_tool.inference.PartitionModeState#
- class graph_tool.inference.PartitionModeState(bs, relabel=True, nested=False, converge=False, **kwargs)[source]#
Bases:
objectThe 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
bto 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.
entropy()Return the model entropy (negative log-likelihood).
get_B()Return the total number of labels used.
get_M()Return the number of partitions
Return the instance of
PartitionModeStaterepresenting the model at the upper hierarchical level.get_marginal(g)Return a
VertexPropertyMapforGraphg, withvector<int>values containing the marginal group membership counts for each node.get_max(g)Return a
VertexPropertyMapforGraphg, withintvalues containing the maximum marginal group membership for each node.Return a hierarchical partition as a list of
numpy.ndarrayobjects, 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
ifrom 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
bwere inserted the ensemble, after relabelling it ifrelabel=True.virtual_remove_partition(b[, relabel])Computes the entropy difference (negative log probability) if partition
bwere removed from the ensemble, after relabelling it ifrelabel=True.- add_partition(b, relabel=True)[source]#
Adds partition
bto 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
PartitionModeStaterepresenting the model at the upper hierarchical level.
- get_marginal(g)[source]#
Return a
VertexPropertyMapforGraphg, withvector<int>values containing the marginal group membership counts for each node.
- get_max(g)[source]#
Return a
VertexPropertyMapforGraphg, withintvalues containing the maximum marginal group membership for each node.
- get_max_nested()[source]#
Return a hierarchical partition as a list of
numpy.ndarrayobjects, 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.