Example #1
0
def test_effect_of_lambda2(lambda2):
    # relative difference in gradients should be the same
    weights = range(-5, 0) + range(1, 6)
    clf = OGDLR(lambda2=lambda2)
    grads = clf._get_grads(0, 0, weights)
    # gradient is proportional to weights
    frac = [gr / w for gr, w in zip(grads, weights)]
    assert np.allclose(frac[0], frac)

    # contingencey test: should fail
    abso = [gr * np.sign(w) for gr, w in zip(grads, weights)]
    with pytest.raises(AssertionError):
        assert np.allclose(abso[0], abso)
Example #2
0
def test_effect_of_lambda2(lambda2):
    # relative difference in gradients should be the same
    weights = range(-5, 0) + range(1, 6)
    clf = OGDLR(lambda2=lambda2)
    grads = clf._get_grads(0, 0, weights)
    # gradient is proportional to weights
    frac = [gr / w for gr, w in zip(grads, weights)]
    assert np.allclose(frac[0], frac)

    # contingencey test: should fail
    abso = [gr * np.sign(w) for gr, w in zip(grads, weights)]
    with pytest.raises(AssertionError):
        assert np.allclose(abso[0], abso)
Example #3
0
def test_effect_of_lambda1(lambda1):
    # gradients should be the same regardless of magnitude of weights
    weights = range(-5, 0) + range(1, 6)
    clf = OGDLR(lambda1=lambda1)
    grads = clf._get_grads(0, 0, weights)
    # gradient only depends on sign of weight
    abso = [gr * np.sign(w) for gr, w in zip(grads, weights)]
    assert np.allclose(abso[0], abso)

    # contingency test: should fail
    frac = [gr / w for gr, w in zip(grads, weights)]
    with pytest.raises(AssertionError):
        assert np.allclose(frac[0], frac)
Example #4
0
def test_effect_of_lambda1(lambda1):
    # gradients should be the same regardless of magnitude of weights
    weights = range(-5, 0) + range(1, 6)
    clf = OGDLR(lambda1=lambda1)
    grads = clf._get_grads(0, 0, weights)
    # gradient only depends on sign of weight
    abso = [gr * np.sign(w) for gr, w in zip(grads, weights)]
    assert np.allclose(abso[0], abso)

    # contingency test: should fail
    frac = [gr / w for gr, w in zip(grads, weights)]
    with pytest.raises(AssertionError):
        assert np.allclose(frac[0], frac)