Alternatively, you could just use comb:

   require'stats'
   2 (i.@] e."1 comb) 6
1 1 0 0 0 0
1 0 1 0 0 0
1 0 0 1 0 0
1 0 0 0 1 0
1 0 0 0 0 1
0 1 1 0 0 0
0 1 0 1 0 0
0 1 0 0 1 0
0 1 0 0 0 1
0 0 1 1 0 0
0 0 1 0 1 0
0 0 1 0 0 1
0 0 0 1 1 0
0 0 0 1 0 1
0 0 0 0 1 1

Or, if you want the previous ordering of items:

   2 (Smps -: i.@] e."1 |.@comb) 6
1

I hope this helps,

--
Raul
On Sun, Aug 1, 2021 at 1:55 PM 'Michael Day' via Programming
<[email protected]> wrote:
>
> Thanks,  Bo.
>
> This variation on comb works pretty well,  except it doesn't test for the
> empty case, ie x = 0:
>
> NB. these boolean verbs are quicker than multiply and add for this case
> twice =: 1 & (32 b.)
> or    =: 23 b.
>
> Smpscomb =: 4 : 0
>   k=. 2^i.>:d=.y-x
>   z=. <"0 k
>   for. i.<: x do.
>     z=. k or &.> ,&.>/\. twice&.> z
>   end.
>   #:/:~;z
> )
>
>     ts
> 6!:2 , 7!:2@]
>     ts'3 Smps 20'
> 0.6071034 2.873121e8
>     ts'3 Smpscomb 20'
> 0.0001229 66976
>     3 (Smps -: Smpscomb) 20
> 1
>
> The sort adds a little time and space;  it is only necessary if you
> require the same
> ordering as your original example.
>
> Cheers,
>
> Mike
>
> On 01/08/2021 18:31, 'Bo Jacoby' via Programming wrote:
> >   Thanks to Mike!
> >
> > comb=: 4 : 0
> >
> > NB.*comb v combinations of size x from i.y
> >
> > comb=: 3 : 0
> >
> > comb~ y
> >
> > :
> >
> > k=. i.>:d=. y-x
> >
> > z=. (d$<i.0 0),<i.1 0
> > for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end.
> >     3 comb 6
> >
> >
> >
> > I need to study in order to make it do what I want. I am aware that my 
> > programming is embarassingly inefficient.
> > Thanks to Raul!
> >     2 (((= +/"1) # ]) f) 6 NB. fork, not hook!
> >
> > I wonder why it is hard to code the hook. It is not important, but it is 
> > strange.
> > I am studying the bessel correction. I turns out that the mean of the 
> > bessel corrected variances of all samples is equal to the bessel corrected 
> > variance of the population.
> >
> >     E   =. +/%# NB. mean
> >
> >     Va =. E@:*:-*:@:E NB. Variance
> >
> >     Bc =. -.&.:%@#*Va NB. Bessel corrected variance
> >
> >     S =. ((((=+/"1)#])#&2#:[:i.2&^) #)#] NB. samples
> >
> >     Bc n=.i.8
> >
> > 6
> >
> >     E Bc |:4 S n
> > 6
> >
> >     E Bc |:5 S n
> > 6
> >
> >     E Bc |:6 S n
> > 6
> >
> >     E Bc |:7 S n
> > 6
> >
> >     E Bc |:8 S n
> > 6
> >
> >
> >
> >
> >      Den søndag den 1. august 2021 16.06.21 CEST skrev 'Mike Day' via 
> > Programming <[email protected]>:
> >
> >   Nice work,  especially persuading 13 : to return a tacit version.
> > I had reached the same solution as Pascal Jasmin’s,  so not worth a comment 
> > in itself.
> >
> > However, it is just about worth pointing out that the filtering approach 
> > gets expensive for larger values of y;  eg 3 Smps 20 would entail filtering 
> > 2^20 rows to obtain 1140. In that case,  I reckon it’s better to use the 1s 
> > indices provided by, eg, 3 comb 20 .
> > comb is in addons/stats/base/combinatorial .
> >
> > In case it matters!
> >
> > Mike
> >
> > Sent from my iPad
> >
> >> On 31 Jul 2021, at 20:48, Raul Miller <[email protected]> wrote:
> >>
> >> That's a bit tricky in this case, but it can be done:
> >>
> >> First off, the problem:
> >>
> >>        13 : '(#~x=+/"1)f y' NB. select row
> >> 4 : '(#~x=+/"1)f y'
> >>
> >> But we can work around this by giving 13 : a variant expression:
> >>
> >>      13 : 't#~x=+/"1 t=.f y'
> >> [ (] #~ [ = [: +/"1 ]) [: f ]
> >>
> >> And, in this example, we can turn this into a hook through inspection:
> >>    Smps=: (] #~ [ = [: +/"1 ]) f
> >>
> >> This could be simplified further, of course:
> >>    2 ((] #~ (= +/"1)) f) 6
> >> and
> >>    2 (((= +/"1) # ]) f) 6
> >>
> >> do the same computation.
> >>
> >> I hope this helps,
> >>
> >> --
> >> Raul
> >>
> >>> On Sat, Jul 31, 2021 at 12:43 PM Srdjan Stipic <[email protected]> 
> >>> wrote:
> >>>
> >>> You can use “13 : ‘…’” construct to get tacit verb.
> >>>
> >>> On Sat 31. Jul 2021 at 18:00, 'Pascal Jasmin' via Programming <
> >>> [email protected]> wrote:
> >>>
> >>>> 2 ([ (] #~ [ = +/"1@:]) f@]) 6
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> On Saturday, July 31, 2021, 11:52:10 a.m. EDT, 'Bo Jacoby' via 
> >>>> Programming
> >>>> <[email protected]> wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> Consider this code
> >>>>
> >>>>    f=.#&2#:[:i.2&^ NB. 0-1 rows
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>    Smps=. 4 : '(#~x=+/"1)f y' NB. select rows
> >>>>
> >>>>    2 Smps 6 NB. for example
> >>>> 0 0 0 0 1 1
> >>>>
> >>>> 0 0 0 1 0 1
> >>>>
> >>>> 0 0 0 1 1 0
> >>>>
> >>>> 0 0 1 0 0 1
> >>>>
> >>>> 0 0 1 0 1 0
> >>>>
> >>>> 0 0 1 1 0 0
> >>>>
> >>>> 0 1 0 0 0 1
> >>>>
> >>>> 0 1 0 0 1 0
> >>>>
> >>>> 0 1 0 1 0 0
> >>>>
> >>>> 0 1 1 0 0 0
> >>>>
> >>>> 1 0 0 0 0 1
> >>>>
> >>>> 1 0 0 0 1 0
> >>>>
> >>>> 1 0 0 1 0 0
> >>>>
> >>>> 1 0 1 0 0 0
> >>>>
> >>>> 1 1 0 0 0 0
> >>>>
> >>>>
> >>>>
> >>>> I want to rewrite it tacit
> >>>>    Smps=.((=+/)"1 f)#f@]
> >>>> This works but is without the hook, so "f" is repeated.
> >>>> How to write the hook tacitly?
> >>>> I believe that this is easy, but I am stuck.
> >>>> Thank you!
> >>>> Bo.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> ----------------------------------------------------------------------
> >>>> 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
> >> ----------------------------------------------------------------------
> >> 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
>
>
> --
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
>
> ----------------------------------------------------------------------
> 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