kneeliverse.curvature

The following module provides knee detection method based on equation curvature.

 1# coding: utf-8
 2
 3'''
 4The following module provides knee detection method
 5based on equation curvature.
 6'''
 7
 8__author__ = 'Mário Antunes'
 9__version__ = '1.0'
10__email__ = 'mario.antunes@ua.pt'
11__status__ = 'Development'
12__license__ = 'MIT'
13__copyright__ = '''
14Copyright (c) 2021-2023 Stony Brook University
15Copyright (c) 2021-2023 The Research Foundation of SUNY
16'''
17
18import logging
19import numpy as np
20import uts.gradient as grad
21import kneeliverse.multi_knee as mk
22
23
24logger = logging.getLogger(__name__)
25
26
27def knee(points: np.ndarray) -> int:
28    """
29    Returns the index of the knee point based on the curvature equations:
30    $$
31    k = \\frac{|f''(x)|}{(1+[f'(2)]^2)^{\\frac{3}{2}}}
32    $$
33
34    Args:
35        points (np.ndarray): numpy array with the points (x, y)
36
37    Returns:
38        int: the index of the knee point
39    """
40
41    x = points[:, 0]
42    y = points[:, 1]
43
44    gradient1 = grad.cfd(x, y)
45    gradient2 = grad.csd(x, y)
46
47    curvature = np.absolute(gradient2) / ((1.0 + gradient1**2.0)**(1.5))
48    # prevents the selection of the first point
49    #idx = np.argmax(curvature[0:-1]) 
50    idx = np.argmax(curvature[1:-1]) + 1
51    return idx
52
53
54def multi_knee(points: np.ndarray, t1: float = 0.001, t2: int = 3) -> np.ndarray:
55    """
56    Recursive knee point detection based on the curvature equations.
57
58    It returns the knee points on the curve.
59
60    Args:
61        points (np.ndarray): numpy array with the points (x, y)
62        t1 (float): coefficient of determination threshold (default 0.01)
63        t2 (int): number of points threshold (default 3)
64
65    Returns:
66        np.ndarray: knee points on the curve
67    """
68    return mk.multi_knee(knee, points, t1, t2)
logger = <Logger kneeliverse.curvature (WARNING)>
def knee(points: numpy.ndarray) -> int:
28def knee(points: np.ndarray) -> int:
29    """
30    Returns the index of the knee point based on the curvature equations:
31    $$
32    k = \\frac{|f''(x)|}{(1+[f'(2)]^2)^{\\frac{3}{2}}}
33    $$
34
35    Args:
36        points (np.ndarray): numpy array with the points (x, y)
37
38    Returns:
39        int: the index of the knee point
40    """
41
42    x = points[:, 0]
43    y = points[:, 1]
44
45    gradient1 = grad.cfd(x, y)
46    gradient2 = grad.csd(x, y)
47
48    curvature = np.absolute(gradient2) / ((1.0 + gradient1**2.0)**(1.5))
49    # prevents the selection of the first point
50    #idx = np.argmax(curvature[0:-1]) 
51    idx = np.argmax(curvature[1:-1]) + 1
52    return idx

Returns the index of the knee point based on the curvature equations: $$ k = \frac{|f''(x)|}{(1+[f'(2)]^2)^{\frac{3}{2}}} $$

Arguments:
  • points (np.ndarray): numpy array with the points (x, y)
Returns:

int: the index of the knee point

def multi_knee(points: numpy.ndarray, t1: float = 0.001, t2: int = 3) -> numpy.ndarray:
55def multi_knee(points: np.ndarray, t1: float = 0.001, t2: int = 3) -> np.ndarray:
56    """
57    Recursive knee point detection based on the curvature equations.
58
59    It returns the knee points on the curve.
60
61    Args:
62        points (np.ndarray): numpy array with the points (x, y)
63        t1 (float): coefficient of determination threshold (default 0.01)
64        t2 (int): number of points threshold (default 3)
65
66    Returns:
67        np.ndarray: knee points on the curve
68    """
69    return mk.multi_knee(knee, points, t1, t2)

Recursive knee point detection based on the curvature equations.

It returns the knee points on the curve.

Arguments:
  • points (np.ndarray): numpy array with the points (x, y)
  • t1 (float): coefficient of determination threshold (default 0.01)
  • t2 (int): number of points threshold (default 3)
Returns:

np.ndarray: knee points on the curve