def test_legendre_val():
    'Test Legendre polynomial (derivative) equivalence.'
    rng = np.random.RandomState(0)
    xs = np.linspace((- 1.0), 1.0, 1000)
    n_terms = 100
    vals_np = legendre.legvander(xs, (n_terms - 1))
    for (nc, interp) in zip([100, 50], ['nearest', 'linear']):
        (lut, n_fact) = _get_legen_table('eeg', n_coeff=nc, force_calc=True)
        lut_fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, interp, axis=0)
        vals_i = lut_fun(xs)
        assert_allclose(vals_np[:, 1:(vals_i.shape[1] + 1)], vals_i, rtol=0.01, atol=0.005)
        ctheta = ((rng.rand(20, 30) * 2.0) - 1.0)
        beta = (rng.rand(20, 30) * 0.8)
        c1 = _comp_sum_eeg(beta.flatten(), ctheta.flatten(), lut_fun, n_fact)
        c1.shape = beta.shape
        n = np.arange(1, n_terms, dtype=float)[:, np.newaxis, np.newaxis]
        coeffs = np.zeros(((n_terms,) + beta.shape))
        coeffs[1:] = (((np.cumprod(([beta] * (n_terms - 1)), axis=0) * ((2.0 * n) + 1.0)) * ((2.0 * n) + 1.0)) / n)
        c2 = np.empty((20, 30))
        for ci1 in range(20):
            for ci2 in range(30):
                c2[(ci1, ci2)] = legendre.legval(ctheta[(ci1, ci2)], coeffs[:, ci1, ci2])
        assert_allclose(c1, c2, 0.01, 0.001)
    ctheta = ((rng.rand((20 * 30)) * 2.0) - 1.0)
    beta = (rng.rand((20 * 30)) * 0.8)
    (lut, n_fact) = _get_legen_table('meg', n_coeff=10, force_calc=True)
    fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, 'nearest', axis=0)
    coeffs = _comp_sums_meg(beta, ctheta, fun, n_fact, False)
    (lut, n_fact) = _get_legen_table('meg', n_coeff=20, force_calc=True)
    fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, 'linear', axis=0)
    coeffs = _comp_sums_meg(beta, ctheta, fun, n_fact, False)
Test Legendre polynomial (derivative) equivalence.
def test_legendre_val():
    
    rng = np.random.RandomState(0)
    xs = np.linspace((- 1.0), 1.0, 1000)
    n_terms = 100
    vals_np = legendre.legvander(xs, (n_terms - 1))
    for (nc, interp) in zip([100, 50], ['nearest', 'linear']):
        (lut, n_fact) = _get_legen_table('eeg', n_coeff=nc, force_calc=True)
        lut_fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, interp, axis=0)
        vals_i = lut_fun(xs)
        assert_allclose(vals_np[:, 1:(vals_i.shape[1] + 1)], vals_i, rtol=0.01, atol=0.005)
        ctheta = ((rng.rand(20, 30) * 2.0) - 1.0)
        beta = (rng.rand(20, 30) * 0.8)
        c1 = _comp_sum_eeg(beta.flatten(), ctheta.flatten(), lut_fun, n_fact)
        c1.shape = beta.shape
        n = np.arange(1, n_terms, dtype=float)[:, np.newaxis, np.newaxis]
        coeffs = np.zeros(((n_terms,) + beta.shape))
        coeffs[1:] = (((np.cumprod(([beta] * (n_terms - 1)), axis=0) * ((2.0 * n) + 1.0)) * ((2.0 * n) + 1.0)) / n)
        c2 = np.empty((20, 30))
        for ci1 in range(20):
            for ci2 in range(30):
                c2[(ci1, ci2)] = legendre.legval(ctheta[(ci1, ci2)], coeffs[:, ci1, ci2])
        assert_allclose(c1, c2, 0.01, 0.001)
    ctheta = ((rng.rand((20 * 30)) * 2.0) - 1.0)
    beta = (rng.rand((20 * 30)) * 0.8)
    (lut, n_fact) = _get_legen_table('meg', n_coeff=10, force_calc=True)
    fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, 'nearest', axis=0)
    coeffs = _comp_sums_meg(beta, ctheta, fun, n_fact, False)
    (lut, n_fact) = _get_legen_table('meg', n_coeff=20, force_calc=True)
    fun = interp1d(np.linspace((- 1), 1, lut.shape[0]), lut, 'linear', axis=0)
    coeffs = _comp_sums_meg(beta, ctheta, fun, n_fact, False)