hyponic.optimizers.swarm_based package
hyponic.optimizers.swarm_based.ABC module
- class hyponic.optimizers.swarm_based.ABC.ABC(epoch: int = 10, population_size: int = 10, minmax: str = None, limits=25, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
BaseOptimizer
Artificial Bee Colony (ABC) algorithm
- Hyperparameters:
limits(int), default=25: the number of trials before abandoning food source
Example
>>> from hyponic.optimizers.swarm_based.ABC import ABC >>> 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' >>> } >>> >>> abc = ABC(epoch=40, population_size=100, verbose=True, early_stopping=4) >>> abc.solve(problem_dict) >>> print(abc.get_best_score()) >>> print(abc.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
hyponic.optimizers.swarm_based.ACO module
- class hyponic.optimizers.swarm_based.ACO.ACO(epoch: int = 10, population_size: int = 10, minmax: str = None, alpha: float = 1, beta: float = 1, rho: float = 0.5, q: float = 1, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
BaseOptimizer
Ant Colony Optimization (ACO)
- Hyperparameters:
alpha(float), default=1: the importance of pheromone
beta(float), default=1: the importance of heuristic information
rho(float), default=0.5: the pheromone evaporation rate
q(float), default=1: the pheromone intensity
Example
>>> from hyponic.optimizers.swarm_based.ACO import ACO >>> 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' >>> } >>> >>> alpha = 1 >>> beta = 1 >>> rho = 0.5 >>> q = 1 >>> >>> aco = ACO(epoch=40, population_size=100, verbose=True, early_stopping=4, alpha=alpha, beta=beta, rho=rho, q=q) >>> aco.solve(problem_dict) >>> print(aco.get_best_score()) >>> print(aco.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
hyponic.optimizers.swarm_based.CS module
- class hyponic.optimizers.swarm_based.CS.CS(epoch: int = 10, population_size: int = 10, minmax: str = None, verbose: bool = False, pa: float = 0.25, alpha: float = 0.5, k: float = 1, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
BaseOptimizer
Cuckoo Search (CS) algorithm
- Hyperparameters:
pa(float), default=0.25: probability of cuckoo’s egg to be discovered
alpha(float), default=0.5: step size
k(float), default=1: Levy multiplication coefficient
Example
>>> from hyponic.optimizers.swarm_based.CS import CS >>> 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' >>> } >>> >>> cs = CS(epoch=40, population_size=100, verbose=True, early_stopping=4) >>> cs.solve(problem_dict) >>> print(cs.get_best_score()) >>> print(cs.get_best_solution())
- evolve(current_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
hyponic.optimizers.swarm_based.GWO module
- class hyponic.optimizers.swarm_based.GWO.GWO(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
Grey Wolf Optimization (GWO) algorithm
Example
>>> from hyponic.optimizers.swarm_based.GWO import GWO >>> 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' >>> } >>> >>> gwo = GWO(epoch=40, population_size=100, verbose=True, early_stopping=4) >>> gwo.solve(problem_dict) >>> print(gwo.get_best_score()) >>> print(gwo.get_best_solution())
- evolve(current_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
hyponic.optimizers.swarm_based.PSO module
- class hyponic.optimizers.swarm_based.PSO.IWPSO(epoch: int = 10, population_size: int = 10, minmax: str = None, a1: float = 0.5, a2: float = 0.5, w: float = 0.8, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
PSO
Inertia Weight Particle Swarm Optimization
- Hyperparameters:
a1(float), default=0.5: acceleration parameter
a2(float), default=0.5: acceleration parameter
w(float), default=0.5: inertia weight
Example
>>> from hyponic.optimizers.swarm_based.PSO import IWPSO >>> 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' >>> } >>> >>> a1, a2 = 0.8, 0.4 >>> w = 0.3 >>> iwpso = IWPSO(epoch=40, population_size=100, verbose=True, early_stopping=4, a1=a1, a2=a2, w=w) >>> iwpso.solve(problem_dict) >>> print(iwpso.get_best_score()) >>> print(iwpso.get_best_solution())
- class hyponic.optimizers.swarm_based.PSO.PSO(epoch: int = 10, population_size: int = 10, minmax: str = None, a1: float = 0.5, a2: float = 0.5, verbose: bool = False, mode: str = 'single', n_workers: int = 4, early_stopping: int | None = None, **kwargs)[source]
Bases:
BaseOptimizer
Particle Swarm Optimization (PSO) algorithm
- Hyperparameters:
a1(float), default=0.5: acceleration parameter
a2(float), default=0.5: acceleration parameter
Example
>>> from hyponic.optimizers.swarm_based.PSO import PSO >>> 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' >>> } >>> >>> a1, a2 = 0.8, 0.4 >>> pso = PSO(epoch=40, population_size=100, verbose=True, early_stopping=4, a1=a1, a2=a2) >>> pso.solve(problem_dict) >>> print(pso.get_best_score()) >>> print(pso.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