Class ChineseWhispers.Implementation<V,​E>

  • Type Parameters:
    V - the type of nodes in the graph
    E - 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 Detail

      • graph

        protected final org.jgrapht.Graph<V,​E> graph
        The graph.
      • 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.
      • labels

        protected final Map<V,​Integer> labels
        The mapping of nodes to labels.
      • 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 graph
        weighting - the node weighting approach
        iterations - the number of iterations
        random - 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 of graph. 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