feat(ga): Implement quality filtering and precision-based clustering #19
Reference in New Issue
Block a user
Delete Branch "v0.5.0-dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The previous GA logic was returning the "top N" solutions, which led to test failures when the algorithm correctly converged on only one of all possible roots (e.g., returning 1000 variations of -1.0).
This commit fixes the root-finding logic to correctly identify and return all unique, high-quality roots:
feat(api): Adds
root_precisiontoGA_Options. This new parameter (default: 5) allows the user to control the number of decimal places for clustering unique roots.fix(ga): Replaces the flawed "top N" logic in both
_solve_x_numpyand_solve_x_cuda. The new process is:quality_thresholdbased on the user'sroot_precision(e.g.,precision=5requires a rank >1e6).root_precision.np.unique()results.This ensures the solver returns all distinct roots that meet the accuracy requirements, rather than just the top N variations of a single root.
The previous GA logic was returning the "top N" solutions, which led to test failures when the algorithm correctly converged on only one of all possible roots (e.g., returning 1000 variations of -1.0). This commit fixes the root-finding logic to correctly identify and return *all* unique, high-quality roots: 1. **feat(api):** Adds `root_precision` to `GA_Options`. This new parameter (default: 5) allows the user to control the number of decimal places for clustering unique roots. 2. **fix(ga):** Replaces the flawed "top N" logic in both `_solve_x_numpy` and `_solve_x_cuda`. The new process is: * Dynamically sets a `quality_threshold` based on the user's `root_precision` (e.g., `precision=5` requires a rank > `1e6`). * Filters the *entire* final population for all solutions that meet this quality threshold. * Rounds these high-quality solutions to `root_precision`. * Returns only the `np.unique()` results. This ensures the solver returns all distinct roots that meet the accuracy requirements, rather than just the top N variations of a single root.