Message Boards Message Boards

1
|
6464 Views
|
7 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Problem with RandomVariate in Mathematica 10 (and 9) Is it a bug?

Attachments:
POSTED BY: Arturo Ramos
7 Replies
POSTED BY: Bruce Miller

Thanks Bruce,

It is another good idea to take into account.

POSTED BY: Arturo Ramos

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.

POSTED BY: Sean Clarke

Thanks a lot Sean,

You have given me a pair of good ideas and now I could write my code more efficiently adapted to the mathematics in play.

In fact, with the Exp transformation anything works well and the Piecewise command is something I will try.

Thanks again!

Best, Arturo

POSTED BY: Arturo Ramos

Dear Sean,

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!

Thanks again and all the best.

POSTED BY: Arturo Ramos

Here you go! Same result as you, it appears.

In[1]:= $Version

Out[1]= "10.0 for Mac OS X x86 (64-bit) (June 29, 2014)"
Attachments:
POSTED BY: Jesse Friedman

Thanks a lot Jesse, you have been of great help!.

Best, Arturo

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

Group Abstract Group Abstract