Skip to content

Tuning

Guide: Tuning.

tune

tune(algorithm_class, problems, budget, *, space=None, max_nfe_per_run=10000, fixed=None, seed=0, n_jobs=1, first_test=5, alpha=0.05, output=None)

Tune the settings of algorithm_class by iterated racing.

Parameters

  • algorithm_class: an Algorithm subclass, for example ypea.DE
  • problems: list of Problem. Each tuning instance is a problem with a fresh seed. Use other problems (or other seeds of the shift and rotation) to test the result.
  • budget: total number of runs (one run is one algorithm run on one instance)
  • space: Space, dict of name to Param, or None for ypea.tuning.space(algorithm_class)
  • max_nfe_per_run: evaluation budget of each run (None keeps the algorithm's own limits)
  • fixed: dict 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 worker processes (problems must then be picklable)
  • 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: 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.

TuneResult dataclass

TuneResult(algorithm_class, best, elites, history, runs, fixed=dict(), max_nfe_per_run=None, budget=None)

The outcome of tune.

best : the best setting found (tuned parameters only) elites : the surviving settings of the last race, best first

  • history: one dict per iteration (new and total settings, instances, runs used, survivors, elites and their mean ranks)
  • 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

algorithm_class instance-attribute

algorithm_class

best instance-attribute

best

elites instance-attribute

elites

history instance-attribute

history

runs instance-attribute

runs

fixed class-attribute instance-attribute

fixed = field(default_factory=dict)

max_nfe_per_run class-attribute instance-attribute

max_nfe_per_run = None

budget class-attribute instance-attribute

budget = None

summary

summary()

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

algorithm

algorithm(**overrides)

The tuned algorithm: algorithm_class(**fixed, **best, **overrides). Give it your own budget, for example result.algorithm(max_nfe=50_000).

to_dict

to_dict()

sweep

sweep(algorithm_class, settings, problems, runs=30, *, n=None, fixed=None, seed=0, **kwargs)

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

  • settings: one of
    • a dict from parameter name to a list of values (a grid: every combination runs),
    • a list of dicts (each dict is one setting),
    • a Space (or a dict of name to Param, or None for the built-in space) with n random settings drawn from it, labeled " 1", " 2" and so on. The report's metadata holds the settings of each label.
  • fixed: settings shared by every run (for example {"pop_size": 50})
  • seed: seed of the runs, and of the random settings

Other keyword arguments (max_nfe, n_jobs, output and so on) go to Experiment, so a sweep is parallel and resumable like any experiment.

space

space(algorithm_class)

The built-in parameter space of an algorithm class.

Space dataclass

Space(params, fixed=dict())

Tunable settings (params, name to Param) and the constructor settings left out on purpose (fixed, name to the reason).

params instance-attribute

params

fixed class-attribute instance-attribute

fixed = field(default_factory=dict)

sample

sample(rng)

One setting drawn uniformly from the typical ranges.

neighbor

neighbor(rng, parent, sigma, probs)

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 (name to a list of probabilities, one per value).

Param dataclass

Param(kind, low=None, high=None, log=False, values=(), valid=(None, None))

One tunable setting. Build it with real, integer or categorical.

kind : "real", "int" or "cat" low, high : typical range for tuning (both included) log : sample on a log scale (needs low > 0) values : the choices of a categorical setting

  • valid: (lowest, highest) value that the algorithm accepts, None for no limit. For documentation and checks, tuning never leaves [low, high].

real

real(low, high, log=False, valid=(None, None))

integer

integer(low, high, log=False, valid=(None, None))

categorical

categorical(*values)

ypea.tuning.SPACES maps each algorithm class to its default search space, which space(cls) returns.