Hi All, How close is the random number generation from numarray.random_array.normal(0,1,x) or numarray.linear_algebra.mlab.randn(x) to matlab's randn? i am having problems with an identical program written in matlab and python, with the results entirely different in both cases :( Warm regards karthik ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND -----------------------------------------------------------------------
Karthikesh Raju wrote:
How close is the random number generation from numarray.random_array.normal(0,1,x) or numarray.linear_algebra.mlab.randn(x) to matlab's randn?
i am having problems with an identical program written in matlab and python, with the results entirely different in both cases :(
Unfortunately, I'm not familiar with matlab and don't have it here to run. Have you tried comparing simple things between the two such as mean and standard deviation to see if you are getting the same result, followed by histograms if you see no differences there? Perry Greenfield
Hi Perry, Yes, i have been trying to compare random number generators. i plotted the histograms, they look quite "gaussian", i have also tried uniform numbers with "rand". May be there is some problem with one of my statements like: def AWGN(Tx_Symbols,No): len_Waveform = len(Tx_Waveform) std_No = sqrt(No/2.0) return Tx_Waveform + std_No*randn(len_Waveform) This function just takes in a bit stream in [1,-1] and adds gaussian noise. No defines the noise power. Now in the main function i am doing: Tx_Bit_Stream = random(n_Bits) > 0.5 Tx_Symbols = 2*Tx_Bit_Stream-1 Rx_Symbols = AWGN(Tx_Symbols, No) Rx_Bit_Stream = Rx_Symbols > 0 n_Errors = sum(not_equal(Tx_Bit_Stream,Rx_Bit_Stream)) Now i have noted that n_Errors is negative? How can that be so? n_Errors should be the number of places where Tx_Bit_Stream differs from Rx_Bit_Stream? How can the sum be negative? With warm regards karthik ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND ----------------------------------------------------------------------- On Wed, 2 Jun 2004, Perry Greenfield wrote:
Karthikesh Raju wrote:
How close is the random number generation from numarray.random_array.normal(0,1,x) or numarray.linear_algebra.mlab.randn(x) to matlab's randn?
i am having problems with an identical program written in matlab and python, with the results entirely different in both cases :(
Unfortunately, I'm not familiar with matlab and don't have it here to run. Have you tried comparing simple things between the two such as mean and standard deviation to see if you are getting the same result, followed by histograms if you see no differences there?
Perry Greenfield
Karthikesh Raju wrote:
n_Errors = sum(not_equal(Tx_Bit_Stream,Rx_Bit_Stream))
Now i have noted that n_Errors is negative? How can that be so?
n_Errors should be the number of places where Tx_Bit_Stream differs from Rx_Bit_Stream? How can the sum be negative?
I'm guessing you are seeing overflow problems with the boolean representation which is the result of logical comparisons (which uses only 8 bit values) try: sum(float(not_equal... to eliminate that problem. Perry
Hi Perry and All, Thankx a lot for your reply. i actually forgot to mention it, but a = rand(100000) > 0.5 b = rand(100000) > 0.5 sum(float(a,b)) results in a TypeError: Only rank-0 numarray can be cast to floats. With warm regards karthik ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND ----------------------------------------------------------------------- On Wed, 2 Jun 2004, Perry Greenfield wrote:
Karthikesh Raju wrote:
n_Errors = sum(not_equal(Tx_Bit_Stream,Rx_Bit_Stream))
Now i have noted that n_Errors is negative? How can that be so?
n_Errors should be the number of places where Tx_Bit_Stream differs from Rx_Bit_Stream? How can the sum be negative?
I'm guessing you are seeing overflow problems with the boolean representation which is the result of logical comparisons (which uses only 8 bit values) try:
sum(float(not_equal...
to eliminate that problem.
Perry
Thankx Perry, now i an getting somewhere near, but there are still some issues, matlab and python (exact algorithms) result in different values :(, looking at it though, Warm regards karthik ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND ----------------------------------------------------------------------- On Wed, 2 Jun 2004, Perry Greenfield wrote:
I'm guessing you are seeing overflow problems with the boolean representation which is the result of logical comparisons (which uses only 8 bit values) try:
sum(float(not_equal...
to eliminate that problem.
Perry
arg, I should have said:
sum(not_equal(...).astype(Float))
"Karthikesh" == Karthikesh Raju
writes:
Karthikesh> Thankx Perry, now i an getting somewhere near, but Karthikesh> there are still some issues, matlab and python (exact Karthikesh> algorithms) result in different values :(, looking at Karthikesh> it though, One obvious difference, which you are likely aware of, is that rand(N) in matlab returns an NxN matrix whereas Numeric's MLab and numarray's linear_algebra.mlab version of rand returns a length N array. So if you naively use rand(N) in both cases, your sample sizes will be wildly different. Just a thought... JDH
Yes, that was something i knew, actually the real problem as Perry, they are a result of overflows due to bools .. With warm regards Karthik ----------------------------------------------------------------------- Karthikesh Raju, email: karthik@james.hut.fi Researcher, http://www.cis.hut.fi/karthik Helsinki University of Technology, Tel: +358-9-451 5389 Laboratory of Comp. & Info. Sc., Fax: +358-9-451 3277 Department of Computer Sc., P.O Box 5400, FIN 02015 HUT, Espoo, FINLAND ----------------------------------------------------------------------- On Wed, 2 Jun 2004, John Hunter wrote:
"Karthikesh" == Karthikesh Raju
writes: Karthikesh> Thankx Perry, now i an getting somewhere near, but Karthikesh> there are still some issues, matlab and python (exact Karthikesh> algorithms) result in different values :(, looking at Karthikesh> it though,
One obvious difference, which you are likely aware of, is that rand(N) in matlab returns an NxN matrix whereas Numeric's MLab and numarray's linear_algebra.mlab version of rand returns a length N array. So if you naively use rand(N) in both cases, your sample sizes will be wildly different.
Just a thought...
JDH
Related to a recent discussion on random numbers: People using RandomArray.random() on 64-bit architectures should also be aware that sometimes the function returns exactly zero or one, which in turn causes problems in many other routines which generate e.g. multinomial or dirichlet variates. I'm not absolutely sure that the problem persists in the newest version of Numeric, and I have not tested it on numarray. Anyway, I have seen it both in Alphas and now later in an AMD Opteron machine - over the years. Unfortunately, as we do not have had time to dig any deeper around here, we have just used wrapper with a test and a loop. -- Janne
participants (4)
-
Janne Sinkkonen
-
John Hunter
-
Karthikesh Raju
-
Perry Greenfield