LatentMaskBlockState#
- class graph_tool.inference.LatentMaskBlockState(g, ecount, f, f_default=0.0, nested=True, state_args={}, init_count=1, bstate=None, **kwargs)[git][source]#
Bases:
UncertainBaseStateInference state of a measured graph, using the stochastic block model as a prior.
- Parameters:
- g
Graph Measured graph.
- ecount
EdgePropertyMap Edge property map of type
int64_t, containing the edge counts in the observed multigraph.- f
EdgePropertyMap Edge property map of type
double, containing the probability of preserving a latent edge count in the observed multigraph.- f_default
float(optional, default:0.) Default probability of preserving a latent edge for edges not present in
g.- nested
boolean(optional, default:True) If
True, aNestedBlockStatewill be used, otherwiseBlockState.- state_args
dict(optional, default:{}) Arguments to be passed to
NestedBlockStateorBlockState.- init_count
float(optional, default:1) If positive, the latent multiplicity of each edge of
gwill be initialized to \(\max(\min(\lfloor m/f\rfloor, m_{\max}), m)\), where \(m\) is its observed count given byecount, \(f\) its value off, and \(m_{\max}\) the maximum multiplicity (the parametermax_mofUncertainBaseState). Otherwise, the latent multiplicities will be initialized to the observed counts. This is ignored ifbstateis given.- bstate
NestedBlockStateorBlockState(optional, default:None) If passed, this will be used to initialize the block state directly.
- g
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 latent multigraph during MCMC runs.
copy(**kwargs)Copies the state.
edge_mcmc_sweep([beta, niter, pedges, ...])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_N()Return the number of nodes of the state.
Return the underlying block state, which can be either
BlockStateorNestedBlockState.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)\).
Return the current default values for the parameters of the function
entropy(), together with other operations that depend on them.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 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
EdgePropertyMapw.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
dmwould be removed.- collect_marginal(g=None)[git]#
Collect marginal inferred network during MCMC runs.
- Parameters:
- g
Graph(optional, default:None) Previous marginal graph.
- g
- Returns:
- g
Graph New marginal graph, with internal edge
EdgePropertyMap"eprob", containing the marginal probabilities for each edge.
- g
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)[git]#
Collect marginal latent multigraph during MCMC runs.
- Parameters:
- g
Graph(optional, default:None) Previous marginal multigraph.
- g
- Returns:
- g
Graph New marginal graph, with internal edge
EdgePropertyMap"wcount", containing the edge multiplicity counts.
- g
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)[git]#
Copies the state. The parameters override the state properties, and have the same meaning as in the constructor.
- edge_mcmc_sweep(beta=1, niter=1, pedges=0.25, puniform=0.25, bisect=False, verbose=False, **kwargs)[git]#
Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample latent edges.
- Parameters:
- beta
float(optional, default:1) Inverse temperature parameter.
- niter
int(optional, default:1) Number of sweeps.
- pedges
double(optional, default:.25) Probability of choosing an existing edge to update.
- puniform
double(optional, default:.25) Probability of choosing uniformly at random an edge to update.
- bisect
boolean(optional, default:False) If true, the edge multiplicity proposals will be sampled using a bisection approach. Otherwise, they will be sampled from a centered geometric distribution.
- verbose
boolean(optional, default:False) If
verbose == True, detailed information will be displayed.
- beta
- Returns:
- dS
float Entropy difference after the sweeps.
- nattempts
int Number of move attempts.
- nmoves
int Number of variables moved.
- dS
- entropy(latent_edges=True, density=False, aE=1.0, sbm=True, **kwargs)[git]#
Return the description length, i.e. the negative log-likelihood.
Warning
The default arguments of this function are overridden by those obtained from
get_entropy_args(). To update the defaults in a stateful way,update_entropy_args()should be called.
- get_block_state()[git]#
Return the underlying block state, which can be either
BlockStateorNestedBlockState.
- get_edge_prob(u, v, entropy_args={}, epsilon=1e-08)[git]#
Return conditional posterior log-probability of edge \((u,v)\).
- get_edges_prob(elist, entropy_args={}, epsilon=1e-08)[git]#
Return conditional posterior log-probability of an edge list, with shape \((E,2)\).
- get_entropy_args()[git]#
Return the current default values for the parameters of the function
entropy(), together with other operations that depend on them.
- mcmc_sweep(beta=1, niter=1, pedges=0.5, multiflip=True, edge_mcmc_args={}, sbm_mcmc_args={}, **kwargs)[git]#
Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample network partitions and latent edges. The parameter
pedgescontrols the probability with which edge moves will be attempted, instead of partition moves. The remaining keyword parameters will be passed tomcmc_sweep()ormultiflip_mcmc_sweep(), ifmultiflip=True.
- reset_entropy_args()[git]#
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)[git]#
Perform sweeps of a Metropolis-Hastings acceptance-rejection sampling MCMC to sample node partitions. The remaining keyword parameters will be passed to
mcmc_sweep()ormultiflip_mcmc_sweep(), ifmultiflip=True.
- set_state(g, w)[git]#
Set all edge multiplicities via
EdgePropertyMapw.
- update_entropy_args(**kwargs)[git]#
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.