本文整理汇总了Python中sympy.stats.density函数的典型用法代码示例。如果您正苦于以下问题:Python density函数的具体用法?Python density怎么用?Python density使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了density函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_rademacher
def test_rademacher():
X = Rademacher('X')
assert E(X) == 0
assert variance(X) == 1
assert density(X)[-1] == S.Half
assert density(X)[1] == S.Half
开发者ID:MCGallaspy,项目名称:sympy,代码行数:7,代码来源:test_finite_rv.py
示例2: test_discreteuniform
def test_discreteuniform():
# Symbolic
a, b, c, t = symbols('a b c t')
X = DiscreteUniform('X', [a, b, c])
assert E(X) == (a + b + c)/3
assert simplify(variance(X)
- ((a**2 + b**2 + c**2)/3 - (a/3 + b/3 + c/3)**2)) == 0
assert P(Eq(X, a)) == P(Eq(X, b)) == P(Eq(X, c)) == S('1/3')
Y = DiscreteUniform('Y', range(-5, 5))
# Numeric
assert E(Y) == S('-1/2')
assert variance(Y) == S('33/4')
for x in range(-5, 5):
assert P(Eq(Y, x)) == S('1/10')
assert P(Y <= x) == S(x + 6)/10
assert P(Y >= x) == S(5 - x)/10
assert dict(density(Die('D', 6)).items()) == \
dict(density(DiscreteUniform('U', range(1, 7))).items())
assert characteristic_function(X)(t) == exp(I*a*t)/3 + exp(I*b*t)/3 + exp(I*c*t)/3
assert moment_generating_function(X)(t) == exp(a*t)/3 + exp(b*t)/3 + exp(c*t)/3
开发者ID:Lenqth,项目名称:sympy,代码行数:26,代码来源:test_finite_rv.py
示例3: test_lognormal
def test_lognormal():
mean = Symbol('mu', real=True, finite=True)
std = Symbol('sigma', positive=True, real=True, finite=True)
X = LogNormal('x', mean, std)
# The sympy integrator can't do this too well
#assert E(X) == exp(mean+std**2/2)
#assert variance(X) == (exp(std**2)-1) * exp(2*mean + std**2)
# Right now, only density function and sampling works
# Test sampling: Only e^mean in sample std of 0
for i in range(3):
X = LogNormal('x', i, 0)
assert S(sample(X)) == N(exp(i))
# The sympy integrator can't do this too well
#assert E(X) ==
mu = Symbol("mu", real=True)
sigma = Symbol("sigma", positive=True)
X = LogNormal('x', mu, sigma)
assert density(X)(x) == (sqrt(2)*exp(-(-mu + log(x))**2
/(2*sigma**2))/(2*x*sqrt(pi)*sigma))
X = LogNormal('x', 0, 1) # Mean 0, standard deviation 1
assert density(X)(x) == sqrt(2)*exp(-log(x)**2/2)/(2*x*sqrt(pi))
开发者ID:vprusso,项目名称:sympy,代码行数:25,代码来源:test_continuous_rv.py
示例4: test_multivariate_laplace
def test_multivariate_laplace():
from sympy.stats.crv_types import Laplace
raises(ValueError, lambda: Laplace('T', [1, 2], [[1, 2], [2, 1]]))
L = Laplace('L', [1, 0], [[1, 2], [0, 1]])
assert density(L)(2, 3) == exp(2)*besselk(0, sqrt(3))/pi
L1 = Laplace('L1', [1, 2], [[x, 0], [0, y]])
assert density(L1)(0, 1) == \
exp(2/y)*besselk(0, sqrt((2 + 4/y + 1/x)/y))/(pi*sqrt(x*y))
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_joint_rv.py
示例5: test_difficult_univariate
def test_difficult_univariate():
""" Since using solve in place of deltaintegrate we're able to perform
substantially more complex density computations on single continuous random
variables """
x = Normal('x', 0, 1)
assert density(x**3)
assert density(exp(x**2))
assert density(log(x))
开发者ID:vprusso,项目名称:sympy,代码行数:8,代码来源:test_continuous_rv.py
示例6: test_MultivariateTDist
def test_MultivariateTDist():
from sympy.stats.joint_rv_types import MultivariateT
t1 = MultivariateT('T', [0, 0], [[1, 0], [0, 1]], 2)
assert(density(t1))(1, 1) == 1/(8*pi)
assert integrate(density(t1)(x, y), (x, -oo, oo), \
(y, -oo, oo)).evalf() == 1
raises(ValueError, lambda: MultivariateT('T', [1, 2], [[1, 1], [1, -1]], 1))
t2 = MultivariateT('t2', [1, 2], [[x, 0], [0, y]], 1)
assert density(t2)(1, 2) == 1/(2*pi*sqrt(x*y))
开发者ID:asmeurer,项目名称:sympy,代码行数:9,代码来源:test_joint_rv.py
示例7: test_rademacher
def test_rademacher():
X = Rademacher('X')
t = Symbol('t')
assert E(X) == 0
assert variance(X) == 1
assert density(X)[-1] == S.Half
assert density(X)[1] == S.Half
assert characteristic_function(X)(t) == exp(I*t)/2 + exp(-I*t)/2
assert moment_generating_function(X)(t) == exp(t) / 2 + exp(-t) / 2
开发者ID:Lenqth,项目名称:sympy,代码行数:10,代码来源:test_finite_rv.py
示例8: test_conditional_1d
def test_conditional_1d():
X = Normal('x', 0, 1)
Y = given(X, X >= 0)
assert density(Y) == 2 * density(X)
assert Y.pspace.domain.set == Interval(0, oo)
assert E(Y) == sqrt(2) / sqrt(pi)
assert E(X**2) == E(Y**2)
开发者ID:vprusso,项目名称:sympy,代码行数:10,代码来源:test_continuous_rv.py
示例9: test_cauchy
def test_cauchy():
x0 = Symbol("x0")
gamma = Symbol("gamma", positive=True)
X = Cauchy('x', x0, gamma)
assert density(X)(x) == 1/(pi*gamma*(1 + (x - x0)**2/gamma**2))
assert cdf(X)(x) == atan((x - x0)/gamma)/pi + S.Half
assert diff(cdf(X)(x), x) == density(X)(x)
gamma = Symbol("gamma", positive=False)
raises(ValueError, lambda: Cauchy('x', x0, gamma))
开发者ID:bjodah,项目名称:sympy,代码行数:11,代码来源:test_continuous_rv.py
示例10: test_Normal
def test_Normal():
m = Normal('A', [1, 2], [[1, 0], [0, 1]])
assert density(m)(1, 2) == 1/(2*pi)
raises (ValueError,\
lambda: Normal('M',[1, 2], [[0, 0], [0, 1]]))
n = Normal('B', [1, 2, 3], [[1, 0, 0], [0, 1, 0], [0, 0, 1]])
p = Normal('C', Matrix([1, 2]), Matrix([[1, 0], [0, 1]]))
assert density(m)(x, y) == density(p)(x, y)
assert marginal_distribution(n, 0, 1)(1, 2) == 1/(2*pi)
assert integrate(density(m)(x, y), (x, -oo, oo), (y, -oo, oo)).evalf() == 1
N1 = Normal('N1', [1, 2], [[x, 0], [0, y]])
assert str(density(N1)(0, 0)) == "exp(-(4*x + y)/(2*x*y))/(2*pi*sqrt(x*y))"
raises (ValueError, lambda: Normal('M', [1, 2], [[1, 1], [1, -1]]))
开发者ID:normalhuman,项目名称:sympy,代码行数:14,代码来源:test_joint_rv.py
示例11: test_bernoulli
def test_bernoulli():
p, a, b = symbols('p a b')
X = Bernoulli('B', p, a, b)
assert E(X) == a*p + b*(-p + 1)
assert density(X)[a] == p
assert density(X)[b] == 1 - p
X = Bernoulli('B', p, 1, 0)
assert E(X) == p
assert simplify(variance(X)) == p*(1 - p)
E(a*X + b) == a*E(X) + b
variance(a*X + b) == a**2 * variance(X)
开发者ID:MCGallaspy,项目名称:sympy,代码行数:14,代码来源:test_finite_rv.py
示例12: test_bernoulli
def test_bernoulli():
p, a, b = symbols("p a b")
X = Bernoulli(p, a, b, symbol="B")
assert E(X) == a * p + b * (-p + 1)
assert density(X)[a] == p
assert density(X)[b] == 1 - p
X = Bernoulli(p, 1, 0, symbol="B")
assert E(X) == p
assert variance(X) == -p ** 2 + p
E(a * X + b) == a * E(X) + b
variance(a * X + b) == a ** 2 * variance(X)
开发者ID:BDGLunde,项目名称:sympy,代码行数:14,代码来源:test_finite_rv.py
示例13: test_coins
def test_coins():
C, D = Coin("C"), Coin("D")
H, T = symbols("H, T")
assert P(Eq(C, D)) == S.Half
assert density(Tuple(C, D)) == {(H, H): S.One / 4, (H, T): S.One / 4, (T, H): S.One / 4, (T, T): S.One / 4}
assert dict(density(C).items()) == {H: S.Half, T: S.Half}
F = Coin("F", S.One / 10)
assert P(Eq(F, H)) == S(1) / 10
d = pspace(C).domain
assert d.as_boolean() == Or(Eq(C.symbol, H), Eq(C.symbol, T))
raises(ValueError, lambda: P(C > D)) # Can't intelligently compare H to T
开发者ID:rpmuller,项目名称:sympy,代码行数:15,代码来源:test_finite_rv.py
示例14: test_coins
def test_coins():
C, D = Coin(), Coin()
H, T = sorted(density(C).keys())
assert P(Eq(C, D)) == S.Half
assert density(Tuple(C, D)) == {(H, H): S.One / 4, (H, T): S.One / 4, (T, H): S.One / 4, (T, T): S.One / 4}
assert density(C) == {H: S.Half, T: S.Half}
E = Coin(S.One / 10)
assert P(Eq(E, H)) == S(1) / 10
d = pspace(C).domain
assert d.as_boolean() == Or(Eq(C.symbol, H), Eq(C.symbol, T))
raises(ValueError, lambda: P(C > D)) # Can't intelligently compare H to T
开发者ID:BDGLunde,项目名称:sympy,代码行数:15,代码来源:test_finite_rv.py
示例15: test_uniformsum
def test_uniformsum():
n = Symbol("n", integer=True)
_k = Symbol("k")
X = UniformSum('x', n)
assert density(X)(x) == (Sum((-1)**_k*(-_k + x)**(n - 1)
*binomial(n, _k), (_k, 0, floor(x)))/factorial(n - 1))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例16: test_quadratic_u
def test_quadratic_u():
a = Symbol("a", real=True)
b = Symbol("b", real=True)
X = QuadraticU("x", a, b)
assert density(X)(x) == (Piecewise((12*(x - a/2 - b/2)**2/(-a + b)**3,
And(x <= b, a <= x)), (0, True)))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例17: test_raised_cosine
def test_raised_cosine():
mu = Symbol("mu", real=True)
s = Symbol("s", positive=True)
X = RaisedCosine("x", mu, s)
assert density(X)(x) == (Piecewise(((cos(pi*(x - mu)/s) + 1)/(2*s),
And(x <= mu + s, mu - s <= x)), (0, True)))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例18: test_frechet
def test_frechet():
a = Symbol("a", positive=True)
s = Symbol("s", positive=True)
m = Symbol("m", real=True)
X = Frechet("x", a, s=s, m=m)
assert density(X)(x) == a*((x - m)/s)**(-a - 1)*exp(-((x - m)/s)**(-a))/s
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例19: test_fisher_z
def test_fisher_z():
d1 = Symbol("d1", positive=True)
d2 = Symbol("d2", positive=True)
X = FisherZ("x", d1, d2)
assert density(X)(x) == (2*d1**(d1/2)*d2**(d2/2)*(d1*exp(2*x) + d2)
**(-d1/2 - d2/2)*exp(d1*x)/beta(d1/2, d2/2))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例20: test_f_distribution
def test_f_distribution():
d1 = Symbol("d1", positive=True)
d2 = Symbol("d2", positive=True)
X = FDistribution("x", d1, d2)
assert density(X)(x) == (d2**(d2/2)*sqrt((d1*x)**d1*(d1*x + d2)**(-d1 - d2))
/(x*beta(d1/2, d2/2)))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
注:本文中的sympy.stats.density函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论