Parameters

#### Next topic

puqutil - Output Functions for PUQ

# PDF¶

class puq.PDF(xvals, yvals)

Create a PDF (Probability Density Function) object.

Use this to create a PDF object given a list or array of x values the corresponding PDF values.

Parameters: xvals (1D array or list) – x values yvals (1D array or list) – values for PDF(x)
__add__(b)

Add two PDFs, returning a new one.

__div__(b)

Divide two PDFs, returning a new PDF

__mul__(b)

Multiply two PDFs, returning a new PDF

__sub__(b)

Subtract two PDFs, returning a new PDF

cdf(arr)

Computes the Cumulative Density Function (CDF) for some values.

Parameters: arr – Array of x values. Array of cdf(x).
ds(num)

Generates a descriptive sample for this distribution.

The order of the numbers in the array is random, so it can be combined with other arrays to form a latin hypercube. This method is used by LHS.

Parameters: num – Number of samples to generate. 1D array of length num.
ds1(num)

Generates a descriptive sample in [-1,1] for this distribution.

The order of the numbers in the array is random, so it can be combined with other arrays to form a latin hypercube. Note that this can return values outside the range [-1,1] for distributions with long tails. This method is used by puq.Smolyak.

Parameters: num – Number of samples to generate. 1D array of length num.
lhs(num)

Latin Hypercube Sample for this distribution.

The order of the numbers in the array is random, so it can be combined with other arrays to form a latin hypercube. This method is used by LHS.

Parameters: num – Number of samples to generate. 1D array of length num.
lhs1(num)

Latin Hypercube Sample in [-1,1] for this distribution.

The order of the numbers in the array is random, so it can be combined with other arrays to form a latin hypercube. Note that this can return values outside the range [-1,1] for distributions with long tails. This method is used by puq.Smolyak.

Parameters: num – Number of samples to generate. 1D array of length num.
mode

Find the mode of the PDF. The mode is the x value at which pdf(x) is at its maximum. It is the peak of the PDF.

pdf(arr)

Computes the Probability Density Function (PDF) for some values.

Parameters: arr – Array of x values. Array of pdf(x).
plot(color='', fig=False)

Plot a PDF.

Parameters: color (String.) – Optional color for the plot. fig (Boolean.) – Create a new matplotlib figure to hold the plot. A list of lines that were added.
ppf(arr)

Percent Point Function (inverse CDF)

Parameters: arr – Array of x values. Array of ppf(x).
random(num)

Generate random numbers fitting this parameter’s distribution.

This method is used by MonteCarlo.

Parameters: num – Number of samples to generate. 1D array of length num.
range

The range for the PDF. For PDFs with long tails, it is truncated to 99.99% by default. You can customize this by setting options[‘pdf’][‘range’].

Returns: A tuple containing the min and max.
srange

The small range for the PDF. For PDFs with long tails, it is truncated to 99.8% by default. You can customize this by setting options[‘pdf’][‘srange’].

Returns: A tuple containing the min and max.
puq.ExponPDF(rate)

Creates Exponential Probability Density Function.

Parameters: rate – The rate parameter for the distribution. Must be > 0. A PDF object
puq.NormalPDF(mean, dev, min=None, max=None)

Creates a normal (gaussian) Probability Density Function.

Parameters: mean – The mean. dev – The standard deviation. min – A minimum value for the PDF (default None). max – A maximum value for the PDF (default None). A PDF object

For the normal distribution, you must specify mean and dev.

>>> n = NormalPDF(10,1)
>>> n = NormalPDF(mean=10, dev=1)
>>> n = NormalPDF(mean=10, dev=1, min=10)

puq.RayleighPDF(scale)

Creates Rayleigh Probability Density Function.

Parameters: scale – The scale. Must be > 0. A PDF object
puq.TrianglePDF(min, mode, max)

Creates a triangle Probability Density Function.

Parameters: min – The minimum value mode – The mode max – The maximum value A PDF object

You can enter the parameters in any order. They will be sorted so that the mode is the middle value.

puq.UniformPDF(min=None, max=None, mean=None)

Creates a uniform Probability Density Function.

Parameters: min – The minimum value max – The maximum value mean – The mean value A PDF object

For the uniform distribution, you must specify two of (min, max, and mean). The third parameter will be calculated automatically.

>>> u = UniformPDF(10,20)
>>> u = UniformPDF(min=10, max=20)
>>> u = UniformPDF(min=10, mean=15)

puq.WeibullPDF(shape, scale)

Creates Weibull Probability Density Function.

Parameters: shape – The shape. Must be > 0. scale – The scale. Must be > 0. A PDF object
puq.ExperimentalPDF(data, min=None, max=None, fit=False, bw=None, nbins=0, prior=None, error=None, force=False)

Create an experimental PDF.

An experimental PDF is derived from the results of an experiment or measurement of some parameter. It has actual data attached to it. That data is then used to create a PDF by one of three different methods.

The PDF can built by binning the data and linearly interpolating, using a Gaussian KDE, or using Bayesian Inference.

Parameters: data (Array of scalars) – Our quantity of interest. nbins (int) – Number of bins (used if fit is false). Default is 2*IQR/n^(1/3) where IQR is the interquartile range of the data. fit (True or “Gaussian”) – Use Gaussian KDE (default=False) bw (string or float. String must be ‘scott’ or ‘silverman’) – Bandwidth for Gaussian KDE (default=None) prior (PDF) – Prior PDF to use for Bayesian Inference. [default=None (uninformative)] error (PDF. Typically a NormalPDF with a mean of 0.) – Error in the data. For example, the measurement error. Required for Bayesian.
puq.HPDF(data, min=None, max=None)

Histogram PDF - initialized with points from a histogram.

This function creates a PDF from a histogram. This is useful when some other software has generated a PDF from your data.

Parameters: data (2D numpy array) – A two dimensional array. The first column is the histogram interval mean, and the second column is the probability. The probability values do not need to be normalized. min – A minimum value for the PDF range. If your histogram has values very close to 0, and you know values of 0 are impossible, then you should set the *min* parameter. max – A maximum value for the PDF range. A PDF object.
puq.NetPDF(addr)

Retrieves a PDF from a remote address.

Parameters: addr – URI. PDF must be stored in JSON format A PDF object
>>> u = NetPDF('http://foo.com/myproject/parameters/density')