Skip to main content

laplacian_spectral_embedding

Function laplacian_spectral_embedding 

Source
pub fn laplacian_spectral_embedding(
    graph: &Graph,
    no: usize,
    weights: Option<&[f64]>,
    which: SpectralWhich,
    lap_type: LaplacianType,
    scaled: bool,
) -> IgraphResult<LaplacianSpectralEmbeddingResult>
Expand description

Compute the Laplacian spectral embedding of an undirected graph.

Decomposes a Laplacian matrix of the graph into its top eigenpairs and returns the eigenvectors as vertex embeddings.

no: embedding dimension (number of eigenpairs to compute).

weights: optional edge weights. Must have length ecount if provided. All weights must be non-negative.

which: which eigenvalues to use. See SpectralWhich.

lap_type: which Laplacian variant. See LaplacianType.

scaled: if true, multiply each eigenvector column by sqrt(|eigenvalue|), giving X = U |D|^{1/2}.

Edge directions are ignored (the graph is treated as undirected).

§Errors

Returns an error if no is 0 or exceeds vcount, if weights has the wrong length or contains non-finite values, or if any weight is negative (for DAD/IDAD types, which require non-negative weights for the square-root degree normalization).

§Examples

use rust_igraph::{Graph, laplacian_spectral_embedding, SpectralWhich, LaplacianType};

let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(1, 2).unwrap();
g.add_edge(2, 3).unwrap();
g.add_edge(0, 3).unwrap();

let r = laplacian_spectral_embedding(&g, 2, None, SpectralWhich::LargestAlgebraic,
                                      LaplacianType::DA, false).unwrap();
assert_eq!(r.eigenvalues.len(), 2);
assert_eq!(r.embedding.len(), 4);
assert_eq!(r.embedding[0].len(), 2);