GA_Options API
5. API Reference: `GA_Options` Class
The GA_Options
dataclass allows you to fine-tune the genetic algorithm used in the solve_x
and get_real_roots
methods.
from polysolve import Function, GA_Options
# Configure a more exhaustive search
custom_options = GA_Options(
min_range=-100.0,
max_range=100.0,
num_of_generations=10,
data_size=500000,
sample_size=100,
mutation_percentage=0.01
)
f = Function(5)
f.set_coeffs([1, 0, -15, 0, 10, 0])
roots = f.get_real_roots(options=custom_options)
- min_range / max_range (float): The lower and upper bounds for the initial random search space. Default: -100.0 / 100.0.
- num_of_generations (int): The number of iterations the algorithm will run. More generations can lead to more accurate results. Default: 10.
- data_size (int): The total number of "solutions" generated in each generation. A larger size increases the chance of finding roots but is more computationally expensive. Default: 100000.
- sample_size (int): The number of top-performing solutions from one generation that are used to create the next. Default: 1000.
- mutation_percentage (float): The small, random amount by which the top solutions are altered each generation to explore the nearby search space. Default: 0.01 (1%).