Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _ppf(self, q, dist, cache):
return numpy.tanh(evaluation.evaluate_inverse(dist, q, cache=cache))
def _cdf(self, x, dist, trans, cache):
output = evaluation.evaluate_forward(dist, x, cache=cache)
output = evaluation.evaluate_forward(trans, output, cache=cache)
return output
Returns:
(numpy.ndarray):
Evaluated distribution function values, where
``out.shape==x_data.shape``.
"""
x_data = numpy.asfarray(x_data)
shape = x_data.shape
x_data = x_data.reshape(len(self), -1)
q_data = numpy.zeros(x_data.shape)
indices = (x_data.T > self.upper.T).T
q_data[indices] = 1
indices = ~indices & (x_data.T >= self.lower).T
q_data[indices] = numpy.clip(evaluation.evaluate_forward(
self, x_data), a_min=0, a_max=1)[indices]
q_data = q_data.reshape(shape)
return q_data
def _lower(self, left, right, cache):
"""
Distribution bounds.
Example:
>>> chaospy.Uniform().lower
array([0.])
>>> chaospy.Add(chaospy.Uniform(), 2).lower
array([2.])
>>> chaospy.Add(2, chaospy.Uniform()).lower
array([2.])
>>> chaospy.Add(1, 1).lower
array([2.])
"""
left = evaluation.get_forward_cache(left, cache)
right = evaluation.get_forward_cache(right, cache)
if isinstance(left, Dist):
left = evaluation.evaluate_lower(left, cache=cache)
if isinstance(right, Dist):
right = evaluation.evaluate_lower(right, cache=cache)
return left+right
def _lower(self, dist, cache, **kwargs):
uloc = evaluation.evaluate_upper(dist, cache=cache)
return self._post_inv(uloc, **kwargs)
xupper = distribution.upper
xloc = 0.5*(xlower+xupper)
xloc = (xloc.T + numpy.zeros(qloc.shape).T).T
xlower = (xlower.T + numpy.zeros(qloc.shape).T).T
xupper = (xupper.T + numpy.zeros(qloc.shape).T).T
uloc = numpy.zeros(qloc.shape)
ulower = -qloc
uupper = 1-qloc
for dim in distribution._precedence_order():
indices = numpy.ones(qloc.shape[-1], dtype=bool)
for idx in range(2*iterations):
# evaluate function:
uloc[dim, indices] = (evaluation.evaluate_forward(
distribution, xloc, cache=cache.copy(),
parameters=parameters)-qloc)[dim, indices]
# convergence criteria:
indices[indices] = numpy.any(numpy.abs(uloc) > tol, 0)[indices]
if not numpy.any(indices):
break
# narrow down lower boundary:
ulower[dim, indices] = numpy.where(uloc < 0, uloc, ulower)[dim, indices]
xlower[dim, indices] = numpy.where(uloc < 0, xloc, xlower)[dim, indices]
# narrow down upper boundary:
uupper[dim, indices] = numpy.where(uloc > 0, uloc, uupper)[dim, indices]
xupper[dim, indices] = numpy.where(uloc > 0, xloc, xupper)[dim, indices]
def _upper(self, dist, cache, **kwargs):
uloc = evaluation.evaluate_lower(dist, cache=cache)
return self._post_inv(uloc, **kwargs)
def _pdf(self, x, dist, cache):
"""Probability density function."""
output = evaluation.evaluate_density(dist, numpy.arccosh(x), cache=cache)
output /= numpy.where(x != 1, numpy.sqrt(x*x-1), numpy.inf)
return output
def _fwd_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.log10(dist)
return self