chaospy.Distribution.pdf

Distribution.pdf(x_data, decompose=False, allow_approx=True, step_size=1e-07)[source]

Probability density function.

If possible the density will be calculated analytically. If not possible, it will be approximated by approximating the one-dimensional derivative of the forward Rosenblatt transformation and multiplying the component parts. Note that even if the distribution is multivariate, each component of the Rosenblatt is one-dimensional.

Args:
x_data (numpy.ndarray):

Location for the density function. If multivariate, len(x_data) == len(self) is required.

decompose (bool):

Decompose multivariate probability density p(x), p(y|x), … instead of multiplying them together into p(x, y, …).

allow_approx (bool):

Allow the density to be estimated using numerical derivative of forward mapping if analytical approach fails. Raises error instead if false.

step_size (float):

The relative step size between two points used to calculate the derivative, assuming approximation is being used.

Raises:
chaospy.UnsupportedFeature:

If analytical calculation is not possible and allow_approx is false.

Returns:
(numpy.ndarray):

Evaluated density function evaluated in x_data. If decompose, output.shape == x_data.shape, else if multivariate the first dimension is multiplied together.

Example:
>>> chaospy.Gamma(2).pdf([1, 2, 3, 4, 5]).round(3)
array([0.368, 0.271, 0.149, 0.073, 0.034])
>>> dist = chaospy.Iid(chaospy.Normal(0, 1), 2)
>>> grid = numpy.mgrid[-1.5:2, -1.5:2]
>>> dist.pdf(grid).round(3)
array([[0.017, 0.046, 0.046, 0.017],
       [0.046, 0.124, 0.124, 0.046],
       [0.046, 0.124, 0.124, 0.046],
       [0.017, 0.046, 0.046, 0.017]])
>>> dist.pdf(grid, decompose=True).round(3)
array([[[0.13 , 0.13 , 0.13 , 0.13 ],
        [0.352, 0.352, 0.352, 0.352],
        [0.352, 0.352, 0.352, 0.352],
        [0.13 , 0.13 , 0.13 , 0.13 ]],

       [[0.13 , 0.352, 0.352, 0.13 ],
        [0.13 , 0.352, 0.352, 0.13 ],
        [0.13 , 0.352, 0.352, 0.13 ],
        [0.13 , 0.352, 0.352, 0.13 ]]])