Exemplo n.º 1
0
def test_elastic_net_hessian_raises():
    with pytest.raises(ValueError):
        regs.ElasticNet(weight=0.5).hessian(np.array([0, 1, 2]))
Exemplo 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)
Exemplo 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)
Exemplo 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))
Exemplo 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]))
Exemplo 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)
Exemplo n.º 7
0
def test_elastic_net_function(beta, expected):
    assert regs.ElasticNet().f(beta) == expected