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: SequenceEncodableProbabilityDistribution

Random Dot Product Graph over n nodes with d-dimensional latent positions X (edge prob X X^T).

Parameters:
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:

ndarray

density(x)[source]

Return the probability of a graph x.

Parameters:

x (Any)

Return type:

float

log_density(x)[source]

Return the log-probability of a binary undirected graph x.

Parameters:

x (Any)

Return type:

float

seq_log_density(x)[source]

Return vectorized log-probabilities for a sequence of graph observations.

Parameters:

x (Sequence[GraphObservation])

Return type:

ndarray

backend_seq_log_density(x, engine)[source]

Engine-routed RDPG edge log-likelihood (reduction runs on the active engine).

Parameters:
Return type:

Any

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: DistributionSampler

Sample 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:

ndarray

sample(size=None)[source]

Draw graphs (adjacency matrices); a single matrix when size is None.

Parameters:

size (int | None)

Return type:

ndarray | list[ndarray]

class RandomDotProductGraphAccumulator(keys=None)[source]

Bases: SequenceEncodableStatisticAccumulator

Accumulate 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.

Parameters:
  • x (Any)

  • weight (float)

  • estimate (RandomDotProductGraphDistribution | None)

Return type:

None

initialize(x, weight, rng)[source]

Initialize the sufficient statistics with one weighted graph.

Parameters:
Return type:

None

seq_update(x, weights, estimate)[source]

Accumulate weighted adjacency matrices for encoded graph observations.

Parameters:
  • x (Sequence[GraphObservation])

  • weights (ndarray)

  • estimate (RandomDotProductGraphDistribution | None)

Return type:

None

seq_initialize(x, weights, rng)[source]

Initialize the sufficient statistics from encoded graph observations.

Parameters:
Return type:

None

combine(suff_stat)[source]

Merge serialized adjacency-sum statistics into this accumulator.

Parameters:

suff_stat (tuple[float, ndarray | None])

Return type:

RandomDotProductGraphAccumulator

value()[source]

Return the total weight and weighted adjacency-matrix sum.

Return type:

tuple[float, ndarray | None]

from_value(x)[source]

Restore the accumulator from serialized adjacency-sum statistics.

Parameters:

x (tuple[float, ndarray | None])

Return type:

RandomDotProductGraphAccumulator

key_merge(stats_dict)[source]

Merge this accumulator into a keyed statistics dictionary.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

key_replace(stats_dict)[source]

Replace this accumulator from a keyed statistics dictionary.

Parameters:

stats_dict (dict[str, Any])

Return type:

None

acc_to_encoder()[source]

Return the undirected graph encoder used by the accumulator.

Return type:

GraphDataEncoder

class RandomDotProductGraphAccumulatorFactory(keys=None)[source]

Bases: StatisticAccumulatorFactory

Factory 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: ParameterEstimator

Adjacency Spectral Embedding estimator for the RDPG latent positions.

Parameters:
  • dim (int)

  • name (str | None)

  • keys (str | None)

accumulator_factory()[source]

Return a factory for RDPG sufficient-statistic accumulators.

Return type:

RandomDotProductGraphAccumulatorFactory

estimate(nobs, suff_stat)[source]

Estimate latent positions from the mean adjacency matrix using ASE.

Parameters:
Return type:

RandomDotProductGraphDistribution