feat(ga): Implement quality filtering and precision-based clustering #19

Merged
jono merged 2 commits from v0.5.0-dev into main 2025-10-27 19:26:50 +00:00

2 Commits

Author SHA1 Message Date
9f22d50fc4 updated GA tests
All checks were successful
Run Python Tests / test (3.12) (pull_request) Successful in 11s
Run Python Tests / test (3.10) (pull_request) Successful in 17s
Run Python Tests / test (3.8) (pull_request) Successful in 12s
2025-10-27 15:25:53 -04:00
eff650bf2c feat(ga): Implement quality filtering and precision-based clustering
Some checks failed
Run Python Tests / test (3.12) (pull_request) Failing after 10s
Run Python Tests / test (3.10) (pull_request) Failing after 18s
Run Python Tests / test (3.8) (pull_request) Failing after 11s
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.
2025-10-27 15:13:20 -04:00