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>
Actual implementation of Chinese Whispers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe graph.protected final intThe number of iterations.The mapping of nodes to labels.protected final RandomThe random number generator.protected intThe number of actual algorithm iterations.protected final NodeWeighting<V,E> The node weighting approach. -
Constructor Summary
ConstructorsConstructorDescriptionImplementation(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
Modifier and TypeMethodDescriptionorg.jgrapht.alg.interfaces.ClusteringAlgorithm.Clustering<V>compute()Perform clustering with Chinese Whispers.intReturn the number of iterations specified in the constructorintgetSteps()Return the number of iterations actually performed duringChineseWhispers.getClustering().Score the label weights in the given neighborhood graph, which is a subgraph ofgraph.protected intPerform one iteration of the algorithm.
-
Field Details
-
graph
The graph. -
weighting
The node weighting approach. -
iterations
protected final int iterationsThe number of iterations. -
random
The random number generator. -
labels
The mapping of nodes to labels. -
steps
protected int stepsThe number of actual algorithm iterations.
-
-
Constructor Details
-
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 Details
-
compute
Perform clustering with Chinese Whispers.- Returns:
- the clustering
-
step
Perform one iteration of the algorithm.- Parameters:
nodes- the list of nodes- Returns:
- whether any label changed or not
-
score
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
-