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
quasinewton methods, could be implemented but likely require adaptations in
the driver classes.)
The module is organized as follows:
drivers
: Set of drivers that interface with GC3Libs to automatically drive the optimization process following a specified algorithm.ParallelDriver
is the core of the optimization module, performing optimization using an algorithm based onEvolutionaryAlgorithm
.dif_evolution
: Implements the Differential Evolution algorithm, in particular the evolution and selection step, based onEvolutionaryAlgorithm
. See the module for details on the algorithm.extra
: Provides tools to printing, plotting etc. that can be used as addons toEvolutionaryAlgorithm
.

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 problemspecific printing and plotting routines. Examples can be found ingc3libs.optimizer.extra
.

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

has_converged
()¶ Checks convergence based on two criteria:
 Is the lowest target value in the population below y_conv_crit.
 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.

gc3libs.optimizer.
draw_population
(lower_bds, upper_bds, dim, size, in_domain=None, seed=None)¶ Draw a random population with the following criteria:
Parameters:  lower_bds – List of length dim indicating the lower bound in each dimension.
 upper_bds – List of length dim indicating the upper bound in each dimension.
 dim (int) – Dimension of each population member.
 size (int) – Population size.
 in_domain (fun) – Determines population’s validity. Takes no arguments and returns a list of bools indicating each members validity.
 seed (float) – Seed to initialize NumPy’s random number generator.
Return type: list of population members

gc3libs.optimizer.
populate
(create_fn, in_domain=None, max_n_resample=100)¶ Generate a new population.
Uses
create_fn()
to generate a new population. Ifin_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 tocreate_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()
Return type: list of population members