Experiments¶
Guide: Experiments and statistics.
ypea.experiment.Experiment¶
Run every algorithm on every problem several times, save each run, and report.
Differs from Python: Has no seeds setting: every run gets its own seed, as with Python's default.
exp = ypea.experiment.Experiment(algorithms, problems, runs=30, max_nfe=[], ...
max_iter=[], seed=0, n_jobs=1, output=[], ...
checkpoints=[], labels=[])
algorithms A cell array of algorithms, labeled by their short_name
(repeated names get " (2)", " (3)" and so on), or by labels=
(a string array, one label per algorithm). A struct also works:
its field names are the labels.
problems A cell array of problems. Problem names must be unique.
runs Number of runs of each algorithm on each problem.
max_nfe, max_iter
The budget of every run. If either is given, both replace the
limits of each algorithm (a copy is made, the caller's objects
are not changed). If both are empty, each algorithm keeps its own.
seed Base seed, an integer from 0 to 2^32 - 1.
Run i of each algorithm on each problem gets its own seed, made
from the base seed, stable hashes of the label and the problem
name, and i, so a result does not depend on n_jobs, on the order
of the algorithms or problems, or on which of them are included.
n_jobs With more than 1, runs go to a parallel pool (parfor) of at most
n_jobs workers when the Parallel Computing Toolbox is installed,
and run one after another otherwise. Results are the same.
output Folder for the run files and metadata.json. With [], results
stay in memory.
checkpoints Fractions of max_nfe at which the best objective value (and the
error, when the problem has an optimum) is recorded. [] gives the
CEC 2017 rule, ypea.experiment.CEC_CHECKPOINTS. Runs without an
evaluation budget record only their final values. With several
objectives the checkpoints hold IGD and hypervolume instead.
Several objectives: each run also stores the IGD and hypervolume of its final
front and of its front at each checkpoint. The problem needs
info.pareto_front or info.ref_point.
Each run file holds result.to_dict(), the checkpoint values, the problem
sense and a run key. The key is a hash of the algorithm class and settings,
the problem name, the budget, the run seed and the checkpoints. run() skips
runs whose file has the same key, so a stopped experiment resumes, and a
changed setting is run again.
Example:
exp = ypea.experiment.Experiment({ypea.PSO(), ypea.DE()}, problems, ...
runs=30, max_nfe=100000, output="results/my-study");
exp.run();
report = exp.report(); % or ypea.experiment.Report.load("results/my-study")
report.table(baseline="DE").to_latex("table.tex");
report.save_html();
tasks¶
Every run of the experiment: label, algorithm, problem, run, seed,
checkpoints, settings, key and file path.
report¶
A ypea.experiment.Report of the stored runs (from the output folder, or from memory).
run¶
Run every missing run, skipping finished ones with the same settings.
metadata¶
The settings of the experiment and the release and machine it runs
on, as saved in metadata.json. algorithms and keys are JSON objects keyed by
label (containers.Map), as in Python, and labels lists the labels in order.
sweep¶
An experiment over several settings of one algorithm, for tuning studies.
exp = ypea.experiment.Experiment.sweep(@ypea.DE, settings, problems, ...)
settings is a struct whose fields list the values of each setting (every
combination is run), for example struct("F", [0.5 0.8], "CR", 0.9), or a
cell array of structs, one per setting. Labels name the settings that
vary, for example "DE(F=0.5, CR=0.9)". Other name-value arguments go to
Experiment.
| Property | Meaning |
|---|---|
algorithms |
the caller's algorithms, a cell array |
labels |
their labels, a string row |
problems |
a cell array of problems |
runs |
runs of each algorithm on each problem |
max_nfe |
evaluation budget of every run, or [] to keep each algorithm's own |
max_iter |
iteration limit of every run, or [] to keep each algorithm's own |
seed |
base seed of the run seeds |
n_jobs |
parallel workers (parfor), 1 for one run after another |
output |
folder of the run files and metadata.json, or [] to keep results in memory |
checkpoints |
fractions of max_nfe at which values are recorded |
ypea.experiment.CEC_CHECKPOINTS() returns the CEC reporting points as shares of the budget, for the checkpoints setting: 0.01, 0.02, 0.03, 0.05, then 0.1 to 1.0 in steps of 0.1.
ypea.experiment.Report¶
Results of an experiment, built from its run records: tables, figures and an HTML page.
Make one with exp.report(), or later from the output folder alone with
ypea.experiment.Report.load(path).
metric="error" uses |f - optimum| (smaller is better). On problems without
a known optimum it falls back to the objective value, compared by the
problem sense.
With several objectives the metrics are "igd" (smaller is better) and
"hypervolume" (larger is better), as stored by the runner. There,
metric="error" means IGD, or the hypervolume on problems without a true front.
zero_below: errors below this value count as 0 (default [], the raw values).
save_html¶
One self-contained HTML page with the settings, the table and the figures.
path = report.save_html(path=[], stat="mean", metric="error", baseline="", figures=true)
Figures are PNG images embedded in the page. path defaults to
report.html in the output folder.
plot_ranks¶
Bar chart of the Friedman average ranks.
ax = report.plot_ranks(stat="mean", metric="error", ax=[])
plot_box¶
Box plots of the final values of each algorithm on one problem.
ax = report.plot_box(problem, metric="error", log=[], ax=[])
plot_convergence¶
Median (or mean) best value against evaluations, with a 25 to 75 percent band.
ax = report.plot_convergence(problem, metric="error", center="median", log=[], ax=[])
table¶
Comparison table, a ypea.experiment.Table.
t = report.table(stat="mean", metric="error", test="wilcoxon", baseline="", ...
alpha=0.05, fmt="%.3e", stats=["mean" "std" "best" "worst" "median"])
Statistics per algorithm and problem with the best in bold, Wilcoxon rank
sum marks and a win/tie/loss row against the control (baseline, or the
best ranked algorithm), and Friedman average ranks of stat with Holm
adjusted post hoc p values (Derrac et al. 2011). test="" skips the rank
sum test. Export with to_csv, to_latex, to_markdown, to_html or to_table.
curves¶
Best value so far of each run at the evaluations in grid.
[grid, Y] = report.curves(label, problem, metric="error", grid=[]) with
one row of Y per run. The default grid has 200 points up to the largest
NFE. With several objectives the values are IGD or hypervolume at the
checkpoints (the default grid), and each grid point takes the last
checkpoint at or before it.
values¶
Final values of the runs of one algorithm on one problem, a column.
smaller_is_better¶
True when smaller values of metric are better on problem.
records¶
The run records of one algorithm on one problem, in run order (a cell array).
load¶
The report of an experiment's output folder.
| Property | Meaning |
|---|---|
zero_below |
errors below this value count as 0, or [] for the raw values |
metadata |
the experiment's metadata (metadata.json), a struct |
output |
the experiment's output folder, or [] for an experiment in memory |
labels |
string row |
problems |
string row of problem names |
ypea.experiment.Table¶
A table of results, with exports to CSV, LaTeX, Markdown, HTML and a MATLAB table.
Differs from Python: to_table() returns a MATLAB table in place of to_dataframe().
header is a string row of column names. rows is a cell array of rows, each
a struct array of cells with text, bold and mark. groups holds the row
numbers where a new group starts (drawn as rules), notes the lines printed
under the table, and data the numbers behind it.
Marks of the rank sum test: "+" (better than the control), "=" (no
significant difference) and a minus sign (worse). The minus sign is U+2212
in CSV, Markdown and HTML, and $-$ in LaTeX.
disp¶
disp - Display value of variable
Syntax
disp(X)
Input Arguments
X - Input array
array
Examples
openExample('matlab/DisplayVariableValuesExample')
openExample('matlab/DisplayMatrixWithColumnLabelsExample')
web('E:\Program Files\MATLAB\R2026b\help/matlab/ref/disp.html#btnoykv-1')
openExample('matlab/DisplayMultipleVariablesOnSameLineExample')
See also format, int2str, num2str, sprintf, fprintf,
formattedDisplayText
Introduced in MATLAB before R2006a
to_table¶
A MATLAB table of the cell texts (Python's to_dataframe).
to_html¶
The table as an HTML fragment with its notes, also written to path when given.
to_latex¶
A booktabs table (needs \usepackage{booktabs}).
text = t.to_latex(path, caption="", label="")
to_markdown¶
The table as Markdown text with its notes, also written to path when given.
to_csv¶
The table as CSV text, also written to path when given.
| Property | Meaning |
|---|---|
header |
column names, a string row |
rows |
a cell array of rows, each a struct array of cells with text, bold and mark |
groups |
row numbers where a new group starts (drawn as rules) |
notes |
lines printed under the table |
data |
the numbers behind the table |
ypea.experiment.stats.rank_sum¶
Wilcoxon rank sum test (the Mann Whitney U test) of sample a against sample b.
[mark, p] = ypea.experiment.stats.rank_sum(a, b, alpha=0.05, smaller_is_better=true)
mark is "+" when a is significantly better than b, "-" when it is
significantly worse, and "=" otherwise. p is the two-sided p value.
The p value is computed as SciPy's mannwhitneyu does by default: the exact
distribution of U when neither sample is larger than 8 and there are no
ties, and otherwise the normal approximation with the tie and continuity
corrections. When all values are equal the test is undefined, and the
result is "=" with p = 1.
ypea.experiment.stats.friedman¶
Friedman test. values has one row per problem and one column per algorithm.
out = ypea.experiment.stats.friedman(values, smaller_is_better=true) is a
struct with ranks (the average rank of each algorithm, 1 is best, a row),
n and k (the numbers of problems and algorithms), chi2 and p (Friedman,
with the tie correction as in SciPy's friedmanchisquare), and f and p_f
(Iman and Davenport). chi2, p, f and p_f are empty with fewer than two
problems or algorithms. Missing values (NaN) rank last.
ypea.experiment.stats.posthoc¶
Each algorithm against a control after a Friedman test (Derrac et al. 2011).
out = ypea.experiment.stats.posthoc(ranks, n, control) with the average
ranks of k algorithms over n problems and control the index of the
control algorithm (from 1). z = (R_i - R_control) / sqrt(k (k + 1) / (6 n))
(Derrac et al. 2011, eq. 12), two-sided normal p values, and Holm adjusted
p values, APV_i = min(1, max over j <= i of (k - j) p_j) for the sorted p
values. out.z, out.p and out.holm are rows with one entry per algorithm and
NaN at the control.