chaospy.approximate_density¶
- chaospy.approximate_density(distribution, idx, xloc, cache=None, step_size=1e-07)[source]¶
Approximate the probability density function.
- Args:
- distribution (Distribution):
Distribution in question. May not be an advanced variable.
- idx (int):
The dimension to take approximation along.
- xloc (numpy.ndarray):
Location coordinates. Requires that xloc.shape=(len(distribution), K).
- cache (Optional[Dict[Distribution, Tuple[numpy.ndarray, numpy.ndarray]]]):
Current state in the evaluation graph. If omitted, assume that evaluations should be done from scratch.
- step_size (float):
The relative step size between two points used to calculate the derivative.
- Returns:
- numpy.ndarray: Local probability density function with
out.shape == xloc.shape
. To calculate actual density function, evaluatenumpy.prod(out, 0)
.
- Example:
>>> distribution = chaospy.Normal(1000, 10) >>> xloc = numpy.array([990, 1000, 1010]) >>> approximate_density(distribution, 0, xloc).round(4) array([0.0242, 0.0399, 0.0242]) >>> distribution.pdf(xloc).round(4) array([0.0242, 0.0399, 0.0242])