Class KMC2.Instance

  • Direct Known Subclasses:
    AFKMC2.Instance
    Enclosing class:
    KMC2

    protected static class KMC2.Instance
    extends java.lang.Object
    Abstract instance implementing the weight handling.
    Author:
    Erich Schubert
    • Field Detail

      • diststat

        protected long diststat
        Count the number of distance computations.
      • m

        protected int m
        Number of sampling attempts.
      • random

        protected java.util.Random random
        Random generator
    • Constructor Detail

      • Instance

        public Instance​(Relation<? extends NumberVector> relation,
                        NumberVectorDistance<?> distance,
                        int m,
                        RandomFactory rnd)
        Constructor.
        Parameters:
        relation - Data relation to process
        distance - Distance function
        m - M parameter
        rnd - Random generator
    • Method Detail

      • initialWeights

        protected double initialWeights​(NumberVector first)
        Initialize the weight list.
        Parameters:
        first - Added ID
        Returns:
        Weight sum
      • run

        public double[][] run​(int k)
        Run k-means++ initialization for number vectors.
        Parameters:
        k - K
        Returns:
        Vectors
      • distance

        protected double distance​(NumberVector a,
                                  DBIDRef b)
        Compute the distance of two objects.
        Parameters:
        a - First object
        b - Second object
        Returns:
        Distance
      • chooseRemaining

        protected void chooseRemaining​(int k,
                                       java.util.List<NumberVector> means,
                                       double weightsum)
        Choose remaining means, weighted by distance.
        Parameters:
        k - Number of means to choose
        means - Means storage
        weightsum - Sum of weights
      • sample

        protected DBIDRef sample​(double weightsum)
        Weighted sampling.
        Parameters:
        weightsum - Total weight sum.
        Returns:
        Sampled object
      • distance

        protected double distance​(DBIDRef cand,
                                  java.util.List<NumberVector> means)
        Minimum distance to the current means.
        Parameters:
        cand - Candidate
        means - Current means
        Returns:
        Minimum distance
      • getLogger

        protected Logging getLogger()
        Class logger.
        Returns:
        Logger