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 exampleypea.DEproblems: 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 forypea.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 anyn_jobsn_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 testsoutput: 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 totunefixed: the settings that were not tunedmax_nfe_per_run: the evaluation budget of each tuning run
algorithm ¶
algorithm(**overrides)
The tuned algorithm: algorithm_class(**fixed, **best, **overrides). Give it
your own budget, for example result.algorithm(max_nfe=50_000).
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 toParam, or None for the built-in space) withnrandom 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
dataclass
¶
Space(params, fixed=dict())
Tunable settings (params, name to Param) and the constructor settings left
out on purpose (fixed, name to the reason).
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].
ypea.tuning.SPACES maps each algorithm class to its default search space, which space(cls) returns.