Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "ml/incr/kmeans/docs/types/index.d"

Index

Interfaces

Functions

Functions

Export assignment incrkmeans

  • Returns an accumulator function which incrementally partitions data into k clusters.

    throws

    must provide valid options

    throws

    when using sampling to generate initial centroids, the sample size must be greater than or equal to the number of clusters

    Parameters

    • k: number | ndarray

      number of clusters or a k x ndims matrix containing initial centroids

    • ndims: number

      number of dimensions (should only be provided if provided a numeric k argument)

    • Optional options: Options

      function options

    Returns Accumulator

    accumulator function

    Example

    var Float64Array = require( `@stdlib/array/float64` );
    var ndarray = require( `@stdlib/ndarray/ctor` );
    
    // Define initial centroid locations:
    var buffer = [
        0.0, 0.0,
        1.0, 1.0,
        1.0, -1.0,
        -1.0, -1.0,
        -1.0, 1.0
    ];
    var shape = [ 5, 2 ];
    var strides = [ 2, 1 ];
    var offset = 0;
    var order = 'row-major';
    
    var centroids = ndarray( 'float64', buffer, shape, strides, offset, order );
    
    // Create a k-means accumulator:
    var accumulator = incrkmeans( centroids );
    
    var out = accumulator();
    // returns {...}
    
    // Create a data vector:
    buffer = new Float64Array( 2 );
    shape = [ 2 ];
    strides = [ 1 ];
    
    var vec = ndarray( 'float64', buffer, shape, strides, offset, order );
    
    // Provide data to the accumulator:
    vec.set( 0, 2.0 );
    vec.set( 1, 1.0 );
    
    out = accumulator( vec );
    // returns {...}
    
    vec.set( 0, -5.0 );
    vec.set( 1, 3.14 );
    
    out = accumulator( vec );
    // returns {...}
    
    // Retrieve the current cluster results:
    out = accumulator();
    // returns {...}