def test_gamma(): k = Symbol('k', positive=True) theta = Symbol('theta', positive=True) X = Gamma('x', k, theta) assert density(X)(x) == x**(k - 1)*theta**(-k)*exp(-x/theta)/gamma(k) assert cdf(X, meijerg=True)(z) == Piecewise( (-k*lowergamma(k, 0)/gamma(k + 1) + k*lowergamma(k, z/theta)/gamma(k + 1), z >= 0), (0, True)) # assert simplify(variance(X)) == k*theta**2 # handled numerically below assert E(X) == moment(X, 1) k, theta = symbols('k theta', real=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})
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 range(niter): assert sample(var) in var.pspace.domain.set
def test_exponential(): rate = Symbol('lambda', positive=True, real=True) X = Exponential('x', rate) assert E(X) == 1 / rate assert variance(X) == 1 / rate**2 assert skewness(X) == 2 assert skewness(X) == smoment(X, 3) assert smoment(2 * X, 4) == smoment(X, 4) assert moment(X, 3) == 3 * 2 * 1 / rate**3 assert P(X > 0) == Integer(1) assert P(X > 1) == exp(-rate) assert P(X > 10) == exp(-10 * rate) assert where(X <= 1).set == Interval(0, 1) # issue sympy/sympy#10003 X = Exponential('x', 3) G = Gamma('g', 1, 2) assert P(X < -1) == 0 assert P(G < -1) == 0
def test_sympyissue_10003(): X = Exponential('x', 3) G = Gamma('g', 1, 2) assert P(X < -1) == 0 assert P(G < -1) == 0
def test_issue_10003(): X = Exponential('x', 3) G = Gamma('g', 1, 2) assert P(X < -1) == S.Zero assert P(G < -1) == S.Zero