feat(ga, api): Implement advanced GA strategy and refactor API for v0.4.0 (#16)
All checks were successful
Publish Python Package to PyPI / deploy (push) Successful in 18s

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.

Reviewed-on: #16
Co-authored-by: Jonathan Rampersad <rampersad.jonathan@gmail.com>
Co-committed-by: Jonathan Rampersad <rampersad.jonathan@gmail.com>
This commit was merged in pull request #16.
This commit is contained in:
2025-10-27 14:20:56 +00:00
committed by Jonathan Rampersad
parent 0536003dce
commit c3b3513e79
4 changed files with 237 additions and 107 deletions

View File

@@ -8,7 +8,7 @@ try:
except ImportError:
_CUPY_AVAILABLE = False
from polysolve import Function, GA_Options, quadratic_solve
from polysolve import Function, GA_Options
@pytest.fixture
def quadratic_func() -> Function:
@@ -60,7 +60,7 @@ def test_nth_derivative(quadratic_func):
def test_quadratic_solve(quadratic_func):
"""Tests the analytical quadratic solver for exact roots."""
roots = quadratic_solve(quadratic_func)
roots = quadratic_func.quadratic_solve()
# Sorting ensures consistent order for comparison
assert sorted(roots) == [-1.0, 2.5]