MeasuredClosureBlockState#

class graph_tool.inference.MeasuredClosureBlockState(g, n, x, n_default=1, x_default=0, L=1, b=None, fn_params={'alpha': 1, 'beta': 1}, fp_params={'mu': 1, 'nu': 1}, aE=nan, nested=True, state_args={}, bstate=None, g_orig=None, ew=None, ex=None, **kwargs)[source]#

Bases: LatentClosureBlockState, UncertainBaseState

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

Parameters:
gGraph

Measured graph.

nEdgePropertyMap

Edge property map of type int, containing the total number of measurements for each edge.

xEdgePropertyMap

Edge property map of type int, containing the number of positive measurements for each edge.

n_defaultint (optional, default: 1)

Total number of measurements for each non-edge.

x_defaultint (optional, default: 0)

Total number of positive measurements for each non-edge.

Lint (optional, default: 1)

Maximum number of triadic closure generations.

bVertexPropertyMap (optional, default: None)

Inital partition (or hierarchical partition nested=True).

fn_paramsdict (optional, default: dict(alpha=1, beta=1))

Beta distribution hyperparameters for the probability of missing edges (false negatives).

fp_paramsdict (optional, default: dict(mu=1, nu=1))

Beta distribution hyperparameters for the probability of spurious edges (false positives).

aEfloat (optional, default: NaN)

Expected total number of edges used in prior. If NaN, a flat prior will be used instead.

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.

g_origGraph (optional, default: None)

Original graph, if g is used to initialize differently from a graph with no triadic closure edges.

ewlist of EdgePropertyMap (optional, default: None)

List of edge property maps of g, containing the initial weights (counts) at each triadic generation.

exlist of EdgePropertyMap (optional, default: None)

List of edge property maps of g, each containing a list of integers with the ego graph memberships of every edge, for every triadic generation.

References

[peixoto-disentangling-2022]

Tiago P. Peixoto, “Disentangling homophily, community structure and triadic closure in networks”, Phys. Rev. X 12, 011004 (2022), DOI: 10.1103/PhysRevX.12.011004 [sci-hub, @tor], arXiv: 2101.02510

Methods

add_edge(u, v[, dm])

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

collect_marginal([gs])

Collect marginal inferred network during MCMC runs.

collect_marginal_multigraph([gs])

Collect marginal latent multigraphs 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 entropy, i.e. negative log-likelihood.

get_block_state()

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

get_ec([ew])

Return edge property map with layer membership.

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.

get_p_posterior()

Get beta distribution parameters for the posterior probability of missing edges.

get_q_posterior()

Get beta distribution parameters for the posterior probability of spurious edges.

mcmc_sweep([r, multiflip])

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

multiflip_mcmc_sweep(**kwargs)

Alias for mcmc_sweep() with multiflip=True.

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.

sample_graph([sample_sbm, canonical_sbm, ...])

Sample graph from inferred model.

sbm_mcmc_sweep([multiflip])

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

set_hparams(alpha, beta, mu, nu)

Set edge and non-edge hyperparameters.

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(gs=None)#

Collect marginal inferred network during MCMC runs.

Parameters:
glist of Graph (optional, default: None)

Previous marginal graphs.

Returns:
glist Graph

New list of marginal graphs, each with internal EdgePropertyMap "eprob", containing the marginal probabilities for each edge, as well as VertexPropertyMap "t", "m", "c", containing the average number of closures, open triads, and fraction of closed triads on each node.

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.

This function returns a list with the marginal graphs for every layer.

collect_marginal_multigraph(gs=None)#

Collect marginal latent multigraphs during MCMC runs.

Parameters:
glist of Graph (optional, default: None)

Previous marginal multigraphs.

Returns:
glist of Graph

New marginal multigraphs, each 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.

This function returns a list with the marginal graphs for every layer.

copy(**kwargs)[source]#

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 entropy, i.e. 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_ec(ew=None)#

Return edge property map with layer membership.

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()[source]#

Return the current inferred graph.

get_p_posterior()[source]#

Get beta distribution parameters for the posterior probability of missing edges.

get_q_posterior()[source]#

Get beta distribution parameters for the posterior probability of spurious edges.

mcmc_sweep(r=0.5, multiflip=True, **kwargs)#

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

multiflip_mcmc_sweep(**kwargs)#

Alias for mcmc_sweep() with 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.

sample_graph(sample_sbm=True, canonical_sbm=False, sample_params=True, canonical_closure=True)#

Sample graph from inferred model.

Parameters:
sample_sbmboolean (optional, default: True)

If True, the substrate network will be sampled anew from the SBM parameters. Otherwise, it will be the same as the current posterior state.

canonical_sbmboolean (optional, default: False)

If True, the canonical SBM will be used, otherwise the microcanonical SBM will be used.

sample_paramsbool (optional, default: True)

If True, and canonical_sbm == True the count parameters (edges between groups and node degrees) will be sampled from their posterior distribution conditioned on the actual state. Otherwise, their maximum-likelihood values will be used.

canonical_closureboolean (optional, default: True)

If True, the canonical version of triadic clousre will be used (i.e. conditioned on a probability), otherwise the microcanonical version will be used (i.e. conditional on the count number).

Returns:
ulist Graph

Sampled graph, with internal edge EdgePropertyMap "gen", containing the triadic generation of each edge.

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_hparams(alpha, beta, mu, nu)[source]#

Set edge and non-edge hyperparameters.

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.