UncertainBlockState#

class graph_tool.inference.UncertainBlockState(g, q, q_default=0.0, nested=True, state_args={}, bstate=None, self_loops=False, **kwargs)[source]#

Bases: UncertainBaseState

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

Parameters:
gGraph

Measured graph.

qEdgePropertyMap

Edge probabilities in range \([0,1]\).

q_defaultfloat (optional, default: 0.)

Non-edge probability in range \([0,1]\).

nestedboolean (optional, default: True)

If True, a NestedBlockState will be used, otherwise BlockState.

state_argsdict (optional, default: {})

Arguments to be passed to NestedBlockState or BlockState.

bstateNestedBlockState or BlockState (optional, default: None)

If passed, this will be used to initialize the block state directly.

self_loopsbool (optional, default: False)

If True, it is assumed that the uncertain graph can contain self-loops.

References

[peixoto-reconstructing-2018]

Tiago P. Peixoto, “Reconstructing networks with unknown and heterogeneous errors”, Phys. Rev. X 8 041011 (2018). DOI: 10.1103/PhysRevX.8.041011 [sci-hub, @tor], arXiv: 1806.07956

Methods

add_edge(u, v[, dm])

Add edge \((u, v)\) with multiplicity dm.

collect_marginal([g])

Collect marginal inferred network during MCMC runs.

collect_marginal_multigraph([g])

Collect marginal latent multigraph during MCMC runs.

copy(**kwargs)

Return a copy of the state.

edge_mcmc_sweep([beta, niter, verbose])

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample latent edges.

entropy([latent_edges, density, aE, sbm])

Return the description length, i.e. the negative log-likelihood.

get_block_state()

Return the underlying block state, which can be either BlockState or NestedBlockState.

get_edge_prob(u, v[, entropy_args, epsilon])

Return conditional posterior log-probability of edge \((u,v)\).

get_edges_prob(elist[, entropy_args, epsilon])

Return conditional posterior log-probability of an edge list, with shape \((E,2)\).

get_entropy_args()

Return the current default values for the parameters of the function entropy(), together with other operations that depend on them.

get_graph()

Return the current inferred graph.

mcmc_sweep([beta, niter, pedges, multiflip, ...])

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample network partitions and latent edges.

remove_edge(u, v[, dm])

Remove edge \((u, v)\) with multiplicity dm.

reset_entropy_args()

Reset the current default values for the parameters of the function entropy(), together with other operations that depend on them.

sbm_mcmc_sweep([multiflip])

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample node partitions.

set_state(g, w)

Set all edge multiplicities via EdgePropertyMap w.

update_entropy_args(**kwargs)

Update the default values for the parameters of the function entropy() from the keyword arguments, in a stateful way, together with other operations that depend on them.

virtual_add_edge(u, v[, dm, entropy_args])

Return the difference in description length if edge \((u, v)\) would be added with multiplicity dm.

virtual_remove_edge(u, v[, dm, entropy_args])

Return the difference in description length if edge \((u, v)\) with multiplicity dm would be removed.

add_edge(u, v, dm=1)#

Add edge \((u, v)\) with multiplicity dm.

collect_marginal(g=None)#

Collect marginal inferred network during MCMC runs.

Parameters:
gGraph (optional, default: None)

Previous marginal graph.

Returns:
gGraph

New marginal graph, with internal edge EdgePropertyMap "eprob", containing the marginal probabilities for each edge.

Notes

The posterior marginal probability of an edge \((i,j)\) is defined as

\[\pi_{ij} = \sum_{\boldsymbol A}A_{ij}P(\boldsymbol A|\boldsymbol D)\]

where \(P(\boldsymbol A|\boldsymbol D)\) is the posterior probability given the data.

collect_marginal_multigraph(g=None)#

Collect marginal latent multigraph during MCMC runs.

Parameters:
gGraph (optional, default: None)

Previous marginal multigraph.

Returns:
gGraph

New marginal graph, with internal edge EdgePropertyMap "w" and "wcount", containing the edge multiplicities and their respective counts.

Notes

The mean posterior marginal multiplicity distribution of a multi-edge \((i,j)\) is defined as

\[\pi_{ij}(w) = \sum_{\boldsymbol G}\delta_{w,G_{ij}}P(\boldsymbol G|\boldsymbol D)\]

where \(P(\boldsymbol G|\boldsymbol D)\) is the posterior probability of a multigraph \(\boldsymbol G\) given the data.

copy(**kwargs)#

Return a copy of the state.

edge_mcmc_sweep(beta=1, niter=1, verbose=False, **kwargs)#

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample latent edges.

Parameters:
betafloat (optional, default: np.inf)

Inverse temperature parameter.

niterint (optional, default: 1)

Number of sweeps.

verboseboolean (optional, default: False)

If verbose == True, detailed information will be displayed.

Returns:
dSfloat

Entropy difference after the sweeps.

nmovesint

Number of variables moved.

entropy(latent_edges=True, density=False, aE=1.0, sbm=True, **kwargs)#

Return the description length, i.e. the negative log-likelihood.

Warning

The default arguments of this function are overriden by those obtained from get_entropy_args(). To update the defaults in a stateful way, update_entropy_args() should be called.

get_block_state()#

Return the underlying block state, which can be either BlockState or NestedBlockState.

get_edge_prob(u, v, entropy_args={}, epsilon=1e-08)#

Return conditional posterior log-probability of edge \((u,v)\).

get_edges_prob(elist, entropy_args={}, epsilon=1e-08)#

Return conditional posterior log-probability of an edge list, with shape \((E,2)\).

get_entropy_args()#

Return the current default values for the parameters of the function entropy(), together with other operations that depend on them.

get_graph()#

Return the current inferred graph.

mcmc_sweep(beta=1, niter=1, pedges=0.5, multiflip=True, edge_mcmc_args={}, sbm_mcmc_args={}, **kwargs)#

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample network partitions and latent edges. The parameter pedges controls the probability with which edge moves will be attempted, instead of partition moves. The remaining keyword parameters will be passed to mcmc_sweep() or multiflip_mcmc_sweep(), if multiflip=True.

remove_edge(u, v, dm=1)#

Remove edge \((u, v)\) with multiplicity dm.

reset_entropy_args()#

Reset the current default values for the parameters of the function entropy(), together with other operations that depend on them.

sbm_mcmc_sweep(multiflip=True, **kwargs)#

Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample node partitions. The remaining keyword parameters will be passed to mcmc_sweep() or multiflip_mcmc_sweep(), if multiflip=True.

set_state(g, w)#

Set all edge multiplicities via EdgePropertyMap w.

update_entropy_args(**kwargs)#

Update the default values for the parameters of the function entropy() from the keyword arguments, in a stateful way, together with other operations that depend on them.

Values updated in this manner are preserved by the copying or pickling of the state.

virtual_add_edge(u, v, dm=1, entropy_args={})#

Return the difference in description length if edge \((u, v)\) would be added with multiplicity dm.

virtual_remove_edge(u, v, dm=1, entropy_args={})#

Return the difference in description length if edge \((u, v)\) with multiplicity dm would be removed.