Package org.nlpub.watset.util
Class Matrices
java.lang.Object
org.nlpub.watset.util.Matrices
Utilities for working with matrices.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classVisitor that normalizes columns.static classVisitor that computes column sums.static classVisitor that raises each element to the specified power.static classVisitor that normalizes rows. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.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 Details
-
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:
-
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:
-