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