From this answer (19542) to my question I need to add the WorkingPrecision
option to RandomVariate
for that particular ProbabilityDistribution
not to experience what I guess is an overflow off some sort and return incorrect values.
Another option given by WRI was to use Rationalize[ #, 0]&
on each of the parameter values to effectively give them infinite precision such that the calculations would not experience any precision anomalies.
Is there a way to set the precision on the function such that it does all its calculations at the prescribe precision?
I tried by setting $MinPrecision
and $MaxPrecision
as in this answer (19542).
ClearAll[genParetoCDF];
genParetoCDF[μ_, ξ_, σ_, x_] :=
Block[{$MinPrecision = 2 $MachinePrecision, $MaxPrecision = 2 $MachinePrecision},
Piecewise[{
{1 - (1 + ((x - μ)*ξ)/σ)^(-ξ^(-1)),
(x >= μ && ξ > 0) || (μ <= x <= μ - σ/ξ && ξ < 0)},
{1 - E^(-((x - μ)/σ)),
x >= μ && ξ == 0}
}]
]
However it still returns MachinePrecision
values.
Precision@genParetoCDF[.2, .5 10^6, 100000, 1 10^6]
MachinePrecision
When used with RandomVariate
without WorkingPrecision
it still results in negatives (from what I think is the overflow).
With
ClearAll[gpdDist];
gpdDist[μ_, ξ_, σ_] :=
ProbabilityDistribution[{"CDF", genParetoCDF[μ, ξ, σ, x]}, {x, μ, ∞},
Assumptions -> {{μ, ξ, σ} ∈ Reals, σ > 0}]
Then (Also curious as to why this does not generate some sort of overflow error)
Min@RandomVariate[dist, 1000000]
-7.49163*10^6
Is it possible to set the precision on the function? I still need to be able to use the function symbolically as well. For example,
Assuming[{ξ > 0, σ > 0, {ξ, μ, σ} ∈ Reals},
Limit[genParetoCDF[ξ, μ, σ, x], x -> ∞]
]
Any ideas?