I have a problema with RandomVariate in Mathematica 10 and 9, in the sense that
for a specific distribution constructed by myself, the RandomVariate sample does not follow
the distribution the sample comes from.
I would like to discard that it be a specific problem of my machine or my installation.
Thus I would be grateful if anyone of you could run the attached notebook with Mathematica 10
and send it back to me. I have scanned the notebook and it is free from viruses according
to my antivirus.
You can always make a function that is hard to numerically integrate. In such a case, it’s sometimes hard to know whether you should consider it to be a bug or not. Similarly, it is always possible to make a PDF that doesn’t get sampled well enough at the tails with RandomVariate for numerical reasons. And it’s hard to know whether it should be considered a bug or not. There isn’t a always a clear yes or no answer.
It looks like it’s not RandomVariate isn’t sampling well at some very extreme tails. If you ask it to make the ProbabilityDistribution of f[Exp[x]] Exp[x] instead of f to make the tails more reasonable, everything seems to work fine.
There’s a couple of things you can try here to help this to work. The first I would try is to rewrite as a Piecewise function. The function f seems numerically complicated and this should help simplify things down a bit. Can you reproduce the problem with simpler values?
The function f doesn’t integrate easily with NIntegrate. This might be better fixed by using a Piecewise function If something is difficult to numerically integrate (say with NIntegrate) it stands to reason that you’d have a hard time making a very good random number generator from it.
Now I have tried the sampling of f[Exp[y]]Exp[y] and works very well.
I have also tried using Piecewise[] instead of the HeavisideTheta[]
and the result is that the computations are quite slower with Piecewise[]
and it does not solve the initial problem. So I keep the first idea for the future!