It is best to do timings to see which would be faster,
because different algorithms are used within /: and I.
depending on the data, and order of complexity
("big O") considerations are not precise enough 
for this kind of comparison.  My guess is that 
x I. y is going to be faster than /:x,y most of the time.  

   x=: /:~ 20 [EMAIL PROTECTED] 0
   y=: 1e4 [EMAIL PROTECTED] 0
   ts 'x I. y'
0.000896483 66112
   ts '/:x,y'
0.00582644 262720



----- Original Message -----
From: Brian Schott <[EMAIL PROTECTED]>
Date: Tuesday, August 12, 2008 20:40
Subject: [Jprogramming] discreterand in statdist.ijs
To: [email protected]

>       The current random variate generating verb for
> discrete probability functions is shown below. In light of
> the new dyadic primitive I. could discreterand be improved?
> One issue that might be considered is that typically such
> verbs can be sped up by arranging the lookup into the
> cumulative probabilities so that the probabilities are
> arranged in descending order, not the discrete values. That
> way the higher probabilities are encountered earlier and
> have a greater chance of quicker lookup.
> 
>       I imagine it would be nice if Roger Hui could weigh
> in on whether it is likely that I. could be quicker than the
> grade approach used in the current discreterand while
> allowing for reordering the choices.
> 
> rand01=: [EMAIL PROTECTED] 0:
> 
> NB. random numbers in a discrete distribution
> NB.
> NB. y has two elements
> NB.   0 =  2-row matrix: 0 =  discrete values
> NB.                      1 =  corresponding probabilities
> NB.   1 =  number of trials
> discreterand=: 3 : 0
> 'm n'=. y
> 'v p'=. m
> f=. 0,+/\p%+/p
> l=. #f
> r=. /:f,rand01 n
> s=. +/\l>r
> r=. s r } r
> v {~ <:l}.r
> )
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to