Skip to content

Commit

Permalink
Added x_transform for unevenly spaced data
Browse files Browse the repository at this point in the history
My proposed solution for arvkevi#98
  • Loading branch information
vhu43 authored Mar 5, 2023
1 parent eb95532 commit 4751a21
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions kneed/knee_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def __init__(
self.y_normalized = self.transform_y(
self.y_normalized, self.direction, self.curve
)

self.x_normalized = self.transform_x(
self.x_normalized, self.direction, self.curve
)
# normalized difference curve
# normalized difference curve
self.y_difference = self.y_normalized - self.x_normalized
self.x_difference = self.x_normalized.copy()
Expand Down Expand Up @@ -228,16 +233,22 @@ def __normalize(a: Iterable[float]) -> Iterable[float]:
def transform_y(y: Iterable[float], direction: str, curve: str) -> float:
"""transform y to concave, increasing based on given direction and curve"""
# convert elbows to knees
if direction == "decreasing":
if curve == "concave":
y = np.flip(y)
elif curve == "convex":
y = y.max() - y
elif direction == "increasing" and curve == "convex":
y = np.flip(y.max() - y)
if curve == "convex":
y = y.max() - y

return y

@staticmethod
def transform_x(x: Iterable[float], direction: str, curve: str) -> float:
"""transform x to concave, increasing based on given direction and curve"""
# convert elbows to knees
if direction == "decreasing" and curve == "concave":
x = x.max - x
elif direction == "increasing" and curve == "convex":
x = x.max - x

return x

def find_knee(self,):
"""This function is called when KneeLocator is instantiated. It identifies the knee value and sets the instance attributes."""
if not self.maxima_indices.size:
Expand Down

0 comments on commit 4751a21

Please sign in to comment.