1
$\begingroup$

I found a very strange behavior of Quantile function when evaluating the following expression:

Quantile[TruncatedDistribution[{0, \[Infinity]}, 
  MixtureDistribution[{0.5, 
    0.5}, {NormalDistribution[30.0505043478260844836, 
     1.6756943154326708889], 
    NormalDistribution[30.0505043478260844836, 
     2.8804367798735217576]}]], 0.5]

Mathematica was freezing after I hit shift+enter, and there seems to be an infinite loop inside because it kept freezing for a couple of hours.

However, if I change the quantile from 0.5 to 0.500001 it gives me the result immediately.

Or if I remove some digits, e.g., the following:

Quantile[TruncatedDistribution[{0, \[Infinity]}, 
  MixtureDistribution[{0.5, 
    0.5}, {NormalDistribution[30.0505043478260844836, 1.6756], 
    NormalDistribution[30.0505043478260844836, 
     2.8804367798735217576]}]], 0.5]

(note the 1.6756 v.s. 1.6756943154326708889) gives me the result almost immediately as well.

This is so weird as I don't see any fundamental differences between these numbers. It should always gives the results immediately.

Is this a BUG or there are some tricky things within these numbers?

System versions:

OS: macOS Catalina 10.15

Mathematica: 12.0.0.0

$\endgroup$
2
  • 1
    $\begingroup$ Works fine in original form on windows 10, MMA 12, returns result in a few milliseconds. $\endgroup$
    – ciao
    Oct 27, 2019 at 4:23
  • $\begingroup$ @ciao Yea, I guess it should be some system/version specific bug. $\endgroup$ Oct 27, 2019 at 20:15

1 Answer 1

1
$\begingroup$

With macOS Catalina 10.15

$Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

The precision of your distribution is only machine precision due to the presence of low precision numbers; specifically, 0.5

dist1 = TruncatedDistribution[{0, ∞},
   MixtureDistribution[{0.5, 0.5}, {
     NormalDistribution[30.0505043478260844836,
      1.6756943154326708889],
     NormalDistribution[30.0505043478260844836,
      2.8804367798735217576]}]];

Precision@dist1

(* MachinePrecision *)

Use arbitrary-precision rather than machine precision

dist2 = TruncatedDistribution[{0, ∞},
    MixtureDistribution[{0.5, 0.5}, {
      NormalDistribution[30.0505043478260844836,
       1.6756943154326708889],
      NormalDistribution[30.0505043478260844836,
       2.8804367798735217576]}]] //
   SetPrecision[#, 20] &;

(q = Quantile[dist2, SetPrecision[0.5, #]] & /@ 
    Range[5, 20, 5]) // AbsoluteTiming

(* {0.031084, {30.1, 30.050504, 30.05050434783, 30.0505043478260845}} *)

The complicated nature of the distribution results in loss of precision from the input precision.

Precision /@ q

(* {2.92646, 7.60064, 12.5271, 17.5271} *)
$\endgroup$
1
  • $\begingroup$ Thanks for your information! Now I know it is caused by the precision differences. However, what is the root cause for the extreme long timing when using MachinePrecision? And why it only happens to these specific numbers? Actually, if you try: dist1 = TruncatedDistribution[{0, ∞}, MixtureDistribution[{0.5, 0.5}, { NormalDistribution[30.0505043478260844836, 2.6756943154326708889], NormalDistribution[30.0505043478260844836, 2.8804367798735217576]}]]; Note the 1.67xxx v.s. 2.67xxx. It also gives me the result in 6ms. $\endgroup$ Oct 27, 2019 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.