Code covered by the BSD License

### Highlights from Apply a function to a set of probability distributions

Be the first to rate this file! 5 Downloads (last 30 days) File Size: 3.62 KB File ID: #34108

# Apply a function to a set of probability distributions

### Mike Sheppard (view profile)

07 Dec 2011 (Updated )

Returns the distribution of the function FUN applied to the set of distributions given in VARARGIN

File Information
Description

PDFFUN Apply a function to a set of probability distributions
[S,P,C]=PDFFUN(FUN,VARARGIN) will return the distribution of the function FUN applied to the set of distributions given in VARARGIN

The output vectors, S, P, and C, are respectively the list of unique outcomes, probability of yielding that outcome, and the total number of ways of obtaining that outcome among all combinations.

FUN can either be a function handle for an arbitrary function that takes one input argument and returns a scalar value, or one of the following built-in functions:

Valid for any number of distributions:
@mean, @average Average
@times Multiply
@max Maximum
@min Minimum

Valid for only two distributions:
@minus Minus
@divide Divide
@power Power

FUN as a user-specified arbitrary function handle is only valid for a single distribution.

VARARGIN is a list of distributions in the form of (X1,P1,N1,X2,P2,N2,...). Where Xn is the possible events for the n'th distribution, with probability Pn, repeated Nn times. The Nn values are needed if the function is valid for any number of distributions, listed above; otherwise it is not needed and assumed to equal one.

EXAMPLES:

Valid for any number of distributions
Distribution of the maximum value when choosing five values
from distribution (A) and three from distribution (B)
x1=[-1 0 2]; p1=[.7 .2 .1]; n1=5; %(A)
x2=[-4 0 1 2]; p2=[.1 .5 .3 .1]; n2=3; %(B)
[S,P,C]=pdffun(@max,x1,p1,n1,x2,p2,n2)

Valid for only two distributions
Difference of two different distributions, A and B
x1=[-1 0 2]; p1=[.7 .2 .1]; %(A)
x2=[-4 0 1 2]; p2=[.1 .5 .3 .1]; %(B)
[S,P,C]=pdffun(@minus,x1,p1,x2,p2)
Difference of a distribution with itself
x1=[-1 0 2]; p1=[.7 .2 .1];
[S,P,C]=pdffun(@minus,x1,p1)

User-specified function
x1=[-2 -1 0 1]; p1=[.05 .7 .2 .05];
[S,P,C]=pdffun(@(x)(x.*(x+1)),x1,p1)

Continuous Distributions
Note: Program assumes discrete distribution. If using continuous distributions, and using densities as inputs, a normalization must be made afterwards. Also, as only a finite number of points are used the results are an approximation to the actual value on a valid domain.

Distribution of the minimum of five standard normal distributions.
(This example requires the statistics toolbox)
x1=linspace(-5,3); y1=normpdf(x1);
[S1,P1,C]=pdffun(@min,x1,y1,5);
P1=P1./trapz(S1,P1); %Convert to density
plot(S1,P1,x1,y1), grid on

Acknowledgements

Sum Of Probability Distributions and All Sums inspired this file.

MATLAB release MATLAB 7.13 (R2011b)