Re: Problem with random variable generation



E.S. wrote:
Imagine you have a zero-mean complex Gaussian variable Z = X + jY,
and you want to determine the expected value of Z*conj(Z), and Z^2.
Theoretically, the expected value of Z*conj(Z) is equal to sigma^2,
where the sigma is standard deviation of Z, and the expected value of
Z^2 is equal to 0. Straight forward, and easy to verify.
In MATLAB, if you try to numerically determine the expected value of
Z*conj(Z), you will get sigma^2. However, if you try to numerically
determine the expected value of Z^2, the result is equal to
j*2*E{X*Y}, which demonstrates that MATLAB is only capable of
generating improper random variables. So, be aware of this
shortcoming, before you rewrite your 8 pages of derivations!
By the way, any suggestions on how to actually obtain a proper random
variable in MATLAB?

E.S. -

If you drew one value from a standard normal distribution, would you expect that value to be exactly zero, simply because the mean of its distribution is zero? Of course not. But your argument is essentially that.

Let's say var(X) == var(Y) == 1. Z*conj(Z) and Z^2 are (pseudo)random variables, and as you say, the theoretical mean of Z.*conj(Z) is 2, and the mean of Z^2 is zero. But you aren't computing theoretical means, you are computing a Monte-Carlo approximation, and those MC approximations are random variables and have a mean and variance of their own. In any given trial with a sample size of, say, n=10^6, there's no reason to expect that your sample mean (the MC approximation to the theoretical mean) will be exactly equal to the theoretical mean. In fact,

zabs_bar = ((z_1)*conj(z_1) + ... + (z_n)*conj(z_n))/n
(theoretical) E(zabs_bar) = 2
(theoretical) var(zabs_bar) = 4/n

zsq_bar = ((z_1)^2 + ... + (z_n)^2)/n
(theoretical) E(zsq_bar) = 0
(theoretical) var(zsq_bar) = 8/n

For n=10^6, you'd expect to see abs(zsq_bar) within 2*sqrt(8/10^6) = 0.0056 of zero most of the time, and that's exactly what you do see if you compute

   z = complex(randn(n,1),randn(n,1));
   zsq_bar = mean(z.*z)
   abs(zsq_bar)

a large number of times. If you increase n, the distribution of the sample means will tighen up, and you will see less variation around the theoretical mean. This has nothing to do with MATLAB or pseudorandom numbers. It is simple probability.


If you do these calculations in MATLAB,

   n = 1000000;
   zabs_bar = zeros(1,100);
   zsq_bar = zeros(1,100);
   for i = 1:length(zabs_bar)
       x = randn(n,1); y = randn(n,1); z = complex(x,y);
       % theoretical mean = 2, theoretical variance of mean = 4/n
       zabs_bar(i) = mean(z.*conj(z));
       % theoretical mean = 0, theoretical variance of mean = 8/n
       zsq_bar(i) = mean(z.*z);
   end

you get

>> 2*sqrt(8/10^6)
ans =
    0.0056569
>> [2 mean(zabs_bar)]
ans =
            2       2.0001
>> [sqrt(4/n) std(zabs_bar)]
ans =
        0.002    0.0022119

>> [0 mean(zsq_bar)]
ans =
            0                 0.00064071 - 0.00034066i
>> [sqrt(8/n) std(zsq_bar)]
ans =
    0.0028284            0

Those numbers are right on.  You have not found a flaw in MATLAB's normal RNG.


E.S. wrote:
This is what I am wondering about. Is it a problem with rounding off
or some problem with a random generator? I am not sure! It seems to
me that the random generator employed in MATLAB is producing somewhat
correlated "random" variables, that is, different runs do not ensure
independent random variables. In my simulations, the value I was
getting for E{Z^2} is exactly equal to j*2*E{X*Y}.

This has nothing to do with roundoff error. It has nothing to do with correlated random variables. The sample correlation of two continuous independent random variables is guaranteed, with probablility ONE, to be nonzero. It is a sample correlation, not a theoretical one. The reason why E{Z^2} is exactly equal to j*2*E{X*Y} is (presumably) because you are computing them using the same sample values.



E.S. wrote:
We're essentially pointing to the same problem. MATLAB produces a
pseudo-random process, and due to that particular matter, we can see
some odd behaviour, such as when generating the complex Gaussian
noise, we are getting so called pseudo-covariance matrix E{Z^2} =
E{X^2} - E{Y^2} + j*2*E{XY}, instead of "true" covariance matrix
E{Z^2}=E{X^2}-E{Y^2} (remember Z = X + jY).

This is not odd behavior at all. Are you expecting that if X and Y are independent random variables, that the SAMPLE mean of X*Y will be exactly zero for a finite number of samples? It will not be. This has nothing at all to do with pseudorandomness vs. randomness. It is the difference between a theoretical mean, and a Monte-Carlo approximation using a finite sample.



- Peter Perkins The MathWorks, Inc. .



Relevant Pages

  • Re: Variance components analysis in random effects ANOVA with one factor
    ... I should somehow test that all the covariance between ... Or again I could invoke the method of the moments not to estimate Ewhich I assumed equal zero, but "to force" epsilon_i._bar to zero. ... sample correlation between tau_i_hat and e_ij does not mean anything because e_ij are a set of single realisations of differrent random variables epsilon_ij and not n realisations of a single random variable. ...
    (sci.stat.math)
  • Re: Determinism
    ... What is meant is a theory containing random variables as opposed ... outcomes happens to be zero, ... If the model contains a random element which has any effect on the ... randomness from the uncertainty in our knowledge, ...
    (sci.physics)
  • Re: Independent Random Varaible
    ... (0,3] and (5,8] and count the number of arrivals in each of these ... be are independent random variables. ... the covariance covshould be equal to zero. ...
    (comp.soft-sys.matlab)
  • random variables - simple questions
    ... Using the cumultative distribution function I follow a similar argument ... Suppose we have independent random variables X and Y, both normally distributed with zero mean and unit variance. ...
    (sci.math)
  • Re: Taking expectation of a function of a normal random variable
    ... numerical integration to take the expectation. ... with mean 1 and variance ... random variables. ...
    (comp.soft-sys.matlab)