EDRep · Chapter 4

API reference

Signatures, parameters and outputs of the public functions of EDRep.

The package exposes three functions:

from EDRep import CreateEmbedding, NodeEmbedding, computeZest

CreateEmbedding

CreateEmbedding(Pv, dim = 128, p0 = None, n_epochs = 30, sum_partials = False,
                k = 1, eta = 0.8, verbose = True, sym = True)

Creates a distributed representation of a probability distribution (Algorithm 1 of the paper). See Using EDRep for a walkthrough.

Parameter Type Default Description
Pv list of sparse arrays required The matrix $P$ is the product of the elements of Pv, from right to left: $P = \cdots P_3P_2P_1$ for Pv = [P1, P2, P3]. If the resulting $P$ is not row-stochastic, a warning is raised.
dim int 128 Embedding dimension.
p0 array None Array of size $n$ specifying the “null model” probability.
n_epochs int 30 Number of iterations of the optimization.
sum_partials bool False If True, $P = (P_1 + P_2P_1 + P_3P_2P_1 + \dots)/\ell$, where $\ell$ is the length of Pv.
k int 1 Order of the mixture-of-Gaussians approximation.
eta float 0.8 Largest admissible learning rate.
verbose bool True Print progress updates.
sym bool True If True, generate a single embedding $X$ (optimizing ${\rm SoftMax}(XX^T)$). If False, generate two embeddings $X$ and $Y$ (optimizing ${\rm SoftMax}(XY^T)$), so that $P$ can be rectangular.

Returns an object with attributes:

  • X (array): the embedding matrix;
  • Y (array): the second embedding matrix (equal to X when sym = True);
  • ℓ (array): the label vector used by the mixture approximation.

NodeEmbedding

NodeEmbedding(A, dim, n_epochs = 30, walk_length = 5, k = 1, verbose = True,
              eta = 0.5, sym = True)

Node embedding of a graph with EDRep, using $P = \frac{1}{L}\sum_{a=1}^{L}(D^{-1}A)^a$, where $L$ is walk_length. See Use case: node embeddings.

Parameter Type Default Description
A scipy.sparse matrix required Graph adjacency matrix. It can be weighted and non-symmetric, but its entries must be non-negative.
dim int required Embedding dimension.
n_epochs int 30 Number of training epochs.
walk_length int 5 Maximal distance reached by the random walker ($L$).
k int 1 Order of the mixture-of-Gaussians approximation.
verbose bool True Print progress updates.
eta float 0.5 Learning rate.
sym bool True Use the symmetric version of the algorithm.

Returns the same object as CreateEmbedding.

computeZest

computeZest(X, indeces, k = 5)

Order-$k$ approximation of the SoftMax normalization constants $Z_i = \sum_{j=1}^n e^{x_i^Tx_j}$ for a set of indices. See Estimating the SoftMax normalization.

Parameter Type Default Description
X array required Embedding matrix, with the vectors $x_i$ in its rows.
indeces array required Indices $i$ for which $Z_i$ is computed. Use np.arange(n) for all of them.
k int 5 Order of the mixture model: larger is more accurate but slower.

Returns an object with attributes:

  • Zest (array): the estimated $Z_i$ for the requested indices;
  • ℓ (array): label vector;
  • μ (array of size $d \times k$): mean embedding vector of each class;
  • Ω (list of $k$ arrays of size $d \times d$): covariance matrix of each class;
  • π (array of size $k$): size of each class.