Пример #1
0
def test_memory_limit():
    "Check that the memory limit works for too large analyses"
    # Request one million samples, approx. 80GB
    yfit = np.linspace(0, 1, int(1e4))
    yexp = yfit + whitegaussnoise(yfit, 0.01)

    def bootfcn(y):
        return y

    with pytest.raises(MemoryError):
        paruq = bootstrap_analysis(bootfcn, yexp, yfit, 1e6)
Пример #2
0
def test_complex_values():
    # ======================================================================
    "Check the functionality of the bootstrapping with complex-valued outputs"

    t = np.linspace(0, 5, 200)
    r = np.linspace(2, 6, 300)
    P = dd_gauss(r, 4, 0.8)
    K = dipolarkernel(t, r)
    Vexp = K @ P + whitegaussnoise(t, 0.01, seed=1)
    Vexp = Vexp + 1j * whitegaussnoise(t, 0.01, seed=1)
    par0 = [3, 0.5]
    Vmodel = lambda par: K @ dd_gauss(r, *par) + 1j * np.zeros_like(t)
    fit = snlls(Vexp, Vmodel, par0)
    Vfit = fit.model

    def bootfcn(V):
        fit = snlls(V, Vmodel, par0)
        return fit.nonlin

    paruq = bootstrap_analysis(bootfcn, Vexp, Vfit, 3)

    assert all(abs(paruq.mean - fit.nonlin) < 1.5e-2)
Пример #3
0
def test_parallelization():
    # ======================================================================
    "Check that bootstrap_analysis can run with multiple cores"

    t = np.linspace(0, 5, 200)
    r = np.linspace(2, 6, 300)
    P = dd_gauss(r, 4, 0.8)
    K = dipolarkernel(t, r)
    Vexp = K @ P + whitegaussnoise(t, 0.01)

    par0 = [3, 0.5]
    Vmodel = lambda par: K @ dd_gauss(r, *par)
    fit = snlls(Vexp, Vmodel, par0)
    Vfit = fit.model

    def bootfcn(V):
        fit = snlls(V, Vmodel, par0)
        return fit.nonlin

    paruq = bootstrap_analysis(bootfcn, Vexp, Vfit, 10, cores=-1)

    assert all(abs(paruq.mean - fit.nonlin) < 1.5e-2)