> 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. [EMAIL PROTECTED]&0 ----- Original Message ----- From: Joey K Tuttle <[EMAIL PROTECTED]> Date: Thursday, November 8, 2007 11:28 Subject: Re: [Jprogramming] speed of matrix*vector operation. To: Programming forum <[email protected]> > There are several confusions here... > > Looking up what matlab's randn(312,256) does, I find that it: > "returns a pseudorandom, 312-by-256 matrix of values drawn > from a normal distribution with mean 0 and standard deviation 1." > > As someone else noted, nothing here involves a 1000x1000 matrix. > In fact, it looks as though the MatLab code was run in a loop > 1000 times for timing purposes as does your verb "jumbo" - > 1000 (6!:2) 'expression' does this in j without creating a > program to do it, returning the average time for 1000 executions. > > As Roger has pointed out, you were using a non random 312x256 > matrix of EXACT integers (caused by the 256x and 312x in your > generations of A and B). The inner product on exact numbers takes > much longer than ordinary floating point numbers. > > In any case, the numbers in the MatLab matrix are floating point > numbers distributed around 0 in such a way that their mean is 0 > and standard deviation is 1. 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. > > > > At 10:13 -0800 2007/11/08, [EMAIL PROTECTED] wrote: > >I told my friend about how nice J was. Am I wrong? > > > >He said, how fast can you multiply a 1000x1000 matrix times > >a 1x1000 vector to get a 1x1000 resultant vector. > > > >his MatLab code ran in about .6 seconds. > > > >His code follows.. > > > >matrix = randn(312,256); > >vector = randn(256,1); > > > >tic > >for i = 1:1000 > > output = matrix*vector; > >end > >toc > > > >I wrote my code which runs in about 2.5 minutes > > > >here is my code: > > > >#!/home/efittery/bin/jconsole > > > >A =: 256 312 $ 1+ i. 312 * 256x > >B =: 312 1 $ 1+ i. 312x > > > >jumbo =: monad define > > for. i. y do. > > yVector =: A > +/ .* B > > end. > > ) > > > >jumbo 1000 > > > ----------------------------------------------------------------- > ----- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
