mixle.stats.graphs.erdos_renyi_graph module¶
Erdos-Renyi graph distributions for binary graph observations.
Data type: a binary graph observation represented as a square adjacency matrix,
a NetworkX-like graph, or a mapping accepted by GraphDataEncoder.
- class ErdosRenyiGraphDistribution(p, directed=False, self_loops=False, num_nodes=None, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionIndependent Bernoulli distribution over binary graph edges.
- Parameters:
- classmethod compute_capabilities()[source]
Return backend capabilities for Bernoulli graph scoring.
- classmethod compute_declaration()[source]
Return the structured declaration for the Erdos-Renyi graph family.
- classmethod from_model(model)[source]
Create a distribution wrapper from an Erdos-Renyi model.
- Parameters:
model (Any)
- Return type:
ErdosRenyiGraphDistribution
- to_model()[source]
Convert this distribution to the corresponding random-graph model.
- Return type:
- density(x)[source]
Return the probability mass of one graph observation.
- log_density(x)[source]
Return the Bernoulli edge log probability of one graph.
- seq_log_density(x)[source]
Score a batch of graph observations.
- backend_seq_log_density(x, engine)[source]
Engine-routed Bernoulli edge log-likelihood.
Per-graph edge opportunities/successes are extracted host-side (the graphs are ragged object data), but the Bernoulli reduction runs on the active engine, so the model’s scoring math is engine-native (and differentiable in
pon torch).
- edge_probability(i=None, j=None, context=None)[source]
Return the common edge probability
p.
- edge_marginals(num_nodes=None)[source]
Return the matrix of marginal edge probabilities for
num_nodes.
- posterior(x)[source]
Return edge opportunities, observed edge count, and fitted probability for
x.
- sampler(seed=None)[source]
Return a sampler for Erdos-Renyi graph observations.
- Parameters:
seed (int | None)
- Return type:
ErdosRenyiGraphSampler
- enumerator()[source]
Enumerate binary graphs in descending probability order (requires
num_nodes).The edges are independent Bernoulli(p) over the free positions
_edge_indices(n, directed, self_loops), so the graph distribution is a product of edge factors and enumerates by best-first over the per-edge supports – exactly like a composite of Bernoullis, with the combined value assembled into an adjacency matrix (mirrored for the undirected case). Each graph carries its exactlog_density.num_nodesmust be set so the edge set is finite.- Return type:
DistributionEnumerator
- estimator(pseudo_count=None)[source]
Return the edge-count estimator for this graph family.
- Parameters:
pseudo_count (float | None)
- Return type:
ErdosRenyiGraphEstimator
- dist_to_encoder()[source]
Return the graph encoder used by vectorized scoring and fitting.
- Return type:
GraphDataEncoder
- class ErdosRenyiGraphEnumerator(dist)[source]
Bases:
DistributionEnumeratorEnumerator over finite Erdos-Renyi binary graph support.
- Parameters:
dist (ErdosRenyiGraphDistribution)
- class ErdosRenyiGraphSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample binary graphs from an Erdos-Renyi distribution.
- Parameters:
dist (ErdosRenyiGraphDistribution)
seed (int | None)
- sample_graph(num_nodes=None)[source]
Draw one binary graph adjacency matrix.
- class ErdosRenyiGraphAccumulator(directed=False, self_loops=False, name=None, keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate edge counts for Erdos-Renyi graph fitting.
- update(x, weight, estimate)[source]
Accumulate weighted edge opportunities and successes from one graph.
- initialize(x, weight, rng)[source]
Initialize sufficient statistics from one weighted graph.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted edge counts from a batch of graphs.
- seq_initialize(x, weights, rng)[source]
Initialize sufficient statistics from a weighted graph batch.
- Parameters:
x (Sequence[GraphObservation])
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized edge-count sufficient statistics.
- value()[source]
Return serialized edge-count sufficient statistics.
- from_value(x)[source]
Restore accumulator state from serialized edge counts.
- key_merge(stats_dict)[source]
Merge tied edge-count statistics into
stats_dict.
- key_replace(stats_dict)[source]
Replace tied edge-count statistics from
stats_dict.
- acc_to_encoder()[source]
Return the encoder associated with this accumulator.
- Return type:
GraphDataEncoder
- class ErdosRenyiGraphAccumulatorFactory(directed=False, self_loops=False, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for ErdosRenyiGraphAccumulator.
- make()[source]
Create a fresh Erdos-Renyi graph accumulator.
- Return type:
ErdosRenyiGraphAccumulator
- class ErdosRenyiGraphEstimator(directed=False, self_loops=False, pseudo_count=None, prior_p=0.5, num_nodes=None, name=None, keys=None)[source]
Bases:
ParameterEstimatorEstimate an Erdos-Renyi graph distribution from edge counts.
- Parameters:
- accumulator_factory()[source]
Return the accumulator factory used by this estimator.
- Return type:
ErdosRenyiGraphAccumulatorFactory