Exemplo n.º 1
0
def test_logit():
    """Test logit calculations."""
    pytest.raises(ValueError, ea.logit, 2)
    # On some versions, this throws warnings about divide-by-zero
    with np.errstate(divide='ignore'):
        assert ea.logit(0) == -np.inf
        assert ea.logit(1) == np.inf
    assert ea.logit(1, max_events=1) < np.inf
    assert ea.logit(0.5) == 0
    if splogit is not None:
        # Travis doesn't support scipy.special.logit, but this passes locally:
        foo = np.random.rand(5)
        assert_allclose(ea.logit(foo), splogit(foo))
    foo = np.array([[0, 0.5, 1], [1, 0.5, 0]])
    bar = np.ones_like(foo).astype(int)
    assert_array_equal(ea.logit(foo, 1), np.zeros_like(foo))
    assert_array_equal(ea.logit(foo, [1, 1, 1]), np.zeros_like(foo))
    assert_array_equal(ea.logit(foo, bar), np.zeros_like(foo))
    pytest.raises(ValueError, ea.logit, foo, [1, 1])  # can't broadcast
Exemplo n.º 2
0
def test_logit():
    """Test logit calculations."""
    pytest.raises(ValueError, ea.logit, 2)
    # On some versions, this throws warnings about divide-by-zero
    with np.errstate(divide='ignore'):
        assert ea.logit(0) == -np.inf
        assert ea.logit(1) == np.inf
    assert ea.logit(1, max_events=1) < np.inf
    assert ea.logit(0.5) == 0
    if splogit is not None:
        # Travis doesn't support scipy.special.logit, but this passes locally:
        foo = np.random.rand(5)
        assert_allclose(ea.logit(foo), splogit(foo))
    foo = np.array([[0, 0.5, 1], [1, 0.5, 0]])
    bar = np.ones_like(foo).astype(int)
    assert_array_equal(ea.logit(foo, 1), np.zeros_like(foo))
    assert_array_equal(ea.logit(foo, [1, 1, 1]), np.zeros_like(foo))
    assert_array_equal(ea.logit(foo, bar), np.zeros_like(foo))
    pytest.raises(ValueError, ea.logit, foo, [1, 1])  # can't broadcast
Exemplo n.º 3
0
def test_logit():
    """Test logit calculations."""
    assert_raises(ValueError, ea.logit, 2)
    # On some versions, this throws warnings about divide-by-zero
    with warnings.catch_warnings(record=True):
        warnings.simplefilter('always')
        assert_equal(ea.logit(0), -np.inf)
        assert_equal(ea.logit(1), np.inf)
    assert_true(ea.logit(1, max_events=1) < np.inf)
    assert_equal(ea.logit(0.5), 0)
    if splogit is not None:
        # Travis doesn't support scipy.special.logit, but this passes locally:
        foo = np.random.rand(5)
        assert_allclose(ea.logit(foo), splogit(foo))
    foo = np.array([[0, 0.5, 1], [1, 0.5, 0]])
    bar = np.ones_like(foo).astype(int)
    assert_true(np.all(np.equal(ea.logit(foo, 1), np.zeros_like(foo))))
    assert_true(np.all(np.equal(ea.logit(foo, [1, 1, 1]), np.zeros_like(foo))))
    assert_true(np.all(np.equal(ea.logit(foo, bar), np.zeros_like(foo))))
    assert_raises(ValueError, ea.logit, foo, [1, 1])  # can't broadcast
Exemplo n.º 4
0
def test_logit():
    """Test logit calculations."""
    assert_raises(ValueError, ea.logit, 2)
    # On some versions, this throws warnings about divide-by-zero
    with warnings.catch_warnings(record=True):
        warnings.simplefilter('always')
        assert_equal(ea.logit(0), -np.inf)
        assert_equal(ea.logit(1), np.inf)
    assert_true(ea.logit(1, max_events=1) < np.inf)
    assert_equal(ea.logit(0.5), 0)
    if splogit is not None:
        # Travis doesn't support scipy.special.logit, but this passes locally:
        foo = np.random.rand(5)
        assert_allclose(ea.logit(foo), splogit(foo))
    foo = np.array([[0, 0.5, 1], [1, 0.5, 0]])
    bar = np.ones_like(foo).astype(int)
    assert_true(np.all(np.equal(ea.logit(foo, 1), np.zeros_like(foo))))
    assert_true(np.all(np.equal(ea.logit(foo, [1, 1, 1]), np.zeros_like(foo))))
    assert_true(np.all(np.equal(ea.logit(foo, bar), np.zeros_like(foo))))
    assert_raises(ValueError, ea.logit, foo, [1, 1])  # can't broadcast