feat(ga, api): Implement advanced GA strategy and refactor API for v0.4.0 #16

Merged
jono merged 3 commits from v0.4.0-dev into main 2025-10-27 14:20:56 +00:00
Owner

This commit introduces a major enhancement to the genetic algorithm's convergence logic and refactors key parts of the API for better clarity and usability.

  • feat(ga): Re-implements the GA solver (CPU & CUDA) to use a more robust strategy based on Elitism, Crossover, and Mutation. This replaces the previous, less efficient model and is designed to significantly improve accuracy and convergence speed.

  • feat(api): Updates GA_Options to expose the new GA strategy parameters:

    • Renames mutation_percentage to mutation_strength for clarity.
    • Adds elite_ratio, crossover_ratio, and mutation_ratio.
    • Includes a __post_init__ validator to ensure ratios are valid.
  • refactor(api): Moves quadratic_solve from a standalone function to a method of the Function class (f1.quadratic_solve()). This provides a cleaner, more object-oriented API.

  • docs: Updates the README, GA_Options doc page, and quadratic_solve doc page to reflect all API changes, new parameters, and updated usage examples.

  • chore: Bumps version to 0.4.0.

This commit introduces a major enhancement to the genetic algorithm's convergence logic and refactors key parts of the API for better clarity and usability. - **feat(ga):** Re-implements the GA solver (CPU & CUDA) to use a more robust strategy based on Elitism, Crossover, and Mutation. This replaces the previous, less efficient model and is designed to significantly improve accuracy and convergence speed. - **feat(api):** Updates `GA_Options` to expose the new GA strategy parameters: - Renames `mutation_percentage` to `mutation_strength` for clarity. - Adds `elite_ratio`, `crossover_ratio`, and `mutation_ratio`. - Includes a `__post_init__` validator to ensure ratios are valid. - **refactor(api):** Moves `quadratic_solve` from a standalone function to a method of the `Function` class (`f1.quadratic_solve()`). This provides a cleaner, more object-oriented API. - **docs:** Updates the README, `GA_Options` doc page, and `quadratic_solve` doc page to reflect all API changes, new parameters, and updated usage examples. - **chore:** Bumps version to 0.4.0.
jono added 1 commit 2025-10-27 14:13:23 +00:00
feat(ga, api): Implement advanced GA strategy and refactor API for v0.4.0
Some checks failed
Run Python Tests / test (3.10) (pull_request) Failing after 16s
Run Python Tests / test (3.8) (pull_request) Failing after 41s
Run Python Tests / test (3.12) (pull_request) Has been cancelled
34019a67b0
This commit introduces a major enhancement to the genetic algorithm's convergence logic and refactors key parts of the API for better clarity and usability.

- **feat(ga):** Re-implements the GA solver (CPU & CUDA) to use a more robust strategy based on Elitism, Crossover, and Mutation. This replaces the previous, less efficient model and is designed to significantly improve accuracy and convergence speed.

- **feat(api):** Updates `GA_Options` to expose the new GA strategy parameters:
    - Renames `mutation_percentage` to `mutation_strength` for clarity.
    - Adds `elite_ratio`, `crossover_ratio`, and `mutation_ratio`.
    - Includes a `__post_init__` validator to ensure ratios are valid.

- **refactor(api):** Moves `quadratic_solve` from a standalone function to a method of the `Function` class (`f1.quadratic_solve()`). This provides a cleaner, more object-oriented API.

- **docs:** Updates the README, `GA_Options` doc page, and `quadratic_solve` doc page to reflect all API changes, new parameters, and updated usage examples.

- **chore:** Bumps version to 0.4.0.
jono added 1 commit 2025-10-27 14:15:03 +00:00
fix: Remove quadratic_solve import from test
Some checks failed
Run Python Tests / test (3.10) (pull_request) Successful in 15s
Run Python Tests / test (3.12) (pull_request) Failing after 15s
Run Python Tests / test (3.8) (pull_request) Failing after 3m8s
415e2a3ef5
jono added 1 commit 2025-10-27 14:20:12 +00:00
fix(ga): Prevent premature convergence by widening parent pool
All checks were successful
Run Python Tests / test (3.10) (pull_request) Successful in 11s
Run Python Tests / test (3.12) (pull_request) Successful in 14s
Run Python Tests / test (3.8) (pull_request) Successful in 10s
663e72eabf
The GA tests were failing because the algorithm converged on a single root (e.g., -1.0) and failed to find the other (e.g., 2.5).

This was caused by creating a 'parent pool' from only the top 50% of solutions. This was too aggressive and discarded the 'niche' solutions that were exploring other valid roots.

This commit modifies the parent selection logic in both `_solve_x_numpy` and `_solve_x_cuda`. Parents for crossover and mutation are now selected from the *entire* sorted population (`data_size`).

This maintains population diversity and allows the algorithm to explore multiple optima, fixing the failing tests.
jono merged commit c3b3513e79 into main 2025-10-27 14:20:56 +00:00
jono deleted branch v0.4.0-dev 2025-10-27 14:20:56 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jono/PolySolve#16