Hey again xash, I've improved the algo some following your example (especially the use of ./). It has reduced the algo (at least with random initialisation) to 3 lines ...
kM_step=: 4 : 0 vec=. (i. <./) each ;/ x {"1 y argm=. 4 : '{ & x (i. <./) (+/ (<(<x),(<x)) { y)' vec (argm & y)/. i. #vec ) kM=: 4 : '(kM_step & y)^:_ (x ? #y)' The syntax for the selection operator (boxes within boxes) is rather awkward: (<(<x),(<x)) { y but I guess its most efficient? Emir ________________________________ From: Emir U Sent: 15 February 2021 13:11 To: programm...@jsoftware.com <programm...@jsoftware.com> Subject: Re: k-mediods PAM algo, help with canonical form (xash) Thanks for your comments xash. You're right about average not mattering. Did your kM2_step and kM functions run correctly for you? It doesn't look like it runs to me so far as I can see the group function seems to assume the data to be in the wrong shape for it to work. Can you confirm? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm