piglot.optimisers.ga.GA

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: ScalarOptimiser

Genetic 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

Methods

optimise

Optimiser for the outside world.

optimise(n_iter: int, parameters: ~piglot.parameter.ParameterSet, output_dir: str, stop_criteria: ~piglot.optimiser.StoppingCriteria = <piglot.optimiser.StoppingCriteria object>, verbose: bool = True) Tuple[float, ndarray]

Optimiser for the outside world.

Parameters

objectiveObjective

Objective function to optimise.

n_iterint

Maximum number of iterations.

parametersParameterSet

Set of parameters to optimise.

output_dirstr

Whether to write output to the output directory, by default None.

stop_criteriaStoppingCriteria

List of stopping criteria, by default none attributed.

verbosebool

Whether to output progress status, by default True.

Returns

float

Best observed objective value.

np.ndarray

Observed optimum of the objective.