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:
Correct way of using Monte Carlo data

Subject: Correct way of using Monte Carlo data

From: kumar vishwajeet

Date: 14 Nov, 2011 19:45:14

Message: 1 of 8

Hi,
I have a doubt. Which is the better (or correct) method to obtain 100,000 monte carlo runs:-
1. Run monte carlo for the equations for 100,000 times, all at once.
2. Run monte carlo run 10 times for the equations and each run should be 10,000 times at once.
I suppose that the mean would not get affected much by either of the methods. But I think higher moments will get affected a lot. I want to confirm which is the correct way?
Thanks,
Kumar Vishwajeet

Subject: Correct way of using Monte Carlo data

From: faid amina

Date: 14 Nov, 2011 20:49:13

Message: 2 of 8

"kumar vishwajeet" wrote in message <j9rr4a$9j8$1@newscl01ah.mathworks.com>...
> Hi,
> I have a doubt. Which is the better (or correct) method to obtain 100,000 monte carlo runs:-
> 1. Run monte carlo for the equations for 100,000 times, all at once.
> 2. Run monte carlo run 10 times for the equations and each run should be 10,000 times at once.
> I suppose that the mean would not get affected much by either of the methods. But I think higher moments will get affected a lot. I want to confirm which is the correct way?
> Thanks,
> Kumar Vishwajeet
The first is true and you must generate the mean after the end of simulation

Subject: Correct way of using Monte Carlo data

From: kumar vishwajeet

Date: 14 Nov, 2011 21:09:10

Message: 3 of 8

"faid amina" <aminafaid@yahoo.fr> wrote in message <j9rus9$ncn$1@newscl01ah.mathworks.com>...
> "kumar vishwajeet" wrote in message <j9rr4a$9j8$1@newscl01ah.mathworks.com>...
> > Hi,
> > I have a doubt. Which is the better (or correct) method to obtain 100,000 monte carlo runs:-
> > 1. Run monte carlo for the equations for 100,000 times, all at once.
> > 2. Run monte carlo run 10 times for the equations and each run should be 10,000 times at once.
> > I suppose that the mean would not get affected much by either of the methods. But I think higher moments will get affected a lot. I want to confirm which is the correct way?
> > Thanks,
> > Kumar Vishwajeet
> The first is true and you must generate the mean after the end of simulation

In each case, I calculate moments after generating all the runs. The difference lies in the fact that in the first case, I have a single data file of 100,000 runs and in the second case I combine 10 different runs to form 100,000 runs. Thus, in each case I calculate the moments using 100,000 runs only.

Subject: Correct way of using Monte Carlo data

From: ImageAnalyst

Date: 15 Nov, 2011 01:36:05

Message: 4 of 8

Kumar Vishwajeet:
That is correct. The mean of the means is the mean. The variance of
the mean of groups of 10,000 will be far, far lower than the variance
of all 100,000 values. Heck the means of blocks of 10,000 will all be
virtually the same, almost no variance at all. Run this demo to see:

array = rand(100000, 1);

% Get the variance of all 100,000 values.
varianceValue = var(array)

% We'll take the mean in the blocks of 10,000.
windowSize = 10000;
myFilterHandle = @(block_struct) mean(block_struct.data);
blockMeans = blockproc(array, [windowSize 1], myFilterHandle)

% Now let's get the variance of those 10 block means.
% It will be a lot lower because there is less variance
% in the mean of 10,000 values than in the original 10,000 values.
varianceValueOfBlocks = var(blockMeans)

You'll see results like this:

varianceValue =
    0.0837
blockMeans =
    0.5005
    0.4977
    0.5032
    0.4973
    0.4970
    0.5005
    0.5026
    0.4993
    0.5001
    0.5038
varianceValueOfBlocks =
  5.8857e-006

Note: 5.8e-6 is different, and a lot less, than 0.0837. This is
because the means of all blocks of 10,000 is very very close to 0.5
for every block.

Defining which way is the "correct" way depends on what you want to
do. Either could be correct depending on what you're after.
ImageAnalyst

Subject: Correct way of using Monte Carlo data

From: kumar vishwajeet

Date: 15 Nov, 2011 02:12:13

Message: 5 of 8

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c2335c66-85d8-4bab-b709-200f44d680c8@s5g2000vbe.googlegroups.com>...
> Kumar Vishwajeet:
> That is correct. The mean of the means is the mean. The variance of
> the mean of groups of 10,000 will be far, far lower than the variance
> of all 100,000 values. Heck the means of blocks of 10,000 will all be
> virtually the same, almost no variance at all. Run this demo to see:
>
> array = rand(100000, 1);
>
> % Get the variance of all 100,000 values.
> varianceValue = var(array)
>
> % We'll take the mean in the blocks of 10,000.
> windowSize = 10000;
> myFilterHandle = @(block_struct) mean(block_struct.data);
> blockMeans = blockproc(array, [windowSize 1], myFilterHandle)
>
> % Now let's get the variance of those 10 block means.
> % It will be a lot lower because there is less variance
> % in the mean of 10,000 values than in the original 10,000 values.
> varianceValueOfBlocks = var(blockMeans)
>
> You'll see results like this:
>
> varianceValue =
> 0.0837
> blockMeans =
> 0.5005
> 0.4977
> 0.5032
> 0.4973
> 0.4970
> 0.5005
> 0.5026
> 0.4993
> 0.5001
> 0.5038
> varianceValueOfBlocks =
> 5.8857e-006
>
> Note: 5.8e-6 is different, and a lot less, than 0.0837. This is
> because the means of all blocks of 10,000 is very very close to 0.5
> for every block.
>
> Defining which way is the "correct" way depends on what you want to
> do. Either could be correct depending on what you're after.
> ImageAnalyst

Thanks for the explanation. But I wanted to ask something different. Here is the thing. I generate 10 blocks, each of 10,000 monte carlo runs. Let's call these blocks, MC1, MC2, MC3......, MC10. Now I combine all these blocks to form a single block as follows:
MC = [MC1 MC2 MC3 MC4 MC5 MC6 MC7 MC8 MC9 MC10]
MC is of size 100,000. Now I calculate the higher moments(since mean does not get affected) of MC. How is this different, if at all, from generating a single block of 100,000 and then calculating the moments. I think both of these will differ from each other. This is what I have experienced. And I assume it has to do something with the random number generating bins. Any help would be appreciated.
Thanks.

Subject: Correct way of using Monte Carlo data

From: ImageAnalyst

Date: 15 Nov, 2011 02:57:24

Message: 6 of 8

On Nov 14, 9:12 pm, "kumar vishwajeet" <kwz...@gmail.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <c2335c66-85d8-4bab-b709-200f44d68...@s5g2000vbe.googlegroups.com>...
> > Kumar Vishwajeet:
> > That is correct.  The mean of the means is the mean.  The variance of
> > the mean of groups of 10,000 will be far, far lower than the variance
> > of all 100,000 values.  Heck the means of blocks of 10,000 will all be
> > virtually the same, almost no variance at all.  Run this demo to see:
>
> > array = rand(100000, 1);
>
> > % Get the variance of all 100,000 values.
> > varianceValue = var(array)
>
> > % We'll take the mean in the blocks of 10,000.
> > windowSize = 10000;
> > myFilterHandle = @(block_struct) mean(block_struct.data);
> > blockMeans = blockproc(array, [windowSize 1], myFilterHandle)
>
> > % Now let's get the variance of those 10 block means.
> > % It will be a lot lower because there is less variance
> > % in the mean of 10,000 values than in the original 10,000 values.
> > varianceValueOfBlocks = var(blockMeans)
>
> > You'll see results like this:
>
> > varianceValue =
> >     0.0837
> > blockMeans =
> >     0.5005
> >     0.4977
> >     0.5032
> >     0.4973
> >     0.4970
> >     0.5005
> >     0.5026
> >     0.4993
> >     0.5001
> >     0.5038
> > varianceValueOfBlocks =
> >   5.8857e-006
>
> > Note: 5.8e-6 is different, and a lot less, than 0.0837.  This is
> > because the means of all blocks of 10,000 is very very close to 0.5
> > for every block.
>
> > Defining which way is the "correct" way depends on what you want to
> > do.  Either could be correct depending on what you're after.
> > ImageAnalyst
>
> Thanks for the explanation. But I wanted to ask something different. Here is the thing. I generate 10 blocks, each of 10,000 monte carlo runs. Let's call these blocks, MC1, MC2, MC3......, MC10. Now I combine all these blocks to form a single block as follows:
> MC = [MC1 MC2 MC3 MC4 MC5 MC6 MC7 MC8 MC9 MC10]
> MC is of size 100,000. Now I calculate the higher moments(since mean does not get affected) of MC. How is this different, if at all, from generating a single block of 100,000 and then calculating the moments. I think both of these will differ from each other. This is what I have experienced. And I assume it has to do something with the random number generating bins. Any help would be appreciated.
> Thanks.

-------------------------------------------------------
No. If you're doing that there should be no significant difference.
See this code for proof:

mc1 = rand(10000, 1);
mc2 = rand(10000, 1);
mc3 = rand(10000, 1);
mc4 = rand(10000, 1);
mc5 = rand(10000, 1);
mc6 = rand(10000, 1);
mc7 = rand(10000, 1);
mc8 = rand(10000, 1);
mc9 = rand(10000, 1);
mc10 = rand(10000, 1);
mc = [mc1 mc2 mc3 mc4 mc5 mc6 mc7 mc8 mc9 mc10];

v1 = var(mc1)
v2 = var(mc2)
v3 = var(mc3)
v4 = var(mc4)
v5 = var(mc5)
v6 = var(mc6)
v7 = var(mc7)
v8 = var(mc8)
v9 = var(mc9)
v10 = var(mc10)
v_all = var(mc(:))

Results:
v1 =
    0.0838
v2 =
    0.0831
v3 =
    0.0843
v4 =
    0.0833
v5 =
    0.0831
v6 =
    0.0845
v7 =
    0.0825
v8 =
    0.0830
v9 =
    0.0831
v10 =
    0.0838
v_all =
    0.0835

See - they're all about 0.0835 or really really close to it.

Subject: Correct way of using Monte Carlo data

From: Peter Perkins

Date: 15 Nov, 2011 15:28:15

Message: 7 of 8

On 11/14/2011 9:12 PM, kumar vishwajeet wrote:
> Here is the thing. I generate 10 blocks, each of 10,000 monte carlo
> runs. Let's call these blocks, MC1, MC2, MC3......, MC10. Now I combine
> all these blocks to form a single block as follows:
> MC = [MC1 MC2 MC3 MC4 MC5 MC6 MC7 MC8 MC9 MC10]
> MC is of size 100,000. Now I calculate the higher moments(since mean
> does not get affected) of MC. How is this different, if at all, from
> generating a single block of 100,000 and then calculating the moments. I
> think both of these will differ from each other. This is what I have
> experienced. And I assume it has to do something with the random number
> generating bins. Any help would be appreciated.

As ImageAnalyst said, that is not correct.

It may be that your two versions use the random values in a different
order, and in that case the sample moments in the two cases could
differ. If they differ by something more than MC random variation, you
are doing something else wrong. You may simply not be using enough MC
iterations, and so you are looking at MC variation. For example, if you
plot one of your sample moments as a function of iteration number, you
should see it converge to a well-defined limit.

Subject: Correct way of using Monte Carlo data

From: Christopher Creutzig

Date: 16 Nov, 2011 10:15:58

Message: 8 of 8

On 15.11.11 03:12, kumar vishwajeet wrote:
> I generate 10 blocks, each of 10,000 monte carlo runs. Let's call these blocks, MC1, MC2, MC3......, MC10. Now I combine all these blocks to form a single block as follows:
> MC = [MC1 MC2 MC3 MC4 MC5 MC6 MC7 MC8 MC9 MC10]
> MC is of size 100,000. Now I calculate the higher moments(since mean does not get affected) of MC. How is this different, if at all, from generating a single block of 100,000 and then calculating the moments. I think both of these will differ from each other. This is what I have experienced. And I assume it has to do something with the random number generating bins.

That means something is wrong with your Monte Carlo runs, since the
basic premise of MC is that the runs are *independently* identically
distributed(*). You don't happen to restart the random number generator
for each run or something like that, do you?

(*) Technically speaking: Realizations of iid random variables or
independent realizations of the same random variable, which is pretty
much the same thing.


Christopher

Tags for 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