hyponic.optimizers.genetic_based package
hyponic.optimizers.genetic_based.GA module
- class hyponic.optimizers.genetic_based.GA.GA(epoch: int = 10, population_size: int = 10, minmax: str = None, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
BaseOptimizer
Genetic Algorithm(GA)
Example
>>> from hyponic.optimizers.genetic_based.GA import GA >>> import numpy as np >>> >>> def sphere(x): >>> return np.sum(x ** 2) >>> >>> problem_dict = { >>> 'fit_func': sphere, >>> 'lb': [-5.12, -5, -14, -6, -0.9], >>> 'ub': [5.12, 5, 14, 6, 0.9], >>> 'minmax': 'min' >>> } >>> >>> ga = GA(epoch=40, population_size=100, verbose=True, early_stopping=4) >>> ga.solve(problem_dict) >>> print(ga.get_best_score()) >>> print(ga.get_best_solution())
- evolve(epoch)[source]
Evolve the population for one epoch
- Parameters:
current_epoch – current epoch number
- get_best_score()[source]
Get the best score of the current population
- Returns:
best score of the fitness function
- get_best_solution()[source]
Get the best solution of the current population
- Returns:
coordinates of the best solution
- get_current_best_score()[source]
Get the best score of the current population
- Returns:
current best score of the fitness function