示例#1
0
def test_multipeak_nnls(peaks, width, noise):
    x = np.linspace(0, 100, 301)
    y = np.random.RandomState(0).randn(301) * noise
    for peak in peaks:
        y = y + profiles.Gauss(x, peak[1], peak[0], width, 0)

    res = fit.multipeak_nnls(x, y, width=width, alpha=0.001, fit_width=False)
    assert np.sum(res["coef"] > 0) == len(peaks)
示例#2
0
def test_nnls_reg(type, alpha):
    template = np.array([1] + [0] * 10 + [0.5])
    x = profiles.Gauss(np.linspace(-1, 1, 101), 1.0, 0.0, 0.1, 0.0)
    y_true = np.convolve(x, template, mode="full")

    rng = np.random.RandomState(0)
    y = y_true + 0.1 * rng.randn(*y_true.shape)
    actual = deconvolve.nnls(
        y, template, regularization_type=type, regularization_parameter=alpha,
    )

    """
示例#3
0
def test_nnls():
    template = np.array([1] + [0] * 10 + [0.5])
    x = profiles.Gauss(np.linspace(-1, 1, 101), 1.0, 0.0, 0.1, 0.0)
    y_true = np.convolve(x, template, mode="full")
    actual = deconvolve.nnls(y_true, template)
    assert np.allclose(actual, x, atol=1e-3)

    rng = np.random.RandomState(0)
    y = y_true + 0.1 * rng.randn(*y_true.shape)
    actual = deconvolve.nnls(y, template)

    """
示例#4
0
def test_simple_fit(n, sn, x0, width, seed, profile):
    rng = np.random.RandomState(seed)
    x = np.linspace(-100, 100, n)
    A = sn * width * np.sqrt(2 * np.pi)
    if profile == "gauss":
        y = profiles.Gauss(x, A, x0, width, 0) + rng.randn(n)
    elif profile == "lorentz":
        y = profiles.Lorentz(x, A, x0, width, 0) + rng.randn(n)

    popt, perr = fit.singlepeak_fit(x, y, profile=profile)
    print(popt[2], width)
    expected = np.array((A, x0, width, 0))
    assert ((popt - 5 * perr < expected) * (expected < popt + 5 * perr)).all()
示例#5
0
def test_multipeak_nnls_fitwidth(peaks, width, noise):
    x = np.linspace(0, 100, 101)
    y = np.random.RandomState(0).randn(101) * noise
    for peak in peaks:
        y = y + profiles.Gauss(x, peak[1], peak[0], width, 0)

    res = fit.multipeak_nnls(x,
                             y,
                             width=width * 1.3,
                             alpha=0.001,
                             fit_width=True,
                             fit_method="L-BFGS-B")
    assert np.sum(res["coef"] > 0) == len(peaks)
    assert np.allclose(res["width"], width, atol=0.03, rtol=0.03)

    res = fit.multipeak_nnls(x,
                             y,
                             width=width * 1.3,
                             alpha=0.001,
                             fit_width=True,
                             fit_method="Nelder-Mead")
    assert np.sum(res["coef"] > 0) == len(peaks)
    assert np.allclose(res["width"], width, atol=0.03, rtol=0.03)