estim8.generalized_islands#

This module implements helper functions for working with pygmo`s generalized islands approach.

class estim8.generalized_islands.Estim8_mp_island(use_pool=True, report_level=1)#

Bases: mp_island

A custom mp_island implementation with evolution logging capabilities.

Attributes:
pid

ID of the evolution process (read-only).

use_pool

Pool usage flag (read-only).

Methods

get_extra_info()

Island's extra info.

get_name()

Island's name.

get_pool_size()

Get the size of the process pool.

init_pool([processes])

Initialise the process pool.

resize_pool(processes)

Resize pool.

run_evolve(algo, pop)

Run evolution with logging of progress.

shutdown_pool()

Shutdown pool.

run_evolve(algo, pop)#

Run evolution with logging of progress.

class estim8.generalized_islands.PygmoArchipelago(*args, **kwargs)#

Bases: Protocol

Methods

evolve

get_champions_f

get_champions_x

push_back

set_migrant_handling

wait

wait_check

evolve(n_evolutions: int = 1) None#
get_champions_f() ndarray[List[float]]#
get_champions_x() List[List[float]]#
push_back(**kwargs) None#
set_migrant_handling(handler: Any) None#
wait() None#
wait_check() None#
class estim8.generalized_islands.PygmoEstimationInfo(archi: PygmoArchipelago, udi_type=<class 'pygmo._py_islands.mp_island'>, fun: float = inf, n_evos: int = 0)#

Bases: object

An object to store additional information from an evolved archipelago as well as the archipelago itself.

Methods

get_f_evals()

Get the number of accumulated objective function evaluations of the archipelago.

get_f_evals() int#

Get the number of accumulated objective function evaluations of the archipelago.

Returns:
int

The number of accumulated objective function evaluations.

class estim8.generalized_islands.PygmoHelpers#

Bases: object

Helper functions for working with pygmo.

Methods

create_archipelago(objective, bounds, algos, ...)

Creates a pygmo.archipelago object using the generalized islands model.

create_pygmo_pop(args)

Create a pygmo population.

extract_archipelago_problem(archi[, i])

Extracts the user defined problem from an archipelago, implemented as pygmo.problem(UDproblem).

get_archipelago_results(archi, estimation_info)

Extracts the results of an evolved archipelago and updates additional estimation info.

get_estimates_from_archipelago(archi)

Extracts the best estimates and corresponding value of the objective function from an archipelago object.

get_pygmo_algorithm_instance(name, **kwargs)

Creates an instance of a pygmo.algorithm given the name and algorithm kwargs.

algo_default_kwargs: Dict[str, Dict[str, Any]] = {'bee_colony': {'gen': 10, 'limit': 2}, 'cmaes': {'force_bounds': False, 'ftol': 1e-08, 'gen': 10, 'xtol': 1e-08}, 'compass_search': {'max_fevals': 100, 'start_range': 1, 'stop_range': 1e-06}, 'de': {'ftol': 1e-08, 'gen': 10, 'xtol': 1e-08}, 'de1220': {'ftol': 1e-08, 'gen': 10, 'variant_adptv': 2, 'xtol': 1e-08}, 'gaco': {'gen': 10}, 'ihs': {'gen': 40}, 'maco': {'gen': 10}, 'mbh': {'algo': 'compass_search', 'perturb': 0.1, 'stop': 2}, 'moead': {'gen': 10}, 'nlopt': {'solver': 'lbfgs'}, 'nsga2': {'gen': 10}, 'nspso': {'gen': 10}, 'pso': {'gen': 10}, 'pso_gen': {'gen': 10}, 'sade': {'ftol': 1e-08, 'gen': 10, 'variant_adptv': 2, 'xtol': 1e-08}, 'scipy_optimize': {}, 'sea': {'gen': 40}, 'sga': {'gen': 10}, 'simulated_annealing': {}, 'xnes': {'eta_mu': 0.05, 'ftol': 1e-08, 'gen': 10, 'xtol': 1e-08}}#
static create_archipelago(objective: ~typing.Callable, bounds: dict, algos: ~typing.List[str], algos_kwargs: ~typing.List[dict], pop_size: int, topology: ~typing.Any = <pygmo.core.fully_connected object>, report=0, n_processes=2, init_pool: bool = True) Tuple[PygmoArchipelago, PygmoEstimationInfo]#

Creates a pygmo.archipelago object using the generalized islands model.

Parameters:
objectivecallable

An instance of an estim8.Objective function that is used to create a UDproblem.

boundsdict

The bounds for the parameters.

algoslist[str]

A list of optimization algorithms for the individual islands of the archipelago.

algos_kwargslist[dict]

A list of algorithm kwargs corresponding to passed optimizers.

pop_sizeint

Population size for each individual island.

topologypygmo.topology, optional

Represents the connection policy between the islands of the archipelago, by default pygmo.fully_connected().

report: int, optional

The report level during optimization, by default 0. In case of report > 0, the evoltions are runned with Estim8_mp_island which logs the evolution trace. A report level of 1 yields data on the archipelago’s island champions over evolutions. With a report level of 2 the islands current states are printed in the Log.

n_processesint, optional

The number of processes to use, by default joblib.cpu_count().

Returns:
pygmo.archipelago

The created archipelago.

PygmoEstimationInfo

An estimation info object containing the archipelago

static create_pygmo_pop(args)#

Create a pygmo population.

Parameters:
argstuple

The arguments for creating the population.

Returns:
pygmo.population

The created population.

static extract_archipelago_problem(archi: PygmoArchipelago, i=0) PygmoProblem#

Extracts the user defined problem from an archipelago, implemented as pygmo.problem(UDproblem).

Parameters:
archiPygmoArchipelago

The evolved archipelago.

iint, optional

Index of the island from which the problem is extracted, by default 0.

Returns:
pygmo.problem

The extracted problem.

static get_archipelago_results(archi: PygmoArchipelago, estimation_info: PygmoEstimationInfo) Tuple[dict, PygmoEstimationInfo]#

Extracts the results of an evolved archipelago and updates additional estimation info.

Parameters:
archiPygmoArchipelago

The evolved archipelago.

estimation_infoPygmoEstimationInfo

Additional information about the archipelago before evolution(s).

Returns:
Tuple[dict, PygmoEstimationInfo]

Dictionary of best estimates according to the smallest loss value. Updated additional information about the evolved archipelago containing the archipelago itself.

static get_estimates_from_archipelago(archi: PygmoArchipelago) Tuple[dict, float]#

Extracts the best estimates and corresponding value of the objective function from an archipelago object.

Parameters:
archiPygmoArchipelago

The evolved archipelago.

Returns:
Tuple[dict, float]

Dictionary of best estimates according to the smallest loss aka objective function value. The smallest loss value among all islands.

static get_pygmo_algorithm_instance(name: str, **kwargs) Any#

Creates an instance of a pygmo.algorithm given the name and algorithm kwargs.

Parameters:
namestr

The name of the optimization algorithm.

kwargsdict, optional

Keyword arguments for the algorithm, by default None, which means the default arguments of the respective pygmo.algorithm will be used.

Returns:
pygmo.algorithm

The pygmo algorithm instance.

Raises:
ValueError

If the algorithm name is not supported.

class estim8.generalized_islands.PygmoMpIsland(use_pool: bool = True)#

Bases: Protocol

Protocol for pygmo.mp_island type checking

Methods

init_pool

run_evolve

shutdown_pool

init_pool(n_processes: int) None#
run_evolve(algo: Any, pop: Any) Any#
shutdown_pool() None#
class estim8.generalized_islands.PygmoProblem(*args, **kwargs)#

Bases: Protocol

Methods

extract

get_fevals

extract(cls: Any) Any#
get_fevals() int#
class estim8.generalized_islands.UDproblem(objective: Callable, bounds: dict)#

Bases: object

A wrapper class around an Objective function with functions required for creating a user defined pygmo.problem.

Methods

fitness(theta)

Evaluate the fitness of a solution.

get_bounds()

Get the bounds of the problem.

get_extra_info()

Get extra information about the problem.

fitness(theta) array#

Evaluate the fitness of a solution.

Parameters:
thetanp.array

The solution to evaluate.

Returns:
np.array

The fitness value.

get_bounds() tuple#

Get the bounds of the problem.

Returns:
tuple

The lower and upper bounds.

get_extra_info() list#

Get extra information about the problem.

Returns:
list

The keys of the bounds dictionary.

estim8.generalized_islands.optional_import(module_name, mock_name=None)#