kM2 takes in `data`, not the `edist data`. Otherwise, it should work.
Though after I realized what this all does, taking in the distance matrix
makes more sense. Thus:

kM2_step=: 4 : 0
groups=. (i. <./)@:{"1
sub=. {"1 {&x
best=. [ {~ [:(i. <./) [:+/"1 sub
(y groups x) best/. (i. # x)
)
kM2=: ] kM2_step^:_ (? #)

edist=: (+/&.:*:@:-"1)/~

data=: ?(50 2$0)
(3 kM2 (edist data)) { data

should compute the same as your kM (depending on the inital k-mediods
of course).
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to