What if there are multiple knee points? #90
Unanswered
shineisagoodgirl
asked this question in
Q&A
Replies: 1 comment
-
Hello @shineisagoodgirl, thanks for your question. There is a unit test that checks the knee points of a sine wave. The trick is that You could use the code from the unit test to help get you started: x = np.arange(0, 10, 0.1)
y_sin = np.sin(x)
sine_combos = [
('decreasing', 'convex'),
('increasing', 'convex'),
('increasing', 'concave'),
('decreasing', 'concave'),
]
expected_knees = [4.5, 4.9, 7.7, 1.8]
detected_knees = []
for direction, curve in sine_combos:
kl_sine = KneeLocator(
x, y_sin, direction=direction, curve=curve, S=1, online=True
)
detected_knees.append(kl_sine.knee)
assert np.isclose(expected_knees, detected_knees).all() You could plot this: plt.style.use("fivethirtyeight")
plt.figure(figsize=(8, 8))
plt.plot(x, y_sin)
plt.vlines(
detected_knees[0],
min(y_sin),
max(y_sin),
linestyles="--",
color="#fc4f30",
label="convex decreasing",
)
plt.vlines(
detected_knees[1],
min(y_sin),
max(y_sin),
linestyles="--",
color="#e5ae38",
label="convex increasing",
)
plt.vlines(
detected_knees[2],
min(y_sin),
max(y_sin),
linestyles="--",
color="#6d904f",
label="concave increasing",
)
plt.vlines(
detected_knees[3],
min(y_sin),
max(y_sin),
linestyles="--",
color="#8b8b8b",
label="concave decreasing",
)
plt.legend() Notice that the concave increasing knee could be at two locations in the figure. If there is more than one potential knee point for a line, kl_sine = KneeLocator(
x, y_sin, direction='increasing', curve='concave', S=1, online=True
)
print(kl_sine.all_knees)
{1.4000000000000001, 7.7} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Your algorithm helps me a lot,but can it only find one point at a time? What if there are multiple knee points?thank you
Beta Was this translation helpful? Give feedback.
All reactions