# Input Random Variable - Shift of Origin

Hello,

If I had a random variable that is modelled as an exponential distribution. Can anyone please help how can I specify it to be distributed with a shifted origin.

For example, for the standard exponential distribution,
Let,
X ~ \mathcal{E} (\lambda)
and
f_\textbf{X} (x) = \lambda e^{-\lambda.x}

Can we define X as
f_\textbf{X} (x) = \lambda e^{-\lambda.(x-a)}

a is a constant.
Which is an exponential distribution with a shifted origin.

Regards,
Maitreya Manoj Kurumbhati

Hi,

If I’m not wrong, there are at least two ways to do this: quick and dirty and cleaner ways.

## Quick and dirty

This might be obvious, but if you want to get a quick result based on using sample points directly, then simply generate an exponential sample and then shift the realizations.

So for instance:

InputOpts.Marginals.Type = 'Exponential';
InputOpts.Marginals.Parameters = 0.6; % lambda = 0.6

myInput = uq_createInput(InputOpts);


To get sample points following the shifted distribution:

X = uq_getSample(myInput,1e6) + 5.0;  % Shift = 5.0
mean(X)
std(X)


Then in this case the sample points should be distributed following the shifted exponential you defined above (I think).

## Custom distribution

A cleaner way is to define a custom distribution in UQLab. You can find the details in Section 2.6 of UQLab v1.2.0 Input Module User manual. Below is a quick summary.

To define a custom distribution in UQLab, you need to define at least three MATLAB functions with very specific names. These functions correspond to the PDF, CDF, and inverse CDF functions. The table below summarizes what you need to do for your particular case (hopefully, the formulas are right):

Function name Description Parameters Formulas
uq_ShiftedExponential_pdf PDF (X, distParameters) \lambda \exp{[- \lambda (x-a)]}
uq_ShiftedExponential_cdf CDF (X, distParameters) 1 - \exp{[-\lambda (x-a)]}
uq_ShiftedExponential_invcdf Inverse CDF (F, distParameters) \frac{-\ln(1-F)}{\lambda} + a
uq_ShiftedExponential_PToM Compute moments from parameters (distParameters) \mu = a + \frac{1}{\lambda}
\sigma = \frac{1}{\lambda}
uq_ShiftedExponential_MToP Compute parameters from moments (distMoments) \lambda = \frac{1}{\sigma}
a = \mu - \frac{1}{\lambda}

where:

• X: vector of sample values of the distribution
• distParameters: vector of parameters of the distribution, \lambda and the shift a
• F: vector of CDF values of X
• distMoments: vector of the first two moments of the distribution, mean and standard deviation.

The two last functions are optional. Define these functions and make them available in your MATLAB path. Having defined them you can now define an INPUT model as follows:

InputOpts.Marginals.Type = 'ShiftedExponential';  % As defined in your function. NOTE: case sensitive
InputOpts.Marginals.Parameters = [0.6 5.0];  % lambda = 0.5, shift = 5.

myInput = uq_createInput(InputOpts);


You can then generate sample points from the distribution as usual:

X = uq_getSample(myInput,1e6);
mean(X)
std(X)


or use the INPUT object like any other INPUT objects.

As I said, the last two functions are optional, but if you provided, say uq_ShiftedExponential_MToP, then you can use the moments to define the distribution instead of the distribution parameters.

InputOpts.Marginals.Type = 'ShiftedExponential';
InputOpts.Marginals.Moments = [5+1/0.6 1/0.6]; % mu = 6.6667, sigma = 1.6667.

myInput = uq_createInput(InputOpts);


As long as you can define the three main functions associated with a random variable above, you can define any custom probability distribution in UQLab. I hope this is clear and helpful.

1 Like

Thank you so much.

Again, this totally solves my problem.