예제 #1
0
def test_estimate_alpha_beta_biased():
    n = 100
    random_state = np.random.RandomState(seed=42)
    X = random_state.rand(n, 3)
    dis = euclidean_distances(X)
    bias = 0.1 + random_state.rand(n)
    bias = bias.reshape(n, 1)
    beta_true, alpha_true = 1., -3.5
    counts = beta_true * dis**alpha_true
    counts *= bias * bias.T
    counts[np.isnan(counts) | np.isinf(counts)] = 0
    counts[np.arange(len(counts)), np.arange(len(counts))] = 0
    counts = sparse.coo_matrix(np.triu(counts))

    alpha, beta = negative_binomial.estimate_alpha_beta(
        counts,
        X,
        bias=bias,
        random_state=random_state,
        use_zero_entries=True,
        infer_beta=False)

    assert_almost_equal(alpha_true, alpha, 3)
    assert_almost_equal(beta_true, beta, 3)

    alpha, beta = negative_binomial.estimate_alpha_beta(
        sparse.coo_matrix(counts),
        X,
        bias=bias,
        random_state=random_state,
        infer_beta=False,
        use_zero_entries=True)
    assert_almost_equal(alpha_true, alpha, 3)
    assert_almost_equal(beta_true, beta, 4)
예제 #2
0
def test_estimate_alpha_beta():
    n = 100
    random_state = np.random.RandomState(seed=42)
    X = 5 * random_state.rand(n, 3)
    dis = euclidean_distances(X)
    beta_true, alpha_true = 2., -3.5
    counts = beta_true * dis**alpha_true
    counts[np.isnan(counts) | np.isinf(counts)] = 0
    counts[np.arange(len(counts)), np.arange(len(counts))] = 0
    counts = sparse.coo_matrix(np.triu(counts))

    alpha, beta = negative_binomial.estimate_alpha_beta(
        sparse.coo_matrix(counts), X, random_state=random_state)
    assert_almost_equal(alpha_true, alpha, 3)
    assert_almost_equal(beta_true, beta, 4)
예제 #3
0
def test_estimate_alpha_beta_biased():
    n = 100
    random_state = np.random.RandomState(seed=42)
    X = random_state.rand(n, 3)
    dis = euclidean_distances(X)
    bias = 0.1 + random_state.rand(n)
    bias = bias.reshape(n, 1)
    beta_true, alpha_true = 2., -3.5
    counts = beta_true * dis ** alpha_true
    counts *= bias * bias.T
    counts[np.isnan(counts) | np.isinf(counts)] = 0
    counts[np.arange(len(counts)), np.arange(len(counts))] = 0
    counts = sparse.coo_matrix(np.triu(counts))

    alpha, beta = negative_binomial.estimate_alpha_beta(
        counts, X, bias=bias, random_state=random_state)
    assert_almost_equal(alpha_true, alpha, 3)
    assert_almost_equal(beta_true, beta, 3)

    alpha, beta = negative_binomial.estimate_alpha_beta(
        sparse.coo_matrix(counts), X, bias=bias,
        random_state=random_state)
    assert_almost_equal(alpha_true, alpha, 5)
    assert_almost_equal(beta_true, beta, 5)
예제 #4
0
def test_estimate_alpha_beta_dispersion():
    n = 100
    random_state = np.random.RandomState(seed=42)
    X = 5 * random_state.rand(n, 3)
    dis = euclidean_distances(X)
    beta_true, alpha_true = 1., -3.5
    counts = beta_true * dis**alpha_true
    counts[np.isnan(counts) | np.isinf(counts)] = 0
    counts[np.arange(len(counts)), np.arange(len(counts))] = 0
    counts = sparse.coo_matrix(np.triu(counts))

    alpha, beta = negative_binomial.estimate_alpha_beta(
        counts,
        X,
        random_state=random_state,
        infer_beta=False,
        use_zero_entries=True)
    assert_almost_equal(alpha_true, alpha, 3)