I have the defined a custom distribution, which is a Gaussian where the exponent can be any real n
greater than 0 (set to actually be >0.5 in use), i.e.
ProbabilityDistribution[
(2^(-((2^n*(Abs[x])^n)/FWHM^n))), {x, -Infinity, Infinity},
Method -> "Normalize"
]
Under this normalisation, the part of the Piecewise function I need simplifies down to (when FullSimplify is used):
CustomFunction[FWHM_, n_] =
ProbabilityDistribution[
(2^(-1 - 2^n FWHM^-n Abs[x]^n) (2^n FWHM^-n)^(1/n) Log[2]^(1/n))/Gamma[1 + 1/n](*Re[n]>0*),
{x, -Infinity, Infinity}
]
I wish to generate N values from this distribution, which I normally would do using RandomVariate
:
RandomVariate[CustomFunction[FWHM, n] /. {FWHM -> 100, n -> 0.5}, 100(*N*)]
However I have noticed that for some values for FWHM
and n
this is very slow. For example:
RandomVariate[
CustomFunction[FWHM, n] /. {FWHM -> 5235.315151`, n -> 0.534124`},
1000
]; // AbsoluteTiming
takes >70s to run on my PC, whereas other numbers take less than 1s.
Is there any reason for this, or a way to speed up the RandomVariate
?
RandomVariate
takes 0.07s on my laptop, which is not particularly performant. It takes roughly 2s to get one million variates. Maybe clear everything and restart? $\endgroup$