Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fwd_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.arcsin(dist)
return self
def _inv_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.tan(dist)
return self
def _inv_cache(self, cache):
left = evaluation.get_forward_cache(self.prm["left"], cache)
right = evaluation.get_forward_cache(self.prm["right"], cache)
if not isinstance(left, Dist) and not isinstance(right, Dist):
return left+right
return self
def _fwd_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.arctanh(dist)
return self
Example:
>>> print(chaospy.Uniform().fwd([-0.5, 0.5, 1.5, 2.5]))
[0. 0.5 1. 1. ]
>>> print(chaospy.Pow(chaospy.Uniform(), 2).fwd([-0.5, 0.5, 1.5, 2.5]))
[0. 0.70710678 1. 1. ]
>>> print(chaospy.Pow(chaospy.Uniform(1, 2), -1).fwd([0.4, 0.6, 0.8, 1.2]))
[0. 0.33333333 0.75 1. ]
>>> print(chaospy.Pow(2, chaospy.Uniform()).fwd([-0.5, 0.5, 1.5, 2.5]))
[0. 0. 0.5849625 1. ]
>>> print(chaospy.Pow(2, chaospy.Uniform(-1, 0)).fwd([0.4, 0.6, 0.8, 1.2]))
[0. 0.26303441 0.67807191 1. ]
>>> print(chaospy.Pow(2, 3).fwd([7, 8, 9]))
[0. 1. 1.]
"""
left = evaluation.get_forward_cache(left, cache)
right = evaluation.get_forward_cache(right, cache)
if isinstance(left, Dist):
if isinstance(right, Dist):
raise StochasticallyDependentError(
"under-defined distribution {} or {}".format(left, right))
elif not isinstance(right, Dist):
return numpy.inf
else:
assert numpy.all(left > 0), "imaginary result"
y = (numpy.log(numpy.abs(xloc) + 1.*(xloc <= 0)) /
numpy.log(numpy.abs(left)+1.*(left == 1)))
out = evaluation.evaluate_forward(right, y, cache=cache.copy())
def _inv_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return 10**dist
return self
def _inv_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.arccos(dist)
return self
def _inv_cache(self, cache):
dist = evaluation.get_forward_cache(self.prm["dist"], cache)
if not isinstance(dist, Dist):
return numpy.sinh(dist)
return self
def _fwd_cache(self, cache):
left = evaluation.get_forward_cache(self.prm["left"], cache)
right = evaluation.get_forward_cache(self.prm["right"], cache)
if not isinstance(left, Dist) and not isinstance(right, Dist):
return left*right
return self
def _pdf(self, xloc, left, right, cache):
"""
Probability density function.
Example:
>>> print(chaospy.Uniform().pdf([-2, 0, 2, 4]))
[0. 1. 0. 0.]
>>> print(chaospy.Add(chaospy.Uniform(), 2).pdf([-2, 0, 2, 4]))
[0. 0. 1. 0.]
>>> print(chaospy.Add(2, chaospy.Uniform()).pdf([-2, 0, 2, 4]))
[0. 0. 1. 0.]
>>> print(chaospy.Add(1, 1).pdf([-2, 0, 2, 4])) # Dirac logic
[ 0. 0. inf 0.]
"""
left = evaluation.get_forward_cache(left, cache)
right = evaluation.get_forward_cache(right, cache)
if isinstance(left, Dist):
if isinstance(right, Dist):
raise evaluation.DependencyError(
"under-defined distribution {} or {}".format(left, right))
elif not isinstance(right, Dist):
return numpy.inf
else:
left, right = right, left
xloc = (xloc.T-numpy.asfarray(right).T).T
output = evaluation.evaluate_density(left, xloc, cache=cache)
assert output.shape == xloc.shape
return output