NestedBlockState#

class graph_tool.inference.NestedBlockState(g, bs=None, base_state=<class 'graph_tool.inference.blockmodel.BlockState'>, base_state_args={}, extra_args=None, **kwargs)[git][source]#

Bases: object

The nested stochastic block model state of a given graph.

Parameters:
gGraph

Graph to be modeled.

bslist of VertexPropertyMap or numpy.ndarray (optional, default: None)

Hierarchical node partition. If not provided it will correspond to a single-group hierarchy of length \(\lceil\log_2(N)\rceil\).

base_statetype (optional, default: BlockState)

State type for lowermost level (one of BlockState, WeightedBlockState, OverlapBlockState, LayeredBlockState, LayeredOverlapBlockState, WeightedOverlapBlockState, LayeredWeightedOverlapBlockState)

base_state_argsdict (optional, default: {})

Keyword arguments to be passed to base type constructor.

extra_argslist of dict (optional, default: None)

Extra parameters to be passed to each hierarchy state.

**kwargskeyword arguments

Keyword arguments to be passed to base type constructor. The base_state_args parameter overrides this.

Methods

collect_partition_histogram([h, update, unlabel])

Collect a histogram of partitions.

copy(**kwargs)

Copies the block state.

draw(**kwargs)

Convenience wrapper to draw_hierarchy() that draws the hierarchical state.

entropy(**kwargs)

Obtain the description length (i.e. negative joint log-likelihood) for the hierarchical partition.

get_bs()

Get hierarchy levels as a list of numpy.ndarray and VertexPropertyMap objects with the group memberships at each level.

get_bstack()

Return the nested levels as individual graphs.

get_levels()

Get hierarchy levels as a list of BlockState instances.

get_state()

Alias to get_bs().

gibbs_sweep(**kwargs)

Perform niter sweeps of a rejection-free Gibbs sampling MCMC to sample network partitions.

level_entropy(l[, bstate])

Compute the entropy of level l.

mcmc_sweep(**kwargs)

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC to sample hierarchical network partitions.

move_vertex(v, s)

Move vertex v to block s.

multiflip_mcmc_sweep(**kwargs)

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC with multiple moves to sample hierarchical network partitions.

multilevel_mcmc_sweep(**kwargs)

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC with multilevel moves to sample hierarchical network partitions.

print_summary()

Print a hierarchy summary.

project_level(l)

Project the partition at level l onto the lowest level, and return the corresponding state.

project_partition(j, l)

Project partition of level j onto level l, and return it.

set_state(bs)

Sets the internal nested partition of the state.

collect_partition_histogram(h=None, update=1, unlabel=True)[git][source]#

Collect a histogram of partitions.

This should be called multiple times, e.g. after repeated runs of the graph_tool.inference.NestedBlockState.mcmc_sweep() function.

Parameters:
hPartitionHist (optional, default: None)

Partition histogram. If not provided, an empty histogram will be created.

updatefloat (optional, default: 1)

Each call increases the current count by the amount given by this parameter.

unlabelbool (optional, default: True)

If True, a canonical labelling of the groups will be used, so that each hierarchical partition is uniquely represented.

Returns:
hPartitionHist

Updated Partition histogram.

copy(**kwargs)[git][source]#

Copies the block state. The parameters override the state properties, and have the same meaning as in the constructor.

draw(**kwargs)[git][source]#

Convenience wrapper to draw_hierarchy() that draws the hierarchical state.

entropy(**kwargs)[git][source]#

Obtain the description length (i.e. negative joint log-likelihood) for the hierarchical partition.

The keyword arguments are passed to the entropy() method of the underlying state objects (e.g. graph_tool.inference.BlockState.entropy(), graph_tool.inference.OverlapBlockState.entropy(), or graph_tool.inference.LayeredBlockState.entropy()).

The upper levels use their own entropy arguments, which they inherit from the base state, except for bip_edges_dl, which if given applies to all levels.

get_bs()[git][source]#

Get hierarchy levels as a list of numpy.ndarray and VertexPropertyMap objects with the group memberships at each level.

get_bstack()[git][source]#

Return the nested levels as individual graphs.

This returns a list of Graph instances representing the inferred hierarchy at each level. Each graph has two internal vertex and edge property maps named “count” which correspond to the vertex and edge counts at the lower level, respectively. Additionally, an internal vertex property map named “b” specifies the block partition.

get_levels()[git][source]#

Get hierarchy levels as a list of BlockState instances.

get_state()[git][source]#

Alias to get_bs().

gibbs_sweep(**kwargs)[git][source]#

Perform niter sweeps of a rejection-free Gibbs sampling MCMC to sample network partitions.

The arguments accepted are the same as in graph_tool.inference.BlockState.gibbs_sweep().

Warning

This function performs niter sweeps at each hierarchical level once. This means that in order for the chain to equilibrate, we need to call this function several times, i.e. it is not enough to call it once with a large value of niter.

level_entropy(l, bstate=None, **kwargs)[git][source]#

Compute the entropy of level l.

mcmc_sweep(**kwargs)[git][source]#

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC to sample hierarchical network partitions.

The arguments accepted are the same as in graph_tool.inference.BlockState.mcmc_sweep().

If the parameter c is a scalar, the values used at each level are c * 2 ** l for l in the range [0, L-1], with c = 1 by default (unlike the default c = 0.5 of the method of BlockState). Optionally, a list of values may be passed instead, which specifies the value of c[l] to be used at each level.

Warning

This function performs niter sweeps at each hierarchical level once. This means that in order for the chain to equilibrate, we need to call this function several times, i.e. it is not enough to call it once with a large value of niter.

move_vertex(v, s)[git][source]#

Move vertex v to block s.

multiflip_mcmc_sweep(**kwargs)[git][source]#

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC with multiple moves to sample hierarchical network partitions.

The arguments accepted are the same as in graph_tool.inference.BlockState.multiflip_mcmc_sweep().

If the parameter c is a scalar, the values used at each level are c * 2 ** l for l in the range [0, L-1], with c = 1 by default (unlike the default c = 0.5 of the method of BlockState). Optionally, a list of values may be passed instead, which specifies the value of c[l] to be used at each level.

Warning

This function performs niter sweeps at each hierarchical level once. This means that in order for the chain to equilibrate, we need to call this function several times, i.e. it is not enough to call it once with a large value of niter.

multilevel_mcmc_sweep(**kwargs)[git][source]#

Perform niter sweeps of a Metropolis-Hastings acceptance-rejection MCMC with multilevel moves to sample hierarchical network partitions.

The arguments accepted are the same as in graph_tool.inference.BlockState.multilevel_mcmc_sweep().

If the parameter c is a scalar, the values used at each level are c * 2 ** l for l in the range [0, L-1], with c = 1 by default (unlike the default c = 0.5 of the method of BlockState). Optionally, a list of values may be passed instead, which specifies the value of c[l] to be used at each level.

Warning

This function performs niter sweeps at each hierarchical level once. This means that in order for the chain to equilibrate, we need to call this function several times, i.e. it is not enough to call it once with a large value of niter.

print_summary()[git][source]#

Print a hierarchy summary.

project_level(l)[git][source]#

Project the partition at level l onto the lowest level, and return the corresponding state.

project_partition(j, l)[git][source]#

Project partition of level j onto level l, and return it.

set_state(bs)[git][source]#

Sets the internal nested partition of the state.