Linear Algebra
Erdos.jl provides the following matrix operations on both directed and undirected graphs:
Erdos.adjacency_matrix
— Functionadjacency_matrix(g, dir=:out, T::DataType=Int)
Returns a sparse boolean adjacency matrix for a graph, indexed by [u, v]
vertices. true
values indicate an edge between u
and v
. Users may specify a direction (:in
, :out
, or :all
are currently supported; :out
is default for both directed and undirected graphs) and a data type for the matrix (defaults to Int
).
Erdos.incidence_matrix
— Functionincidence_matrix(g::AGraphOrDiGraph, T::DataType=Int; oriented=false)
Returns a sparse node-arc incidence matrix for a graph, indexed by [v, i]
, where i
is in 1:ne(g)
, indexing an edge e
. For directed graphs, a value of -1
indicates that src(e) == v
, while a value of 1
indicates that dst(e) == v
. Otherwise, the value is 0
.
For undirected graphs, both entries are 1
if oriented=false
, otherwise [v, i] -> -1
and [u, i] -> 1
if v < u
.
Erdos.laplacian_matrix
— Functionlaplacian_matrix(g, dir::Symbol=:out, T::DataType=Int)
Returns a sparse Laplacian matrix for a graph g
, indexed by [u, v]
vertices. dir
has to be :in, :out
or :all
.
Erdos.spectral_distance
— Methodspectral_distance(G₁, G₂ [, k])
Compute the spectral distance between undirected n-vertex graphs G₁ and G₂ using the top k ≤ n greatest eigenvalues. If k is ommitted, uses full spectrum.
For further details, please refer to:
JOVANOVIC, I.; STANIC, Z., 2014. Spectral Distances of Graphs Based on their Different Matrix Representations
Erdos.nonbacktracking_matrix
— Methodnonbacktracking_matrix(g)
Return a non-backtracking matrix B
and an edgemap storing the oriented edges' positions in B
. Given two arcs $A_{i j}` and `A_{k l}` in `g`, the non-backtraking matrix$B$is defined as$B{A{i j}, A{k l}} = δ{j k} * (1 - δ_{i l})``