-
Notifications
You must be signed in to change notification settings - Fork 6
Rewritten implementations of the KLIEP and RuLSIF algorithms #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look closely at the algorithms, because there're no tests to run it. Imo metrics here look redundand.
:param detected_change_points: list of detected change point indices. | ||
:return: a dictionary with evaluation metrics (precision, recall, F1 score). | ||
def evaluate_detection_accuracy( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this here? It seems this logic belongs to benchmarking.
@@ -1,112 +1,155 @@ | |||
from abc import abstractmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add license/copyright metadata here (and header docstring)
:param window: input data window | ||
:return: True if window can be processed, else False | ||
""" | ||
return len(window) >= 2 * self.min_window_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why len
must be at least twice as the minimal? It looks a little bit confusing.
def loss(alpha_array: npt.NDArray[np.float64], /) -> float: | ||
alpha = alpha_array[0] | ||
ratio = np.exp(np.log(test_density) - np.log(ref_density + 1e-10) - alpha) | ||
return float(-np.mean(np.log(ratio + 1e-10)) + self.regularization * alpha**2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these 1e-10
? Is it for numerical stability? Should it be a parameter? Or maybe make it a private field of class?
) | ||
|
||
return cast(list[int], np.where(weights > self.threshold)[0].tolist()) | ||
def _kde_on_grid( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method '_kde_on_grid' may be 'static'
|
||
def objective_function_wrapper(alpha: npt.NDArray[np.float64], /) -> float: | ||
"""Wrapper for the objective function to calculate the density ratio. | ||
def _validate_window(self, window: npt.NDArray[Any]) -> npt.NDArray[np.float64]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method '_validate_window' may be 'static'
test_density = self._kernel_density_estimation(test_value, bandwidth) | ||
reference_density = self._kernel_density_estimation(reference_value, bandwidth) | ||
window = self._validate_window(window) | ||
if not self._is_window_valid(window): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why previously validated window can be not valid here? Naming looks a little bit confusing.
Based on #43