Esempio n. 1
0
def test_elastic_net_hessian_raises():
    with pytest.raises(ValueError):
        regs.ElasticNet(weight=0.5).hessian(np.array([0, 1, 2]))
Esempio n. 2
0
def test_elastic_net_proximal_operator():
    beta = np.array([1, 2, 3])
    npt.assert_array_equal(
        regs.ElasticNet(weight=0.5).proximal_operator(beta, 1), beta)
Esempio n. 3
0
def test_elastic_net_hessian():
    beta = np.array([1, 2, 3])
    npt.assert_array_equal(
        regs.ElasticNet(weight=0.5).hessian(beta),
        np.eye(len(beta)) * regs.ElasticNet().weight)
Esempio n. 4
0
def test_elastic_net_gradient_zero_weight_is_l1():
    beta = np.array([1, 2, 3])
    npt.assert_array_equal(
        regs.ElasticNet(weight=1).gradient(beta),
        regs.L1().gradient(beta))
Esempio n. 5
0
def test_elastic_net_gradient():
    beta = np.array([1, 2, 3])
    npt.assert_array_equal(
        regs.ElasticNet(weight=0.5).gradient(beta), np.array([1, 1.5, 2]))
Esempio n. 6
0
def test_elastic_net_function_zero_weight_is_l1():
    beta = np.array([1, 2, 3])
    assert regs.ElasticNet(weight=1).f(beta) == regs.L1().f(beta)
Esempio n. 7
0
def test_elastic_net_function(beta, expected):
    assert regs.ElasticNet().f(beta) == expected