Пример #1
0
def knee(points: np.ndarray) -> int:
    """Returns the index of the knee point based on the DFDT method.

    It uses the iterative refinement  method.

    Args:
        points (np.ndarray): numpy array with the points (x, y)

    Returns:
        int: the index of the knee point
    """
    x = points[:, 0]
    y = points[:, 1]

    gradient = grad.cfd(x, y)

    knee = cutoff = 0
    last_knee = -1

    while last_knee < knee and (len(x) - cutoff) > 2:
        last_knee = knee
        knee = get_knee_gradient(gradient[cutoff:]) + cutoff
        cutoff = int(math.ceil(knee / 2.0))

    return knee
Пример #2
0
def knee(points: np.ndarray) -> int:
    """
    Returns the index of the knee point based on the curvature equations:
    $$
    k = \\frac{|f''(x)|}{(1+[f'(2)]^2)^{\\frac{3}{2}}}
    $$

    Args:
        points (np.ndarray): numpy array with the points (x, y)

    Returns:
        int: the index of the knee point
    """

    x = points[:, 0]
    y = points[:, 1]

    gradient1 = grad.cfd(x, y)
    gradient2 = grad.csd(x, y)

    curvature = np.absolute(gradient2) / ((1.0 + gradient1**2.0)**(1.5))
    # prevents the selection of the first point
    #idx = np.argmax(curvature[0:-1])
    idx = np.argmax(curvature[1:-1]) + 1
    return idx
Пример #3
0
def get_knee(x: np.ndarray, y: np.ndarray) -> int:
    """Return the index of the knee point based on the DFDT method.

    Args:
        x (np.ndarray): the value of the points in the x axis coordinates
        y (np.ndarray): the value of the points in the y axis coordinates

    Returns:
        int: the index of the knee point
    """
    gradient = grad.cfd(x, y)
    return get_knee_gradient(gradient)
Пример #4
0
def knee(points: np.ndarray) -> int:
    """
    Returns the index of the knee point based on the curvature equations:
    $$
    k = \\frac{|f''(x)|}{(1+[f'(2)]^2)^{\\frac{3}{2}}}
    $$

    Args:
        points (np.ndarray): numpy array with the points (x, y)

    Returns:
        int: the index of the knee point
    """

    x = points[:, 0]
    y = points[:, 1]

    gradient1 = grad.cfd(x, y)
    gradient2 = grad.csd(x, y)

    curvature = gradient2 / ((1.0 + gradient1**2.0)**(1.5))
    return np.argmax(curvature[0:-1])
Пример #5
0
 def test_gradient_cfd_even(self):
     x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
     y = np.array([1, 4, 9, 16, 25, 36, 49, 64, 81])
     result = gradient.cfd(x, y)
     desired = np.array([2., 4., 6., 8., 10., 12., 14., 16., 18.])
     npt.assert_almost_equal(result, desired, decimal=2)
Пример #6
0
 def test_gradient_cfd_uneven(self):
     x = np.array([1, 3, 4, 5, 6, 8, 9])
     y = np.array([1, 9, 16, 25, 36, 64, 81])
     result = gradient.cfd(x, y)
     desired = np.array([2, 6, 8, 10, 12, 16, 18])
     npt.assert_almost_equal(result, desired, decimal=2)
Пример #7
0
 def test_gradient_cfd_even_2(self):
     x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
     y = x**3
     result = gradient.cfd(x, y)
     desired = np.array([1, 13, 28, 49, 76, 109, 148, 193, 241])
     npt.assert_almost_equal(result, desired, decimal=2)