Bayes' Theorem.
For let k=:?p, then for every integer i in i.p
P(k=i) = 1/p.
We can then model your selective keeping process with a posterior distribution
on this pdf. For every i in i.q,
P(k=i|k<q) = P(k<q|k=i)P(k=i)/P(k<q)
= 1 * 1/p / (q/p)
= 1/q.
Happily, this corresponds to the discrete uniform pdf you want. Of course, the
standard provisions apply---your random variables are independent, q<:p, etc.
Roger Hui <[email protected]> wrote:
> A question for the statisticians and mathematicians among us.
>
> Suppose I want to generate uniform random numbers ?n$q. Is it valid to
> generate ?m$p where p>q, and keep only the numbers which are less than p?
> Assume that m can be as large as we like.
>
> An example where p is 30 and q is 10.
>
> x=: ?1e6$30
> y=: (x<10)#x
> n=: #y
> n
> 332824
> c=: <: #/.~(i.10),y
> +/c
> 332824
>
> Here, c are the count of the numbers 0,1,2,...,9 in y.
>
> The maximum absolute difference between the sample cumulative distribution
> n%~+/\c and the the theoretical cumulative distribution +/\10$0.1 is:
>
> >./ | (n%~+/\c) - +/\10$0.1
> 0.000795616
>
> The ⍺=0.01 critical value for the Kolmogorov test
> <https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test> is
> approximately
>
> 1.63 % %: n
> 0.0028254
>
> Therefore, for this one test, y is uniformly distributed with confidence >
> 1-⍺=0.99, like ?n⍴10.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm