def test_given(): X = Normal('X', 0, 1) Y = Normal('Y', 0, 1) A = given(X, True) B = given(X, Y > 2) assert X == A == B
def test_given(): X = Normal("X", 0, 1) Y = Normal("Y", 0, 1) A = given(X, True) B = given(X, Y > 2) assert X == A == B
def test_dependent_finite(): X, Y = Die('X'), Die('Y') # Dependence testing requires symbolic conditions which currently break # finite random variables assert dependent(X, Y + X) XX, YY = given(Tuple(X, Y), X + Y > 5) # Create a dependency assert dependent(XX, YY)
def test_ContinuousDomain(): X = Normal('x', 0, 1) assert where(X**2 <= 1).set == Interval(-1, 1) assert where(X**2 <= 1).symbol == X.symbol where(And(X**2 <= 1, X >= 0)).set == Interval(0, 1) raises(ValueError, lambda: where(sin(X) > 1)) Y = given(X, X >= 0) assert Y.pspace.domain.set == Interval(0, oo)
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)
def test_where(): X, Y = Die(), Die() Z = Normal(0, 1) assert where(Z**2<=1).set == Interval(-1, 1) assert where(Z**2<=1).as_boolean() == Interval(-1,1).as_relational(Z.symbol) assert where(And(X>Y, Y>4)).as_boolean() == And( Eq(X.symbol, 6), Eq(Y.symbol, 5)) assert len(where(X<3).set) == 2 assert 1 in where(X<3).set X, Y = Normal(0, 1), Normal(0, 1) assert where(And(X**2 <= 1, X >= 0)).set == Interval(0, 1) XX = given(X, And(X**2 <= 1, X >= 0)) assert XX.pspace.domain.set == Interval(0, 1) assert XX.pspace.domain.as_boolean() == And(0 <= X.symbol, X.symbol**2 <= 1) with raises(TypeError): XX = given(X, X+3)
def test_dependence(): X, Y = Die('X'), Die('Y') assert independent(X, 2*Y) assert not dependent(X, 2*Y) X, Y = Normal('X', 0, 1), Normal('Y', 0, 1) assert independent(X, Y) assert dependent(X, 2*X) # Create a dependency XX, YY = given(Tuple(X, Y), Eq(X + Y, 3)) assert dependent(XX, YY)
def test_random_parameters_given(): mu = Normal('mu', 2, 3) meas = Normal('T', mu, 1) assert given(meas, Eq(mu, 5)) == Normal('T', 5, 1)
def test_random_parameters_given(): mu = Normal("mu", 2, 3) meas = Normal("T", mu, 1) assert given(meas, Eq(mu, 5)) == Normal("T", 5, 1)
from sympy.stats import given, density, Die ## 6개의 면이 있는 주사위 생성 Die6 = Die("Die6", 6) Die6_dict = density(Die6).dict print(Die6) print(Die6_dict) ## 3 초과의 면만 나오는 조건을 가진 주사위 생성 condi = given(Die6, Die6 > 3) condi_dict = density(condi).dict print(condi) print(condi_dict)