mixle.stats.graphs.erdos_renyi_graph module¶
Create, estimate, and sample from an Erdos-Renyi graph distribution.
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]
- classmethod compute_declaration()[source]
- classmethod from_model(model)[source]
- Parameters:
model (Any)
- Return type:
ErdosRenyiGraphDistribution
- density(x)[source]
Return the probability density or mass at a single observation.
Concrete default: exponentiate
log_density(the abstract method subclasses must provide). Leaves with a cheaper closed form may override this.
- log_density(x)[source]
Return the log-density or log-mass at a single observation.
- seq_log_density(x)[source]
Return vectorized log-density values for sequence-encoded 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]
- sampler(seed=None)[source]
Return a sampler for drawing observations from this distribution.
- 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 an estimator for fitting this distribution from data.
- Parameters:
pseudo_count (float | None)
- Return type:
ErdosRenyiGraphEstimator
- dist_to_encoder()[source]
Return the data encoder used by this distribution for vectorized methods.
- Return type:
GraphDataEncoder
- class ErdosRenyiGraphEnumerator(dist)[source]
Bases:
DistributionEnumerator- 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(size=None, num_nodes=None)[source]
Draw observations.
Combinator samplers (mixture/sequence/…) accept
batched. Withbatched=True(the default) each child stream is drawn in one vectorized call instead of a per-draw Python loop – far faster. Because every child sampler owns an independentRandomState, batching consumes each stream in the same order as the loop, so the draws are identical to the legacy path.batched=Falseforces that legacy per-draw loop as a guaranteed- stable reference. Leaf samplers are already vectorized and ignore the flag.
- 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]
- initialize(x, weight, rng)[source]
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
- seq_initialize(x, weights, rng)[source]
- Parameters:
x (Sequence[GraphObservation])
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
- key_merge(stats_dict)[source]
Pool this accumulator’s statistics into
stats_dictunder its merge key.The structural default implements the common single-key pattern: store the accumulator under
self.keysthe first time the key is seen, elsecombineinto the one already there. Accumulators with several named keys (e.g. an HMM’s init/trans/state keys) or a non-accumulator stats payload override this. AkeysofNone(the default) is a no-op.
- key_replace(stats_dict)[source]
Replace this accumulator’s statistics from the pooled
stats_dictentry (see key_merge).
- acc_to_encoder()[source]
- Return type:
GraphDataEncoder
- class ErdosRenyiGraphAccumulatorFactory(directed=False, self_loops=False, name=None, keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for ErdosRenyiGraphAccumulator.
- make()[source]
- 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 type:
ErdosRenyiGraphAccumulatorFactory