Package org.nlpub.watset.graph
Class MarkovClustering<V,E>
- java.lang.Object
-
- org.nlpub.watset.graph.MarkovClustering<V,E>
-
- Type Parameters:
V- the type of nodes in the graphE- the type of edges in the graph
- All Implemented Interfaces:
Clustering<V>
public class MarkovClustering<V,E> extends Object implements Clustering<V>
Naïve implementation of the Markov Clustering (MCL) algorithm.This implementation assumes processing of relatively small graphs due to the lack of pruning optimizations.
- See Also:
- van Dongen (2008)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMarkovClustering.InflateVisitorVisitor that raises each element to the power ofr.static classMarkovClustering.NormalizeVisitorVisitor that normalizes columns.
-
Field Summary
Fields Modifier and Type Field Description protected inteThe expansion parameter.protected org.jgrapht.Graph<V,E>graphThe graph.protected Map<V,Integer>indexThe mapping of graph nodes to the columns ofmatrix.protected MarkovClustering.InflateVisitorinflateVisitorThe inflation visitor that raises each element ofmatrixto the power ofr.static IntegerITERATIONSThe default number of Markov Clustering iterations.protected org.apache.commons.math3.linear.RealMatrixmatrixThe stochastic matrix.protected org.apache.commons.math3.linear.RealMatrixonesThe row matrix filled by ones.protected doublerThe inflation parameter.
-
Constructor Summary
Constructors Constructor Description MarkovClustering(org.jgrapht.Graph<V,E> graph, int e, double r)Create an instance of the Markov Clustering algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<V,Integer>buildIndex()Index the nodes of the input graph.protected org.apache.commons.math3.linear.RealMatrixbuildMatrix(Map<V,Integer> index)Construct an adjacency matrix for the given graph.protected voidexpand()Perform the expansion step.voidfit()Run the algorithm to induce the parameters of the clusters.Collection<Collection<V>>getClusters()Return a collection of clusters, each cluster is a collection of objects.protected voidinflate()Perform the inflation step.protected voidnormalize()Normalize the matrix.static <V,E>
Function<org.jgrapht.Graph<V,E>,Clustering<V>>provider(int e, double r)A factory function that sets up the algorithm for the given graph.
-
-
-
Field Detail
-
ITERATIONS
public static final Integer ITERATIONS
The default number of Markov Clustering iterations.
-
e
protected final int e
The expansion parameter.
-
r
protected final double r
The inflation parameter.
-
inflateVisitor
protected final MarkovClustering.InflateVisitor inflateVisitor
The inflation visitor that raises each element ofmatrixto the power ofr.
-
matrix
protected org.apache.commons.math3.linear.RealMatrix matrix
The stochastic matrix.
-
ones
protected org.apache.commons.math3.linear.RealMatrix ones
The row matrix filled by ones.
-
-
Method Detail
-
provider
public static <V,E> Function<org.jgrapht.Graph<V,E>,Clustering<V>> provider(int e, double r)
A factory function that sets up the algorithm for the given graph.- Type Parameters:
V- the type of nodes in the graphE- the type of edges in the graph- Parameters:
e- the expansion parameterr- the inflation parameter- Returns:
- a factory function that sets up the algorithm for the given graph
-
fit
public void fit()
Description copied from interface:ClusteringRun the algorithm to induce the parameters of the clusters.- Specified by:
fitin interfaceClustering<V>
-
getClusters
public Collection<Collection<V>> getClusters()
Description copied from interface:ClusteringReturn a collection of clusters, each cluster is a collection of objects. Usually this method is called after theClustering.fit()method.- Specified by:
getClustersin interfaceClustering<V>- Returns:
- clusters
-
buildIndex
protected Map<V,Integer> buildIndex()
Index the nodes of the input graph.- Returns:
- a node index
-
buildMatrix
protected org.apache.commons.math3.linear.RealMatrix buildMatrix(Map<V,Integer> index)
Construct an adjacency matrix for the given graph.Note that the loops in the graph are ignored.
- Parameters:
index- the node index- Returns:
- an adjacency matrix
-
normalize
protected void normalize()
Normalize the matrix.
-
expand
protected void expand()
Perform the expansion step.
-
inflate
protected void inflate()
Perform the inflation step.
-
-