# Racing¶

## Overview¶

Two types of racing are supported in PyGMO, namely the racing between individuals in a population, and racing between algorithms.

Racing of individuals in a population can be done as the following. Note that in PyGMO.population, there is also a race method which can be conveniently called. However, in order to utilize the caching mechanism in racing, one has to invoke racing explicitly via PyGMO.util.race_pop.

from PyGMO import *
prob = problem.noisy(problem.ackley(2))
pop = population(prob,20)
racer = util.race_pop(population=pop,seed=0)
winners, fevals = racer.run(1) # Extract the single best winner


Illustration of the effects of caching:

from PyGMO import *
pop = population(problem.noisy(), 10, 0)

# Race overlapping individuals without caching
winners, fevalsA = pop.race(1, racers_idx=range(0,5))
winners, fevalsB = pop.race(1, racers_idx=range(3,8))

# Race overlapping individuals with caching via race_pop
racer = util.race_pop(pop)
winners, fevalsA_cache = racer.run(1, racers_idx=range(0,5))
winners, fevalsB_cache = racer.run(1, racers_idx=range(3,8))

print 'Consumed fevals', fevalsA + fevalsB                          # 39
print 'Consumed fevals [caching]', fevalsA_cache + fevalsB_cache    # 26


Racing of algorithms can be done as follows:

from PyGMO import *
algos = [algorithm.de(), algorithm.cmaes(), algorithm.pso()]

prob = problem.ackley()                            # To race over a single problem
racer1 = util.race_algo(algos, prob)
winners1, fevals1 = racer1.run(1)

probs = [problem.ackley(), problem.griewank()]     # To race over multiple problems
racer2 = util.race_algo(algos, probs)
winners2, fevals2 = racer2.run(1)


## Detailed documentation¶

class PyGMO.util.race_pop(pop=None, seed=0)
__init__()

Constructs a racing object responsible for racing individuals in a population

USAGE: race_pop(pop, seed=0)

• pop: The pop containing the individuals to be raced
• seed: Seed of the racing object
get_mean_fitness(ind_list=[])

Returns the average fitness value of the individuals based on the evaluation history

• ind_list: The indices of the individuals whose mean fitness vectors are to be extracted. If this is empty, mean data of all the individuals will be returned.
inherit_memory(race_pop_src)

Transfer compatible evaluation history from another race_pop object.

The source race_pop object and the current race_pop object must have the same seed. Upon calling, the current race_pop object will inherit evaluation history of individuals who also happen to reside in source.

USAGE: race_pop.inherit_memory(race_pop_src)

• race_pop_src: The source race_pop object from which compatible evaluation history will be transferred to current object
register_pop(pop)

Load a population into the race environment.

This step is required before the calling to run(), if during construction no population was supplied.

• pop Population to be registered. Racing will operate over this population.
reset_cache()

Clears the cached fitness and constraint vectors.

run(n_final, min_trials=0, max_count=500, delta=0.05, racers_idx=, []term_cond=PyGMO.util._util._termination_condition.MAX_BUDGET, race_best=True, screen_output=False)

Start a race among the individuals

Returns a tuple of winning indices and consumed objective function evaluation.

USAGE: race_pop.run(n_final, min_trials=0, max_count=500, delta=0.05, racers_idx=[], term_cond=util.race_pop.termination_condition.MAX_BUDGET, race_best=True, screen_output=False):

• n_final: The desired number of winners when race ends
• min_trials: Each individuals be evaluated at least this number of times before being dropped
• max_count: The allow number of function evaluations (MAX_BUDGET), or the maximum number of data points to be considered for each individual (MAX_DATA_COUNT)
• delta: Confidence level of the statistical test
• racers_idx: Indices of the individuals to be raced, empty means to race all individuals
• term_cond: Can be util.race_pop.termination_condition.MAX_BUDGET or util.race_pop.termination_condition.MAX_DATA_COUNT
• race_best: When True winners are the best, otherwise winners are the worst
• screen_output: Log racing stats at each iteration onto the screen
set_seed(seed)

Reset the seed for racing.

• seed: The new seed to be set. This automatically clears the evaluation cache.
size()

Returns the number of individuals contained in the underlying population

USAGE: race_pop.size()

class PyGMO.util.race_algo(algo_list, probs, pop_size=100, seed=0)

Similar to race_pop, this class contains the mechanisms to race different algorithms. The race among the algorithms can be performed over a single problem, or over a multiple of them.

__init__()

Construct the racing object responsible for racing algorithms

• algo_list: The algorithms to be raced
• probs: Can be a single PyGMO problem or a list of them
• pop_size: All the algorithms will be evolving internally some random population of this size
• seed: Seed of the race
run(n_final, min_trials=0, max_count=500, delta=0.05, racers_idx=, []race_best=True, screen_output=False)

Start a race among several algorithms

Returns a tuple of winning indices and the total number of evolve() made.

USAGE: race_algo.run(n_final, min_trials=0, max_count=500, delta=0.05, racers_idx=[], race_best=True, screen_output=False):

• n_final: The desired number of winners when race ends
• min_trials: Each algorithms be evaluated at least this number of times before being dropped
• max_count: The allow number of algorithm performance evaluation (i.e. number of calls to evolve)
• delta: Confidence level of the statistical test
• racers_idx: Indices of the algorithms to be raced, empty means to race all algorithms
• race_best: When True winners are the best, otherwise winners are the worst
• screen_output: Log racing stats at each iteration onto the screen