graph_tool.inference#

This module contains algorithms for the identification of large-scale network structure via the statistical inference of generative models.

Note

An introduction to the concepts used here, as well as a basic HOWTO, are included in the cookbook section: Inferring modular network structure.

Nonparametric stochastic block model inference#

State classes#

BlockState

The stochastic block model state of a given graph.

WeightedBlockState

The weighted stochastic block model state of a given graph (i.e. with edge covariates).

OverlapBlockState

The overlapping (mixed-membership) stochastic block model state of a given graph.

WeightedOverlapBlockState

The weighted overlapping stochastic block model state of a given graph.

LayeredBlockState

The layered stochastic block model state of a given graph.

LayeredWeightedBlockState

The layered and weighted stochastic block model state of a given graph.

LayeredOverlapBlockState

The layered overlapping stochastic block model state of a given graph.

LayeredWeightedOverlapBlockState

The layered weighted overlapping stochastic block model state of a given graph.

NestedBlockState

The nested stochastic block model state of a given graph.

PPBlockState

Obtain the partition of a network according to the Bayesian planted partition model.

RankedBlockState

Obtain the ordered partition of a network according to the ranked stochastic block model.

CliqueState

The state of a clique decomposition of a given graph.

Abstract base classes#

PickleState

Base state that implements pickling and copying.

EntropyState

Base state that implements entropy arguments.

CLabelState

Base state that implements partition constraints.

MCMCState

Base state that implements single-flip MCMC sweeps.

MultiflipMCMCState

Base state that implements multiflip (merge-split) MCMC sweeps.

MultilevelMCMCState

Base state that implements multilevel agglomerative MCMC sweeps.

GibbsMCMCState

Base state that implements rejection-free Gibbs MCMC sweeps.

ExhaustiveSweepState

Base state that implements exhaustive enumerative sweeps.

DrawBlockState

Base state that implements group-based drawing.

Sampling and minimization#

minimize_blockmodel_dl

Fit the stochastic block model, by minimizing its description length using an agglomerative heuristic.

minimize_nested_blockmodel_dl

Fit the nested stochastic block model, by minimizing its description length using an agglomerative heuristic.

mcmc_equilibrate

Equilibrate a MCMC with a given starting state.

mcmc_anneal

Equilibrate a MCMC at a specified target temperature by performing simulated annealing.

Descriptive community detection#

ModularityState

Obtain the partition of a network according to the maximization of Newman's modularity.

NormCutState

Obtain the partition of a network according to the normalized cut.

MapEquationState

Obtain the partition of a network according to the map equation.

label_propagation

Find communities with the label propagation heuristic.

Tree partitioning#

lukes_partition

Find the optimal partition of a tree into connected parts of bounded size, with the algorithm of Lukes.

Hierarchical random graphs#

hrg_fit

Fit a hierarchical random graph to a graph.

hrg_predict

Predict missing edges with the hierarchical random graph.

hrg_consensus

Return the majority consensus tree of the dendrograms of the hierarchical random graph.

hrg_generate

Sample a graph from a hierarchical random graph.

Semi-supervised vertex classification#

harmonic_function

Predict the labels of the unlabeled vertices with the harmonic function.

local_and_global_consistency

Predict the labels of the unlabeled vertices with the local and global consistency method.

Comparing and manipulating partitions#

PartitionModeState

The random label model state for a set of labelled partitions, which attempts to align them with a common group labelling.

ModeClusterState

The mixed random label model state for a set of labelled partitions, which attempts to align them inside clusters with a common group labelling.

PartitionCentroidState

Obtain the center of a set of partitions, according to the variation of information metric or reduced mutual information.

partition_overlap

Returns the maximum overlap between partitions, according to an optimal label alignment.

nested_partition_overlap

Returns the hierarchical maximum overlap between nested partitions, according to an optimal recursive label alignment.

variation_information

Returns the variation of information between two partitions.

mutual_information

Returns the mutual information between two partitions.

reduced_mutual_information

Returns the reduced mutual information between two partitions.

rand_index

Returns the (adjusted) Rand index between two partitions.

split_join_distance

Returns the split-join distance between two partitions.

contingency_graph

Returns the contingency graph between both partitions.

shuffle_partition_labels

Returns a copy of partition x, with the group labels randomly shuffled.

shuffle_nested_partition_labels

Returns a copy of nested partition x, with the group labels randomly shuffled.

order_partition_labels

Returns a copy of partition x, with the group labels ordered decreasingly according to group size.

order_nested_partition_labels

Returns a copy of nested partition x, with the group labels ordered decreasingly according to group size at each level.

align_partition_labels

Returns a copy of partition x, with the group labels aligned so as to maximize the overlap with y.

align_nested_partition_labels

Returns a copy of nested partition x, with the group labels aligned so as to maximize the overlap with y.

partition_overlap_center

Find a partition with a maximal overlap to all items of the list of partitions given.

nested_partition_overlap_center

Find a nested partition with a maximal overlap to all items of the list of nested partitions given.

nested_partition_clear_null

Returns a copy of nested partition x where the null values -1 are replaced with 0.

contiguous_map

Remap the values of prop in the contiguous range \([0, N-1]\).

nested_contiguous_map

Remap the values of the nested partition bs in the contiguous range \([0, N_l-1]\) for each level \(l\).

Auxiliary functions#

mf_entropy

Compute the "mean field" entropy given the vertex block membership marginals.

bethe_entropy

Compute the Bethe entropy given the edge block membership marginals.

microstate_entropy

Compute microstate entropy given a histogram of partitions.

marginal_multigraph_entropy

Compute the entropy of the marginal latent multigraph distribution.

marginal_multigraph_sample

Sample edge multiplicities from the marginal latent multigraph distribution.

marginal_multigraph_lprob

Compute the log-probability of edge multiplicities according to the marginal latent multigraph distribution.

marginal_graph_sample

Sample a graph from the marginal edge probabilities.

marginal_graph_lprob

Compute the log-probability of a graph according to the marginal edge probabilities.

get_block_edge_gradient

Get edge gradients corresponding to the block membership at the endpoints of the edges given by the be edge property map.

get_hierarchy_tree

Obtain the nested hierarchical levels as a tree.

Auxiliary classes#

PartitionHist

Histogram of partitions, implemented in C++.

BlockPairHist

Histogram of block pairs, implemented in C++.

HistState

Bayesian nonparametric histogram of multivariate data.

Nonparametric network reconstruction#

Reconstruction from direct measurements#

LatentLayerBaseState

Base state for uncertain latent layer network inference.

LatentMultigraphBlockState

Inference state of an erased Poisson multigraph, using the stochastic block model as a prior.

LatentClosureBlockState

Inference state of the stochastic block model with latent triadic closure edges.

MeasuredBlockState

Inference state of a measured graph, using the stochastic block model as a prior.

MeasuredClosureBlockState

Inference state of a measured graph, using the stochastic block model with triadic closure as a prior.

MixedMeasuredBlockState

Inference state of a measured graph with heterogeneous errors, using the stochastic block model as a prior.

LatentMaskBlockState

Inference state of a measured graph, using the stochastic block model as a prior.

UncertainBlockState

Inference state of an uncertain graph, using the stochastic block model as a prior.

UncertainBaseState

Base state for uncertain network inference.

Expectation-maximization inference#

latent_multigraph

Infer latent Poisson multigraph model given an "erased" simple graph.

Reconstruction from dynamics and behavior#

DynamicsBlockStateBase

Base state for network reconstruction based on dynamical or behavioral data, using the stochastic block model as a prior.

BPBlockStateBase

Base state for network reconstruction where the respective model can be used with belief-propagation.

PseudoNormalBlockState

State for network reconstruction based on the multivariate normal distribution, using the pseudolikelihood approximation and the stochastic block model as a prior.

NormalGlauberBlockState

State for network reconstruction based on the dynamical multivariate normal distribution, using the pseudolikelihood approximation and the stochastic block model as a prior.

LinearNormalBlockState

State for network reconstruction based on a linear dynamical model.

LVBlockState

State for network reconstruction based on the generalized Lotka-Volterra dynamics, using the stochastic block model as a prior.

EpidemicsBlockState

Inference state for network reconstruction based on epidemic dynamics, using the stochastic block model as a prior.

IsingBlockStateBase

Base state for network reconstruction based on the Ising model, using the stochastic block model as a prior.

IsingGlauberBlockState

State for network reconstruction based on the Glauber dynamics of the Ising model, using the stochastic block model as a prior.

CIsingGlauberBlockState

State for network reconstruction based on the Glauber dynamics of the continuous Ising model, using the stochastic block model as a prior.

PseudoIsingBlockState

State for network reconstruction based on the equilibrium configurations of the Ising model, using the pseudolikelihood approximation and the stochastic block model as a prior.

PseudoCIsingBlockState

State for network reconstruction based on the equilibrium configurations of the continuous Ising model, using the pseudolikelihood approximation and the stochastic block model as a prior.

PottsBlockStateBase

Base state for network reconstruction based on the generalized Potts model, using the stochastic block model as a prior.

PottsGlauberBlockState

State for network reconstruction based on the Glauber dynamics of the generalized Potts model, using the stochastic block model as a prior.

PseudoPottsBlockState

State for network reconstruction based on the equilibrium configurations of the generalized Potts model, using the pseudolikelihood approximation and the stochastic block model as a prior.

Spin models#

PottsState

Sample from a generalized Potts model.

Semiparametric stochastic block model inference#

State classes#

EMBlockState

The parametric, undirected stochastic block model state of a given graph.

Expectation-maximization inference#

em_infer

Infer the model parameters and latent variables using the expectation-maximization (EM) algorithm with initial state given by state.

Large-scale descriptors#

modularity

Calculate Newman's (generalized) modularity of a network partition.

partition_quality

Calculate the coverage and the performance of a network partition.

cpm_quality

Calculate the quality function of the constant Potts model for a network partition.