"pickFrom" is only a part of the solution - I meant the example I gave
#results =. 4e5 pickFrom 5 10 25 60#/i.4
to illustrate the weighted pick using the numbers from your example. You
could combine the weighting the indexes part like this:
wtdPick=: [ (] {~ [ ?@$ [: # ]) ] # [: i. [: # ]
#results=. 4e5 wtdPick 5 10 25 60
400000
1 round 100*mean results =/ i.4
5 10 25 60
but, for my problem, I was doing different things with the weights depending
on the data, so I kept that part of it separate.
On Fri, May 27, 2011 at 5:21 PM, Dan Bron <[email protected]> wrote:
> Devon wrote:
> > We must be on the same wavelength lately
> > I came up with pickFrom=: ] {~ [ ?@$ [: # ]
>
> Devon, we're on the same wavelength but in a different phase. Your code
> picks a random item from a list (and could leverage a hook if you like:
> pickFrom=: ] {~ (?@$ #) ).
>
> My code does something similar, except not all indices are equally likely:
> in my situation, the probability of selecting a given index is weighted by
> its value.
>
>
--
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm