Defining your own probability density function in MATLAB

安稳与你 提交于 2020-01-02 05:04:06

问题


Is it possible to define your own probability density function in MATLAB or Octave and use it for generating random numbers?

MATLAB and Octave have default functions like rand, randn built in to draw points at random from a uniform, or normal distributions but there seems to be no documentation of how to define my very own proability density function.


回答1:


Sampling from an arbitrary random distribution is not always trivial. For well known distributions there are tricks to implement them and most of them are implemented in stats toolbox as Oli said.

If your distribution of interest is of difficult form, there are many sampling algorithms that may help you, such as, rejection sampling, slice sampling, Metropolis–Hastings algorithm.

If your distribution is discrete, or can be approximated by a discrete distribution fairly well, then you can just do multinomial sampling using randsamp.




回答2:


If you have the stats toolbox, you can use random(), as it has a lot of useful PDFs built-in.




回答3:


I've had to do that a few times recently, and it's not exactly an easy thing to accomplish. My favorite technique was to use Inverse transform sampling.

The idea is quite simple:

  1. create a cdf
  2. use a uniform random number generator.
  3. identify the RV that maps to your cdf value.


来源:https://stackoverflow.com/questions/9637703/defining-your-own-probability-density-function-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!