本文整理汇总了Python中sympy.stats.variance函数的典型用法代码示例。如果您正苦于以下问题:Python variance函数的具体用法?Python variance怎么用?Python variance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了variance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: test_ContinuousRV
def test_ContinuousRV():
x = Symbol('x')
pdf = sqrt(2)*exp(-x**2/2)/(2*sqrt(pi)) # Normal distribution
# X and Y should be equivalent
X = ContinuousRV(x, pdf)
Y = Normal('y', 0, 1)
assert variance(X) == variance(Y)
assert P(X > 0) == P(Y > 0)
开发者ID:vprusso,项目名称:sympy,代码行数:9,代码来源:test_continuous_rv.py
示例3: test_multiple_normal
def test_multiple_normal():
X, Y = Normal('x', 0, 1), Normal('y', 0, 1)
assert E(X + Y) == 0
assert variance(X + Y) == 2
assert variance(X + X) == 4
assert covariance(X, Y) == 0
assert covariance(2*X + Y, -X) == -2*variance(X)
assert E(X, Eq(X + Y, 0)) == 0
assert variance(X, Eq(X + Y, 0)) == S.Half
开发者ID:archipleago-creature,项目名称:sympy,代码行数:11,代码来源:test_continuous_rv.py
示例4: test_literal_probability
def test_literal_probability():
X = Normal('X', 2, 3)
Y = Normal('Y', 3, 4)
Z = Poisson('Z', 4)
W = Poisson('W', 3)
x, y, w, z = symbols('x, y, w, z')
assert Probability(X > 0).doit() == probability(X > 0)
assert Probability(X > x).doit() == probability(X > x)
assert Expectation(X).doit() == expectation(X)
assert Expectation(X**2).doit() == expectation(X**2)
assert Expectation(x*X) == x*Expectation(X)
assert Expectation(2*X + 3*Y + z*X*Y) == 2*Expectation(X) + 3*Expectation(Y) + z*Expectation(X*Y)
assert Expectation(2*X + 3*Y + z*X*Y, evaluate=False).args == (2*X + 3*Y + z*X*Y,)
assert Expectation(sin(X)) == Expectation(sin(X), evaluate=False)
assert Expectation(2*x*sin(X)*Y + y*X**2 + z*X*Y) == 2*x*Expectation(sin(X)*Y) + y*Expectation(X**2) + z*Expectation(X*Y)
assert Variance(w) == 0
assert Variance(X).doit() == variance(X)
assert Variance(X + z) == Variance(X)
assert Variance(X*Y).args == (Mul(X, Y),)
assert type(Variance(X*Y)) == Variance
assert Variance(z*X) == z**2*Variance(X)
assert Variance(X + Y) == Variance(X) + Variance(Y) + 2*Covariance(X, Y)
assert Variance(X + Y + Z + W) == (Variance(X) + Variance(Y) + Variance(Z) + Variance(W) +
2 * Covariance(X, Y) + 2 * Covariance(X, Z) + 2 * Covariance(X, W) +
2 * Covariance(Y, Z) + 2 * Covariance(Y, W) + 2 * Covariance(W, Z))
assert Variance(X**2).doit() == variance(X**2)
assert Variance(X**2, evaluate=False) == Variance(X**2)
assert Variance(x*X**2) == x**2*Variance(X**2)
assert Variance(sin(X)).args == (sin(X),)
assert Variance(sin(X), evaluate=False) == Variance(sin(X))
assert Variance(x*sin(X)) == x**2*Variance(sin(X))
assert Covariance(w, z) == 0
assert Covariance(X, w) == 0
assert Covariance(w, X) == 0
assert Covariance(X, Y).args == (X, Y)
assert type(Covariance(X, Y)) == Covariance
assert Covariance(z*X + 3, Y) == z*Covariance(X, Y)
assert Covariance(X, X) == Variance(X)
assert Covariance(z*X + 3, w*Y + 4) == w*z*Covariance(X,Y)
assert Covariance(X, Y) == Covariance(Y, X)
assert Covariance(X + Y, Z + W) == Covariance(W, X) + Covariance(W, Y) + Covariance(X, Z) + Covariance(Y, Z)
assert Covariance(x*X + y*Y, z*Z + w*W) == (x*w*Covariance(W, X) + w*y*Covariance(W, Y) +
x*z*Covariance(X, Z) + y*z*Covariance(Y, Z))
assert Covariance(x*X**2 + y*sin(Y), z*Y*Z**2 + w*W) == (w*x*Covariance(W, X**2) + w*y*Covariance(sin(Y), W) +
x*z*Covariance(Y*Z**2, X**2) + y*z*Covariance(Y*Z**2, sin(Y)))
assert Covariance(X, X**2) == Covariance(X, X**2, evaluate=False)
assert Covariance(X, sin(X)) == Covariance(sin(X), X, evaluate=False)
assert Covariance(X**2, sin(X)*Y) == Covariance(sin(X)*Y, X**2, evaluate=False)
开发者ID:Asnelchristian,项目名称:sympy,代码行数:52,代码来源:test_symbolic_probability.py
示例5: 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
示例6: 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
示例7: 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
示例8: test_pareto_numeric
def test_pareto_numeric():
xm, beta = 3, 2
alpha = beta + 5
X = Pareto('x', xm, alpha)
assert E(X) == alpha*xm/S(alpha - 1)
assert variance(X) == xm**2*alpha / S(((alpha - 1)**2*(alpha - 2)))
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例9: test_Logarithmic
def test_Logarithmic():
p = S.One / 2
x = Logarithmic('x', p)
assert E(x) == -p / ((1 - p) * log(1 - p))
assert variance(x) == -1/log(2)**2 + 2/log(2)
assert E(2*x**2 + 3*x + 4) == 4 + 7 / log(2)
assert isinstance(E(x, evaluate=False), Sum)
开发者ID:asmeurer,项目名称:sympy,代码行数:7,代码来源:test_discrete_rv.py
示例10: test_rayleigh
def test_rayleigh():
sigma = Symbol("sigma", positive=True)
X = Rayleigh('x', sigma)
assert density(X)(x) == x*exp(-x**2/(2*sigma**2))/sigma**2
assert E(X) == sqrt(2)*sqrt(pi)*sigma/2
assert variance(X) == -pi*sigma**2/2 + 2*sigma**2
开发者ID:vprusso,项目名称:sympy,代码行数:7,代码来源:test_continuous_rv.py
示例11: test_bernoulli
def test_bernoulli():
p, a, b, t = symbols('p a b t')
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
assert characteristic_function(X)(t) == p * exp(I * a * t) + (-p + 1) * exp(I * b * t)
assert moment_generating_function(X)(t) == p * exp(a * t) + (-p + 1) * exp(b * t)
X = Bernoulli('B', p, 1, 0)
assert E(X) == p
assert simplify(variance(X)) == p*(1 - p)
assert E(a*X + b) == a*E(X) + b
assert simplify(variance(a*X + b)) == simplify(a**2 * variance(X))
开发者ID:Lenqth,项目名称:sympy,代码行数:16,代码来源:test_finite_rv.py
示例12: test_gamma
def test_gamma():
k = Symbol("k", positive=True)
theta = Symbol("theta", positive=True)
X = Gamma('x', k, theta)
assert density(X) == Lambda(_x,
_x**(k - 1)*theta**(-k)*exp(-_x/theta)/gamma(k))
assert cdf(X, meijerg=True) == Lambda(_z, Piecewise(
(-k*lowergamma(k, 0)/gamma(k + 1) + k*lowergamma(k, _z/theta)/gamma(k + 1), _z >= 0), (0, True)))
assert variance(X) == (-theta**2*gamma(k + 1)**2/gamma(k)**2 +
theta*theta**(-k)*theta**(k + 1)*gamma(k + 2)/gamma(k))
k, theta = symbols('k theta', real=True, bounded=True, positive=True)
X = Gamma('x', k, theta)
assert simplify(E(X)) == k*theta
# can't get things to simplify on this one so we use subs
assert variance(X).subs(k, 5) == (k*theta**2).subs(k, 5)
开发者ID:archipleago-creature,项目名称:sympy,代码行数:17,代码来源:test_continuous_rv.py
示例13: test_negative_binomial
def test_negative_binomial():
r = 5
p = S(1) / 3
x = NegativeBinomial('x', r, p)
assert E(x) == p*r / (1-p)
assert variance(x) == p*r / (1-p)**2
assert E(x**5 + 2*x + 3) == S(9207)/4
assert isinstance(E(x, evaluate=False), Sum)
开发者ID:asmeurer,项目名称:sympy,代码行数:8,代码来源:test_discrete_rv.py
示例14: test_Poisson
def test_Poisson():
l = 3
x = Poisson('x', l)
assert E(x) == l
assert variance(x) == l
assert density(x) == PoissonDistribution(l)
assert isinstance(E(x, evaluate=False), Sum)
assert isinstance(E(2*x, evaluate=False), Sum)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:8,代码来源:test_discrete_rv.py
示例15: test_rayleigh
def test_rayleigh():
sigma = Symbol("sigma", positive=True)
x = Symbol("x")
X = Rayleigh(sigma, symbol=x)
assert density(X) == Lambda(_x, _x*exp(-_x**2/(2*sigma**2))/sigma**2)
assert E(X) == sqrt(2)*sqrt(pi)*sigma/2
assert variance(X) == -pi*sigma**2/2 + 2*sigma**2
开发者ID:BDGLunde,项目名称:sympy,代码行数:8,代码来源:test_continuous_rv.py
示例16: test_symbolic
def test_symbolic():
mu1, mu2 = symbols("mu1 mu2", real=True, bounded=True)
s1, s2 = symbols("sigma1 sigma2", real=True, bounded=True, positive=True)
rate = Symbol("lambda", real=True, positive=True, bounded=True)
X = Normal("x", mu1, s1)
Y = Normal("y", mu2, s2)
Z = Exponential("z", rate)
a, b, c = symbols("a b c", real=True, bounded=True)
assert E(X) == mu1
assert E(X + Y) == mu1 + mu2
assert E(a * X + b) == a * E(X) + b
assert variance(X) == s1 ** 2
assert simplify(variance(X + a * Y + b)) == variance(X) + a ** 2 * variance(Y)
assert E(Z) == 1 / rate
assert E(a * Z + b) == a * E(Z) + b
assert E(X + a * Z + b) == mu1 + a / rate + b
开发者ID:Maihj,项目名称:sympy,代码行数:18,代码来源:test_continuous_rv.py
示例17: test_Poisson
def test_Poisson():
l = 3
x = Poisson('x', l)
assert E(x) == l
assert variance(x) == l
assert density(x) == PoissonDistribution(l)
assert isinstance(E(x, evaluate=False), Sum)
assert isinstance(E(2*x, evaluate=False), Sum)
assert characteristic_function(x)(0).doit() == 1
开发者ID:carstimon,项目名称:sympy,代码行数:9,代码来源:test_discrete_rv.py
示例18: test_symbolic
def test_symbolic():
mu1, mu2 = symbols('mu1 mu2', real=True, finite=True)
s1, s2 = symbols('sigma1 sigma2', real=True, finite=True, positive=True)
rate = Symbol('lambda', real=True, positive=True, finite=True)
X = Normal('x', mu1, s1)
Y = Normal('y', mu2, s2)
Z = Exponential('z', rate)
a, b, c = symbols('a b c', real=True, finite=True)
assert E(X) == mu1
assert E(X + Y) == mu1 + mu2
assert E(a*X + b) == a*E(X) + b
assert variance(X) == s1**2
assert simplify(variance(X + a*Y + b)) == variance(X) + a**2*variance(Y)
assert E(Z) == 1/rate
assert E(a*Z + b) == a*E(Z) + b
assert E(X + a*Z + b) == mu1 + a/rate + b
开发者ID:vprusso,项目名称:sympy,代码行数:18,代码来源:test_continuous_rv.py
示例19: 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
示例20: test_maxwell
def test_maxwell():
a = Symbol("a", positive=True)
x = Symbol("x")
X = Maxwell(a, symbol=x)
assert density(X) == (Lambda(_x, sqrt(2)*_x**2*exp(-_x**2/(2*a**2))/
(sqrt(pi)*a**3)))
assert E(X) == 2*sqrt(2)*a/sqrt(pi)
assert simplify(variance(X)) == a**2*(-8 + 3*pi)/pi
开发者ID:BDGLunde,项目名称:sympy,代码行数:10,代码来源:test_continuous_rv.py
注:本文中的sympy.stats.variance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论