Package org.nlpub.watset.graph
Class ChineseWhispers.Implementation<V,E>
- java.lang.Object
-
- org.nlpub.watset.graph.ChineseWhispers.Implementation<V,E>
-
- Type Parameters:
V- the type of nodes in the graphE- the type of edges in the graph
- Enclosing class:
- ChineseWhispers<V,E>
protected static class ChineseWhispers.Implementation<V,E> extends Object
Actual implementation of Chinese Whispers.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.jgrapht.Graph<V,E>graphThe graph.protected intiterationsThe number of iterations.protected Map<V,Integer>labelsThe mapping of nodes to labels.protected RandomrandomThe random number generator.protected intstepsThe number of actual algorithm iterations.protected NodeWeighting<V,E>weightingThe node weighting approach.
-
Constructor Summary
Constructors Constructor Description Implementation(org.jgrapht.Graph<V,E> graph, NodeWeighting<V,E> weighting, int iterations, Random random)Create an instance of the Chinese Whispers clustering algorithm implementation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.jgrapht.alg.interfaces.ClusteringAlgorithm.Clustering<V>compute()Perform clustering with Chinese Whispers.intgetIterations()Return the number of iterations specified in the constructorintgetSteps()Return the number of iterations actually performed duringChineseWhispers.getClustering().protected Map<Integer,Double>score(V node)Score the label weights in the given neighborhood graph, which is a subgraph ofgraph.protected intstep(List<V> nodes)Perform one iteration of the algorithm.
-
-
-
Field Detail
-
weighting
protected final NodeWeighting<V,E> weighting
The node weighting approach.
-
iterations
protected final int iterations
The number of iterations.
-
random
protected final Random random
The random number generator.
-
steps
protected int steps
The number of actual algorithm iterations.
-
-
Constructor Detail
-
Implementation
public Implementation(org.jgrapht.Graph<V,E> graph, NodeWeighting<V,E> weighting, int iterations, Random random)
Create an instance of the Chinese Whispers clustering algorithm implementation.- Parameters:
graph- the graphweighting- the node weighting approachiterations- the number of iterationsrandom- the random number generator
-
-
Method Detail
-
compute
public org.jgrapht.alg.interfaces.ClusteringAlgorithm.Clustering<V> compute()
Perform clustering with Chinese Whispers.- Returns:
- the clustering
-
step
protected int step(List<V> nodes)
Perform one iteration of the algorithm.- Parameters:
nodes- the list of nodes- Returns:
- whether any label changed or not
-
score
protected Map<Integer,Double> score(V node)
Score the label weights in the given neighborhood graph, which is a subgraph ofgraph. This method sums the node weights corresponding to each label.- Parameters:
node- the target node- Returns:
- a mapping of labels to sums of their weights
-
getIterations
public int getIterations()
Return the number of iterations specified in the constructor- Returns:
- the number of iterations
-
getSteps
public int getSteps()
Return the number of iterations actually performed duringChineseWhispers.getClustering(). Should be no larger than the value ofgetIterations().- Returns:
- the number of iterations
-
-