def test_cauchy(): x0 = Symbol("x0") gamma = Symbol("gamma", positive=True) X = Cauchy('x', x0, gamma) assert density(X)(x) == 1 / (pi * gamma * (1 + (x - x0)**2 / gamma**2)) gamma = Symbol("gamma", positive=False) raises(ValueError, lambda: Cauchy('x', x0, gamma))
def test_cauchy(): x0 = Symbol("x0") gamma = Symbol("gamma", positive=True) X = Cauchy('x', x0, gamma) assert density(X)(x) == 1 / (pi * gamma * (1 + (x - x0)**2 / gamma**2)) assert cdf(X)(x) == atan((x - x0) / gamma) / pi + S.Half assert diff(cdf(X)(x), x) == density(X)(x) gamma = Symbol("gamma", positive=False) raises(ValueError, lambda: Cauchy('x', x0, gamma))
def test_cauchy(): x0 = Symbol("x0") gamma = Symbol("gamma", positive=True) p = Symbol("p", positive=True) X = Cauchy('x', x0, gamma) assert density(X)(x) == 1 / (pi * gamma * (1 + (x - x0)**2 / gamma**2)) assert diff(cdf(X)(x), x) == density(X)(x) assert quantile(X)(p) == gamma * tan(pi * (p - S.Half)) + x0 gamma = Symbol("gamma", nonpositive=True) raises(ValueError, lambda: Cauchy('x', x0, gamma))
def test_cauchy(): x0 = Symbol("x0") gamma = Symbol("gamma", positive=True) p = Symbol("p", positive=True) X = Cauchy('x', x0, gamma) # Tests the characteristic function assert characteristic_function(X)(x) == exp(-gamma * Abs(x) + I * x * x0) assert density(X)(x) == 1 / (pi * gamma * (1 + (x - x0)**2 / gamma**2)) assert diff(cdf(X)(x), x) == density(X)(x) assert quantile(X)(p) == gamma * tan(pi * (p - S.Half)) + x0 gamma = Symbol("gamma", nonpositive=True) raises(ValueError, lambda: Cauchy('x', x0, gamma))
def test_cauchy(): x0 = Symbol("x0") gamma = Symbol("gamma", positive=True) X = Cauchy('x', x0, gamma) assert density(X) == Lambda( _x, 1 / (pi * gamma * (1 + (_x - x0)**2 / gamma**2)))
def test_sample_scipy(): distribs_scipy = [ Beta("B", 1, 1), BetaPrime("BP", 1, 1), Cauchy("C", 1, 1), Chi("C", 1), Normal("N", 0, 1), Gamma("G", 2, 7), GammaInverse("GI", 1, 1), GaussianInverse("GUI", 1, 1), Exponential("E", 2), LogNormal("LN", 0, 1), Pareto("P", 1, 1), StudentT("S", 2), ChiSquared("CS", 2), Uniform("U", 0, 1) ] size = 3 scipy = import_module('scipy') if not scipy: skip('Scipy is not installed. Abort tests for _sample_scipy.') else: for X in distribs_scipy: samps = sample(X, size=size, library='scipy') samps2 = sample(X, size=(2, 2), library='scipy') for sam in samps: assert sam in X.pspace.domain.set for i in range(2): for j in range(2): assert samps2[i][j] in X.pspace.domain.set
def test_sample_pymc3(): distribs_pymc3 = [ Beta("B", 1, 1), Cauchy("C", 1, 1), Normal("N", 0, 1), Gamma("G", 2, 7), GaussianInverse("GI", 1, 1), Exponential("E", 2), LogNormal("LN", 0, 1), Pareto("P", 1, 1), ChiSquared("CS", 2), Uniform("U", 0, 1) ] size = 3 pymc3 = import_module('pymc3') if not pymc3: skip('PyMC3 is not installed. Abort tests for _sample_pymc3.') else: with ignore_warnings( UserWarning ): ### TODO: Restore tests once warnings are removed for X in distribs_pymc3: samps = next(sample(X, size=size, library='pymc3')) for sam in samps: assert sam in X.pspace.domain.set raises(NotImplementedError, lambda: next(sample(Chi("C", 1), library='pymc3')))
def test_sample_scipy(): distribs_scipy = [ Beta("B", 1, 1), BetaPrime("BP", 1, 1), Cauchy("C", 1, 1), Chi("C", 1), Normal("N", 0, 1), Gamma("G", 2, 7), GammaInverse("GI", 1, 1), GaussianInverse("GUI", 1, 1), Exponential("E", 2), LogNormal("LN", 0, 1), Pareto("P", 1, 1), StudentT("S", 2), ChiSquared("CS", 2), Uniform("U", 0, 1) ] size = 3 numsamples = 5 scipy = import_module('scipy') if not scipy: skip('Scipy is not installed. Abort tests for _sample_scipy.') else: with ignore_warnings( UserWarning ): ### TODO: Restore tests once warnings are removed g_sample = list( sample(Gamma("G", 2, 7), size=size, numsamples=numsamples)) assert len(g_sample) == numsamples for X in distribs_scipy: samps = next(sample(X, size=size, library='scipy')) samps2 = next(sample(X, size=(2, 2), library='scipy')) for sam in samps: assert sam in X.pspace.domain.set for i in range(2): for j in range(2): assert samps2[i][j] in X.pspace.domain.set