本文整理汇总了Python中sympy.Eq.__class__方法的典型用法代码示例。如果您正苦于以下问题:Python Eq.__class__方法的具体用法?Python Eq.__class__怎么用?Python Eq.__class__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Eq
的用法示例。
在下文中一共展示了Eq.__class__方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: probability
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import __class__ [as 别名]
def probability(self, condition, **kwargs):
cond_inv = False
if isinstance(condition, Ne):
condition = Eq(condition.args[0], condition.args[1])
cond_inv = True
expr = condition.lhs - condition.rhs
rvs = random_symbols(expr)
z = Dummy('z', real=True, Finite=True)
dens = self.compute_density(expr)
if any([pspace(rv).is_Continuous for rv in rvs]):
from sympy.stats.crv import (ContinuousDistributionHandmade,
SingleContinuousPSpace)
if expr in self.values:
# Marginalize all other random symbols out of the density
randomsymbols = tuple(set(self.values) - frozenset([expr]))
symbols = tuple(rs.symbol for rs in randomsymbols)
pdf = self.domain.integrate(self.pdf, symbols, **kwargs)
return Lambda(expr.symbol, pdf)
dens = ContinuousDistributionHandmade(dens)
space = SingleContinuousPSpace(z, dens)
result = space.probability(condition.__class__(space.value, 0))
else:
from sympy.stats.drv import (DiscreteDistributionHandmade,
SingleDiscretePSpace)
dens = DiscreteDistributionHandmade(dens)
space = SingleDiscretePSpace(z, dens)
result = space.probability(condition.__class__(space.value, 0))
return result if not cond_inv else S.One - result
示例2: probability
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import __class__ [as 别名]
def probability(self, condition, **kwargs):
z = Dummy('z', real=True, finite=True)
cond_inv = False
if isinstance(condition, Ne):
condition = Eq(condition.args[0], condition.args[1])
cond_inv = True
# Univariate case can be handled by where
try:
domain = self.where(condition)
rv = [rv for rv in self.values if rv.symbol == domain.symbol][0]
# Integrate out all other random variables
pdf = self.compute_density(rv, **kwargs)
# return S.Zero if `domain` is empty set
if domain.set is S.EmptySet or isinstance(domain.set, FiniteSet):
return S.Zero if not cond_inv else S.One
if isinstance(domain.set, Union):
return sum(
Integral(pdf(z), (z, subset), **kwargs) for subset in
domain.set.args if isinstance(subset, Interval))
# Integrate out the last variable over the special domain
return Integral(pdf(z), (z, domain.set), **kwargs)
# Other cases can be turned into univariate case
# by computing a density handled by density computation
except NotImplementedError:
from sympy.stats.rv import density
expr = condition.lhs - condition.rhs
dens = density(expr, **kwargs)
if not isinstance(dens, ContinuousDistribution):
dens = ContinuousDistributionHandmade(dens)
# Turn problem into univariate case
space = SingleContinuousPSpace(z, dens)
result = space.probability(condition.__class__(space.value, 0))
return result if not cond_inv else S.One - result
示例3: probability
# 需要导入模块: from sympy import Eq [as 别名]
# 或者: from sympy.Eq import __class__ [as 别名]
def probability(self, condition):
complement = isinstance(condition, Ne)
if complement:
condition = Eq(condition.args[0], condition.args[1])
try:
_domain = self.where(condition).set
if condition == False or _domain is S.EmptySet:
return S.Zero
if condition == True or _domain == self.domain.set:
return S.One
prob = self.eval_prob(_domain)
except NotImplementedError:
from sympy.stats.rv import density
expr = condition.lhs - condition.rhs
dens = density(expr)
if not isinstance(dens, DiscreteDistribution):
dens = DiscreteDistributionHandmade(dens)
z = Dummy('z', real = True)
space = SingleDiscretePSpace(z, dens)
prob = space.probability(condition.__class__(space.value, 0))
if (prob == None):
prob = Probability(condition)
return prob if not complement else S.One - prob