Package org.nlpub.watset.util
Class Matrices
- java.lang.Object
-
- org.nlpub.watset.util.Matrices
-
public final class Matrices extends Object
Utilities for working with matrices.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMatrices.ColumnNormalizeVisitorVisitor that normalizes columns.static classMatrices.ColumnSumVisitorVisitor that computes column sums.static classMatrices.InflateVisitorVisitor that raises each element to the specified power.static classMatrices.RowNormalizeVisitorVisitor that normalizes rows.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <V,E>
org.apache.commons.math3.linear.RealMatrixbuildAdjacencyMatrix(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.RealMatrixbuildDegreeMatrix(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.RealMatrixbuildSymmetricLaplacian(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.RealVectorcomputeRowNorms(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 graphE- the type of edges in the graph- Parameters:
graph- the graphmapping- the mappingaddLoops- 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 graphE- the type of edges in the graph- Parameters:
graph- the graphmapping- 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 matrixadjacency- 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
-
computeSpectralEmbedding
public 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.- Type Parameters:
V- the type of nodes in the graph- Parameters:
laplacian- the graph Laplacianmapping- the mappingk- the number of dimensions- Returns:
- spectral embeddings of the graph nodes
- See Also:
- Shi & Malik (IEEE PAMI 22:8), Ng et al. (NIPS 2002), von Luxburg (Statistics and Computing 17:4), sklearn.manifold.SpectralEmbedding
-
computeSpectralEmbedding
public 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.- Type Parameters:
V- the type of nodes in the graph- Parameters:
graph- the graphmapping- the mappingk- the number of dimensions- Returns:
- spectral embeddings of the graph nodes
- See Also:
- Shi & Malik (IEEE PAMI 22:8), Ng et al. (NIPS 2002), von Luxburg (Statistics and Computing 17:4), sklearn.manifold.SpectralEmbedding
-
-