Sunteți pe pagina 1din 6

Uniform Distribution (Continuous)

Overview
The uniform distribution (also called the rectangular distribution) is notable because it has a constant
probability distribution function (pdf) between its two bounding parameters. It is appropriate for
representing the distribution of round-off errors in values tabulated to a particular number of decimal
places, and is used in random number generating techniques such as the inversion method.

Parameters
The uniform distribution uses the following parameters.
Parameter

Description

Constraints

lower

Lower limit

<lower<upper

upper

Upper limit

lower<upper<

Parameter Estimation
The maximum likelihood estimator (MLE) for lower is the sample minimum. The MLE for upper is the
sample maximum.

Probability Density Function


The probability density function (pdf) of the continuous uniform distribution is

f(xlower,upper)=(
otherwise.

1upperlower

);lowerxupper0;

The pdf is constant between lower and upper.


This plot illustrates how changing the value of the parameters lower and upper affects the shape of the
pdf.
% Create three distribution objects with different parameters
pd1 = makedist('Uniform');
pd2 = makedist('Uniform','lower',-2,'upper',2);
pd3 = makedist('Uniform','lower',-2,'upper',1);
% Compute the pdfs
x = -3:.01:3;
pdf1 = pdf(pd1,x);
pdf2 = pdf(pd2,x);
pdf3 = pdf(pd3,x);
% Plot the pdfs
figure;
stairs(x,pdf1,'r','LineWidth',2);
hold on;
stairs(x,pdf2,'k:','LineWidth',2);
stairs(x,pdf3,'b-.','LineWidth',2);
ylim([0 1.1]);
legend({'lower = 0, upper = 1','lower = -2, upper = 2',...
'lower = -2, upper = 1'},'Location','NW');
hold off;

As the distance between lower and upper increases, the density at any particular value within the
distribution boundaries decreases. Because the density function integrates to 1, the height of the pdf plot
decreases as its width increases.

Cumulative Distribution Function


The cumulative distribution function (cdf) of the continuous uniform distribution is

(
)
F xlower,upper =0;
x
;lower1;x<lowerx<upperupper.
xlowerupperlower
This plot illustrates how changing the value of the parameters lower and upper affects the shape of the
cdf.
% Create three distribution objects with different parameters
pd1 = makedist('Uniform');
pd2 = makedist('Uniform','lower',-2,'upper',2);
pd3 = makedist('Uniform','lower',-2,'upper',1);
% Compute the cdfs
x = -3:.01:3;
cdf1 = cdf(pd1,x);
cdf2 = cdf(pd2,x);
cdf3 = cdf(pd3,x);
% Plot the cdfs
figure;

plot(x,cdf1,'r','LineWidth',2);
hold on;
plot(x,cdf2,'k:','LineWidth',2);
plot(x,cdf3,'b-.','LineWidth',2);
ylim([0 1.1]);
legend({'lower = 0, upper = 1','lower = -2, upper = 2',...
'lower = -2, upper = 1'},'Location','NW');
hold off;

Descriptive Statistics
The mean and variance of the continuous uniform distribution are related to the
parameters lower and upper.
The mean is

mean=

(
12

)
lower+upper .

The variance is

(
)2
var=
upperlower .
112

Generate Random Numbers Using Uniform Distribution


Inversion

This example shows how to generate random numbers using the uniform distribution inversion method.
This is useful for distributions when it is possible to compute the inverse cumulative distribution function,
but there is no support for sampling from the distribution directly.

Step 1. Generate random numbers from the standard uniform distribution.

Step 2. Generate random numbers from the Weibull distribution.

Step 3. Generate random numbers from the standard normal distribution.

Step 1. Generate random numbers from the standard uniform distribution.


Use rand to generate 1000 random numbers from the uniform distribution on the interval (0,1).
rng('default') % For reproducibility
u = rand(1000,1);
The inversion method relies on the principle that continuous cumulative distribution functions (cdfs) range
uniformly over the open interval (0,1). If u is a uniform random number on (0,1), then x = F1(u) generates
a random number x from any continuous distribution with the specified cdf F.

Step 2. Generate random numbers from the Weibull distribution.


Use the inverse cumulative distribution function to generate the random numbers from a Weibull
distribution with parameters A = 1 and B = 1 that correspond to the probabilities in u. Plot the results.
figure;
x = wblinv(u,1,1);
hist(x,20);

The histogram shows that the random numbers generated using the Weibull inverse cdf
function wblinv have a Weibull distribution.

Step 3. Generate random numbers from the standard normal distribution.


The same values in u can generate random numbers from any distribution, for example the standard
normal, by following the same procedure using the inverse cdf of the desired distribution.
figure;
x_norm = norminv(u,1,0);
hist = (x_norm,20);

The histogram shows that, by using the standard normal inverse cdf norminv, the random numbers
generated from u now have a standard normal distribution.

S-ar putea să vă placă și