UNPKG

ml-kmeans

Version:
54 lines 2.85 kB
import { KMeansResult } from './KMeansResult'; /** * Each step operation for kmeans * @ignore * @param {Array<Array<number>>} centers - K centers in format [x,y,z,...] * @param {Array<Array<number>>} data - Points [x,y,z,...] to cluster * @param {Array<number>} clusterID - Cluster identifier for each data dot * @param {number} K - Number of clusters * @param {object} [options] - Option object * @param {number} iterations - Current number of iterations * @return {KMeansResult} */ export type InitializationMethod = 'kmeans++' | 'random' | 'mostDistant'; export interface OptionsWithDefault { distanceFunction?: (p: number[], q: number[]) => number; tolerance?: number; initialization?: InitializationMethod | number[][]; maxIterations?: number; } export interface OptionsWithoutDefault { seed?: number; } export type Options = OptionsWithDefault & OptionsWithoutDefault; /** * Generator version for the algorithm * @ignore * @param {Array<Array<number>>} centers - K centers in format [x,y,z,...] * @param {Array<Array<number>>} data - Points [x,y,z,...] to cluster * @param {Array<number>} clusterID - Cluster identifier for each data dot * @param {number} K - Number of clusters * @param {object} [options] - Option object */ export declare function kmeansGenerator(data: number[][], K: number, options: Options): Generator<KMeansResult, void, unknown>; /** * K-means algorithm * @param {Array<Array<number>>} data - Points in the format to cluster [x,y,z,...] * @param {number} K - Number of clusters * @param {object} [options] - Option object * @param {number} [options.maxIterations = 100] - Maximum of iterations allowed * @param {number} [options.tolerance = 1e-6] - Error tolerance * @param {function} [options.distanceFunction = squaredDistance] - Distance function to use between the points * @param {number} [options.seed] - Seed for random initialization. * @param {string|Array<Array<number>>} [options.initialization = 'kmeans++'] - K centers in format [x,y,z,...] or a method for initialize the data: * * You can either specify your custom start centroids, or select one of the following initialization method: * * `'kmeans++'` will use the kmeans++ method as described by http://ilpubs.stanford.edu:8090/778/1/2006-13.pdf * * `'random'` will choose K random different values. * * `'mostDistant'` will choose the more distant points to a first random pick * @return {KMeansResult} - Cluster identifier for each data dot and centroids with the following fields: * * `'clusters'`: Array of indexes for the clusters. * * `'centroids'`: Array with the resulting centroids. * * `'iterations'`: Number of iterations that took to converge */ export declare function kmeans(data: number[][], K: number, options: Options): KMeansResult; //# sourceMappingURL=kmeans.d.ts.map