combT =: ([: ; ([ ; [: i.@>: -~) ((1 {:: [) ,.&.> [: ,&.>/.
>:&.>@:]):(0 {:: [) (<i.1 0),~ (< i.0 0) $~ -~)
|spelling error

But this works:
   require'stats'
   comb=: combT

Meanwhile... have you timed any of this?

Consider a dead simple approach:
   close=: 3 :'y #~ +/@(= [: <./ 0-.~,)+/"1 *: -"1/~y'

   close p
6.42201 5.83321
6.62593 6.08499

   timespacex 'close p'
5.13156e_5 39680

   timespacex '({~ ({. , >:@:+/)@:(] ((<./@] I.@:= ]) {.@,. (<./@]
I.@:=  [ >@{~ <./@] I.@:= ])) <./ every)@:(([: +/ *:@-/@,:)tritable))
p'
0.000201414 35712% 5.13156e_5 39680

   timespacex '(#~ [: (] = <./) ([:+/"1 *:@-/)"_1)@:({~ 2 comb #) p'
0.000491026 35584

Thanks,

-- 
Raul


On Wed, Sep 16, 2015 at 4:17 PM, 'Pascal Jasmin' via Programming
<[email protected]> wrote:
> One much better approach, is to use combinations index
>
> combT =: ([: ; ([ ; [: i.@>: -~) ((1 {:: [) ,.&.> [: ,&.>/. >:&.>@:]):(0 {:: 
> [) (<i.1 0),~ (< i.0 0) $~ -~)
>
> (#~ [: (] = <./) ([:+/"1 *:@-/)"_1)@:({~ 2 combT #) p
>
>
>
> ----- Original Message -----
> From: 'Pascal Jasmin' via Programming <[email protected]>
> To: Programming Forum <[email protected]>
> Cc:
> Sent: Wednesday, September 16, 2015 3:49 PM
> Subject: [Jprogramming] An adverb for a loopy algorithm
>
> finding the 2 closest points in a set, has a loopy algorithm of "for each 
> point, compare it with all of the points to its right"
>
> p =: 0 ". every cutLF 0 : 0
> 6.42201  5.83321
> 3.15448  4.06327
> 8.89456 0.352235
> 6.00479  7.07121
> 8.10462  9.19487
> 9.63448  4.00534
> 6.74378 0.791349
> 5.56034  9.27039
> 4.67282  8.45993
> 0.301042   9.4069
> 6.62593  6.08499
> 9.0307  2.37372
> 9.36324  1.80147
> 2.67396  1.62207
> 4.76667  1.94554
> 7.43839  6.05369
> )
>
> A J adverb to do this,
>
> tritable =: 1 : '<"_1 u"1 each <@}.\.'
>
> this results in a boxed triangular table which conveniently avoids fills
>
> a slower alternative is to filter "1 1/~ (self table) by upper triangle
>
> -.@(1#~"0 >:@i.) 4
> 0 1 1 1
> 0 0 1 1
> 0 0 0 1
> 0 0 0 0
>
>
>   ({~ ({. , >:@:+/)@:(] ((<./@] I.@:= ]) {.@,. (<./@] I.@:=  [ >@{~ <./@] 
> I.@:= ])) <./ every)@:(([: +/ *:@-/@,:)tritable)) p
> 6.42201 5.83321
> 6.62593 6.08499
>
>
> The one thing I don't like about the adverb is that it hard codes "1.  I'm 
> unsure if there isn't a better way to do it.
>
> The code to fish out which points have the minimum distance is also 
> improvable I'm sure.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to