Ejemplo n.º 1
0
def test_lognormal():
    mean = Symbol('mu', real=True)
    std = Symbol('sigma', positive=True, real=True)
    X = LogNormal('x', mean, std)
    # The diofant 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 sample(X) == N(exp(i))
    # The diofant integrator can't do this too well
    # assert E(X) ==

    mu = Symbol('mu', extended_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))
Ejemplo n.º 2
0
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