[Jprogramming] speed of matrix*vector operation.

Joey K Tuttle jkt at qued.com
Fri Nov 9 04:34:58 HKT 2007


At 11:56  -0800 2007/11/08, Roger Hui wrote:
>  > There isn't a built in function that
>>  j uses to generate normal distributions, and writing an equivalent
>>  to MatLab randn() would be an interesting exercise.
>
>  >From http://www.jsoftware.com/jwiki/Essays/Normal_CDF
>erf   =: (1 H. 1.5)@*: * 2p_0.5&* % ^@:*:
>n01cdf=: -: @ >: @ erf @ %&(%:2)
>
>Whence an approximation to randn:
>ny=: n01cdf nx=: i:5j2000
>randn=: nx {~ ny I. ?@$&0
>

Lovely! In praise for DOJ, erf and n01cdf are given on the
H. page (although I didn't immediately think to look there :)

There are a couple of subtle differences from the ones above,
DOJ doesn't include the, apparently redundant, parens of your
erf and n01cdf differs a bit, but their results are very close
with no greater than 4.996e_16 difference in your example.

In any case, thanks for the exposition -- certainly in the
case of timing the original inner product, the generation of
the random normal distributions should be excluded from the
timing (as they were in MatLab).




More information about the Programming mailing list