mixle.stats.graphs.random_dot_product_graph module¶
Create, estimate, and sample from a Random Dot Product Graph (RDPG) distribution.
Defines the RandomDotProductGraphDistribution, RandomDotProductGraphSampler, RandomDotProductGraphAccumulatorFactory, RandomDotProductGraphAccumulator, RandomDotProductGraphEstimator, and reuses the shared GraphDataEncoder for use with mixle.
Data type: a binary undirected graph on n nodes (a square adjacency matrix, a NetworkX-like graph, or
any mapping accepted by GraphDataEncoder).
The RDPG is a latent-position graph model: each node i carries a latent vector x_i in R^d, and
edges are independent Bernoulli draws with probability equal to the dot product of the endpoints’
positions,
P(A_ij = 1) = clip(<x_i, x_j>, 0, 1).
This generalizes Erdos-Renyi (rank-1, constant positions) and captures community / homophily structure
through the geometry of the positions. Sampling draws independent Bernoulli edges from the probability
matrix X X^T. Estimation uses Adjacency Spectral Embedding (ASE): the latent positions are the top-d
scaled eigenvectors of the mean adjacency matrix, the standard consistent RDPG estimator.
- class RandomDotProductGraphDistribution(positions, name=None, keys=None)[source]
Bases:
SequenceEncodableProbabilityDistributionRandom Dot Product Graph over n nodes with d-dimensional latent positions X (edge prob X X^T).
- classmethod compute_capabilities()[source]
- edge_marginals()[source]
Return the n-by-n matrix of edge probabilities P(A_ij = 1).
- Return type:
- log_density(x)[source]
Return the log-probability of a binary undirected graph x.
- seq_log_density(x)[source]
Return vectorized log-probabilities for a sequence of graph observations.
- backend_seq_log_density(x, engine)[source]
Engine-routed RDPG edge log-likelihood (reduction runs on the active engine).
- sampler(seed=None)[source]
Return a sampler for drawing graphs from this distribution.
- Parameters:
seed (int | None)
- Return type:
RandomDotProductGraphSampler
- estimator(pseudo_count=None)[source]
Return an ASE estimator that keeps the latent dimension fixed at this distribution’s d.
- Parameters:
pseudo_count (float | None)
- Return type:
RandomDotProductGraphEstimator
- dist_to_encoder()[source]
Return the shared graph data encoder.
- Return type:
GraphDataEncoder
- class RandomDotProductGraphSampler(dist, seed=None)[source]
Bases:
DistributionSamplerSample binary undirected graphs from an RDPG (independent Bernoulli edges with prob X X^T).
- Parameters:
dist (RandomDotProductGraphDistribution)
seed (int | None)
- class RandomDotProductGraphAccumulator(keys=None)[source]
Bases:
SequenceEncodableStatisticAccumulatorAccumulate the weighted sum of adjacency matrices (the sufficient statistic for ASE).
- Parameters:
keys (str | None)
- 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]
- from_value(x)[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 RandomDotProductGraphAccumulatorFactory(keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for RandomDotProductGraphAccumulator.
- Parameters:
keys (str | None)
- make()[source]
- Return type:
RandomDotProductGraphAccumulator