Skip to content

Commit d09b1ab

Browse files
committed
update soft k-means to use stable softmax and add unit tests
1 parent 0ae6140 commit d09b1ab

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

kmeans.q

+7
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ show .ut.plt s:(avg raze .ml.silhouette[.ml.edist;X]::) peach I
9191
ks i:.ml.imax s
9292
-1"superimpose the centroids on the data";
9393
show .ut.plot[39;20;.ut.c10;avg] .ml.append[0N;X],'.ml.append[1] C i
94+
95+
-1"a soft version of Lloyds algorithm is available with .ml.lloyds";
96+
-1".ml.kmeanss and .ml.kmeanssmax should be identical to ml.kmeans";
97+
X:iris.X
98+
C:asc flip .ml.kmeans[X] over C0:last 3 .ml.kmeanspp[X]// 2#()
99+
.ut.assert[C] asc flip .ml.kmeanss[X] over C0
100+
.ut.assert[C] asc flip .ml.kmeanssmax[500;X] over C0

ml.q

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ skmeans:lloyd[cosdist;normalize (avg'')::] / spherical k-means
310310
kmeanss:lloyds[edist2;wavg\:/:;ismin] / k-means using Lloyd with rf
311311
/ v1 David Mackay using stiffness parameter (b)eta. 1%sqrt b represents the
312312
/ sigma (or radius) of the cluster
313-
kmeanssmax:{[b;X]lloyds[edist2;wavg\:/:;softmax neg[b]*;X]}
313+
kmeanssmax:{[b;X]lloyds[edist2;wavg\:/:;ssoftmax neg[b]*;X]}
314314

315315
/ using (d)istance (f)unction, find the medoid in matri(X)
316316
medoid:{[df;X]X@\:imin f2nd[sum df[X]::] X}

0 commit comments

Comments
 (0)