def test_overlap(): X = Normal('x', 0, 1) Y = Normal('x', 0, 2) raises(ValueError, lambda: P(X > Y))
def test_Normal(): m = Normal('A', [1, 2], [[1, 0], [0, 1]]) A = MultivariateNormal('A', [1, 2], [[1, 0], [0, 1]]) assert m == A assert density(m)(1, 2) == 1 / (2 * pi) assert m.pspace.distribution.set == ProductSet(S.Reals, S.Reals) raises(ValueError, lambda: m[2]) 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) raises(ValueError, lambda: marginal_distribution(m)) assert integrate(density(m)(x, y), (x, -oo, oo), (y, -oo, oo)).evalf() == 1 N = Normal('N', [1, 2], [[x, 0], [0, y]]) assert density(N)(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]])) # symbolic n = symbols('n', natural=True) mu = MatrixSymbol('mu', n, 1) sigma = MatrixSymbol('sigma', n, n) X = Normal('X', mu, sigma) assert density(X) == MultivariateNormalDistribution(mu, sigma) raises(NotImplementedError, lambda: median(m)) # Below tests should work after issue #17267 is resolved # assert E(X) == mu # assert variance(X) == sigma # test symbolic multivariate normal densities n = 3 Sg = MatrixSymbol('Sg', n, n) mu = MatrixSymbol('mu', n, 1) obs = MatrixSymbol('obs', n, 1) X = MultivariateNormal('X', mu, Sg) density_X = density(X) eval_a = density_X(obs).subs({ Sg: eye(3), mu: Matrix([0, 0, 0]), obs: Matrix([0, 0, 0]) }).doit() eval_b = density_X(0, 0, 0).subs({ Sg: eye(3), mu: Matrix([0, 0, 0]) }).doit() assert eval_a == sqrt(2) / (4 * pi**Rational(3 / 2)) assert eval_b == sqrt(2) / (4 * pi**Rational(3 / 2)) n = symbols('n', natural=True) Sg = MatrixSymbol('Sg', n, n) mu = MatrixSymbol('mu', n, 1) obs = MatrixSymbol('obs', n, 1) X = MultivariateNormal('X', mu, Sg) density_X_at_obs = density(X)(obs) expected_density = MatrixElement( exp((S(1)/2) * (mu.T - obs.T) * Sg**(-1) * (-mu + obs)) / \ sqrt((2*pi)**n * Determinant(Sg)), 0, 0) assert density_X_at_obs == expected_density
def test_union(): N = Normal('N', 3, 2) assert simplify(P(N**2 - N > 2)) == \ -erf(sqrt(2))/2 - erfc(sqrt(2)/4)/2 + S(3)/2 assert simplify(P(N**2 - 4 > 0)) == \ -erf(5*sqrt(2)/4)/2 - erfc(sqrt(2)/4)/2 + S(3)/2
def sample_normal(mu, std): return int(sample(Normal('temp_normal', mu, std)))
def test_density_unevaluated(): X = Normal('X', 0, 1) Y = Normal('Y', 0, 2) assert isinstance(density(X + Y, evaluate=False)(z), Integral)
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_literal_probability(): X = Normal('X', 2, 3) Y = Normal('Y', 3, 4) Z = Poisson('Z', 4) W = Poisson('W', 3) x = symbols('x', real=True) y, w, z = symbols('y, w, z') assert Probability(X > 0).evaluate_integral() == probability(X > 0) assert Probability(X > x).evaluate_integral() == probability(X > x) assert Probability(X > 0).rewrite(Integral).doit() == probability(X > 0) assert Probability(X > x).rewrite(Integral).doit() == probability(X > x) assert Expectation(X).evaluate_integral() == expectation(X) assert Expectation(X).rewrite(Integral).doit() == expectation(X) assert Expectation(X**2).evaluate_integral() == expectation(X**2) assert Expectation(x * X).args == (x * X, ) assert Expectation(x * X).doit() == x * Expectation(X) assert Expectation(2 * X + 3 * Y + z * X * Y).doit( ) == 2 * Expectation(X) + 3 * Expectation(Y) + z * Expectation(X * Y) assert Expectation(2 * X + 3 * Y + z * X * Y).args == (2 * X + 3 * Y + z * X * Y, ) assert Expectation(sin(X)) == Expectation(sin(X)).doit() assert Expectation( 2 * x * sin(X) * Y + y * X**2 + z * X * Y).doit() == 2 * x * Expectation(sin(X) * Y) + y * Expectation( X**2) + z * Expectation(X * Y) assert Variance(w).args == (w, ) assert Variance(w).doit() == 0 assert Variance(X).evaluate_integral() == Variance(X).rewrite( Integral).doit() == variance(X) assert Variance(X + z).args == (X + z, ) assert Variance(X + z).doit() == Variance(X) assert Variance(X * Y).args == (Mul(X, Y), ) assert type(Variance(X * Y)) == Variance assert Variance(z * X).doit() == z**2 * Variance(X) assert Variance( X + Y).doit() == Variance(X) + Variance(Y) + 2 * Covariance(X, Y) assert Variance(X + Y + Z + W).doit() == (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).evaluate_integral() == variance(X**2) assert unchanged(Variance, X**2) assert Variance(x * X**2).doit() == x**2 * Variance(X**2) assert Variance(sin(X)).args == (sin(X), ) assert Variance(sin(X)).doit() == Variance(sin(X)) assert Variance(x * sin(X)).doit() == x**2 * Variance(sin(X)) assert Covariance(w, z).args == (w, z) assert Covariance(w, z).doit() == 0 assert Covariance(X, w).doit() == 0 assert Covariance(w, X).doit() == 0 assert Covariance(X, Y).args == (X, Y) assert type(Covariance(X, Y)) == Covariance assert Covariance(z * X + 3, Y).doit() == z * Covariance(X, Y) assert Covariance(X, X).args == (X, X) assert Covariance(X, X).doit() == Variance(X) assert Covariance(z * X + 3, w * Y + 4).doit() == w * z * Covariance(X, Y) assert Covariance(X, Y) == Covariance(Y, X) assert Covariance(X + Y, Z + W).doit() == Covariance(W, X) + Covariance( W, Y) + Covariance(X, Z) + Covariance(Y, Z) assert Covariance( x * X + y * Y, z * Z + w * W).doit() == (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).doit() == (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).doit() == Covariance(X, X**2) assert Covariance(X, sin(X)).doit() == Covariance(sin(X), X) assert Covariance(X**2, sin(X) * Y).doit() == Covariance(sin(X) * Y, X**2)
def test_moment_generating_function(): t = symbols('t', positive=True) # Symbolic tests a, b, c = symbols('a b c') mgf = moment_generating_function(Beta('x', a, b))(t) assert mgf == hyper((a, ), (a + b, ), t) mgf = moment_generating_function(Chi('x', a))(t) assert mgf == sqrt(2)*t*gamma(a/2 + S(1)/2)*\ hyper((a/2 + S(1)/2,), (S(3)/2,), t**2/2)/gamma(a/2) +\ hyper((a/2,), (S(1)/2,), t**2/2) mgf = moment_generating_function(ChiSquared('x', a))(t) assert mgf == (1 - 2 * t)**(-a / 2) mgf = moment_generating_function(Erlang('x', a, b))(t) assert mgf == (1 - t / b)**(-a) mgf = moment_generating_function(Exponential('x', a))(t) assert mgf == a / (a - t) mgf = moment_generating_function(Gamma('x', a, b))(t) assert mgf == (-b * t + 1)**(-a) mgf = moment_generating_function(Gumbel('x', a, b))(t) assert mgf == exp(b * t) * gamma(-a * t + 1) mgf = moment_generating_function(Gompertz('x', a, b))(t) assert mgf == b * exp(b) * expint(t / a, b) mgf = moment_generating_function(Laplace('x', a, b))(t) assert mgf == exp(a * t) / (-b**2 * t**2 + 1) mgf = moment_generating_function(Logistic('x', a, b))(t) assert mgf == exp(a * t) * beta(-b * t + 1, b * t + 1) mgf = moment_generating_function(Normal('x', a, b))(t) assert mgf == exp(a * t + b**2 * t**2 / 2) mgf = moment_generating_function(Pareto('x', a, b))(t) assert mgf == b * (-a * t)**b * uppergamma(-b, -a * t) mgf = moment_generating_function(QuadraticU('x', a, b))(t) assert str(mgf) == ( "(3*(t*(-4*b + (a + b)**2) + 4)*exp(b*t) - " "3*(t*(a**2 + 2*a*(b - 2) + b**2) + 4)*exp(a*t))/(t**2*(a - b)**3)") mgf = moment_generating_function(RaisedCosine('x', a, b))(t) assert mgf == pi**2 * exp(a * t) * sinh(b * t) / (b * t * (b**2 * t**2 + pi**2)) mgf = moment_generating_function(Rayleigh('x', a))(t) assert mgf == sqrt(2)*sqrt(pi)*a*t*(erf(sqrt(2)*a*t/2) + 1)\ *exp(a**2*t**2/2)/2 + 1 mgf = moment_generating_function(Triangular('x', a, b, c))(t) assert str(mgf) == ("(-2*(-a + b)*exp(c*t) + 2*(-a + c)*exp(b*t) + " "2*(b - c)*exp(a*t))/(t**2*(-a + b)*(-a + c)*(b - c))") mgf = moment_generating_function(Uniform('x', a, b))(t) assert mgf == (-exp(a * t) + exp(b * t)) / (t * (-a + b)) mgf = moment_generating_function(UniformSum('x', a))(t) assert mgf == ((exp(t) - 1) / t)**a mgf = moment_generating_function(WignerSemicircle('x', a))(t) assert mgf == 2 * besseli(1, a * t) / (a * t) # Numeric tests mgf = moment_generating_function(Beta('x', 1, 1))(t) assert mgf.diff(t).subs(t, 1) == hyper((2, ), (3, ), 1) / 2 mgf = moment_generating_function(Chi('x', 1))(t) assert mgf.diff(t).subs(t, 1) == sqrt(2) * hyper( (1, ), (S(3) / 2, ), S(1) / 2) / sqrt(pi) + hyper((S(3) / 2, ), (S(3) / 2, ), S(1) / 2) + 2 * sqrt(2) * hyper( (2, ), (S(5) / 2, ), S(1) / 2) / (3 * sqrt(pi)) mgf = moment_generating_function(ChiSquared('x', 1))(t) assert mgf.diff(t).subs(t, 1) == I mgf = moment_generating_function(Erlang('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == 1 mgf = moment_generating_function(Exponential('x', 1))(t) assert mgf.diff(t).subs(t, 0) == 1 mgf = moment_generating_function(Gamma('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == 1 mgf = moment_generating_function(Gumbel('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == EulerGamma + 1 mgf = moment_generating_function(Gompertz('x', 1, 1))(t) assert mgf.diff(t).subs(t, 1) == -e * meijerg(((), (1, 1)), ((0, 0, 0), ()), 1) mgf = moment_generating_function(Laplace('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == 1 mgf = moment_generating_function(Logistic('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == beta(1, 1) mgf = moment_generating_function(Normal('x', 0, 1))(t) assert mgf.diff(t).subs(t, 1) == exp(S(1) / 2) mgf = moment_generating_function(Pareto('x', 1, 1))(t) assert mgf.diff(t).subs(t, 0) == expint(1, 0) mgf = moment_generating_function(QuadraticU('x', 1, 2))(t) assert mgf.diff(t).subs(t, 1) == -12 * e - 3 * exp(2) mgf = moment_generating_function(RaisedCosine('x', 1, 1))(t) assert mgf.diff(t).subs(t, 1) == -2*e*pi**2*sinh(1)/\ (1 + pi**2)**2 + e*pi**2*cosh(1)/(1 + pi**2) mgf = moment_generating_function(Rayleigh('x', 1))(t) assert mgf.diff(t).subs(t, 0) == sqrt(2) * sqrt(pi) / 2 mgf = moment_generating_function(Triangular('x', 1, 3, 2))(t) assert mgf.diff(t).subs(t, 1) == -e + exp(3) mgf = moment_generating_function(Uniform('x', 0, 1))(t) assert mgf.diff(t).subs(t, 1) == 1 mgf = moment_generating_function(UniformSum('x', 1))(t) assert mgf.diff(t).subs(t, 1) == 1 mgf = moment_generating_function(WignerSemicircle('x', 1))(t) assert mgf.diff(t).subs(t, 1) == -2*besseli(1, 1) + besseli(2, 1) +\ besseli(0, 1)
from sympy import Symbol, Dummy, sympify, exp from sympy.abc import mu, x, y, w from sympy.stats import density, Normal from sympy.solvers import solve from sympy.holonomic.holonomic import expr_to_holonomic sigma = Symbol('sigma', positive=True) want_dens = w * density(Normal(Dummy(), mu, sigma))(y) have_dens = exp(-x**2 - y**2 + x * y) want_hol = expr_to_holonomic(want_dens, y) have_hol = expr_to_holonomic(have_dens, y) print(want_hol) print(have_hol) def annihilator_coeff(hol, i): return hol.annihilator.listofpoly[i] if i <= hol.annihilator.order else 0 equations = set(h - w for (h, w) in zip(have_hol.y0, want_hol.y0)) order = max(want_hol.annihilator.order, have_hol.annihilator.order) have_top_coeff = annihilator_coeff(have_hol, order) want_top_coeff = annihilator_coeff(want_hol, order) for i in range(0, order): equations.update( c.as_expr() if hasattr(c, 'as_expr') else sympify(c) for c in ( annihilator_coeff(have_hol, i) * want_top_coeff - annihilator_coeff(want_hol, i) * have_top_coeff).all_coeffs()) print(equations) print(solve(equations, [w, mu, sigma]))
a = MatrixSymbol("a", k, 1) b = MatrixSymbol("b", k, 1) A2 = MatrixSymbol("A2", 2, 2) B2 = MatrixSymbol("B2", 2, 2) X = RandomMatrixSymbol("X", k, 1) Y = RandomMatrixSymbol("Y", k, 1) Z = RandomMatrixSymbol("Z", k, 1) W = RandomMatrixSymbol("W", k, 1) R = RandomMatrixSymbol("R", k, k) X2 = RandomMatrixSymbol("X2", 2, 1) normal = Normal("normal", 0, 1) m1 = Matrix([[1, j * Normal("normal2", 2, 1)], [normal, 0]]) def test_multivariate_expectation(): expr = Expectation(a) assert expr == Expectation(a) == ExpectationMatrix(a) assert expr.expand() == a expr = Expectation(X) assert expr == Expectation(X) == ExpectationMatrix(X) assert expr.shape == (k, 1) assert expr.rows == k assert expr.cols == 1 assert isinstance(expr, ExpectationMatrix)
''' # Imports and definitions from sympy import * from sympy.stats import Normal, density init_printing(use_latex='mathjax') from IPython.display import display x1, x2, y = symbols("x1,x2,y") # End imports and definitions # Expectation of a normally distributed variable mu1 = symbols("mu1", positive=True) V1 = symbols("sigma1", positive=True) X1 = Normal("X", mu1, V1) D1 = density(X1)(x1) E1 = Integral(x1 * D1, (x1, -oo, oo)) display(Eq(E1, E1.doit())) # use doit to evaluate an unevaluated integral # Compute the variance analytically V = Integral((x1 - E1.doit())**2 * D1, (x1, -oo, oo)) display(Eq(V, V.doit())) # Expectation of the product of two normally distributed parameters mu2 = symbols("mu2", positive=True) V2 = symbols("sigma2", positive=True) X2 = Normal("X", mu2, V2) D2 = density(X2)(x2) jpdf = D1 * D2 E2 = Integral(x1 * x2 * jpdf, (x2, -oo, oo), (x1, -oo, oo))
# each region all_xhat_reduced = {} #same as above but only store float values config = {'K': K, 'sigmas': sigmas.tolist(), 'Rs': Rs.tolist()} with open("results/config.txt", "wb") as fp: pickle.dump(config, fp) # the algorithm for jj in range(len(Rs)): for ii in range(len(sigmas)): #points = np.sort(np.random.rand(2**Rs[jj]))*2-1 #initalize points randomly from -1 to 1 # initalize half of the points from -1 to 0 and half of them from 0 to 1 points = np.sort(np.concatenate( ((-1) * np.random.rand(2**(Rs[jj] - 1)), np.random.rand(2**(Rs[jj] - 1)))), axis=0) * sigmas[ii] rvs = st.norm(scale=sigmas[ii]) rvs2 = Normal('rvs2', 0, sigmas[ii]) for i in range(K): v_bounds = get_v_bounds(points) exps, exps_symb = get_new_xhat(rvs, rvs2, v_bounds) points = exps final_v_bounds = get_v_bounds(points) err, exps, exps_symb, distortions = get_new_xhat(rvs, rvs2, final_v_bounds, get_distortion=True) while err == True: points = np.sort(np.concatenate( ((-1) * np.random.rand(2**(Rs[jj] - 1)),
def generate(save=False): c, p, d1, d2, S, t, K, r, vol, q = symbols('c p d1 d2 S t K r vol q') normal = Normal('normal', 0, 1) d1 = (ln(S / K) + (r - q + vol ** 2 / 2) * t) / (sqrt(t) * vol) d2 = d1 - sqrt(t) * vol c = simplify(S * s_exp(-q * t) * N(normal < d1) - K * s_exp(-r * t) * N(normal < d2)) p = simplify(-S * s_exp(-q * t) * N(normal < -d1) + K * s_exp(-r * t) * N(normal < -d2)) c_lambda = lambdify([S, t, K, r, vol, q], c, 'math') p_lambda = lambdify([S, t, K, r, vol, q], p, 'math') c_delta = simplify(diff(c, S)) p_delta = simplify(diff(p, S)) c_delta_lambda = lambdify([S, t, K, r, vol, q], c_delta, 'math') p_delta_lambda = lambdify([S, t, K, r, vol, q], p_delta, 'math') c_theta = simplify(diff(c, t)) p_theta = simplify(diff(p, t)) c_theta_lambda = lambdify([S, t, K, r, vol, q], c_theta, 'math') p_theta_lambda = lambdify([S, t, K, r, vol, q], p_theta, 'math') c_gamma = simplify(diff(c_delta, S)) p_gamma = simplify(diff(p_delta, S)) c_gamma_lambda = lambdify([S, t, K, r, vol, q], c_gamma, 'math') p_gamma_lambda = lambdify([S, t, K, r, vol, q], p_gamma, 'math') c_vega = simplify(diff(c, vol)) p_vega = simplify(diff(p, vol)) c_vega_lambda = lambdify([S, t, K, r, vol, q], c_vega, 'math') p_vega_lambda = lambdify([S, t, K, r, vol, q], p_vega, 'math') c_rho = simplify(diff(c, r)) p_rho = simplify(diff(p, r)) c_rho_lambda = lambdify([S, t, K, r, vol, q], c_rho, 'math') p_rho_lambda = lambdify([S, t, K, r, vol, q], p_rho, 'math') def fc_lambda(*args, **kwargs): global c_lambda return c_lambda(*args, **kwargs) def fp_lambda(*args, **kwargs): global p_lambda return p_lambda(*args, **kwargs) def fc_delta_lambda(*args, **kwargs): global c_delta_lambda return c_delta_lambda(*args, **kwargs) def fp_delta_lambda(*args, **kwargs): global p_delta_lambda return p_delta_lambda(*args, **kwargs) def fc_gamma_lambda(*args, **kwargs): global c_gamma_lambda return c_gamma_lambda(*args, **kwargs) def fp_gamma_lambda(*args, **kwargs): global p_gamma_lambda return p_gamma_lambda(*args, **kwargs) def fc_vega_lambda(*args, **kwargs): global c_vega_lambda return c_vega_lambda(*args, **kwargs) def fp_vega_lambda(*args, **kwargs): global p_vega_lambda return p_vega_lambda(*args, **kwargs) def fc_theta_lambda(*args, **kwargs): global c_theta_lambda return c_theta_lambda(*args, **kwargs) def fp_theta_lambda(*args, **kwargs): global p_theta_lambda return p_theta_lambda(*args, **kwargs) def fc_rho_lambda(*args, **kwargs): global c_rho_lambda return c_rho_lambda(*args, **kwargs) def fp_rho_lambda(*args, **kwargs): global p_rho_lambda return p_rho_lambda(*args, **kwargs) price = { "call": fc_lambda, "put": fp_lambda, } greeks = { "call": { "delta": fc_delta_lambda, "gamma": fc_gamma_lambda, "theta": fc_theta_lambda, "rho": fc_rho_lambda, "vega": fc_vega_lambda, }, "put": { "delta": fp_delta_lambda, "gamma": fp_gamma_lambda, "theta": fp_theta_lambda, "rho": fp_rho_lambda, "vega": fp_vega_lambda, } } european_option = {"price": price, "greeks": greeks} if save: import pickle as pkl with open("./bin/european_option.lib", "wb") as fp: pkl.dump(european_option, fp) return european_option
def test_expectation(): m = Normal('A', [x, y], [[1, 0], [0, 1]]) assert simplify(E(m[1])) == y
def test_FiniteSet_prob(): E = Exponential('E', 3) N = Normal('N', 5, 7) assert P(Eq(E, 1)) is S.Zero assert P(Eq(N, 2)) is S.Zero assert P(Eq(N, x)) is S.Zero
def test_joint_vector_expectation(): m = Normal('A', [x, y], [[1, 0], [0, 1]]) assert E(m) == (x, y)
from sympy import * from sympy.stats import Normal, density, E, variance var("tau nact pact dt std damping scale tau_threshold act_threshold", real=True) var("dt std alpha scale time_constant", real=True, positive=True) noise = Normal("noise", 0, std) alpha = 1 - exp(-dt/time_constant) #nact = alpha*pact + (1 - alpha)*(atan((tau - tau_threshold)*scale) + noise) #dact = (nact - pact).simplify() #pprint(dact) #nact = pact + (-damping*pact + atan((tau - tau_threshold)*scale) + noise)*dt dact = -alpha*pact + atan((tau - tau_threshold)*scale)*dt + noise*sqrt(dt) print(dact) pprint(density(dact)) m = E(dact) v = variance(dact).simplify() print(m) print(v)
def test_probability_unevaluated(): T = Normal('T', 30, 3) assert type(P(T > 33, evaluate=False)) == Integral
def test_normality(): X, Y = Normal('X', 0, 1), Normal('Y', 0, 1) x, z = symbols('x, z', real=True, finite=True) dens = density(X - Y, Eq(X + Y, z)) assert integrate(dens(x), (x, -oo, oo)) == 1
def test_random_parameters(): mu = Normal('mu', 2, 3) meas = Normal('T', mu, 1) assert density(meas, evaluate=False)(z) assert isinstance(pspace(meas), JointPSpace)
def test_real(): x = Normal('x', 0, 1) assert x.is_real
def test_conjugate_priors(): mu = Normal('mu', 2, 3) x = Normal('x', mu, 1) assert isinstance(simplify(density(mu, Eq(x, y), evaluate=False)(z)), Mul)
def test_RandomSymbol_diff(): X = Normal('x', 0, 1) assert (2 * X).diff(X)
def test_Or(): N = Normal('N', 0, 1) assert simplify(P(Or(N > 2, N < 1))) == \ -erf(sqrt(2))/2 - erfc(sqrt(2)/2)/2 + S(3)/2 assert P(Or(N < 0, N < 1)) == P(N < 1) assert P(Or(N > 0, N < 0)) == 1
def test_random_parameters(): mu = Normal('mu', 2, 3) meas = Normal('T', mu, 1) assert density(meas, evaluate=False)(z)