From 0914b604223ea300486c8067a995ab38df8e4b16 Mon Sep 17 00:00:00 2001 From: Seth Date: Sun, 27 Sep 2020 18:17:53 -0400 Subject: [PATCH] handle input data of any size --- kmeans.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kmeans.ts b/kmeans.ts index a2129d4..53066c2 100644 --- a/kmeans.ts +++ b/kmeans.ts @@ -5,7 +5,7 @@ export interface KMeans { centroids: Centroids; } -export type UniMultiDimensionalArray = Array; +export type UniMultiDimensionalArray = Array; // needs to be able to handle array of any size export type Vector = Array; export type Vectors = Array; export type Centroid = Array; @@ -31,7 +31,7 @@ function kmeans( let indexes: Array = []; let cent_moved: boolean = false; let iterations: number = max_it || MAX; - let count: Array = []; + let count: Vector = []; if (!init_cent) { let def_indexes: Array = []; @@ -72,8 +72,8 @@ function kmeans( } // Recalculate centroids - let sum: Array = []; - let old: Array> = []; + let sum: UniMultiDimensionalArray = []; + let old: Centroids = []; if (data[0].length > 0) { for (let j = 0; j < k; j++) { sum[j] = init(data[0].length, 0, sum[j]);