Convolution

degree_matrix

spektral.utils.degree_matrix(A)

Computes the degree matrix of the given adjacency matrix.

Arguments

  • A: rank 2 array or sparse matrix.

Return
If A is a dense array, a dense array; if A is sparse, a sparse matrix in DIA format.


degree_power

spektral.utils.degree_power(A, k)

Computes from the given adjacency matrix. Useful for computing normalised Laplacian.

Arguments

  • A: rank 2 array or sparse matrix.

  • k: exponent to which elevate the degree matrix.

Return
If A is a dense array, a dense array; if A is sparse, a sparse matrix in DIA format.


normalized_adjacency

spektral.utils.normalized_adjacency(A, symmetric=True)

Normalizes the given adjacency matrix using the degree matrix as either or (symmetric normalization).

Arguments

  • A: rank 2 array or sparse matrix;

  • symmetric: boolean, compute symmetric normalization;

Return
The normalized adjacency matrix.


laplacian

spektral.utils.laplacian(A)

Computes the Laplacian of the given adjacency matrix as .

Arguments

  • A: rank 2 array or sparse matrix;

Return
The Laplacian.


normalized_laplacian

spektral.utils.normalized_laplacian(A, symmetric=True)

Computes a normalized Laplacian of the given adjacency matrix as or (symmetric normalization).

Arguments

  • A: rank 2 array or sparse matrix;

  • symmetric: boolean, compute symmetric normalization;

Return
The normalized Laplacian.


rescale_laplacian

spektral.utils.rescale_laplacian(L, lmax=None)

Rescales the Laplacian eigenvalues in [-1,1], using lmax as largest eigenvalue.

Arguments

  • L: rank 2 array or sparse matrix;

  • lmax: if None, compute largest eigenvalue with scipy.linalg.eisgh. If the eigendecomposition fails, lmax is set to 2 automatically. If scalar, use this value as largest eigenvalue when rescaling.

Return


add_self_loops

spektral.utils.add_self_loops(a, value=1)

Sets the inner diagonals of a to value.

Arguments

  • a: a np.array or scipy.sparse matrix, the innermost two dimensions must be equal.

  • value: value to set the diagonals to.

Return
A np.array or scipy.sparse matrix with the same shape as a.


gcn_filter

spektral.utils.gcn_filter(A, symmetric=True)

Computes the graph filter described in Kipf & Welling (2017).

Arguments

  • A: array or sparse matrix with rank 2 or 3;

  • symmetric: boolean, whether to normalize the matrix as or as ;

Return
Array or sparse matrix with rank 2 or 3, same as A;


chebyshev_polynomial

spektral.utils.chebyshev_polynomial(X, k)

Calculates Chebyshev polynomials of X, up to order k.

Arguments

  • X: rank 2 array or sparse matrix;

  • k: the order up to which compute the polynomials,

Return
A list of k + 1 arrays or sparse matrices with one element for each degree of the polynomial.


chebyshev_filter

spektral.utils.chebyshev_filter(A, k, symmetric=True)

Computes the Chebyshev filter from the given adjacency matrix, as described in Defferrard et at. (2016).

Arguments

  • A: rank 2 array or sparse matrix;

  • k: integer, the order of the Chebyshev polynomial;

  • symmetric: boolean, whether to normalize the matrix as or as ;

Return
A list of k + 1 arrays or sparse matrices with one element for each degree of the polynomial.