Skip to content

Tuning

Guide: Tuning.

ypea.tuning.tune

Tune the settings of an algorithm by iterated racing, as in irace.

res = ypea.tuning.tune(@ypea.DE, problems, budget, space=[], max_nfe_per_run=10000,
                       fixed=struct(), seed=0, n_jobs=1, first_test=5, alpha=0.05, output="")

algorithm   the algorithm class, as a function handle (@ypea.DE) or a name
problems    a cell (or array) of single-objective ypea.Problem objects with
            unique names. Each tuning instance is a problem with a fresh seed.
            Use other problems (or other shifts and rotations) to test the result.
budget      total number of runs (one run is one algorithm run on one instance)
space       a ypea.tuning.Space, a struct of name to ypea.tuning.Param, or
            empty for the built-in space, ypea.tuning.Space(algorithm)
max_nfe_per_run  evaluation budget of each run (empty keeps the algorithm's limits)
fixed       a struct of settings that are not tuned (removed from the space)
seed        the same seed gives the same result, for any n_jobs
n_jobs      number of parallel workers. Above 1 the runs use parfor, which
            needs the Parallel Computing Toolbox. Without it they run one by
            one, with the same result.
first_test  number of instances before the first elimination test (at least 2)
alpha       significance level of the Friedman test and of the Holm post hoc tests
output      folder for one file per run. A repeated call with the same arguments
            reads finished runs instead of running them again, so an interrupted
            tuning resumes.

Each run is scored by its error when the problem has an optimum, otherwise by
its objective value (negated for maximization). Infeasible results rank after
feasible ones. Within an instance the settings are ranked, and the ranks feed
the Friedman test.

The schedule follows irace (Lopez-Ibanez et al. 2016) with the F-Race of
Birattari et al. (2002): about 2 + log2(d) iterations for d tuned parameters,
each with an equal share of the remaining budget. Iteration j races
share / (first_test + min(5, j)) settings. After first_test instances a
Friedman test runs after every instance, and when it is significant, every
setting that the post hoc test (each setting against the best one, Holm
corrected, see ypea.experiment.stats.posthoc) finds worse is dropped. irace
uses Conover's post hoc test here. A race ends at 2 + log2(d) survivors or
when its share is used. The survivors (elites) go on to the next race with
their results, and new settings are sampled around them: a parent is chosen
with a probability that falls linearly with its rank, numbers come from a
truncated normal distribution whose width shrinks each iteration, and
categories from probabilities that move toward the parent's value. Elites
cannot be dropped before the new settings have seen the instances that the
elites have seen. Returns a ypea.tuning.TuneResult.

ypea.tuning.TuneResult

The outcome of ypea.tuning.tune.

best             the best setting found (tuned parameters only), a struct
elites           the surviving settings of the last race, best first (struct array)
history          one entry per iteration (new and total settings, instances, runs
                 used, survivors, elites and their mean ranks), a struct array
runs             runs used in total, at most the budget. A race step runs every
                 remaining setting on one more instance, so a few runs too few for
                 a whole step stay unused.
budget           the budget given to tune
fixed            the settings that were not tuned
max_nfe_per_run  the evaluation budget of each tuning run

res.algorithm(max_nfe=50000) builds the tuned algorithm with your own budget.

to_dict

Plain data, as written to tune.json.

algorithm

The tuned algorithm: the fixed settings, then the best ones, then

the name, value pairs given here, for example res.algorithm(max_nfe=50000).

summary

The best setting and the runs used, as readable text.

Property Meaning
algorithm_class function handle, for example @ypea.DE
best the best setting found (tuned parameters only), a struct
elites the surviving settings of the last race, best first (struct array)
history one entry per iteration, a struct array (see the class help)
runs runs used in total, at most the budget
fixed the settings that were not tuned
max_nfe_per_run the evaluation budget of each tuning run
budget the budget given to tune

ypea.tuning.sweep

Run several settings of one algorithm on problems and return the report.

rep = ypea.tuning.sweep(@ypea.DE, settings, problems, runs=30, n=[], fixed=struct(), seed=0, ...)

settings is one of
  - a struct whose fields list the values of each setting (a grid: every
    combination runs), for example struct("crossover_prob", [0.1 0.5 0.9]),
  - a cell array of structs, each one setting,
  - a ypea.tuning.Space (or a struct of name to ypea.tuning.Param, or empty
    for the built-in space) with n random settings drawn from it, labeled
    "<name> 1", "<name> 2" and so on. The report's metadata holds the
    settings of each label.
fixed   settings shared by every run, for example struct("pop_size", 50)
seed    seed of the runs, and of the random settings
Other name-value arguments (max_nfe, n_jobs, output and so on) go to
ypea.experiment.Experiment, so a sweep is parallel and resumable like any
experiment. Returns a ypea.experiment.Report.

space

Not in this toolbox under this name. The default space of an algorithm is ypea.tuning.Space(@ypea.DE). On Windows, file names ignore case, so space.m would replace Space.m.

ypea.tuning.Space

Tunable settings and the settings left out on purpose.

sp = ypea.tuning.Space(params, fixed)
params is a struct from setting name to ypea.tuning.Param. fixed
(optional) is a struct from setting name to the reason it is not tuned.

sp = ypea.tuning.Space(@ypea.DE) is the built-in space of an algorithm
(also by class name, "ypea.DE", or from an algorithm object). Python
calls this ypea.tuning.space(ypea.DE). MATLAB cannot have a function
space next to the class Space, because Windows file names ignore case.
See ypea.tuning.SPACES for the whole table.

Example:
    sp = ypea.tuning.Space(struct("crossover_prob", ypea.tuning.real(0.5, 1), ...
                                  "pop_size", ypea.tuning.integer(20, 100)));

without

The space without the settings in names (a string array).

neighbor

A setting near parent: numbers from a normal distribution with

standard deviation sigma (in units of the range) truncated to the range,
categories from probs (a struct from name to one probability per value).

sample

One setting drawn uniformly from the typical ranges, as a struct.

Property Meaning
params struct from setting name to ypea.tuning.Param
fixed struct from setting name to the reason it is not tuned

ypea.tuning.Param

One tunable setting. Build it with ypea.tuning.real, ypea.tuning.integer or

ypea.tuning.categorical.

kind    "real", "int" or "cat"
low     typical range for tuning, low to high, both included
high
log     sample on a log scale (needs low > 0)
values  the choices of a categorical setting (a cell row)
valid   [lowest, highest] value that the algorithm accepts, -Inf or Inf for no
        limit. For documentation and checks: tuning never leaves [low, high].

ypea.tuning.real

A tunable real setting from low to high.

p = ypea.tuning.real(low, high, log=false, valid=[-Inf Inf])
log samples on a log scale (needs low > 0). valid is the range the
algorithm accepts, for documentation and checks.

ypea.tuning.integer

A tunable integer setting from low to high, both included.

p = ypea.tuning.integer(low, high, log=false, valid=[-Inf Inf])
log samples on a log scale (needs low > 0). valid is the range the
algorithm accepts, for documentation and checks.

ypea.tuning.categorical

A tunable setting with a fixed list of choices.

p = ypea.tuning.categorical("rand", "best") or ypea.tuning.categorical(true, false)

ypea.tuning.SPACES() returns a map from each algorithm class name, such as "ypea.DE", to its default search space, which ypea.tuning.Space(@ypea.DE) also returns.