Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
out = numpy.where(xloc <= 0, 0., out)
return out
y = numpy.sign(xloc)*numpy.abs(xloc)**(1./right)
pairs = numpy.sign(xloc**right) != -1
out1, out2 = (
evaluation.evaluate_forward(left, y, cache=cache),
evaluation.evaluate_forward(left, -y, cache=cache),
)
out = numpy.where(right < 0, 1-out1, out1-pairs*out2)
return out
def _cdf(self, x, dist, cache):
return evaluation.evaluate_forward(dist, numpy.arcsinh(x), cache=cache)
def _cdf(self, x, dist, cache):
return evaluation.evaluate_forward(dist, numpy.arctan(x))
def _cdf(self, xloc, dist, cache):
"""Cumulative distribution function."""
return evaluation.evaluate_forward(dist, 10**xloc, cache=cache)
>>> approximate_density(distribution, xloc).round(4)
array([[0.0242, 0.0399, 0.0242]])
>>> distribution.pdf(xloc).round(4)
array([[0.0242, 0.0399, 0.0242]])
"""
if parameters is None:
parameters = dist.prm.copy()
if cache is None:
cache = {}
xloc = numpy.asfarray(xloc)
lo, up = numpy.min(xloc), numpy.max(xloc)
mu = .5*(lo+up)
eps = numpy.where(xloc < mu, eps, -eps)*xloc
floc = evaluation.evaluate_forward(
dist, xloc, parameters=parameters.copy(), cache=cache.copy())
for d in range(len(dist)):
xloc[d] += eps[d]
tmp = evaluation.evaluate_forward(
dist, xloc, parameters=parameters.copy(), cache=cache.copy())
floc[d] -= tmp[d]
xloc[d] -= eps[d]
floc = numpy.abs(floc / eps)
return floc
"""
if parameters is None:
parameters = dist.prm.copy()
if cache is None:
cache = {}
xloc = numpy.asfarray(xloc)
lo, up = numpy.min(xloc), numpy.max(xloc)
mu = .5*(lo+up)
eps = numpy.where(xloc < mu, eps, -eps)*xloc
floc = evaluation.evaluate_forward(
dist, xloc, parameters=parameters.copy(), cache=cache.copy())
for d in range(len(dist)):
xloc[d] += eps[d]
tmp = evaluation.evaluate_forward(
dist, xloc, parameters=parameters.copy(), cache=cache.copy())
floc[d] -= tmp[d]
xloc[d] -= eps[d]
floc = numpy.abs(floc / eps)
return floc
def _cdf(self, x, dist, cache):
return evaluation.evaluate_forward(dist, numpy.sin(x), cache=cache)
if isinstance(left, Dist):
if isinstance(right, Dist):
raise StochasticallyDependentError(
"under-defined distribution {} or {}".format(left, right))
right = (numpy.array(right).T*numpy.ones(q.shape).T).T
uloc = evaluation.evaluate_forward(left, right, cache=cache.copy())
out = evaluation.evaluate_inverse(left, q*uloc, cache=cache)
elif not isinstance(right, Dist):
raise StochasticallyDependentError(
"truncated variable indirectly depends on underlying variable")
else:
left = (numpy.array(left).T*numpy.ones(q.shape).T).T
uloc = evaluation.evaluate_forward(right, left)
out = evaluation.evaluate_inverse(right, q*(1-uloc)+uloc, cache=cache)
return out
def _cdf(self, x, dist, cache):
return evaluation.evaluate_forward(dist, numpy.arccosh(x), cache=cache)