Example #1
0
def test_mvslice():
    g = distl.gaussian(10, 2, label='gaussian')
    u = distl.uniform(0, 5, label='uniform')

    mvg = distl.mvgaussian([5, 10, 12],
                           np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                           allow_singular=True,
                           labels=['mvg_a', 'mvg_b', 'mvg_c'])

    # passing a multivariate (non-sliced) must raise a TypeError
    assert_raises(TypeError, distl.DistributionCollection, g, u, mvg)

    dc = distl.DistributionCollection(g, u, mvg.slice('mvg_a'))

    dc.labels

    dc = distl.from_dict(dc.to_dict())

    dc.sample(size=2)
    dc.sample()
    dc.pdf()
    dc.pdf([6, 4, 2])
    dc.plot(size=100)

    # passing the wrong shape to pdf should raise a ValueError
    assert_raises(ValueError, dc.pdf, [1, 1])
    assert_raises(TypeError, dc.pdf, 1)
    assert_raises(TypeError, dc.pdf, 1.0)
Example #2
0
def test_slice():
    mvg = distl.mvgaussian([5, 10, 12],
                           np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                           allow_singular=True,
                           labels=['a', 'b', 'c'])

    mvg_ab = mvg.take_dimensions(['a', 'b'])

    mvg_a = mvg.slice('a')
    mvg_b = mvg.slice('b')
Example #3
0
def test_mvsamples():
    mvg = distl.mvgaussian([5, 10, 12],
                           np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                           allow_singular=True,
                           labels=['a', 'b', 'c'])

    d = distl.mvsamples(mvg.sample(size=100), labels=['a', 'b', 'c'])
    d = d.copy()

    _test_conversions(d)
    _test_methods_properties(d)
    _test_plotting(d)
    _test_json(d)
Example #4
0
def test_mvgaussianslice():
    d = distl.mvgaussian([5, 10, 12],
                         np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                         allow_singular=True,
                         labels=['a', 'b', 'c'])

    d = d.slice('a')
    d = d.copy()

    _test_conversions(d)
    _test_methods_properties(d)
    _test_plotting(d)
    _test_json(d)
Example #5
0
def test_mvgaussian():
    d = distl.mvgaussian([5, 10, 12],
                         np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                         allow_singular=True,
                         labels=['a', 'b', 'c'])

    d_with_units = d.copy()
    d_with_units.units = ['solRad', 'deg', 'kg']

    for d in [d, d_with_units]:
        _test_conversions(d)
        _test_methods_properties(d)
        _test_plotting(d)
        _test_json(d)
Example #6
0
def test_math():
    mvg = distl.mvgaussian([5, 10, 12],
                           np.array([[2, 1, -1], [1, 2, 1], [-1, 1, 2]]),
                           allow_singular=True,
                           labels=['a', 'b', 'c'])

    mvg_a = mvg.slice('a')
    mvg_b = mvg.slice('b')

    g = distl.gaussian(10, 2)

    assert_raises(TypeError, mvg_a.__and__, mvg_b)
    assert_raises(TypeError, mvg_a.__and__, g)
    assert_raises(TypeError, g.__and__, mvg_a)