Skip to content

Commit 4751a21

Browse files
authored
Added x_transform for unevenly spaced data
My proposed solution for arvkevi#98
1 parent eb95532 commit 4751a21

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

kneed/knee_locator.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ def __init__(
188188
self.y_normalized = self.transform_y(
189189
self.y_normalized, self.direction, self.curve
190190
)
191+
192+
self.x_normalized = self.transform_x(
193+
self.x_normalized, self.direction, self.curve
194+
)
195+
# normalized difference curve
191196
# normalized difference curve
192197
self.y_difference = self.y_normalized - self.x_normalized
193198
self.x_difference = self.x_normalized.copy()
@@ -228,16 +233,22 @@ def __normalize(a: Iterable[float]) -> Iterable[float]:
228233
def transform_y(y: Iterable[float], direction: str, curve: str) -> float:
229234
"""transform y to concave, increasing based on given direction and curve"""
230235
# convert elbows to knees
231-
if direction == "decreasing":
232-
if curve == "concave":
233-
y = np.flip(y)
234-
elif curve == "convex":
235-
y = y.max() - y
236-
elif direction == "increasing" and curve == "convex":
237-
y = np.flip(y.max() - y)
236+
if curve == "convex":
237+
y = y.max() - y
238238

239239
return y
240240

241+
@staticmethod
242+
def transform_x(x: Iterable[float], direction: str, curve: str) -> float:
243+
"""transform x to concave, increasing based on given direction and curve"""
244+
# convert elbows to knees
245+
if direction == "decreasing" and curve == "concave":
246+
x = x.max - x
247+
elif direction == "increasing" and curve == "convex":
248+
x = x.max - x
249+
250+
return x
251+
241252
def find_knee(self,):
242253
"""This function is called when KneeLocator is instantiated. It identifies the knee value and sets the instance attributes."""
243254
if not self.maxima_indices.size:

0 commit comments

Comments
 (0)