Message Boards Message Boards

0
|
6588 Views
|
6 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Why isn't this random number generation implemented?

Posted 6 years ago

Dear community,

I tried to generate bivariate random numbers from the following code,

RandomVariate[
 ProbabilityDistribution[
  Piecewise[{{1/\[Pi], 0 <= Sqrt[x^2 + y^2] <= 1}}], {x, -1, 
   1}, {y, -1, 1}]]

but was given a response as follows,

RandomVariate::noimp: Sampling from ProbabilityDistribution[\[Piecewise]    1/\[Pi]    0<=Sqrt[Power[<<2>>]+Power[<<2>>]]<=1
0   True

,{\[FormalX]1,-1,1},{\[FormalX]2,-1,1}] is not implemented.

The ProbabilityDistribution was taken from an example from the Documentation Center and it worked well with Mean and StandardDeviation. Does anyone have ideas why it won't work for generating random numbers?

Many thanks,

Chi-Hsiang

POSTED BY: Chi-Hsiang Wang
6 Replies

Yes, I found a lack of robust MCMC in Mathematica is surprising, and disappointing, too! In the last couple decades full Bayesian analysis has become fairly popular and MCMC is at present one of the most powerful methods to obtain any posterior distributions. In fact my need was to obtain a simulated posterior distribution that involves logistic functions and beta distributions, both of which are basic functions/distributions for categorical data analysis.

Hope Wolfram ups its efforts in improving robust functional capabilities for statistical data analysis, particularly Bayesian data analysis!

POSTED BY: Chi-Hsiang Wang

Ok, I didn't expect that to work. I tried some other distributions myself and didn't find any other ones that worked even when while attempting some really elementary ones (like a 2D normal distribution). It's good to know polynomials work, but the fact remains that you basically have to be creative to get it to work and there are no guarantees. It's not like there's a robust MCMC sampler that just works for arbitrary PDFs. Something like that is quite high on my wish list, frankly speaking, and I'm a bit surprised that WL seems to be behind the curve with that, given how many applications there are for functionality like that.

POSTED BY: Sjoerd Smit

Wolfram hasn't implemented multivariate random number generation for user-defined distributions.

This is not true. It depends on the symbolic form of the distribution. Try a simple polynomial one, and it will likely work.

d = ProbabilityDistribution[x^2 + y^4, {x, -1, 1}, {y, -1, 1}, 
  Method -> "Normalize"]

RandomVariate[d]

This, along with features like RandomPoint, opens up a lot of flexibility for designing an efficient rejection sampling scheme for more complicated distributions too.

POSTED BY: Szabolcs Horvát

Many thanks, Sjoerd and Marco. So it seems, as Sjoerd suggested, Wolfram hasn't implemented multivariate random number generation for user-defined distributions. It's certainly possible to use conditional probability for simulation, but let's hope Wolfram provide handy, automatic functions like RandomVariate for this purpose very soon.

POSTED BY: Chi-Hsiang Wang

In the special case described in the original post, this one should generate the points:

RandomPoint[Disk[], 10]

Cheers,

Marco

POSTED BY: Marco Thiel

I'm guessing that this is because sampling from arbitrary multi-dimensional distributions is generally not a simple problem which they haven't got around to implement yet. There are some trivial exceptions like ProbabilityDistribution[1, {x, 0, 1}, {y, 0, 1}], but in general it seems like you can only use build-in multi-dimensional distributions with RandomVariate.

In your case, you could try to sample the unit disk by transforming the coordinates to r and theta. This will factorize the distribution so you can draw from two 1D distributions, which should be easy to do.

POSTED BY: Sjoerd Smit
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