Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining your own probability density function in MATLAB

Tags:

matlab

octave

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.

like image 891
curiousexplorer Avatar asked Mar 09 '12 16:03

curiousexplorer


People also ask

How do you write probability density in Matlab?

y = pdf( name , x , A ) returns the probability density function (pdf) for the one-parameter distribution family specified by name and the distribution parameter A , evaluated at the values in x .

How do you write a probability density function?

The function fX(x) gives us the probability density at point x. It is the limit of the probability of the interval (x,x+Δ] divided by the length of the interval as the length of the interval goes to 0. Remember that P(x<X≤x+Δ)=FX(x+Δ)−FX(x). =dFX(x)dx=F′X(x),if FX(x) is differentiable at x.

How is probability density function defined?

probability density function (PDF), in statistics, a function whose integral is calculated to find probabilities associated with a continuous random variable (see continuity; probability theory). Its graph is a curve above the horizontal axis that defines a total area, between itself and the axis, of 1.

How do you write conditional probability in Matlab?

Conditional probability is written P(A|B), and is read 'the probability of A, given B'. P(AB) is the probability of the intersection of the events.


2 Answers

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.

like image 162
Memming Avatar answered Sep 21 '22 19:09

Memming


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

like image 39
Oliver Charlesworth Avatar answered Sep 24 '22 19:09

Oliver Charlesworth