本文整理汇总了Python中sympy.stats.sample函数的典型用法代码示例。如果您正苦于以下问题:Python sample函数的具体用法?Python sample怎么用?Python sample使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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))
示例2: test_Sample
def test_Sample():
X = Die(6)
Y = Normal(0,1)
z = Symbol('z')
assert sample(X) in [1,2,3,4,5,6]
assert sample(X+Y).is_Float
P(X+Y>0, Y<0, numsamples=10).is_number
assert E(X+Y, numsamples=10).is_number
assert variance(X+Y, numsamples=10).is_number
raises(ValueError, lambda: P(Y>z, numsamples=5))
assert P(sin(Y)<=1, numsamples=10) == 1
assert P(sin(Y)<=1, cos(Y)<1, numsamples=10) == 1
# Make sure this doesn't raise an error
E(Sum(1/z**Y, (z,1,oo)), Y>2, numsamples=3)
示例3: test_prefab_sampling
def test_prefab_sampling():
N = Normal('X', 0, 1)
L = LogNormal('L', 0, 1)
E = Exponential('Ex', 1)
P = Pareto('P', 1, 3)
W = Weibull('W', 1, 1)
U = Uniform('U', 0, 1)
B = Beta('B', 2, 5)
G = Gamma('G', 1, 3)
variables = [N, L, E, P, W, U, B, G]
niter = 10
for var in variables:
for i in xrange(niter):
assert sample(var) in var.pspace.domain.set
示例4: test_sample
def test_sample():
z = Symbol('z')
Z = ContinuousRV(z, exp(-z), set=Interval(0, oo))
assert sample(Z) in Z.pspace.domain.set
sym, val = Z.pspace.sample().items()[0]
assert sym == Z and val in Interval(0, oo)
示例5: test_given
def test_given():
X = Die('X', 6)
assert density(X, X > 5) == {S(6): S(1)}
assert where(X > 2, X > 5).as_boolean() == Eq(X.symbol, 6)
assert sample(X, X > 5) == 6
示例6: test_given
def test_given():
X = Die(6)
density(X, X > 5) == {S(6): S(1)}
where(X > 2, X > 5).as_boolean() == Eq(X.symbol, 6)
sample(X, X > 5) == 6