Exemplo n.º 1
0
def test_compute_reg_neighbors():
    """Test fast calculation of laplacian regularizer."""
    for reg_type in (('ridge', 'ridge'), ('ridge', 'laplacian'),
                     ('laplacian', 'ridge'), ('laplacian', 'laplacian')):
        for n_ch_x, n_delays in ((1, 1), (1, 2), (2, 1), (1, 3), (3, 1),
                                 (1, 4), (4, 1), (2, 2), (2, 3), (3, 2),
                                 (3, 3), (2, 4), (4, 2), (3, 4), (4, 3),
                                 (4, 4), (5, 4), (4, 5), (5, 5), (20,
                                                                  9), (9, 20)):
            for normed in (True, False):
                reg_direct = _compute_reg_neighbors(n_ch_x,
                                                    n_delays,
                                                    reg_type,
                                                    'direct',
                                                    normed=normed)
                reg_csgraph = _compute_reg_neighbors(n_ch_x,
                                                     n_delays,
                                                     reg_type,
                                                     'csgraph',
                                                     normed=normed)
                assert_allclose(reg_direct,
                                reg_csgraph,
                                atol=1e-7,
                                err_msg='%s: %s' % (reg_type,
                                                    (n_ch_x, n_delays)))
Exemplo n.º 2
0
def test_compute_reg_neighbors():
    """Test fast calculation of laplacian regularizer."""
    for reg_type in (
            ('ridge', 'ridge'),
            ('ridge', 'laplacian'),
            ('laplacian', 'ridge'),
            ('laplacian', 'laplacian')):
        for n_ch_x, n_delays in (
                (1, 1), (1, 2), (2, 1), (1, 3), (3, 1), (1, 4), (4, 1),
                (2, 2), (2, 3), (3, 2), (3, 3),
                (2, 4), (4, 2), (3, 4), (4, 3), (4, 4),
                (5, 4), (4, 5), (5, 5),
                (20, 9), (9, 20)):
            for normed in (True, False):
                reg_direct = _compute_reg_neighbors(
                    n_ch_x, n_delays, reg_type, 'direct', normed=normed)
                reg_csgraph = _compute_reg_neighbors(
                    n_ch_x, n_delays, reg_type, 'csgraph', normed=normed)
                assert_allclose(
                    reg_direct, reg_csgraph, atol=1e-7,
                    err_msg='%s: %s' % (reg_type, (n_ch_x, n_delays)))