Exemplo n.º 1
0
def test_bad_params_t():
    with pytest.raises(ValueError) as e:
        t_copula(cov,
                 df=0,
                 samples=4,
                 seed=123,
                 chunks=None,
                 rng="Mersenne Twister")
    assert str(e.value) == "df must always be greater than zero"

    with pytest.raises(ValueError) as e:
        t_copula(cov,
                 df=[1, 0, 1],
                 samples=4,
                 seed=123,
                 chunks=None,
                 rng="Mersenne Twister")
    assert str(e.value) == "df must always be greater than zero"

    with pytest.raises(ValueError) as e:
        t_copula(cov,
                 df=[1, 1],
                 samples=4,
                 seed=123,
                 chunks=None,
                 rng="Mersenne Twister")
    assert str(e.value) == (
        "df must be either a scalar or a 1D vector with as many points as the width "
        "of the correlation matrix")
Exemplo n.º 2
0
def test_student_t_mersenne_da():
    actual = t_copula(cov,
                      df=3,
                      samples=4,
                      seed=123,
                      chunks=2,
                      rng="Mersenne Twister")
    expect = [
        [0.9251499, 0.78838765, 0.52075254],
        [0.00733126, 0.58581369, -0.50181461],
        [-0.46342698, -0.55862319, -0.25037537],
        [-0.92150594, -0.70869994, -0.84036731],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    assert actual.chunks == ((2, 2), (2, 1))
Exemplo n.º 3
0
def test_student_t_mersenne_np():
    actual = t_copula(cov,
                      df=3,
                      samples=4,
                      seed=123,
                      chunks=None,
                      rng="Mersenne Twister")
    expect = [
        [-1.48810072, -0.86441534, -1.54668921],
        [-1.29120595, -1.35445918, 0.04614266],
        [-1.69841381, -1.67427423, -0.76713426],
        [-0.52427748, -0.64222262, -0.18205599],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    assert isinstance(actual, np.ndarray)
Exemplo n.º 4
0
def test_tail_dependence(df, expect_td, rng, chunks):
    cov2 = [
        [1.0, 0.5, 0.5, 0.5],
        [0.5, 1.0, 0.5, 0.5],
        [0.5, 0.5, 1.0, 0.5],
        [0.5, 0.5, 0.5, 1.0],
    ]
    s = t_copula(cov2, df=df, samples=262143, rng=rng, chunks=chunks)
    s = scipy.stats.norm.cdf(s)
    actual_td = [
        tail_dependence(s[:, 0], s[:, 1], 0.99),
        tail_dependence(s[:, 1], s[:, 2], 0.99),
        tail_dependence(s[:, 2], s[:, 3], 0.99),
    ]
    assert_allclose(expect_td, actual_td, atol=0.02, rtol=0)
Exemplo n.º 5
0
def test_it_mersenne_da():
    actual = t_copula(cov,
                      df=[3, 4, 5],
                      samples=4,
                      seed=123,
                      chunks=2,
                      rng="Mersenne Twister")
    expect = [
        [0.92514990, 0.84367196, 0.57859631],
        [0.00733126, 0.60760124, -0.53208793],
        [-0.46342698, -0.60402557, -0.28417274],
        [-0.92150594, -0.75838980, -0.94757843],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    assert actual.chunks == ((2, 2), (2, 1))
Exemplo n.º 6
0
def test_it_mersenne_np():
    actual = t_copula(cov,
                      df=[3, 4, 5],
                      samples=4,
                      seed=123,
                      chunks=None,
                      rng="Mersenne Twister")
    expect = [
        [-1.48810072, -0.80579141, -1.48680149],
        [-1.29120595, -1.40226642, 0.04565698],
        [-1.69841381, -1.77537961, -0.79048734],
        [-0.52427748, -0.68508399, -0.20095568],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    assert isinstance(actual, np.ndarray)
Exemplo n.º 7
0
def test_it_sobol(chunks, expect_chunks):
    actual = t_copula(cov,
                      df=[3, 4, 5],
                      samples=4,
                      seed=123,
                      chunks=chunks,
                      rng="Sobol")
    expect = [
        [0.0, 0.0, 0.0],
        [-0.90292647, -0.41928686, -1.35361744],
        [0.51756147, 0.25248047, 0.91032037],
        [0.59093028, 1.20943444, -0.81940488],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    if chunks:
        assert actual.chunks == expect_chunks
    else:
        assert isinstance(actual, np.ndarray)
Exemplo n.º 8
0
def test_student_t_sobol(chunks, expect_chunks):
    actual = t_copula(cov,
                      df=3,
                      samples=4,
                      seed=123,
                      chunks=chunks,
                      rng="Sobol")
    expect = [
        [0.0, 0.0, 0.0],
        [-0.90292647, -0.44513114, -1.38033019],
        [0.51756147, 0.24504617, 0.84650386],
        [0.59093028, 1.28328308, -0.94456215],
    ]
    assert_allclose(expect, actual, 1e-6, 0)
    if chunks:
        assert actual.chunks == expect_chunks
    else:
        assert isinstance(actual, np.ndarray)