示例#1
0
def test_cd_sweep():
    """Test one pass through the coordinate sweep function."""

    poisson = Poisson(fit_intercept=False)

    w, z = Poisson.adjusted_response(X, y, beta)
    active_idx = np.argwhere(beta != 0).ravel()
    beta_new, intercept_new = poisson.cd_sweep(beta, X, w, z, active_idx)

    beta_new_true = np.array(
        [2.922553187460584, 0.909849302128083, 0, -1.850644198436912, 0])

    assert np.allclose(beta_new_true, beta_new)
    assert intercept_new == 0
示例#2
0
def test_adjusted_response():
    """Tests the adjusted response function against equivalent output from a
    MATLAB implementation."""

    w, z = Poisson.adjusted_response(X, y, beta)

    w_true = np.array([
        1.419067548593257, 6.488296399286710, 0.990049833749168,
        4.854955811237434, 6.488296399286709, 2.054433210643888,
        1.537257523548281, 17.115765537145876, 7.099327065156633,
        3.706173712210199])

    z_true = np.array([
        0.759376179437427, 1.794741970890788, -1.01,
        1.403900392819534, 1.794741970890788, 1.180256767879915,
        -0.57, 2.774810655432013, 2.086867367368360,
        2.198740394692808])

    assert_allclose(w_true, w)
    assert_allclose(z_true, z)