Exemplo n.º 1
0
def test_tvl1_from_gradient(size=5, n_samples=10, random_state=42):
    rng = np.random.RandomState(random_state)
    shape = [size] * 3
    n_voxels = np.prod(shape)
    X = rng.randn(n_samples, n_voxels)
    y = rng.randn(n_samples)
    w = rng.randn(*shape)
    mask = np.ones_like(w).astype(np.bool)
    for alpha in [0., 1e-1, 1e-3]:
        for l1_ratio in [0., .5, 1.]:
            gradid = _gradient_id(w, l1_ratio=l1_ratio)
            assert_equal(
                _tvl1_objective(X, y,
                                w.copy().ravel(), alpha, l1_ratio, mask),
                _squared_loss(X, y, w.copy().ravel(), compute_grad=False) +
                alpha * _tvl1_objective_from_gradient(gradid))
Exemplo n.º 2
0
def test_tvl1_from_gradient(size=5, n_samples=10, random_state=42):
    rng = np.random.RandomState(random_state)
    shape = [size] * 3
    n_voxels = np.prod(shape)
    X = rng.randn(n_samples, n_voxels)
    y = rng.randn(n_samples)
    w = rng.randn(*shape)
    mask = np.ones_like(w).astype(np.bool)
    for alpha in [0., 1e-1, 1e-3]:
        for l1_ratio in [0., .5, 1.]:
            gradid = _gradient_id(w, l1_ratio=l1_ratio)
            assert_equal(_tvl1_objective(
                X, y, w.copy().ravel(), alpha, l1_ratio, mask),
                _squared_loss(X, y, w.copy().ravel(),
                              compute_grad=False
                              ) + alpha * _tvl1_objective_from_gradient(
                    gradid))
Exemplo n.º 3
0
def test_tvl1_objective_raises_value_error_if_invalid_loss():
    pytest.raises(ValueError, lambda loss: _tvl1_objective(
        None, None, None, None, None, None, loss=loss),
        "invalidloss")
Exemplo n.º 4
0
def test_tvl1_objective_raises_value_error_if_invalid_loss():
    assert_raises(ValueError, lambda loss: _tvl1_objective(
        None, None, None, None, None, None, loss=loss),
        "invalidloss")