# gc3libs.optimizer¶

Support for finding minima of functions with GC3Pie.

GC3Pie can run a large number of Application instances in parallel. The idea of this optimization module is to use these core capabilities to perform optimization, which is particularly effective for optimization using evolutionary algorithms, as they require several independent evaluations of the target function.

The optimization module has two main components, the driver and the algorithm. You need both an instance of a driver and an instance of an algorithm to perform optimization of a given function.

Drivers perform optimization following a specific algorithm. Two drivers are currently implemented: drivers.SequentialDriver that runs the entire algorithm on the local computer (hence, all the evaluations of the target function required by the algorithm are performed one after the other), and drivers.ParallelDriver splits the evaluations into tasks that are executed in parallel using GC3Pie’s remote execution facilities.

This module implements a generic framework for evolutionary algorithms, and one particular type of global optimization algorithm called Differential Evolution is worked out in full. Other Evolutionary Algorithms can easily be incorporated by subclassing EvolutionaryAlgorithm. (Different optimization algorithms, for example gradient based methods such as quasi-newton methods, could be implemented but likely require adaptations in the driver classes.)

The module is organized as follows:

class gc3libs.optimizer.EvolutionaryAlgorithm(initial_pop, itermax=100, dx_conv_crit=None, y_conv_crit=None, logger=None, after_update_opt_state=[])

Base class for building an evolutionary algorithm for global optimization.

Parameters: initial_pop – Initial population for the optimization. The value can be any sequence that can be passed to np.array() itermax (int) – Maximum # of iterations. dx_conv_crit (float) – Abort optimization if all population members are within a certain distance to each other. y_conv_crit (float) – Declare convergence when the target function is below a y_conv_crit. logger (obj) – Configured logger to use. after_update_opt_state – List of functions that are called at the end of update_opt_state(). Use this list to provide problem-specific printing and plotting routines. Examples can be found in gc3libs.optimizer.extra.
evolve()

Generates a new population fullfilling in_domain(). :rtype list of population members

has_converged()

Checks convergence based on two criteria:

1. Is the lowest target value in the population below y_conv_crit.
2. Are all population members within dx_conv_crit from the first population member.
Return type: bool
select(new_pop, new_vals)

Update self.pop and self.vals given the new population and the corresponding fitness vector.

update_opt_state(new_pop, new_vals)

Stores set of function values corresponding to the current population, then updates optimizer state in many ways:

• update the .best* variables accordingly;
• uses select() to determine the surviving population.
gc3libs.optimizer.draw_population(lower_bds, upper_bds, dim, size, in_domain=None, seed=None)
gc3libs.optimizer.populate(create_fn, in_domain=None, max_n_resample=100)
Uses create_fn() to generate a new population. If in_domain() is not fulfilled, create_fn() is called repeatedly. Invalid population members are replaced until reaching the desired valid population size or max_n_resample calls to create_fn(). If max_n_resample is reached, a warning is issued and the optimization continues with the remaining “invalid” members.
Parameters: create_fn (fun) – Generates a new population. Takes no arguments. in_domain (fun) – Determines population’s validity. Takes no arguments and returns a list of bools indicating each members validity. max_n_resample (int) – Maximum number of resamples to be drawn to satisfy in_domain() list of population members