You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ml/incr/kmeans/lib/init_kmeansplusplus.js
+12-10Lines changed: 12 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -41,25 +41,27 @@ var squaredCorrelation = require( './squared_correlation.js' );
41
41
* @param {Array} out - output array
42
42
* @param {Function} dist - distance function to apply
43
43
* @param {PositiveInteger} npts - number of data points
44
+
* @param {PositiveInteger} ndims - number of dimensions
44
45
* @param {ndarray} matrix - data point matrix
45
46
* @param {NonNegativeInteger} ci - centroid row index
46
47
* @returns {Array} output array
47
48
*/
48
-
functiondapply(out,dist,npts,matrix,ci){
49
+
functiondapply(out,dist,npts,ndims,matrix,ci){
49
50
varoffsetC;
50
-
varstride;
51
-
varoffset;
51
+
varoffsetD;
52
+
varstrideD;
52
53
varbuf;
53
-
varN;
54
54
vari;
55
55
56
56
buf=matrix.data;
57
-
N=matrix.shape[1];
58
-
stride=matrix.strides[0];
59
-
offsetC=stride*ci;
57
+
58
+
strideD=matrix.strides[0];
59
+
offsetC=strideD*ci;
60
+
offsetD=0;
61
+
60
62
for(i=0;i<npts;i++){
61
-
offset=stride*i;
62
-
out[i]=dist(N,buf,1,offset,buf,1,offsetC);// Magic number `1` for stride is based on knowing that the matrix is row-major single-segment contiguous
63
+
out[i]=dist(ndims,buf,1,offsetD,buf,1,offsetC);// Magic number `1` for stride is based on knowing that the matrix is row-major single-segment contiguous
// 2-5. For each data point, compute the distances to each centroid, find the closest centroid, and, based on the distance to the closest centroid, assign a probability to the data point to be chosen as centroid `c_j`...
204
206
for(j=1;j<k;j++){
205
207
// Note: instead of repeatedly computing centroid distances for each data point, we only need to compute the distances for the most recent centroid and to maintain a hash of closest distance results...
0 commit comments