piglot.optimisers package
Subpackages
Submodules
piglot.optimisers.aoa module
AOA optimiser module.
- class AOA(objective: Objective, n_solutions=10, alpha=5.0, mu=0.5, epsilon=1e-12, seed=1, MOA_start=0.2, MOA_end=1.0)[source]
Bases:
ScalarOptimiserAOA optimiser. Documentation: https://www.sciencedirect.com/science/article/pii/S0045782520307945
Attributes
- n_solutionsinteger
population size (number of candidate solutions)
- alphafloat
non-negative sensitive parameter used to define the accuracy of the exploitation over the iterations
- mufloat
non-negative control parameter to adjust the search process
- epsilonfloat
small number to avoid division by zero
- seedint
random state seed
- MOA_startfloat
Math Optimizer Accelerated function initial value
- MOA_endfloat
Math Optimizer Accelerated function end value
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.direct module
DIRECT optimiser module.
- class DIRECT(objective: Objective, epsilon=0)[source]
Bases:
ScalarOptimiserDIRECT method for optimisation.
Reference: https://doi.org/10.1007/BF00941892
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.ga module
Genetic Algorithm optimiser module.
- class GA(objective: Objective, variable_type='real', variable_type_mixed=None, function_timeout=3600, algorithm_parameters={'crossover_probability': 0.5, 'crossover_type': 'uniform', 'elit_ratio': 0.01, 'max_iteration_without_improv': None, 'max_num_iteration': None, 'mutation_probability': 0.1, 'parents_portion': 0.3, 'population_size': 100}, convergence_curve=True, progress_bar=False)[source]
Bases:
ScalarOptimiserGenetic Algorithm optimiser. Documentation: https://pypi.org/project/geneticalgorithm/
Attributes
- variable_typestring
‘bool’ if all variables are Boolean; ‘int’ if all variables are integer; and ‘real’ if all variables are real value or continuous (for mixed type see parameter variable_type_mixed)
- variable_type_mixednumpy array/None
Default None; leave it None if all variables have the same type; otherwise this can be used to specify the type of each variable separately. For example if the first variable is integer but the second one is real the input is: np.array([‘int’],[‘real’]). NOTE: it does not accept ‘bool’. If variable type is Boolean use ‘int’ and provide a boundary as [0,1] in variable_boundaries. Also if variable_type_mixed is applied, variable_boundaries has to be defined.
- function_timeoutfloat
if the given function does not provide output before function_timeout (unit is seconds) the algorithm raise error. For example, when there is an infinite loop in the given function.
- algorithm_parametersdictionary
Algorithm parameters.
- convergence_curveTrue/False
Plot the convergence curve or not. Default is True.
- progress_barTrue/False
Show progress bar or not. Default is True.
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.lipo_opt module
LIPO optimiser module.
- class LIPO(objective: Objective, log_args='auto', flexible_bounds={}, flexible_bound_threshold=-1.0, epsilon=0.0, seed=None)[source]
Bases:
ScalarOptimiserLIPO optimiser. Documentation: https://github.com/jdb78/lipo http://blog.dlib.net/2017/12/a-global-optimization-algorithm-worth.html
Attributes
- log_argslist[str]
list of arguments to treat in log space, if “auto”, then a variable is optimized in log space if (default = ‘auto’): - The lower bound on the variable is > 0 - The ratio of the upper bound to lower bound is > 1000 - The variable is not an integer variable
- flexible_boundsdict[str, list[bool]]
dictionary of parameters and list of booleans indicating if parameters are deemed flexible or not. By default all parameters are deemed flexible but only if flexible_bound_threshold > 0 (default = {}).
- flexible_bound_thresholdfloat
enlarge bounds if optimum is top or bottom flexible_bound_threshold quantile (default = -1.0)
- epsilonfloat
accuracy below which exploration will be priorities vs exploitation (default = 0)
- random_stateint
random state
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.pso module
PSO optimiser module.
- class GlobalBestPSOMod(**kwargs)[source]
Bases:
Missing_pyswarms- compute_objective_function(swarm, objective_func, pool=None, **kwargs)[source]
Evaluate particles using the objective function
This method evaluates each particle in the swarm according to the objective function passed.
If a pool is passed, then the evaluation of the particles is done in parallel using multiple processes.
Parameters
- swarmpyswarms.backend.swarms.Swarm
a Swarm instance
- objective_funcfunction
objective function to be evaluated
- pool: multiprocessing.Pool
multiprocessing.Pool to be used for parallel particle evaluation
- kwargsdict
arguments for the objective function
Returns
- numpy.ndarray
Cost-matrix for the given swarm
- optimize(optimiser, objective_func, iters, n_processes=None, verbose=False, **kwargs)[source]
Optimize the swarm for a number of iterations
Performs the optimization to evaluate the objective function
ffor a number of iterationsiter.Parameters
- objective_funccallable
objective function to be evaluated
- itersint
number of iterations
- n_processesint
number of processes to use for parallel particle evaluation (default: None = no parallelization)
- verbosebool
enable or disable the logs and progress bar (default: True = enable logs)
- kwargsdict
arguments for the objective function
Returns
- tuple
the global best cost and the global best position.
- class PSO(objective: Objective, n_part, options, oh_strategy=None, bh_strategy='periodic', velocity_clamp=None, vh_strategy='unmodified', center=1.0, ftol_iter=1, n_processes=None)[source]
Bases:
ScalarOptimiserPSO optimiser. Documentation: https://pyswarms.readthedocs.io/en/latest/_modules/pyswarms/single/global_best.html#GlobalBestPSO
Attributes
- n_partint
number of particles in the swarm.
options : dict with keys
{'c1', 'c2', 'w'}a dictionary containing the parameters for the specific optimization technique.- c1float
cognitive parameter
- c2float
social parameter
- wfloat
inertia parameter
- oh_strategydict, optional, default=None(constant options)
a dict of update strategies for each option.
- bh_strategystr
a strategy for the handling of out-of-bounds particles.
- velocity_clamptuple, optional
a tuple of size 2 where the first entry is the minimum velocity and the second entry is the maximum velocity. It sets the limits for velocity clamping.
- vh_strategystr
a strategy for the handling of the velocity of out-of-bounds particles.
- centerlist (default is
None) an array of size
dimensions- ftol_iterint
number of iterations over which the relative error in objective_func(best_pos) is acceptable for convergence. Default is
1- n_processesint
number of processes to use for parallel particle evaluation (default: None = no parallelization)
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.random_search module
Pure random search optimiser module.
- class PureRandomSearch(objective: Objective, sampling='uniform', seed=1)[source]
Bases:
ScalarOptimiserPure Random Search optimiser.
Three sampling methods for generating random numbers are available: - Uniform distribution. - Normal distribution, centered around the best value, and with decreasing standard deviation throughout the iterative process. - Sampling based on the Sobol sequence (requires scipy >= 1.7).
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.spsa module
SPSA optimiser module.
- class SPSA(objective: Objective, alpha=0.602, gamma=0.101, prob=0.5, seed=1, A=None, a=None, c=None)[source]
Bases:
ScalarOptimiserSimultaneous Perturbation Stochastic Approximation method for optimisation.
Reference: https://ieeexplore.ieee.org/document/705889
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
piglot.optimisers.spsa_adam module
Hybrid SPSA-Adam optimiser module.
- class SPSA_Adam(objective: Objective, alpha=0.01, beta1=0.9, beta2=0.999, epsilon=1e-08, gamma=0.101, prob=0.5, c=None, seed=1)[source]
Bases:
ScalarOptimiserHybrid Simultaneous Perturbation Stochastic Approximation-Adam method for optimisation.
References: https://ieeexplore.ieee.org/document/705889 https://arxiv.org/abs/1412.6980
Methods
- _optimise(self, func, n_dim, n_iter, bound, init_shot):
Solves the optimization problem
Module contents
Module for optimisers.