本文整理汇总了Python中sympy.stats.rv.random_symbols函数的典型用法代码示例。如果您正苦于以下问题:Python random_symbols函数的具体用法?Python random_symbols怎么用?Python random_symbols使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random_symbols函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: set
def set(self):
rvs = [i for i in random_symbols(self.args[1])]
marginalise_out = [i for i in random_symbols(self.args[1]) \
if i not in self.args[1]]
for i in rvs:
if i in marginalise_out:
rvs.remove(i)
return ProductSet((i.pspace.set for i in rvs))
开发者ID:normalhuman,项目名称:sympy,代码行数:8,代码来源:joint_rv.py
示例2: where
def where(self, condition):
rvs = frozenset(random_symbols(condition))
if not (len(rvs) == 1 and rvs.issubset(self.values)):
raise NotImplementedError("Multiple continuous random variables not supported")
rv = tuple(rvs)[0]
interval = reduce_rational_inequalities_wrap(condition, rv)
interval = interval.intersect(self.domain.set)
return SingleContinuousDomain(rv.symbol, interval)
开发者ID:brajeshvit,项目名称:virtual,代码行数:8,代码来源:crv.py
示例3: __new__
def __new__(cls,dist, rvs):
if not all([isinstance(rv, (Indexed, RandomSymbol))] for rv in rvs):
raise ValueError(filldedent('''Marginal distribution can be
intitialised only in terms of random variables or indexed random
variables'''))
rvs = Tuple.fromiter(rv for rv in rvs)
if not isinstance(dist, JointDistribution) and len(random_symbols(dist)) == 0:
return dist
return Basic.__new__(cls, dist, rvs)
开发者ID:normalhuman,项目名称:sympy,代码行数:9,代码来源:joint_rv.py
示例4: restricted_domain
def restricted_domain(self, condition):
rvs = random_symbols(condition)
assert all(r.symbol in self.symbols for r in rvs)
if (len(rvs) > 1):
raise NotImplementedError(filldedent('''Multivariate discrete
random variables are not yet supported.'''))
conditional_domain = reduce_rational_inequalities_wrap(condition,
rvs[0])
conditional_domain = conditional_domain.intersect(self.domain.set)
return conditional_domain
开发者ID:carstimon,项目名称:sympy,代码行数:10,代码来源:drv.py
示例5: pdf
def pdf(self, *x):
expr, rvs = self.args[0], self.args[1]
marginalise_out = [i for i in random_symbols(expr) if i not in self.args[1]]
syms = [i.pspace.symbol for i in self.args[1]]
for i in expr.atoms(Indexed):
if isinstance(i, Indexed) and isinstance(i.base, RandomSymbol)\
and i not in rvs:
marginalise_out.append(i)
if isinstance(expr, CompoundDistribution):
syms = Dummy('x', real=True)
expr = expr.args[0].pdf(syms)
elif isinstance(expr, JointDistribution):
count = len(expr.domain.args)
x = Dummy('x', real=True, finite=True)
syms = [Indexed(x, i) for i in count]
expr = expression.pdf(syms)
return Lambda(syms, self.compute_pdf(expr, marginalise_out))(*x)
开发者ID:normalhuman,项目名称:sympy,代码行数:17,代码来源:joint_rv.py
示例6: compute_expectation
def compute_expectation(self, expr, rvs=None, evaluate=False, **kwargs):
syms = tuple(self.value[i] for i in range(self.component_count))
rvs = rvs or syms
if not any([i in rvs for i in syms]):
return expr
expr = expr*self.pdf
for rv in rvs:
if isinstance(rv, Indexed):
expr = expr.xreplace({rv: Indexed(str(rv.base), rv.args[1])})
elif isinstance(rv, RandomSymbol):
expr = expr.xreplace({rv: rv.symbol})
if self.value in random_symbols(expr):
raise NotImplementedError(filldedent('''
Expectations of expression with unindexed joint random symbols
cannot be calculated yet.'''))
limits = tuple((Indexed(str(rv.base),rv.args[1]),
self.distribution.set.args[rv.args[1]]) for rv in syms)
return Integral(expr, *limits)
开发者ID:asmeurer,项目名称:sympy,代码行数:18,代码来源:joint_rv.py
示例7: JointRV
def JointRV(symbol, pdf, _set=None):
"""
Create a Joint Random Variable where each of its component is conitinuous,
given the following:
-- a symbol
-- a PDF in terms of indexed symbols of the symbol given
as the first argument
NOTE: As of now, the set for each component for a `JointRV` is
equal to the set of all integers, which can not be changed.
Returns a RandomSymbol.
Examples
========
>>> from sympy import symbols, exp, pi, Indexed, S
>>> from sympy.stats import density
>>> from sympy.stats.joint_rv_types import JointRV
>>> x1, x2 = (Indexed('x', i) for i in (1, 2))
>>> pdf = exp(-x1**2/2 + x1 - x2**2/2 - S(1)/2)/(2*pi)
>>> N1 = JointRV('x', pdf) #Multivariate Normal distribution
>>> density(N1)(1, 2)
exp(-2)/(2*pi)
"""
#TODO: Add support for sets provided by the user
symbol = sympify(symbol)
syms = list(i for i in pdf.free_symbols if isinstance(i, Indexed)
and i.base == IndexedBase(symbol))
syms.sort(key = lambda index: index.args[1])
_set = S.Reals**len(syms)
pdf = Lambda(syms, pdf)
dist = JointDistributionHandmade(pdf, _set)
jrv = JointPSpace(symbol, dist).value
rvs = random_symbols(pdf)
if len(rvs) != 0:
dist = MarginalDistribution(dist, (jrv,))
return JointPSpace(symbol, dist).value
return jrv
开发者ID:asmeurer,项目名称:sympy,代码行数:42,代码来源:joint_rv_types.py
示例8: probability
def probability(self, condition):
cond_symbols = frozenset(rs.symbol for rs in random_symbols(condition))
assert cond_symbols.issubset(self.symbols)
return sum(self.prob_of(elem) for elem in self.where(condition))
开发者ID:malikdiarra,项目名称:sympy,代码行数:4,代码来源:frv.py
示例9: where
def where(self, condition):
assert all(r.symbol in self.symbols for r in random_symbols(condition))
return ConditionalFiniteDomain(self.domain, condition)
开发者ID:malikdiarra,项目名称:sympy,代码行数:3,代码来源:frv.py
示例10: domain
def domain(self):
rvs = random_symbols(self.distribution)
if len(rvs) == 0:
return SingleDomain(self.symbol, self.set)
return ProductDomain(*[rv.pspace.domain for rv in rvs])
开发者ID:normalhuman,项目名称:sympy,代码行数:5,代码来源:joint_rv.py
示例11: latent_distributions
def latent_distributions(self):
return random_symbols(self.args[0])
开发者ID:normalhuman,项目名称:sympy,代码行数:2,代码来源:joint_rv.py
注:本文中的sympy.stats.rv.random_symbols函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论