Class AbstractKMeans<V extends NumberVector,​M extends Model>

    • Field Detail

      • k

        protected int k
        Number of cluster centers to initialize.
      • maxiter

        protected int maxiter
        Maximum number of iterations
    • Constructor Detail

      • AbstractKMeans

        public AbstractKMeans​(int k,
                              int maxiter,
                              KMeansInitialization initializer)
        Constructor.
        Parameters:
        k - k parameter
        maxiter - Maxiter parameter
        initializer - Function to generate the initial means
      • AbstractKMeans

        public AbstractKMeans​(NumberVectorDistance<? super V> distance,
                              int k,
                              int maxiter,
                              KMeansInitialization initializer)
        Constructor.
        Parameters:
        distance - distance function
        k - k parameter
        maxiter - Maxiter parameter
        initializer - Function to generate the initial means
    • Method Detail

      • getInputTypeRestriction

        public TypeInformation[] getInputTypeRestriction()
        Description copied from interface: Algorithm
        Get the input type restriction used for negotiating the data query.
        Specified by:
        getInputTypeRestriction in interface Algorithm
        Returns:
        Type restriction
      • initialMeans

        protected double[][] initialMeans​(Relation<V> relation)
        Choose the initial means.
        Parameters:
        relation - Relation
        Returns:
        Means
      • means

        protected static double[][] means​(java.util.List<? extends DBIDs> clusters,
                                          double[][] means,
                                          Relation<? extends NumberVector> relation)
        Returns the mean vectors of the given clusters in the given database.
        Parameters:
        clusters - the clusters to compute the means
        means - the recent means
        relation - the database containing the vectors
        Returns:
        the mean vectors of the given clusters in the given database
      • denseMeans

        private static double[][] denseMeans​(java.util.List<? extends DBIDs> clusters,
                                             double[][] means,
                                             Relation<? extends NumberVector> relation)
        Returns the mean vectors of the given clusters in the given database.
        Parameters:
        clusters - the clusters to compute the means
        means - the recent means
        relation - the database containing the vectors
        Returns:
        the mean vectors of the given clusters in the given database
      • plusEquals

        public static void plusEquals​(double[] sum,
                                      NumberVector vec)
        Similar to VMath.plusEquals, but accepts a number vector.
        Parameters:
        sum - Aggregation array
        vec - Vector to add
      • densePlusEquals

        private static void densePlusEquals​(double[] sum,
                                            NumberVector vec)
        Similar to VMath.plusEquals, but accepts a number vector.
        Parameters:
        sum - Aggregation array
        vec - Vector to add
      • sparsePlusEquals

        private static void sparsePlusEquals​(double[] sum,
                                             SparseNumberVector vec)
        Similar to VMath.plusEquals, but for sparse number vectors.
        Parameters:
        sum - Aggregation array
        vec - Vector to add
      • minusEquals

        public static void minusEquals​(double[] sum,
                                       NumberVector vec)
        Similar to VMath.minusEquals, but accepts a number vector.
        Parameters:
        sum - Aggregation array
        vec - Vector to subtract
      • plusMinusEquals

        public static void plusMinusEquals​(double[] add,
                                           double[] sub,
                                           NumberVector vec)
        Add to one, remove from another.
        Parameters:
        add - Array to add to
        sub - Array to remove from
        vec - Vector to subtract
      • densePlusMinusEquals

        private static void densePlusMinusEquals​(double[] add,
                                                 double[] sub,
                                                 NumberVector vec)
        Add to one, remove from another.
        Parameters:
        add - Array to add to
        sub - Array to remove from
        vec - Vector to subtract
      • sparsePlusMinusEquals

        private static void sparsePlusMinusEquals​(double[] add,
                                                  double[] sub,
                                                  SparseNumberVector vec)
        Add to one, remove from another.
        Parameters:
        add - Array to add to
        sub - Array to remove from
        vec - Vector to subtract
      • sparseMeans

        private static double[][] sparseMeans​(java.util.List<? extends DBIDs> clusters,
                                              double[][] means,
                                              Relation<? extends SparseNumberVector> relation)
        Returns the mean vectors of the given clusters in the given database.
        Parameters:
        clusters - the clusters to compute the means
        means - the recent means
        relation - the database containing the vectors
        Returns:
        the mean vectors of the given clusters in the given database
      • nearestMeans

        protected static void nearestMeans​(double[][] cdist,
                                           int[][] cnum)
        Recompute the separation of cluster means.

        Used by sort, and our exponion implementation.

        Parameters:
        cdist - Center-to-Center distances
        cnum - Center numbers
      • incrementalUpdateMean

        protected static void incrementalUpdateMean​(double[] mean,
                                                    NumberVector vec,
                                                    int newsize,
                                                    double op)
        Compute an incremental update for the mean.
        Parameters:
        mean - Mean to update
        vec - Object vector
        newsize - (New) size of cluster
        op - Cluster size change / Weight change
      • setK

        public void setK​(int k)
        Description copied from interface: KMeans
        Set the value of k. Needed for some types of nested k-means.
        Specified by:
        setK in interface KMeans<V extends NumberVector,​M extends Model>
        Parameters:
        k - K parameter
      • getLogger

        protected abstract Logging getLogger()
        Get the (STATIC) logger for this class.
        Returns:
        the static logger