number of clusters or a k x ndims
matrix containing initial centroids
number of dimensions (should only be provided if provided a numeric k
argument)
function options
accumulator function
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 {...}
Returns an accumulator function which incrementally partitions data into
k
clusters.must provide valid options
when using sampling to generate initial centroids, the sample size must be greater than or equal to the number of clusters