Group Abstract Group Abstract

Message Boards Message Boards

0
|
18K Views
|
21 Replies
|
17 Total Likes
View groups...
Share
Share this post:

Fix issues with Machine Precision in NMaximize?

I am having daily problems with the new Machine Precision standard from V11.3 and now in V12.

Please suggest a quick fix that will work for all functions/procedures.

I will not be able to use Mathematica in the future if this problem is not fixed.

21 Replies

First of all thank you all for your replies. Specifically the term my term analysis. A term as

(E^(3 [Pi]^2 (16/Subscript[c, 4] + 25/Subscript[c, 5])) k^4 Subscript[c, 4] Subscript[c, 5])/(3600 [Pi]^4)

should not occur at first place it should have been mapped as per the rule: E^(X/Subscript[c, a] + Y/Subscript[c, b]) -> 2^(Subscript[n, a]/2) (( E^Subscript[T, a] Sqrt[1 + (4 X )/Subscript[c, a]] Csch[Subscript[T, a] Sqrt[1 + (4 X )/Subscript[c, a]]])/( 2 + (4 X )/Subscript[c, a] + 2 Sqrt[1 + (4 X )/Subscript[c, a]] Coth[Subscript[T, a] Sqrt[1 + (4 X )/Subscript[c, a]]]))^( Subscript[n, a]/2)* 2^( Subscript[n, b]/2) (( E^Subscript[T, b] Sqrt[1 + (4 Y )/Subscript[c, b]] Csch[Subscript[T, b] Sqrt[1 + (4 Y)/Subscript[c, b]]])/( 2 + (4 Y )/Subscript[c, b] + 2 Sqrt[1 + (4 Y )/Subscript[c, b]] Coth[Subscript[T, b] Sqrt[1 + (4 Y )/Subscript[c, b]]]))^( Subscript[n, b]/2)

which didn't happen. So I changed one of the integers like 6 to 6.0 in Subscript[G, p] -> Subscript[c, p]/(6 [Pi]^2), and the mapping went through and I can get the desired result. Thanks again.

What is surprising is one day the mapping works and other day it doesn't. Nevertheless, thanks.

POSTED BY: Pallavi Debnath

Dear John, Thanks for your answer. Now the file that I shared with you yesterday for

N[termn6 /. {Subscript[T, 1] -> 5.020, Subscript[n, 1] -> 1020, Subscript[c, 1] -> 1.420, Subscript[T, 2] -> 5.020, Subscript[n, 2] -> 1020, Subscript[c, 2] -> 1.420, Subscript[T, 3] -> 5.020, Subscript[n, 3] -> 1020, Subscript[c, 3] -> 1.420, Subscript[T, 4] -> 5.020, Subscript[n, 4] -> 1020, Subscript[c, 4] -> 1.420, Subscript[T, 5] -> 5.020, Subscript[n, 5] -> 1020, Subscript[c, 5] -> 1.420, Subscript[T, 6] -> 5.020, Subscript[n, 6] -> 1020, Subscript[c, 6] -> 1.420, k -> 0.01`20}]

its no more giving 0.999993 but 4.76145665529708310^546 today*

What might have changed in a day? All the results are from mathematica 11.3. I trust 0.999993 because its more of an answer that one would expect physically as it enters into a probability distribution function. Sharing today's file again. Daniel please see to it too termn6 is giving the same unphysical answer today as termn5 (today & yesterday).

Daniel & John, I would be more than grateful if I can retreive my old results (at least for termn6 of yesterday). Thanks, Pallavi

POSTED BY: Pallavi Debnath
POSTED BY: John Doty

I, like Daniel, see similar results from controlled and machine precision. Why do you trust the old laptop's results?

POSTED BY: John Doty

The problem is the 2.141507701982923310^363 result for termn5* at some parameter values, it should be something like .999993 (shown on old laptop, for the same set of parameters). How can I get this result on evaluating by: termn5/.{set of parameters}

So what should I do? using `20 didn't help as shown in the notebook shared now. Thanks. Pallavi

POSTED BY: Pallavi Debnath

Dear John, Thanks for the reply. I tried what you suggested but that didn't help when {p=5} in the sum from p=1 to p=5 (it just removed the error messages), bit it just works fine when the upper limit is changed to p=6. Sharing the mathematica notebook. So the problem remains and it may pop up again in a corresponding higher order calculation.

POSTED BY: Pallavi Debnath
POSTED BY: Daniel Lichtblau

It would be easier for us to help if you posted code we could copy rather than an image.

I suggest using controlled precision: replace each machine number (numbers with a decimal point, like 1.5) with a controlled precision number like 1.5`20.

POSTED BY: John Doty
POSTED BY: Pallavi Debnath

I believe I may too have similar kind of problem in Mathematica 11.3. enter image description here

In my students' old laptop the same input gives a different correct (the one to be expected) result enter image description here

Can you please suggest a fix?

Thanks. Pallavi

POSTED BY: Pallavi Debnath

The same happened with Mathematica 10 version and so I installed Mathematica 11.3 it too had the same problem. But worked fine in an old laptop.

POSTED BY: Pallavi Debnath

The purpose of machine numbers is to give you access to the underlying machine arithmetic. Most machines are optimized for double arithmetic, so this gives you access to efficiency. Underflowing to zero is part of machine arithmetic, so trapping underflow and substituting a different kind of number was a troublesome violation of the basic design.

Using machine numbers inappropriately has always been a problem in Mathematica, as in other computing contexts. You're on shaky ground when you use machine numbers as input to symbolic machinery like Solve or Integrate, and the usual numeric hazards are also present. Fortunately, these are easily avoided. For symbolic calculation, use exact numbers, like 3/2 in place of 1.5. For safer, more rigorous numerics, use controlled precision like 1.5`10 .

You're in control here. Underflowing to zero improves that control: rather than arbitrarily switching the arithmetic domain, it keeps your calculation in the machine domain when that's the way you've formulated your problem.

POSTED BY: John Doty

I think there is no need to stay in 11.2 world, you just need to remember to ask Mathematica to use extended precision for its calculations.

Your data coincidentally were given as exact numbers (integers), so it was sufficient to simply use WorkingPrecision->20. If the data itself contains machine precision floating point numbers, it will necessary to execute epdata = SetPrecision[data, 20] and remember to use epdata in place of data.

The only important takeaway from my solution that I would recommend for you to apply going forward to replace Log[PDF[dist, x]] with LogLikelihood[dist, {x}].

Oleksandr

POSTED BY: Oleksandr Pavlyk
POSTED BY: Oleksandr Pavlyk

Dear Oleksandr,

I am sure your solution is very clever. But my problem is that I am not able to reproduce something like that the next time I have a similar problem.

I am not a mathematician but a biologist who work with applied mathematics. For 20+ years Mathematica has helped me to develop mathematical models to population biological questions and apply them to data.

I am extremely sad that it now will be more difficult for me take advantage of the coming new developments in Mathematica. I will be forced to live in a V11.2 world.

Please rethink this decision and get back to the philosophy of providing a simple to use software for users who are not mathematicians but use mathematics to solve applied problems.

Christian

Thank you Marvin and Daniel.

As noted by Daniel it now works.

I hope I can use the same modification in similar problems.

Daniel, I understand from your response that in the future Mathematica will automatically increase working precision instead of not evaluating the expression. Is that correct?

Christian

Why limit NMaximize to machine precision? You might want to try the option WorkingPrecision. Like

         NMaximize[Cos[x^2 - 3 y] + Sin[x^2 + y^2], {x, y},WorkingPrecision -> 20]

.

There are more examples, but here is my latest example with NMaximize[]:

gbdist[n, q, [Delta]_] := ParameterMixtureDistribution[BinomialDistribution[n, p], p [Distributed] BetaDistribution[ q (-1 + 1/[Delta]), ((-1 + q) (-1 + [Delta]))/[Delta]]];

loglikelihood[data, {q, [Delta]_}] := \!( *UnderoverscriptBox[([Sum]), (i = 1), (Length[data])](Log[ PDF[gbdist[data[([)(i, 1)(])], q, [Delta]], data[([)(i, 2)(])]]]))

antdata={{200, 40}, {200, 78}, {200, 97}, {200, 81}, {200, 96}}

max1 = NMaximize[{loglikelihood[antdata1, {q, [Delta]}], 0 < q < 1, 0 < [Delta] < 1}, {q, [Delta]}]

In Mathematica V 11.2: Out[26]= {-23.49, {q -> 0.370439, [Delta] -> 0.073078}}

In Mathematica V 13: General::munfl: 1.9125910^-158 (-4.167710^-216) is too small to represent as a normalized machine number; precision may be lost.

POSTED BY: Daniel Lichtblau

We can't help you if you don't tell use what the problem is. Just start telling us what's going on.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard