Class Matrices


  • public final class Matrices
    extends Object
    Utilities for working with matrices.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <V,​E>
      org.apache.commons.math3.linear.RealMatrix
      buildAdjacencyMatrix​(org.jgrapht.Graph<V,​E> graph, org.jgrapht.util.VertexToIntegerMapping<V> mapping, boolean addLoops)
      Construct an adjacency matrix for the given graph.
      static <V,​E>
      org.apache.commons.math3.linear.RealMatrix
      buildDegreeMatrix​(org.jgrapht.Graph<V,​E> graph, org.jgrapht.util.VertexToIntegerMapping<V> mapping)
      Construct a degree matrix for the given graph.
      static org.apache.commons.math3.linear.RealMatrix buildSymmetricLaplacian​(org.apache.commons.math3.linear.RealMatrix degree, org.apache.commons.math3.linear.RealMatrix adjacency)
      Construct a symmetric Laplacian for the given graph.
      static org.apache.commons.math3.linear.RealVector computeRowNorms​(org.apache.commons.math3.linear.RealMatrix matrix)
      Compute row norms of the given matrix.
      static <V> List<NodeEmbedding<V>> computeSpectralEmbedding​(org.apache.commons.math3.linear.RealMatrix laplacian, org.jgrapht.util.VertexToIntegerMapping<V> mapping, int k)
      Compute spectral embedding of the graph nodes using the pre-computed Laplacian.
      static <V> List<NodeEmbedding<V>> computeSpectralEmbedding​(org.jgrapht.Graph<V,​?> graph, org.jgrapht.util.VertexToIntegerMapping<V> mapping, int k)
      Compute spectral embedding of the graph nodes.
    • Method Detail

      • buildAdjacencyMatrix

        public static <V,​E> org.apache.commons.math3.linear.RealMatrix buildAdjacencyMatrix​(org.jgrapht.Graph<V,​E> graph,
                                                                                                  org.jgrapht.util.VertexToIntegerMapping<V> mapping,
                                                                                                  boolean addLoops)
        Construct an adjacency matrix for the given graph.

        Note that the loops in the graph are ignored.

        Type Parameters:
        V - the type of nodes in the graph
        E - the type of edges in the graph
        Parameters:
        graph - the graph
        mapping - the mapping
        addLoops - should self-loops be added
        Returns:
        an adjacency matrix
      • buildDegreeMatrix

        public static <V,​E> org.apache.commons.math3.linear.RealMatrix buildDegreeMatrix​(org.jgrapht.Graph<V,​E> graph,
                                                                                               org.jgrapht.util.VertexToIntegerMapping<V> mapping)
        Construct a degree matrix for the given graph.
        Type Parameters:
        V - the type of nodes in the graph
        E - the type of edges in the graph
        Parameters:
        graph - the graph
        mapping - the mapping
        Returns:
        a degree matrix
      • buildSymmetricLaplacian

        public static org.apache.commons.math3.linear.RealMatrix buildSymmetricLaplacian​(org.apache.commons.math3.linear.RealMatrix degree,
                                                                                         org.apache.commons.math3.linear.RealMatrix adjacency)
        Construct a symmetric Laplacian for the given graph.
        Parameters:
        degree - the degree matrix
        adjacency - the adjacency matrix
        Returns:
        a symmetric Laplacian
      • computeRowNorms

        public static org.apache.commons.math3.linear.RealVector computeRowNorms​(org.apache.commons.math3.linear.RealMatrix matrix)
        Compute row norms of the given matrix.
        Parameters:
        matrix - the matrix
        Returns:
        a vector with row norms