mixle.stats.graphs.random_dot_product_graph module¶
Random dot-product graph distributions for binary undirected graphs.
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]
Return compute-backend metadata for RDPG log-density evaluation.
- 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)
- sample_graph()[source]
Draw one symmetric binary adjacency matrix with no self-loops.
- Return type:
- 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]
Accumulate the weighted adjacency matrix for one graph observation.
- initialize(x, weight, rng)[source]
Initialize the sufficient statistics with one weighted graph.
- Parameters:
x (Any)
weight (float)
rng (RandomState | None)
- Return type:
None
- seq_update(x, weights, estimate)[source]
Accumulate weighted adjacency matrices for encoded graph observations.
- seq_initialize(x, weights, rng)[source]
Initialize the sufficient statistics from encoded graph observations.
- Parameters:
x (Sequence[GraphObservation])
weights (ndarray)
rng (RandomState | None)
- Return type:
None
- combine(suff_stat)[source]
Merge serialized adjacency-sum statistics into this accumulator.
- value()[source]
Return the total weight and weighted adjacency-matrix sum.
- from_value(x)[source]
Restore the accumulator from serialized adjacency-sum statistics.
- key_merge(stats_dict)[source]
Merge this accumulator into a keyed statistics dictionary.
- key_replace(stats_dict)[source]
Replace this accumulator from a keyed statistics dictionary.
- acc_to_encoder()[source]
Return the undirected graph encoder used by the accumulator.
- Return type:
GraphDataEncoder
- class RandomDotProductGraphAccumulatorFactory(keys=None)[source]
Bases:
StatisticAccumulatorFactoryFactory for RandomDotProductGraphAccumulator.
- Parameters:
keys (str | None)
- make()[source]
Create an empty RDPG accumulator.
- Return type:
RandomDotProductGraphAccumulator
- class RandomDotProductGraphEstimator(dim, name=None, keys=None)[source]
Bases:
ParameterEstimatorAdjacency Spectral Embedding estimator for the RDPG latent positions.
- accumulator_factory()[source]
Return a factory for RDPG sufficient-statistic accumulators.
- Return type:
RandomDotProductGraphAccumulatorFactory