Ejemplo n.º 1
0
def test_list_input():
    """Indirectly test that flip works on lists as input"""
    x, y = dg.figure2()
    kl = KneeLocator(
        x.tolist(), y.tolist(), S=1.0, curve="concave", interp_method="polynomial"
    )
    assert math.isclose(kl.knee, 0.22, rel_tol=0.05)
Ejemplo n.º 2
0
def test_concave_decreasing(interp_method):
    """test a concave decreasing function"""
    x, y = dg.concave_decreasing()
    kn = KneeLocator(
        x, y, curve="concave", direction="decreasing", interp_method=interp_method
    )
    assert kn.knee == 7
Ejemplo n.º 3
0
def test_figure2(interp_method):
    """From the kneedle manuscript"""
    x, y = dg.figure2()
    kl = KneeLocator(x, y, S=1.0, curve="concave", interp_method=interp_method)
    assert math.isclose(kl.knee, 0.22, rel_tol=0.05)
    assert math.isclose(kl.elbow, 0.22, rel_tol=0.05)
    assert math.isclose(kl.norm_elbow, kl.knee, rel_tol=0.05)
Ejemplo n.º 4
0
def test_convex_decreasing_bumpy(interp_method, expected):
    """test a bumpy convex decreasing function"""
    x, y = dg.bumpy()
    kl = KneeLocator(
        x, y, curve="convex", direction="decreasing", interp_method=interp_method
    )
    assert kl.knee == expected
Ejemplo n.º 5
0
def test_convex_increasing_truncated(interp_method):
    """test a truncated convex increasing function"""
    x, y = dg.convex_increasing()
    kl = KneeLocator(
        x[:-3] / 10, y[:-3] / 10, curve="convex", interp_method=interp_method
    )
    assert kl.knee == 0.4
Ejemplo n.º 6
0
def test_convex_decreasing(interp_method):
    """test a convex decreasing function"""
    x, y = dg.convex_decreasing()
    kl = KneeLocator(
        x, y, curve="convex", direction="decreasing", interp_method=interp_method
    )
    assert kl.knee == 2
Ejemplo n.º 7
0
def test_plot_knee():
    """Test that plotting is functional"""
    x, y = dg.figure2()
    kl = KneeLocator(x, y, S=1.0, curve="concave", interp_method="interp1d")
    num_figures_before = plt.gcf().number
    kl.plot_knee()
    num_figures_after = plt.gcf().number
    assert num_figures_before < num_figures_after
Ejemplo n.º 8
0
def test_y():
    """Test the y value"""
    x, y = dg.figure2()
    kl = KneeLocator(x, y, S=1.0, curve="concave", interp_method="interp1d")
    assert math.isclose(kl.knee_y, 1.897, rel_tol=0.03)
    assert math.isclose(kl.all_knees_y[0], 1.897, rel_tol=0.03)
    assert math.isclose(kl.norm_knee_y, 0.758, rel_tol=0.03)
    assert math.isclose(kl.all_norm_knees_y[0], 0.758, rel_tol=0.03)
Ejemplo n.º 9
0
def test_convex_decreasing_truncated(interp_method):
    """test a truncated convex decreasing function"""
    x, y = dg.convex_decreasing()
    kl = KneeLocator(x[:-3] / 10,
                     y[:-3] / 10,
                     curve='convex',
                     direction='decreasing',
                     interp_method=interp_method)
    assert kl.knee == 0.2
Ejemplo n.º 10
0
def test_find_shape():
    """Test that find_shape can detect the right shape of curve line"""
    x, y = dg.concave_increasing()
    direction, curve = find_shape(x, y)
    assert direction == 'increasing'
    assert curve == 'concave'
    x, y = dg.concave_decreasing()
    direction, curve = find_shape(x, y)
    assert direction == 'decreasing'
    assert curve == 'concave'
    x, y = dg.convex_decreasing()
    direction, curve = find_shape(x, y)
    assert direction == 'decreasing'
    assert curve == 'convex'
    x, y = dg.convex_increasing()
    direction, curve = find_shape(x, y)
    assert direction == 'increasing'
    assert curve == 'convex'
Ejemplo n.º 11
0
def test_concave_decreasing_truncated(interp_method):
    """test a truncated concave decreasing function"""
    x, y = dg.concave_decreasing()
    kl = KneeLocator(
        x[:-3] / 10,
        y[:-3] / 10,
        curve="concave",
        direction="decreasing",
        interp_method=interp_method,
    )
    assert kl.knee == 0.4
Ejemplo n.º 12
0
def test_all_knees():
    x, y = dg.bumpy()
    kl = KneeLocator(x, y, curve='convex', direction='decreasing', online=True)
    kl.all_elbows == set([41, 46, 53, 26, 31])
    kl.all_norm_elbows == set([
        0.2921348314606742,
        0.348314606741573,
        0.5955056179775281,
        0.4606741573033708,
        0.5168539325842696,
    ])
Ejemplo n.º 13
0
def test_NoisyGaussian():
    """From the Kneedle manuscript"""
    x, y = dg.noisy_gaussian(mu=50, sigma=10, N=1000, seed=42)
    kl = KneeLocator(
        x,
        y,
        S=1.0,
        curve="concave",
        interp_method="polynomial",
        polynomial_degree=11,
        online=True,
    )
    assert math.isclose(kl.knee, 63.0, rel_tol=1e-02)
Ejemplo n.º 14
0
def test_all_knees():
    x, y = dg.bumpy()
    kl = KneeLocator(x, y, curve="convex", direction="decreasing", online=True)
    assert np.isclose(sorted(kl.all_elbows), [26, 31, 41, 46, 53]).all()
    assert np.isclose(
        sorted(kl.all_norm_elbows),
        [
            0.2921348314606742,
            0.348314606741573,
            0.4606741573033708,
            0.5168539325842696,
            0.5955056179775281,
        ],
    ).all()
Ejemplo n.º 15
0
def test_NoisyGaussian(interp_method):
    """From the Kneedle manuscript"""
    x, y = dg.noisy_gaussian(mu=50, sigma=10, N=10000)
    kl = KneeLocator(x, y, S=1.0, curve='concave', interp_method=interp_method)
    assert math.isclose(kl.knee, 60.5, rel_tol=7.0)
Ejemplo n.º 16
0
def test_NoisyGaussian():
    """From the Kneedle manuscript"""
    DG = DataGenerator()
    x, y = DG.noisy_gaussian(mu=50, sigma=10, N=10000)
    kl = KneeLocator(x, y, S=1.0, curve='concave')
    assert math.isclose(kl.knee, 60.5, rel_tol=7.0)
Ejemplo n.º 17
0
def test_figure2():
    """From the kneedle manuscript"""
    DG = DataGenerator()
    x, y = DG.figure2()
    kl = KneeLocator(x, y, S=1.0, curve='concave')
    assert math.isclose(kl.knee, 0.22, rel_tol=0.05)
Ejemplo n.º 18
0
def test_concave_increasing(interp_method):
    """test a concave increasing function"""
    x, y = dg.concave_increasing()
    kn = KneeLocator(x, y, curve='concave', interp_method=interp_method)
    assert kn.knee == 2
Ejemplo n.º 19
0
def test_convex_increasing(interp_method):
    """test a convex increasing function"""
    x, y = dg.convex_increasing()
    kl = KneeLocator(x, y, curve='convex', interp_method=interp_method)
    assert kl.knee == 7
Ejemplo n.º 20
0
def test_interp_method():
    """Test that the interp_method argument is valid."""
    x, y = dg.figure2()
    with pytest.raises(ValueError):
        kl = KneeLocator(x, y, interp_method="not_a_method")