Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
mvnrnd output

Subject: mvnrnd output

From: Beth

Date: 15 Feb, 2009 21:50:03

Message: 1 of 5

I am trying to generate random data for a simulation using the mvnrnd command. To start, I'm using mu=zeros(1,n). I'm trying out a couple of processes to generate an nxn Sigma using covariance functions (Wiener, Brownian Bridge, Ornstein-Uhlenbck).

The issue: when mu is all zeros and Sigma has patterns of zero as well, I end up with mvnrnd(mu,Sigma,n) generating n rows of data which all start with zero. If I change mu to ones, for example, my mvnrnd generates n rows of data which all start with one. There seems to be some connection between the patterns of zeros in my Sigma and the mu values. This strikes me as working against my attempt to generate random data.

Any thoughts would be appreciated.
Thanks,
Beth

Subject: mvnrnd output

From: Roger Stafford

Date: 15 Feb, 2009 22:30:04

Message: 2 of 5

"Beth " <brownep@uwm.edu> wrote in message <gna2ma$l6s$1@fred.mathworks.com>...
> I am trying to generate random data for a simulation using the mvnrnd command. To start, I'm using mu=zeros(1,n). I'm trying out a couple of processes to generate an nxn Sigma using covariance functions (Wiener, Brownian Bridge, Ornstein-Uhlenbck).
>
> The issue: when mu is all zeros and Sigma has patterns of zero as well, I end up with mvnrnd(mu,Sigma,n) generating n rows of data which all start with zero. If I change mu to ones, for example, my mvnrnd generates n rows of data which all start with one. There seems to be some connection between the patterns of zeros in my Sigma and the mu values. This strikes me as working against my attempt to generate random data.
>
> Any thoughts would be appreciated.
> Thanks,
> Beth

  You haven't given enough information to go on here, Beth. Are you using the 'cases' third input argument to 'mvnrnd'? When you say "Sigma has patterns of zero", do you mean all elements of 'Sigma' are zero? If so, there would be zero variance and all output values would just be the same as 'MU' with no randomness about them. Your statement "all start with zero" means what exactly? The first output is exactly zero, its first digit is a 0, what?

  I think you would do well to give some specific information about your matlab code. Show some results using 'format long' but only for a (hopefully short) row or two of output. We can't do anything for you as you have posed the problem?

Roger Stafford

Subject: mvnrnd output

From: Beth

Date: 15 Feb, 2009 22:56:01

Message: 3 of 5

Sorry if my question was not clear - I'm fairly new to all of this, so I appreciate your clarifying questions.

I am using the 'cases' third input argument for mvnrnd - here it is 8 for ease of viewing the output, although it needs to be much higher eventually. My Sigma is generated by a covariance function, hence the first row and column of Sigma are zero.

Again my concern is the apparent lack of randomness in my output since each row of mvnrnd data begins with zero.


Here's the basic part of my code:

t=0:.2:1; %time points
[m,n]=size(t);
mu=zeros(1,n); %mean vector (row vector)
[S,T]=meshgrid(t, t);
Sigma=min(S,T) %Sigma is Wiener covariance matrix based on R(s,t)=min(s,t)
x=mvnrnd(mu,Sigma,8)

And here's the output:

Sigma =
         0 0 0 0 0 0
         0 0.2000 0.2000 0.2000 0.2000 0.2000
         0 0.2000 0.4000 0.4000 0.4000 0.4000
         0 0.2000 0.4000 0.6000 0.6000 0.6000
         0 0.2000 0.4000 0.6000 0.8000 0.8000
         0 0.2000 0.4000 0.6000 0.8000 1.0000

x =
         0 -0.0736 0.2493 -0.1080 0.2456 0.4455
         0 0.1888 0.2057 0.2752 0.7117 0.5520
         0 0.2968 -0.2304 -0.2909 -0.0418 0.0206
         0 0.4921 0.8112 0.5221 0.7661 0.6145
         0 0.4981 0.0464 0.1461 -0.1544 -0.6289
         0 -0.9377 -1.0224 -1.6863 -0.7339 -0.6709
         0 -0.0345 0.2519 0.7153 0.1456 0.2328
         0 -0.2093 -0.4491 -0.8115 -0.2979 -0.1080

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gna51c$k59$1@fred.mathworks.com>...
> "Beth " <brownep@uwm.edu> wrote in message <gna2ma$l6s$1@fred.mathworks.com>...
> > I am trying to generate random data for a simulation using the mvnrnd command. To start, I'm using mu=zeros(1,n). I'm trying out a couple of processes to generate an nxn Sigma using covariance functions (Wiener, Brownian Bridge, Ornstein-Uhlenbck).
> >
> > The issue: when mu is all zeros and Sigma has patterns of zero as well, I end up with mvnrnd(mu,Sigma,n) generating n rows of data which all start with zero. If I change mu to ones, for example, my mvnrnd generates n rows of data which all start with one. There seems to be some connection between the patterns of zeros in my Sigma and the mu values. This strikes me as working against my attempt to generate random data.
> >
> > Any thoughts would be appreciated.
> > Thanks,
> > Beth
>
> You haven't given enough information to go on here, Beth. Are you using the 'cases' third input argument to 'mvnrnd'? When you say "Sigma has patterns of zero", do you mean all elements of 'Sigma' are zero? If so, there would be zero variance and all output values would just be the same as 'MU' with no randomness about them. Your statement "all start with zero" means what exactly? The first output is exactly zero, its first digit is a 0, what?
>
> I think you would do well to give some specific information about your matlab code. Show some results using 'format long' but only for a (hopefully short) row or two of output. We can't do anything for you as you have posed the problem?
>
> Roger Stafford

Subject: mvnrnd output

From: Roger Stafford

Date: 16 Feb, 2009 00:13:02

Message: 4 of 5

"Beth " <brownep@uwm.edu> wrote in message <gna6i1$qq9$1@fred.mathworks.com>...
> Sorry if my question was not clear - I'm fairly new to all of this, so I appreciate your clarifying questions.
>
> I am using the 'cases' third input argument for mvnrnd - here it is 8 for ease of viewing the output, although it needs to be much higher eventually. My Sigma is generated by a covariance function, hence the first row and column of Sigma are zero.
>
> Again my concern is the apparent lack of randomness in my output since each row of mvnrnd data begins with zero.
>
>
> Here's the basic part of my code:
>
> t=0:.2:1; %time points
> [m,n]=size(t);
> mu=zeros(1,n); %mean vector (row vector)
> [S,T]=meshgrid(t, t);
> Sigma=min(S,T) %Sigma is Wiener covariance matrix based on R(s,t)=min(s,t)
> x=mvnrnd(mu,Sigma,8)
>
> And here's the output:
>
> Sigma =
> 0 0 0 0 0 0
> 0 0.2000 0.2000 0.2000 0.2000 0.2000
> 0 0.2000 0.4000 0.4000 0.4000 0.4000
> 0 0.2000 0.4000 0.6000 0.6000 0.6000
> 0 0.2000 0.4000 0.6000 0.8000 0.8000
> 0 0.2000 0.4000 0.6000 0.8000 1.0000
>
> x =
> 0 -0.0736 0.2493 -0.1080 0.2456 0.4455
> 0 0.1888 0.2057 0.2752 0.7117 0.5520
> 0 0.2968 -0.2304 -0.2909 -0.0418 0.0206
> 0 0.4921 0.8112 0.5221 0.7661 0.6145
> 0 0.4981 0.0464 0.1461 -0.1544 -0.6289
> 0 -0.9377 -1.0224 -1.6863 -0.7339 -0.6709
> 0 -0.0345 0.2519 0.7153 0.1456 0.2328
> 0 -0.2093 -0.4491 -0.8115 -0.2979 -0.1080
> .......

  I don't see the problem here, Beth. You have given the first variable of your first output column a zero variance as given by Sigma(1,1)=0 and naturally that variable will necessarily have a constant value, namely whatever mean you give it in MU. Why does that surprise you?

  I suggest you do the following. Let your 'cases' value be a very large number, many thousands or tens of thousands maybe a million, with this Sigma. Then use matlab's 'cov' function to calculate the sample covariance from x, and it should resemble 'Sigma' values rather closely, the larger the number in the sample, the closer the match will be.

  You should be aware that the covariance matrix you give to 'mvnrdn' has a profound effect on the statistical nature of its results, including the production of constant values as you have seen here. A constant value is an extreme (and degenerate) case of a normally distributed distribution.

  This is not an oddity with 'mvnrnd' and matlab. It is behaving exactly as any self-respecting generator of multivariate normal distributions should behave. Look carefully at the definition of variance for a variable and think how it must behave if its variance must be zero.

Roger Stafford

Subject: mvnrnd output

From: Beth

Date: 16 Feb, 2009 00:47:09

Message: 5 of 5

Thanks for the detailed clarification, Roger. Your explanation makes a lot of sense, and I can see that I wasn't putting together all the pieces of what I was requesting from the code.

I'll try your suggestions, and I'll think a bit more about my ulitmate objective here.

Thanks, Beth

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message
> I don't see the problem here, Beth. You have given the first variable of your first output column a zero variance as given by Sigma(1,1)=0 and naturally that variable will necessarily have a constant value, namely whatever mean you give it in MU. Why does that surprise you?
>
> I suggest you do the following. Let your 'cases' value be a very large number, many thousands or tens of thousands maybe a million, with this Sigma. Then use matlab's 'cov' function to calculate the sample covariance from x, and it should resemble 'Sigma' values rather closely, the larger the number in the sample, the closer the match will be.
>
> You should be aware that the covariance matrix you give to 'mvnrdn' has a profound effect on the statistical nature of its results, including the production of constant values as you have seen here. A constant value is an extreme (and degenerate) case of a normally distributed distribution.
>
> This is not an oddity with 'mvnrnd' and matlab. It is behaving exactly as any self-respecting generator of multivariate normal distributions should behave. Look carefully at the definition of variance for a variable and think how it must behave if its variance must be zero.
>
> Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us