コード例 #1
0
def test_2_vector_api(data: np.ndarray):
    assert np.isclose(corr(data[:, 0], data[:, 1])[0, 1], -0.1687177, atol=DP)

    data[-1, 0] = np.nan

    with np.errstate(invalid='ignore'):
        # Adding ignore because comparing nans raise invalid runtime warning
        assert np.isnan(corr(data[:, 0], data[:, 1])[0, 1])
    assert np.isclose(corr(data[:, 0], data[:, 1], use='complete')[0, 1],
                      -0.16634284,
                      atol=DP)
    assert np.isclose(corr(data[:, 0], data[:, 1], use='complete')[0, 1],
                      -0.16634284,
                      atol=DP)
コード例 #2
0
def test_raise_error_if_x_y_not_vector():
    with pytest.raises(ValueError):
        corr(np.zeros((10, 2)), np.zeros(10))

    with pytest.raises(ValueError):
        corr(np.zeros(10), np.zeros((10, 2)))

    with pytest.raises(ValueError):
        corr(np.zeros((10, 2)), np.zeros((10, 2)))
コード例 #3
0
def test_corr(data):
    assert_array_almost_equal(
        corr(data),
        np.array([[1.0000000, -0.16871767, -0.23407923],
                  [-0.1687177, 1.00000000, 0.05121912],
                  [-0.2340792, 0.05121912, 1.00000000]]), DP)
コード例 #4
0
def test_raise_error_if_x_y_different_length():
    with pytest.raises(ValueError):
        corr(np.zeros(10), np.ones(5))
コード例 #5
0
def test_raise_error_if_only_input_not_matrix():
    with pytest.raises(ValueError):
        corr(np.zeros(10))
コード例 #6
0
def test_raise_error_if_invalid_use(data: np.ndarray):
    with pytest.raises(ValueError):
        corr(data, use='SOMETHING STRANGE')
コード例 #7
0
def test_raise_error_if_invalid_method(data: np.ndarray):
    with pytest.raises(ValueError):
        corr(data, method='WRONG METHOD')
コード例 #8
0
ファイル: _data_ext.py プロジェクト: chrisburr/copulae
def tau_rho_sample(copula: BaseCopula, nsim: int, method="spearman") -> float:
    u = copula.random(nsim)
    u = u[~np.isnan(u).any(1)]

    return corr(u, method=method)[0, 1]