API

Utility functions

indago.minimize(evaluation_function, lb=None, ub=None, optimizer_name='PSO', optimize_seed=None, **kwargs)

Shorthand one-line utility function for running an optimization.

Parameters:
  • evaluation_function (callable) – Evaluation function. Takes a design vector (ndarray) and returns fitness value (float), or in case of multiobjective and/or constrainted optimization a tuple with objectives (float) and constraints (float).

  • lb (list or ndarray or float or None) – Lower bounds. If None lower bounds will be taken from evaluation_function.lb.

  • ub (list or ndarray or float or None) – Upper bounds. If None upper bounds will be taken from evaluation_function.ub.

  • optimizer_name (str) – Name (abbreviation) of the optimization method used. Default value is 'PSO'.

  • optimize_seed (int or None) – A random seed. Use the same value for reproducing identical stochastic procedures.

  • **kwargs (kwarg) – Keyword arguments passed to the Optimizer object correspoding to the optimizer_name.

Returns:

(X, f) or (X, f, O, C) – Results of the optimization, comprising the design vector X (ndarray) and the corresponding minimum fitness f (float). In case of more than one objective and/or defined constraints, results also include objectives O (ndarray), and constraints C (ndarray).

Return type:

tuple

indago.minimize_exhaustive(evaluation_function, lb=None, ub=None, optimizer_name='PSO', params_ranges_dict=None, hyper_optimizer_name='FWA', runs=50, hyper_evaluations=1000, optimize_seed=None, **kwargs)

Utility function for exhaustive optimization with meta-optimizing optimizer parameters. The defined meta-optimizer (hyper_optimizer_name) will be used for meta-optimizing the defined optimizer (optimizer_name), namely its default variant. The meta-optimization will be conducted for a number of evaluations (hyper_evaluations). Each evaluation in the meta-optimization will return a median result of multiple runs (runs) of the optimizer used (optimizer_name). After the meta-optimization is conducted, a final round of multiple runs (runs) of optimization with the defined optimizer (optimizer_name) and optimal method parameters is performed, and the overall best result is returned together with the optimal method parameters.

Parameters:
  • evaluation_function (callable) – Evaluation function. Takes a design vector (ndarray) and returns fitness value (float), or in case of multiobjective and/or constrainted optimization a tuple with objectives (float) and constraints (float).

  • lb (list or ndarray or float or None) – Lower bounds. If None lower bounds will be taken from evaluation_function.lb.

  • ub (list or ndarray or float or None) – Upper bounds. If None upper bounds will be taken from evaluation_function.ub.

  • optimizer_name (str) – Name (abbreviation) of the optimization method used. Default value is 'PSO'.

  • params_ranges_dict (dict or None) – A dict with method parameter names as dict keys and lists of minimum and maximum values of the parameter in question as dict values (e.g. params_ranges_dict={'param_name': [min, max], ...}). If None given as range value, the default range will be used. If None, all available parameters are used with default value minimums and maximums.

  • hyper_optimizer_name (str) – Name (abbreviation) of the optimization method used for meta-optimizing the optimizer defined with optimizer_name.

  • runs (int) – Number of optimizer runs.

  • hyper_evaluations (int) – Number of evaluations used by the meta-optimizer (as defined by hyper_optimizer_name).

  • optimize_seed (int or None) – A random seed. Use the same value for reproducing identical stochastic procedures.

  • **kwargs (kwarg) – Keyword arguments passed to the Optimizer object correspoding to the optimizer_name.

Returns:

(best_result, optimal_params) – Results of the procedure, comprising overall best result (dict) in the form (X, f) or (X, f, O, C), as returned by the minimize utility function, and optimal method parameters (dict) found through meta-optimization.

Return type:

tuple

indago.inspect(evaluation_function, lb=None, ub=None, objectives=1, constraints=0, evaluations=None, optimizers_name_list=None, runs=10, xtol=0.0001, processes=1, printout=True)

Utility function for benchmarking default-set methods on a goal function. The methods defined in optimizers_name_list will be used for optimizing the evaluation function given in evaluation_function. Each optimization will be conducted on multiple runs (runs). Unique optima (defined with mutual relative distance of xtol) are counted and reported.

Parameters:
  • evaluation_function (callable) – Evaluation function. Takes a design vector (ndarray) and returns fitness value (float), or in case of multiobjective and/or constrainted optimization a tuple with objectives (float) and constraints (float).

  • lb (list or ndarray or float or None) – Lower bounds. If None lower bounds will be taken from evaluation_function.lb.

  • ub (list or ndarray or float or None) – Upper bounds. If None upper bounds will be taken from evaluation_function.ub.

  • objectives (int) – Number of objectives.

  • constraints (int) – Number of constraints.

  • optimizer_name_list (list of str) – A list of names (abbreviations) of the used Indago methods. If None then indago.optimizers_name_list is used.

  • runs (int) – Number of optimizer runs.

  • xtol (float) – Relative tolerance for calculating distance between found optima. If (np.abs(Xnew - Xold)) / (ub - lb) < xtol).all() == True then Xnew is considered non-unique.

  • processes (int) – Number of processes for parallel evaluation.

  • printout (bool) – If True a console printout of a tabular summary of the benchmarking results is produced.

Returns:

(TABLE, X_best) – Results of the benchmarking procedure. TABLE (dict) contains results as they are given in the printout. X_best (ndarray) is the best design vector found throughout the benchmarking.

Return type:

tuple

indago.inspect_optimizers(prepared_optimizers_dict, runs=10, xtol=0.0001, printout=True)

Utility function for benchmarking fully prepared Indago optimizers. The optimizer objects in prepared_optimizers_dict will be run multiple times (runs). Unique optima (defined with mutual relative distance of xtol) are counted and reported.

Parameters:
  • prepared_optimizers_dict (dict) – A dict of fully prepared optimizer objects in the form {'opt1 description': opt1, 'opt2 description': opt2, ...}.

  • runs (int) – Number of optimizer runs.

  • xtol (float) – Relative tolerance for calculating distance between found optima. If (np.abs(Xnew - Xold)) / (ub - lb) < xtol).all() == True then Xnew is considered non-unique.

  • printout (bool) – If True a console printout of a tabular summary of the benchmarking results is produced.

Returns:

(TABLE, X_best) – Results of the benchmarking procedure. TABLE (dict) contains results as they are given in the printout. X_best (ndarray) is the best design vector found throughout the benchmarking.

Return type:

tuple

indago.unconstrain(f, f0, p0=0.1)

Utility function (decorator) for creating unconstrained version of a single-objective constrained evaluation function.

Parameters:
  • f (callable) – Evaluation function for which the unconstrained penalty-based version is to be created.

  • f0 (float) – Reference value of function minimum.

  • p0 (float) – Relative size of penalty step. Penalty for each constrain (c) is computed as f0 * p0 + c

Returns:

f_penalty – Penalty-based single-objective evaluation function.

Return type:

callable

Utility constants

indago.optimizers

A list of all available Indago optimizer classes.

Type:

list of Optimizer

indago.optimizers_name_list

A list of all available Indago method names (abbreviations).

Type:

list of str

indago.optimizers_dict

A dict of all available Indago optimizers, in the form of method name (abbreviation, type: str) as key, and optimizer class (type: Optimizer) as value.

Type:

dict

Classes

class indago.Optimizer

Base class for all optimization methods.

Variables:
  • dimensions (int) – Number of dimensions of the search space i.e. number of optimization variables.

  • evaluation_function (callable) – A function (or a callable class) which takes a ndarray as argument and returns fitness value (float), or in case of multi-objective and/or constrained optimization returns a tuple containing objectives’ and constraints’ values. Optionally, it can take a keyword argument s (str) in order to handle a unique string generated by the optimizer.

  • processes (int or str) – Number of processes in a multiprocessing pool used for parallel evaluation of evaluation_function. If 'max' all available processor(s) cores will be used. Default: 1.

  • _pool (Pool) – Private multiprocessing Pool object, used for parallel evaluation.

  • objectives (int) – Number of objectives. Default: 1.

  • objective_weights (list of float) – Weights for objectives used in weighted sum multi-objective optimization. The weighted sum allows combining multiple objectives into a single value (fitness) function employed in the optimization. In order to properly utilize the weighted sum method, all objectives should be normalized to values of the same order of magnitude. This authorizes using several objectives and appointing their importance or priority in the optimization by setting the objective weights. By default, all objectives are of same priority, and their values are set to 1.

  • objective_labels (list of str) – Names of objectives. Used in outputs such as monitoring, logs, plots etc. Default objective labels are ['obj_0', 'obj_1', ... etc].

  • constraints (int) – Number of constraints. Default: 0.

  • constraint_labels (list of str) – Names of constraints. Used in outputs such as monitoring, logs, plots etc. By default, constraint labels are set to ['cnstr_0', 'cnstr_1', ... etc].

  • max_iterations (int) – Maximum allowed number of iterations of the used optimization method. Default: None.

  • max_evaluations (int) – Maximum allowed number of evaluations to be used in the optimization process. Default: None. If max_iterations, max_evaluations, max_stalled_iterations, max_stalled_evaluations, target_fitness, and max_elapsed_time are all None, defaults to: 50 * dimensions ^2.

  • max_stalled_iterations (int) – Maximum allowed number of method iterations without any progress. Default: None.

  • max_stalled_evaluations (int) – Maximum allowed number of evaluations without any progress. Default: None.

  • target_fitness (float) – Target fitness value at which the optimization will be stopped. Default: None.

  • max_elapsed_time (float) – Maximum allowed time (in seconds) to be used in the optimization process. Default: None.

  • lb (ndarray or list of float or float) – Lower bounds. If float it will be expanded to ndarray of float of size dimensions. Default: None.

  • ub (ndarray or list of float or float) – Upper bounds. If float it will be expanded to ndarray of float of size dimensions. Default: None.

  • best (CandidateState) – The best candidate state insofar encountered in the optimization process.

  • X0 (ndarray or int) – Starting point(s) for the optimization. 1d ndarray, or 2d ndarray with each row representing one design vector. If int, represents the number of random candidates generated at the start of optimization. Each method embeds these candidates, fully or partially, in initial population, swarm or starting points. Initial candidates are selected in order of their fitness.

  • _cS0 (ndarray) – Private array of CandidateState instances populated and evaluated according to given Optimizer.X0 parameter. The array is adopted in each method for establishing initial population, swarm or starting point.

  • _evaluated_candidates (ndarray of CandidateState) – Private array used as a buffer of evaluated candidates in current iteration. Enables forwarding a list of all evaluated candidates in an interation to be forwarded to post_iteration_processing function even if multiple collective evaluations are utilized in a single iteration of a method.

  • scatter_method (str) – Method for initializing starting points for the optimization. If 'random' a uniform random generator is used. If 'halton' a Halton sequence is used, which will cover the domain more evenly. Default: 'random'.

  • _halton_sampler (Halton or None) – Private Halton sampler used for generating starting points.

  • _seed (int or None) – Private integer for seeding random number generation.

  • _scatter (callable (list of CandidateState)) – Private method for generating initial positions of given candidates, by using the appropriate method (Optimizer.scatter_method).

  • status (str) – Text description of optimizer status.

  • _err_msg (str or None) – Private string for storing error message. When an error message is generated, the message is reported and the optimization is aborted.

  • history (dict) – Dictionary of appropriately formatted arrays that keeps record of optimization convergence. Using dict keys one can access the information for the best candidate in any iteration: history['eval'] for number of evaluations (shape [iterations, 1]), history['X'] for optimization vector (shape: [iterations, dimensions]), history['O'] for objectives (shape [iterations, objectives]), history['C'] for constraints (shape [iterations, constraints]), and history['f'] for fitness (shape [iterations, 1]. The same data rearranged in a single matrix is stored in convergence_log_file.

  • monitoring (str) – Adjust the monitoring style and level of output produced during the optimization. 'none' or None suppresses all output. For displaying a line-per-iteration output to the terminal use 'basic' which can display a colored output if supported by your terminal. For displaying a progress bar and the dynamically updated best solution use 'dashboard'. Default: 'none'.

  • _rich_console (Console) – Private rich Console, used for rich output.

  • convergence_log_file (str) – Convergence log file name. The convergence log file is suitably formatted allowing reading it using numpy.loadtxt, and it includes rows for: number of iterations, number of evaluations, optimization variables, objectives, constraints and fitness. Default: None (no convergence log is stored).

  • evals_db (str) – A file name for storing all evaluated candidates . The evaluation database is stored in Numpy’s binary (.npy) file format that can be read using numpy.load, and it includes rows for: optimization variables, objectives, constraints and fitness. Default: None (evaluations database is not stored).

  • forward_unique_str (bool) – If True, unique string forwarding is used. The strings are generated by Indago and are then passed on to evaluation_function as an additional argument. Default: False.

  • _unique_str_list (list) – Private list for tracking used unique strings.

  • post_iteration_processing (callable) – Handle for a callable object (e.g. function) that is being evoked after each iteration of the method. The function is expected to process following arguments it (int, current iteration), candidates (an array of CandidateStates evaluated in the current iteration) and best (best CandidateState found until current iteration).

  • safe_evaluation (bool) – If True, in case of failed evaluations exceptions thrown by the evaluation_function are caught and np.nan is returned instead. Default: False.

  • eval_fail_count (int) – Used for counting failed evaluations.

  • eval_fail_behavior (str) – Controlling behavior in case of evaluation_function returning np.nan. If 'abort' the optimization is stopped at the first event of evaluation function returning np.nan. If 'ignore' the optimizer will ignore any np.nan values returned by the evaluation function (not all Indago methods support this). If 'retry' the optimizer will try to resolve the issue by repeatedly receding a failed design vector a small step towards the best solution thus far. Default: 'abort'.

  • eval_retry_attempts (int) – Number of retry attempts in case of failed evaluation. Used only if eval_fail_behavior='retry'. Default: 10.

  • eval_retry_recede (float) – Relative distance in the range [0, 1] for which the failed evaluation vector will be translated in the direction of the best solution thus far. Used only if eval_fail_behavior='retry'. Default: 0.01.

  • it (int) – Used for counting iterations.

  • eval (int) – Used for counting evaluations.

  • _stalled_it (int) – Used for counting stalled iterations.

  • _stalled_eval (int) – Used for counting stalled evaluations.

  • elapsed_time (float) – Used for tracking time elapsed during optimization.

  • _clock_start (float) – Clock time at the start of the optimization (used for computing elapsed_time).

  • params (dict) – Method parameters, in the form of parameter name (dict key as str), parameter value (dict value). Defaults specific to the optimization method used.

Returns:

Optimizer instance

Return type:

Optimizer

_check_params(mandatory_params, optional_params, defined_params)

Private method which checks if optimizer parameters are defined in Optimizer.params dict. Should be called in initializations of derived Optimizer classes. It asserts if any of mandatory parameters is missing and prints a warning if unknown/excessive parameter is provided.

Parameters:
  • mandatory_params (list of str) – A list of mandatory parameter names/keys for given method.

  • optional_params (list of str) – A list of optional parameter names/keys for given method.

  • defined_params (list of str) – A list of method’s parameters names/keys defined in Optimizer.params dict.

Returns:

Nothing

Return type:

None

_collective_evaluation(candidates)

Private function used for evaluation of multiple candidates which automatically conducts parallel or serial evaluation and forwards a unique string to the evaluation function. Evaluation is performed in-place and the candidates provided as argument are updated.

Parameters:

candidates (list of CandidateState) – A list of candidates to be evaluated.

Returns:

Nothing

Return type:

None

_convergence_log_line()

Private method used to produce and write a line to convergence log file for each iteration.

Returns:

Nothing

Return type:

None

_evaluate_initial_candidates()

Private method for evaluating initial candidates. This method populates and evaluates private list of initial candidates (Optimizer._cS0) according to provided initial points Optimizer.X0.

Returns:

Nothing

Return type:

None

_evaluation_function_safe(X, s=None)

Private method for wrapping evaluation function in try-except.

Parameters:
  • X (np.array) – Design vector.

  • s (str) – Unique string.

Returns:

fitness – Fitness value as computed by evaluation function, or np.nan if failed to compute evaluation function.

Return type:

float

_finalize_iteration()

Private method used to perform all administrative tasks at the end of a method’s iteration.

Returns:

stopTrue or False, whether the optimization should stop or not.

Return type:

bool

_gen_unique_str()

Private method for generating a unique string of 16 characters. This string is then used when forwarding a unique string to the evaluation function is enabled (Optimizer.forward_unique_str = True). The generated string is guaranteed to be unique within an optimizer.

Returns:

s – A unique string.

Return type:

str

_init_convergence_log()

Private method for initializing convergence log. It creates log file and writes optimization setup summary and header row.

Returns:

Nothing

Return type:

None

_init_optimizer()

Private method for Optimizer initialization performed just prior to starting the optimization. Checks the types and values of user defined Optimizer attributes. Automatically sets optional Optimizer-level parameters to default values if they are not provided.

Returns:

Nothing

Return type:

None

_initialize_X(cS)

Private method for initializing CandidateState positions.

Parameters:

cS (list of CandidateState) – Candidates of which X must be initialized.

Returns:

Nothing

Return type:

None

_log(msg, indent=0)

Utility function for consistently displaying messages in the output.

Parameters:
  • msg (str) – Message to be displayed in the output.

  • indent (int) – Number of characters used for indentation of the message. Default is 0.

Returns:

Nothing

Return type:

None

_multiprocess_evaluate(candidates)

Private method used for calling parallel evaluation of multiple candidates. It relies on multiprocessing pool using map and starmap methods. The objectives, constraints and fitness of candidates in the list are updated after the evaluation.

Parameters:

candidates (list of CandidateState) – A list of candidates to be evaluated.

Returns:

Nothing

Return type:

None

_progress_factor()

Private method for calculating progress factor ranging from zero to one, based on iterations or evaluations (whichever is running out faster). Used in optimization methods which adapt their behavior during the optimization process based on the time passed.

Returns:

progress_factor – A number between zero and one, representing the procedural progress of the optimization process.

Return type:

float

_progress_log()

Private method used to produce and print a line for each iteration.

Returns:

Nothing

Return type:

None

_stopping_criteria()

Private method used to evaluate all specified stopping conditions.

Returns:

stopTrue or False, whether the optimization should stop.

Return type:

bool

_update_history()

Private method that updates Optimizer.history dict entries according to current Optimizer.best CandidateState.

Returns:

Nothing

Return type:

None

_update_progress_bar()

Private function for updating rich progress bar for ‘dashboard’ monitoring.

Returns:

Nothing

Return type:

None

copy()

Method for creating a true (deep) copy of the Optimizer.

Returns:

Optimizer instance

Return type:

opt

optimize(resume=False, seed=None)

Method which starts the optimization. The method wraps _run method of the optimizer’s subclass.

Parameters:
  • resume (bool) – If True, the user is intentionally running an optimizer instance which has been run earlier. Otherwise, error is thrown when trying to re-run an optimizer instance.

  • seed (int or None) – Random seed. Provide the same value for reproducing identical stochastic procedures.

Returns:

optimum – The best solution found in the optimization.

Return type:

CandidateState

plot_history(filename=None, title='Optimization convergence')

Plot the convergence of optimization variables, objectives, constraints and fitness.

Parameters:
  • filename (str) – Saves the convergence figure according to provided filename and closes the figure.

  • title (str) – Optional title of the figure.

Returns:

If filename is specified nothing (None) is returned, otherwise the tuple of figure and axis array is returned.

Return type:

None or (fig, axes)

class indago.CandidateState(optimizer: Optimizer)

Base class for search agents in all optimization methods. Candidate solution for the optimization problem.

Variables:
  • X (ndarray) – Design vector.

  • O (ndarray) – Objectives’ values.

  • C (ndarray) – Constraints’ values.

  • f (float) – Fitness.

Returns:

CandidateState instance.

Return type:

CandidateState

static _eq_fast(a, b)

Private method for fast candidate solution equality check. Used in single objective, unconstrained optimization.

Parameters:
  • a (CandidateState) – The first of the two candidate solutions.

  • b (CandidateState) – The second of the two candidate solutions.

Returns:

equalTrue if candidate solutions are equal, False otherwise.

Return type:

bool

static _eq_full(a, b)

Private method for full candidate solution equality check. Used in multiobjective and/or constrained optimization.

Parameters:
  • a (CandidateState) – The first of the two candidate solutions.

  • b (CandidateState) – The second of the two candidate solutions.

Returns:

equalTrue if candidate solutions are equal, False otherwise.

Return type:

bool

static _lt_fast(a, b)

Fast less-than operator. Used in single objective, unconstrained optimization.

Parameters:
  • a (CandidateState) – The first of the two candidate solutions.

  • b (CandidateState) – The second of the two candidate solutions.

Returns:

lower_thanTrue if a is better than b, False otherwise.

Return type:

bool

static _lt_full(a, b)

Private method for full less-than check. Used in multiobjective and/or constrained optimization.

Parameters:
  • a (CandidateState) – The first of the two candidate solutions.

  • b (CandidateState) – The second of the two candidate solutions.

Returns:

lower_thanTrue if a is better than b, False otherwise.

Return type:

bool

clip(optimizer)

Method for clipping (trimming) the design vector (CandidateState.X) values to lower and upper bounds.

Returns:

Nothing

Return type:

None

copy()

Method for creating a true (deep) copy of the CandidateState.

Returns:

CandidateState instance

Return type:

CandidateState

is_feasible()

Determines whether the design vector of a CandidateState is a feasible solution. A feasible solution is a solution which satisfies all constraints.

Returns:

is_feasibleTrue if the CandidateState design vector is feasible, False otherwise.

Return type:

bool

class indago.PSO

Particle Swarm Optimization method class.

Variables:
  • variant (str) – Name of the PSO variant (Vanilla, TVAC, or Chaotic). Default: Vanilla.

  • params (dict) – A dictionary of PSO parameters.

Returns:

optimizer – PSO optimizer instance.

Return type:

PSO

_check_params()

Private method which performs some PSO-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_find_neighborhood_best()

Method for determining the best particle of each neighborhood.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the PSO optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_reinitialize_topology(k=3)

Method for reinitializing the PSO swarm topology. Removes existing and creates new connections in the swarm topology.

Variables:

k (int) – Size of PSO swarm neighborhood.

Returns:

Nothing

Return type:

None

_run()

Main loop of PSO method.

Returns:

optimum – Best solution found during the PSO optimization.

Return type:

Particle

class indago._pso.Particle(optimizer: Optimizer)

PSO Particle class. PSO Particle is a member of a PSO swarm.

Variables:

V (ndarray) – Particle velocity.

Returns:

particle – Particle instance.

Return type:

Particle

class indago.FWA

Fireworks Algorithm method class.

Variables:
  • variant (str) – Name of the FWA variant (Vanilla or Rank). Default: Rank.

  • params (dict) – A dictionary of FWA parameters.

Returns:

optimizer – FWA optimizer instance.

Return type:

FWA

_check_params()

Private method which performs some FWA-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_explosion()

Private method for computing explosion sparks.

Returns:

explosion_sparks – FWA explosion sparks.

Return type:

list of CandidateState

_gaussian_mutation()

Private method for computing mutation sparks.

Returns:

mutation_sparks – FWA mutation sparks.

Return type:

list of CandidateState

_init_method()

Private method for initializing the FWA optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_min_max_round(s, smin, smax)

Private method for calculating round of min of max of input parameters.

Parameters:
  • s (float) – Preliminary population size.

  • smin (float) – Preliminary population size.

  • smax (float) – Preliminary population size.

Returns:

min_max_round – Round of min of max of input parameters.

Return type:

int

_run()

Main loop of FWA method.

Returns:

optimum – Best solution found during the FWA optimization.

Return type:

CandidateState

class indago.SSA

Squirrel Search Algorithm method class.

Reference: Jain, M., Singh, V., & Rani, A. (2019). A novel nature-inspired algorithm for optimization: Squirrel search algorithm. Swarm and evolutionary computation, 44, 148-175.

Variables:
  • variant (str) – Name of the SSA variant. Default: Vanilla.

  • params (dict) – A dictionary of SSA parameters.

Returns:

optimizer – SSA optimizer instance.

Return type:

SSA

_check_params()

Private method which prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the SSA optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_run()

Main loop of SSA method.

Returns:

optimum – Best solution found during the SSA optimization.

Return type:

FlyingSquirrel

class indago.DE

Differential Evolution method class.

Reference: R. Tanabe and A. S. Fukunaga. Improving the search performance of SHADE using linear population size reduction”, in Proceedings of the 2014 IEEE Congress on Evolutionary Computation (CEC), pp. 1658–1665, Beijing, China, July 2014.

Variables:
  • variant (str) – Name of the DE variant (SHADE or LSHADE). Default: SHADE.

  • params (dict) – A dictionary of DE parameters.

Returns:

optimizer – DE optimizer instance.

Return type:

DE

_check_params()

Private method which performs some DE-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the DE optimizer instance. Initializes and evaluates the population.

Returns:

Nothing

Return type:

None

_run()

Main loop of DE method.

Returns:

optimum – Best solution found during the DE optimization.

Return type:

Solution

class indago._de.Solution(optimizer: Optimizer)

DE solution class.

Variables:
  • V (ndarray) – Mutant vector.

  • CR (float) – DE control parameter CR.

  • F (float) – DE control parameter F.

Returns:

solution – Solution instance.

Return type:

Solution

class indago.BA

Bat Algorithm method class.

References: [1] Yang, Xin‐She, and Amir Hossein Gandomi. Bat algorithm: a novel approach for global engineering optimization. Engineering computations (2012). https://arxiv.org/pdf/1211.6663.pdf, [2] Yang, Xin‐She. Nature-inspired optimization algorithms (2021).

In this implementation loudness A and pulse rate r are generated for each Bat seperately (initial*2*rand).

Variables:
  • variant (str) – Name of the BA variant. Default: Vanilla.

  • params (dict) – A dictionary of BA parameters.

Returns:

optimizer – BA optimizer instance.

Return type:

BA

_check_params()

Private method which performs some BA-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the BA optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_run()

Main loop of BA method.

Returns:

optimum – Best solution found during the BA optimization.

Return type:

Bat

class indago._ba.Bat(optimizer: Optimizer)

BA Bat class. A Bat is a member of a BA swarm.

Variables:
  • V (ndarray) – Bat velocity.

  • Freq (ndarray) – Bat frequency.

  • A (float) – Bat loudness.

  • r (float) – Bat pulse rate.

Returns:

agent – Bat instance.

Return type:

Bat

class indago.EFO

Electromagnetic Field Optimization method class.

Reference: Abedinpourshotorban, H., Shamsuddin, S.M., Beheshti, Z., & Jawawi, D.N. (2016). Electromagnetic field optimization: a physics-inspired metaheuristic optimization algorithm. Swarm and Evolutionary Computation, 26, 8-22.

Due to evaluating only one particle per iteration, this method:

  • needs many iterations to be efficient (much more than other methods)

  • is effectively not parallelized in _collective_evaluation (hence parallel evaluation is not allowed, in order to avoid user confusion)

Parameters:
  • variant (str) – Name of the EFO variant. Default: Vanilla.

  • params (dict) – A dictionary of EFO parameters.

Returns:

optimizer – EFO optimizer instance.

Return type:

EFO

_check_params()

Private method which performs some EFO-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the EFO optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_run()

Main loop of EFO method.

Returns:

optimum – Best solution found during the EFO optimization.

Return type:

emParticle

class indago.MRFO

Manta Ray Foraging Optimization method class.

Reference: Zhao, Weiguo, Zhenxing Zhang, and Liying Wang. Manta ray foraging optimization: An effective bio-inspired optimizer for engineering applications. Engineering Applications of Artificial Intelligence 87 (2020): 103300.

Variables:
  • variant (str) – Name of the MRFO variant. Default: Vanilla.

  • params (dict) – A dictionary of MRFO parameters.

Returns:

optimizer – MRFO optimizer instance.

Return type:

MRFO

_check_params()

Private method which performs some MRFO-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the MRFO optimizer instance. Initializes and evaluates the swarm.

Returns:

Nothing

Return type:

None

_run()

Main loop of MRFO method.

Returns:

optimum – Best solution found during the MRFO optimization.

Return type:

CandidateState

class indago.ABC

Artificial Bee Colony Algorithm class method class.

Variables:
  • variant (str) – Name of the ABC variant (Vanilla or FullyEmployed). Default: Vanilla.

  • params (dict) – A dictionary of ABC parameters.

Returns:

optimizer – ABC optimizer instance.

Return type:

ABC

_check_params()

Private method which performs some ABC-specific parameter checks and prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the ABC optimizer instance. Initializes and evaluates the population.

Returns:

Nothing

Return type:

None

_run()

Main loop of ABC method.

Returns:

optimum – Best solution found during the ABC optimization.

Return type:

CandidateState

class indago.NM

Nelder-Mead method class.

Reference: Gao, F., Han, L. Implementing the Nelder-Mead simplex algorithm with adaptive parameters. Comput Optim Appl 51, 259–277 (2012). https://doi.org/10.1007/s10589-010-9329-3

Returns:

optimizer – NelderMead optimizer instance.

Return type:

NM

_check_params()

Private method which prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_init_method()

Private method for initializing the NelderMead optimizer instance. Evaluates given initial candidates, selects starting point, constructs initial polytope/simplex.

Returns:

Nothing

Return type:

None

_run()

Main loop of NelderMead method.

Returns:

optimum – Best solution found during the NelderMead optimization.

Return type:

CandidateState

class indago.MSGS

Multi Scale Grid Search class.

Parameters:
  • _x (CandidateState) – CandidateState for current point.

  • _y (ndarray of int) – The search grid indices for current point.

_check_params()

Private method which prepares the parameters to be validated by Optimizer._check_params.

Returns:

Nothing

Return type:

None

_find_dir(y, dy=None)

Finds a search direction based on finite difference approximation of a gradiend using points on the search grid. It utilizes a 2-point or 3-point gradient calculation, if existing direction dy is given or not, respectively.

Parameters:
  • y (ndarray of int) – The coordinates of current point defined using indices of the search grid.

  • dy (ndarray of int) – A step utilized in previous step of the method defined as an array of possible directions [-1, 0, 1] for each dimension.

Returns:

new_direction – New direction in terms of steps (one of [-1, 0, 1]) on the search grid for each dimension.

Return type:

ndarray of int

_init_method()

Private method for initializing the MSGS optimizer instance. Evaluates given initial candidates, selects starting point, constructs and deforms (if needed) initial grid, initializes grid search history.

Returns:

Nothing

Return type:

None

_reinit_grid(center, scale, grid_action)

(Re)creates the search grid according to given center of the grid and grid scale. Grid action is only informative argument and it does not influence the generation of the search grid. If current point (MSGS._x) is not on the grid, only the closest discrete values are adjusted to the current point resulting with locally deformed search grid.

Parameters:
  • center (ndarray) – The center of the search grid. Grid is initially constructed using n divisions before and after the center (2n + 1 divisions). If needed, due to bounds, center is automatically shifted and adjusted in order to ensure the search mesh is inside the bounds.

  • scale (int) – The scale of the search grid. The initial grid is generated using scale=1 which covers entire domain. The discretization step for each optimization variable is defined as dx = (self.ub - self.lb) / (2 * self._n * scale).

  • grid_action (string) – Information about the reason why the search grid reinitialization is being conducted. Possible values are: none, scale_up, scale_down or shift.

_run()

Main loop of MSGS method.

Returns:

optimum – Best solution found during the MSGS optimization.

Return type:

CandidateState

_x_to_y(x: CandidateState)

Converts the candidate defined with coordinates in the search space to indices of candidates location on the search grid.

Parameters:

x (CandidateState) – The candidate state you want to transform.

Returns:

y – The indices of the search grid where point x is located.

Return type:

ndarray of int

_y_to_x(y: ndarray)

Converts the indices of the search grid to a candidate.

Parameters:

y (ndarray of int) – The indices of the search grid where point x is located.

Returns:

x – The candidate state you want to transform.

Return type:

CandidateState