Precision issues in Mathematica (i think)

In summary, precision in Mathematica refers to the accuracy of numerical calculations and the number of digits displayed. Mathematica uses arbitrary-precision arithmetic and allows for control of precision through the use of options. Common precision issues include loss of precision and the use of machine-precision numbers, which can be avoided by using appropriate numerical methods and explicitly setting the precision of numbers.
  • #1
yourgoldteeth
10
0
Hi everyone. It's my first time posting in here.

I have a mathematica notebook that defines a four-parameter prob density function (PDF). I define a likelihood function, import some data, and run a Nelder-Mead optimization strategy on the likelihood function using the data.

My likelihood function uses NIntegrate on the PDF.

It's all fine and dandy until one of my parameters gets big (>5). Then, the small data points (<10e-5) give the following error:

NIntegrate::inumri: The integrand 0.0366328 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.111281 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.216745 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.270682 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.216745 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.111281 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>]))+0.0366328 5.75^UnitStep[0.05-p] (0.1+0.9 E^(InverseErf[<<1>>]^2-1/2 Power[<<2>>])) has evaluated to Overflow, Indeterminate, or Infinity for all sampling points in the region with boundaries {{2.15155*10^-22,9.23051*10^-18}}. >>

That's with WorkingPrecision->MachinePrecision. Here's the thing. My $MachinePrecision is 15.9546. If I specify my WorkingPrecision to be 10, it works more slowly, but at a rate I can deal with.

If I specify my WorkingPrecision to be 20, it works VERY slowly. And it gives almost the same answer, but with more digits.

Why is MachinePrecision giving me such problems? Also, why is a lower precision calculation taking more time than a machine precision? And if I decide to set a lower precision, say 10, will I even know if it is affecting my optimization result?Thanks
Craig
 
Last edited:
Physics news on Phys.org
  • #2


Dear Craig,

Thank you for sharing your experience with the Mathematica community. It sounds like you are facing some challenges with your likelihood function and NIntegrate. Let me address your questions one by one.

Firstly, it is not uncommon for high values of parameters to cause numerical issues in calculations, especially when using machine precision. This is because machine precision can only represent a limited range of numbers, and when values get too large, it can result in overflow or underflow errors. In your case, when your parameter gets bigger than 5, the values in your integrand become very large, causing the NIntegrate function to fail.

Secondly, it is not surprising that setting a lower precision can result in a slower calculation. This is because setting a lower precision means that the computer has to work with more digits and perform more calculations to achieve the desired precision. On the other hand, when using machine precision, the computer can work with fewer digits and perform calculations more quickly.

Lastly, setting a lower precision can affect your optimization result. It is important to carefully consider the precision that is needed for your calculations and make sure it is sufficient to achieve accurate results. If you set a lower precision, it is possible that your optimization result may not be as accurate as it could be. It is always a good idea to check the sensitivity of your results to changes in precision.

In conclusion, I recommend that you carefully consider the precision needed for your calculations and try using higher precision if possible. You can also try using other numerical integration methods in Mathematica to see if they can handle your likelihood function better. I hope this helps and wish you success in your research.
 

1. What is precision in Mathematica?

Precision in Mathematica refers to the accuracy of numerical calculations and the number of digits displayed. It is important for obtaining reliable and accurate results in scientific and mathematical computations.

2. How does Mathematica handle precision?

Mathematica uses a system of arbitrary-precision arithmetic, which means it can work with numbers of any size and precision. It automatically adjusts the precision based on the input and the desired accuracy of the output.

3. Can I control the precision in my calculations?

Yes, you can control the precision in Mathematica by using the PrecisionGoal and AccuracyGoal options. These allow you to specify the desired precision and accuracy for your calculations.

4. What are some common precision issues in Mathematica?

One common issue is the loss of precision when performing operations on numbers with different precisions. This can lead to inaccurate results. Another issue is the use of machine-precision numbers, which have limited precision and can result in rounding errors.

5. How can I avoid precision issues in Mathematica?

To avoid precision issues, it is important to use appropriate numerical methods and to carefully choose the precision of your input and output. You can also use functions such as Rationalize and SetPrecision to explicitly set the precision of your numbers.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
736
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top