Numerical vs. Monte-Carlo Simulations
- Context: Mathematica
- Thread starter EngWiPy
- Start date
Click For Summary
This discussion centers on the comparison between numerical integration using Mathematica's NIntegrate and Monte Carlo simulations for evaluating integrals. The participants conclude that NIntegrate is more reliable due to its sophisticated algorithm selection and error control mechanisms. Monte Carlo methods, while useful, are prone to inaccuracies stemming from random number generation and sample size limitations. The conversation emphasizes the importance of understanding the limitations of both methods, particularly in terms of numerical precision and the representation of continuous ranges.
PREREQUISITES- Familiarity with Mathematica's NIntegrate function
- Understanding of Monte Carlo simulation techniques
- Knowledge of random number generation in MATLAB using exprnd
- Concept of numerical precision and error analysis
- Explore advanced features of Mathematica's NIntegrate, including different methods like "AdaptiveMonteCarlo" and "DoubleExponential"
- Investigate the statistical properties of random number generators in MATLAB
- Learn about convergence and accuracy in Monte Carlo simulations
- Study numerical integration techniques and their error control mechanisms
Researchers, mathematicians, and data scientists involved in numerical analysis, particularly those comparing numerical integration methods and Monte Carlo simulations for scientific computations.
- 36,607
- 15,426
Yes, that seems right. Notice how it does not go out to infinity and how it is not strictly monotonically decreasing. The variations are small, but they will make a difference in achieving a given level of numerical precision.S_David said:It's histogram(x). When I used with the data I have, I got the attached figure. Does that make sense?
- 1,361
- 61
Dale said:Yes, that seems right. Notice how it does not go out to infinity and how it is not strictly monotonically decreasing. The variations are small, but they will make a difference in achieving a given level of numerical precision.
Can I do anything about it? I'm writing a scientific journal, do you think such justification is acceptable for why there is a difference between the two curves?
- 36,607
- 15,426
First, instead of generating 1,000,000 numbers that are exponentially distributed and plotting the histogram of the distribution, let's investigate the sampling distribution. Instead of 1,000,000 numbers, generate 1,000 sets of 1,000 numbers each. For each set calculate the mean and the standard deviation (1,000 means and 1,000 standard deviations) and then plot the histograms of those. Let's see if there is any bias.
Second, see if you can easily get a qq plot in Matlab.
- 36,607
- 15,426
No. It still shows the same key features, but it is smaller and harder to see. The range is not infinite and the curve is not smooth. This is to be expected in any random number generator, but it is a source of numerical error.S_David said:In the first figure, I didn't generate ##10^6## samples. In the attached figure I did. Does this change anything before going to implement your suggestion?
If we are lucky then the sampling distribution will show some small bias.
- 36,607
- 15,426
Can you do a qq plot of the ySim against the exponential distribution instead of the normal distribution?
Also, what is the mean and standard deviation of the sampling distribution of the mean?
- 1,361
- 61
Dale said:So it looks like the RNG is not too bad but the sampling distribution does show a bit heavier tails than normal and a bit of right skew.
Q1: Can you do a qq plot of the ySim against the exponential distribution instead of the normal distribution?
Q2: Also, what is the mean and standard deviation of the sampling distribution of the mean?
I didn't understand your questions. For Q1: What do you mean by qq plotting ySim against the exponential distribution? and how? I qq plot ySim alone and got the attached figure.
I also didn't understand Q2. Sorry, but can you elaborate, please.
Attachments
- 1,361
- 61
- 36,607
- 15,426
OK, that is essentially unbiased.S_David said:OK, for Q2: the mean and the standard deviation of the mean are 1.0001 and 0.0309, respectively.
- 1,361
- 61
- 36,607
- 15,426
So the qq plots you have posted so far plot against the normal distribution. The ySim values are not normally distributed so the qq plot should be done against the exponential distribution.S_David said:I didn't understand your questions. For Q1: What do you mean by qq plotting ySim against the exponential distribution? and how? I qq plot ySim alone and got the attached figure
- 36,607
- 15,426
- 36,607
- 15,426
It appears that there is not much, if any, bias in the sampling distribution, but the asymmetric numerical errors make those results suspicious.
- 1,361
- 61
- 1,361
- 61
- 283
- 99
S_David said:Is it acceptable to say on a scientific article that the small discrepancy in results is due to some inaccuracy in the simulations?
What is the small discrepancy? 1 part in 1 million? 1 part in 1 billion? Is there some reason you are using an exponential distribution and not a uniform distribution for your sampling? If you post just the MC integration code, we might be able to see a problem with it.
- 648
- 2
https://www.google.no/url?sa=t&rct=...0zK3Z2x4EE9nJ0DI8Y282w&bvm=bv.123664746,d.bGs
- 1,361
- 61
mfig said:What is the small discrepancy? 1 part in 1 million? 1 part in 1 billion? Is there some reason you are using an exponential distribution and not a uniform distribution for your sampling? If you post just the MC integration code, we might be able to see a problem with it.
See this thread for more details. The discrepancy is shown on the figure attached on post #41. Mathematica code can be found on post #35.
- 283
- 99
S_David said:Mathematica code can be found on post #35.
Thanks, but I was asking about the Monte-Carlo code for the integration. If you post this code, someone might be able to see a shortcoming in the code, or explain the discrepancy.
- 1,361
- 61
- 283
- 99
S_David said:Monte-Carlo is not for the integration by the way.
I see. I was under the impression you were comparing the results of some numerical integration technique to a MC integration method. Now that I know there are other, unseen, codes involved somewhere along the way I see no way of relating the results of the numerical integration technique mentioned in the first post to the results of some other simulation involving a MC technique somehow. :(
Good luck!
- 36,607
- 15,426
I wouldn't even report the Monte Carlo results. I don't trust them. There are too many unknowns and uncontrolled errors.S_David said:Any comment on this? Is it acceptable to say on a scientific article that the small discrepancy in results is due to some inaccuracy in the simulations?
- 1,361
- 61
Dale said:I wouldn't even report the Monte Carlo results. I don't trust them. There are too many unknowns and uncontrolled errors.
But it's a good practice in my field to verify the numerical results. Most reviewers don't follow the mathematical derivations, and judge by the results and the general trend.
- 36,607
- 15,426
In any case, the Monte Carlo is also a numerical result, so how can you use one numerical result to verify another. Since the two methods disagree then there are two possibilities, either you made a mistake in the code or numerical errors are causing the disagreement. If the disagreement is due to numerical errors then the problem is in the Monte Carlo since it does not control numerical errors.
- 1,361
- 61
Dale said:Isn't your whole concern that the Monte Carlo simulation does not verify your result?
In any case, the Monte Carlo is also a numerical result, so how can you use one numerical result to verify another. Since the two methods disagree then there are two possibilities, either you made a mistake in the code or numerical errors are causing the disagreement. If the disagreement is due to numerical errors then the problem is in the Monte Carlo since it does not control numerical errors.
If the discrepancy is huge or not constant, then yes, I would say there is something wrong definitely. But the discrepancy is very small and constant. By numerical I meant plotting a mathematical equation vs. averaging which is the case in Monte Carlo simulations. Both are two different and independent methods to evaluate the same results. Monte Carlo is a verification in this sense. You are right though, I might have made a mistake. In that case I haven't found it.
Similar threads
- · Replies 13 ·
- Replies
- 13
- Views
- 3K
- · Replies 4 ·
- Replies
- 4
- Views
- 3K
- · Replies 3 ·
- Replies
- 3
- Views
- 3K
- · Replies 5 ·
- Replies
- 5
- Views
- 2K
- · Replies 1 ·
- Replies
- 1
- Views
- 2K
- · Replies 3 ·
- Replies
- 3
- Views
- 2K
- · Replies 27 ·
- Replies
- 27
- Views
- 4K
- · Replies 34 ·
- Replies
- 34
- Views
- 5K
- · Replies 5 ·
- Replies
- 5
- Views
- 3K
- · Replies 8 ·
- Replies
- 8
- Views
- 3K