Selection heuristics

When EvoDAG builds an offspring it has to choose the individuals that are the arguments of the function. By default, in classification, they are chosen at random, and not by fitness. The selection heuristics of the second EvoDAG article (see Citing) are the alternative: they pick, for the functions that profit from it, arguments that are different from each other. This page explains the idea, says what each heuristic computes and how to select one with the parameters selection, first_selection and heuristic_functions. The Performance page compares them on 30 classification problems.

The idea

In a tournament selection the parents are the fittest individuals among a few that were drawn at random. The heuristics replace fitness in that tournament by a measure of how different a candidate is from a parent that was already chosen. The argument is that the functions EvoDAG uses to combine parents profit from varied inputs:

  • a sum \(\sum_j \alpha_j p_j\) fitted by least squares gains nothing from arguments that are almost the same vector, and gains most from arguments that are linearly independent (ideally orthogonal) to each other: the coefficients can only be identified when the arguments are linearly independent, orthogonal vectors are the simplest case of that, and uncorrelated vectors are linearly independent too, which is what motivates Pearson’s correlation;
  • the Naive Bayes classifiers assume that their inputs are independent given the class, and since independence is expensive to measure the correlation is used in its place;
  • the Nearest Centroid classifier likewise gets more information from inputs that do not repeat each other, although for this one it is only a conjecture that more diverse inputs help.

Because of that, the heuristics are applied only when the function that is being built is the sum, Naive Bayes (both variants) or Nearest Centroid; for every other function the arguments are chosen at random. The first argument is picked at random, without the heuristic; each remaining argument is the winner of a small tournament in which the lowest value of the similarity to the first argument wins.

The proposal takes the fitness out of the selection of the arguments entirely. The fitness still acts in two places: the coefficients of every new individual are fitted by least squares against the target, and the model that is returned is the individual that is best on the validation set. This is why random or diversity-driven selection works here; in a system that does not fit constants it would not be expected to be competitive.

The heuristics are related to Novelty Search, which rewards an individual for being different from the whole population. Here the arguments of one offspring are only asked to be different from each other, and only the individuals of the tournament are looked at.

The three similarity measures

Let \(\mathbf{u}\) and \(\mathbf{v}\) be the semantics of two individuals.

  • Cosine similarity. Close to zero when the two vectors are close to orthogonal. Its absolute value is used, since a cosine of \(1\) and of \(-1\) are the same thing for linear independence: \[\bigl|\cos(\mathbf{u}, \mathbf{v})\bigr| = \frac{|\mathbf{u} \cdot \mathbf{v}|}{\lVert\mathbf{u}\rVert\,\lVert\mathbf{v}\rVert}.\]
  • Pearson’s correlation. The same expression applied to the vectors after subtracting their means, so it measures linear correlation. It coincides with the cosine when the semantics are centred.
  • Agreement. The semantics are first turned into predicted labels (the position of the largest output) and the measure is the proportion of examples on which the two individuals predict the same label. It looks at what is predicted rather than at the raw values, and it is defined only for classification. For the vectors \(\mathbf{p}\) and \(\mathbf{q}\) of predicted labels \[\operatorname{agr}(\mathbf{p}, \mathbf{q}) = \frac{1}{n}\sum_{i=1}^{n} \delta(p_i = q_i),\] and when \(\mathbf{q}\) is the target the agreement is the accuracy of \(\mathbf{p}\).

With several classes the cosine and Pearson’s correlation are summed over the outputs.

Each heuristic can be combined with two ways of choosing which individual leaves the population when an offspring arrives: the usual negative tournament on fitness, or a random choice. The default configuration of classification uses the random choice for the arguments and for the individual that leaves, that is, no heuristic; it is the one best ranked on the Performance page.

The parameters

Three keyword parameters, selection, first_selection and heuristic_functions, choose the scheme. They are keys of the classification parameter file, which sets them to "random", "random" and "tailored": together with negative_selection false and fitness_function "macro-F1" that is the default configuration of classification, called rnd-rnd on the Performance page. With selection "random" the other two keys are not read, so they matter only when you choose a heuristic. The regression parameter file does not have them and the constructor of the engine has selection=None (see the orthogonal booleans). They are accepted by EvoDAGE, EvoDAG.model.EvoDAG and RGP.init, but not by the explicit arguments of the scikit-learn classes (give them through params).

Scheme selection What it does
fit, tournament on fitness "fitness" every argument is the winner of a tournament on fitness
rnd, random "random" every argument is chosen uniformly at random
agr, agreement "agreement" smallest agreement of the predicted labels with the reference
sim, absolute cosine similarity "cosine" smallest sum, over the outputs, of the absolute cosine with the reference
prs, absolute Pearson correlation "pearson" smallest sum, over the outputs, of the absolute Pearson correlation with the reference
ads, Angle-Driven Selection "angle" largest angle between the relative semantics (target minus output) of the candidate and of the reference
nvs, Novelty Search "novelty" most novel individual of a tournament; classification only

When selection is not None it takes precedence over the two booleans described below, which are then ignored without an error. negative_selection, which chooses the individual that leaves, is independent of it.

first_selection says how the first individual of "agreement", "cosine", "pearson" and "angle" is chosen: "random" (the default) or "fitness", a tournament. The other three values ignore it. heuristic_functions says to which functions a heuristic applies ("agreement", "cosine", "pearson", "angle" and "novelty"): "tailored" (the default) only to the sum, NaiveBayes, NaiveBayesMN and Centroid, the functions that motivate it, and "all" to every function with more than one argument. The functions a heuristic does not apply to get their arguments at random, not by fitness; with selection="fitness" every function uses the tournament.

Each heuristic with a reference works like this: the first individual, which is the first argument, is drawn with first_selection, and each other argument is the winner of a tournament of tournament_size random individuals (ten for "angle", drawn like the first one, duplicates included) that is decided by the measure of the table against the first individual. The measures are computed on the masked outputs, that is, on the training part of the data; the zeros of the validation examples are part of the vectors, so the mean in Pearson’s correlation is taken over all the examples. For Pearson, an output where one of the two vectors is zero or constant adds 99, so such a candidate tends to lose; for the cosine such an output adds nothing, and the value is 99 only when every output is degenerate. The outputs are finite but can be huge; when a squared norm overflows, that output contributes 0 to the cosine and to Pearson and π/2 to the angle. In ties the first candidate wins. If the reference of "angle" has no error on some output, the arguments are chosen at random.

The default and the article

The default is the configuration of the 21 of the Performance page with the lowest average rank, the one called rnd-rnd. The article proposes agr-rnd, which was its best system: the arguments of the sum, the two Naive Bayes and the Nearest Centroid are chosen by agreement with a reference drawn at random (selection "agreement", first_selection "random", heuristic_functions "tailored"). The two share the random choice of the individual that leaves (negative_selection false), macro-F1 as fitness and every other parameter; they differ only in selection, which is "random" in the default and "agreement" in agr-rnd. To ask for agr-rnd give that one key (the file already has the rest), or write all of them out:

from EvoDAG import EvoDAGClassifier

agr_rnd = EvoDAGClassifier(params={"selection": "agreement",
                                   "first_selection": "random",
                                   "heuristic_functions": "tailored",
                                   "negative_selection": False})

On the command line it is EvoDAG-train -C --kw '{"selection": "agreement"}'.

The first argument is the reference

The individual that is drawn first is the first argument of the function and the winners of the tournaments are the others.1 A winner that is already an argument is drawn again, up to three times, and dropped after that, so a function can receive fewer arguments than its number; if fewer than its minimum are left, another function is tried. The sum, which has 60 arguments in the default function set, therefore receives up to 60 arguments.

Novelty Search has no reference: all the arguments are winners of tournaments, and the winner is the candidate with the largest sum, over the training examples, of \(1/(p_j + 10^{-5})\), where \(p_j\) is the fraction of the population that predicts for example \(j\) the same class as the candidate. The engine keeps the predicted labels of the population and the counts of each class per example up to date as individuals are added and replaced, so the cost of a tournament is that of one pass over the training examples; the labels take one byte per individual and example, which for a population of 4000 and 100000 training examples is 400 MB. It is not implemented for regression, and it needs the SteadyState population.

Angle-Driven Selection follows Chen et al. (2019): the relative semantics of an individual is the target minus its output, normalised to unit length, and the candidate that forms the largest angle with the reference (the sum of the angles of the outputs) wins.

The validation of the three parameters raises ValueError for an unknown value, and for selection="novelty" in regression or with a population other than SteadyState.

The orthogonal booleans

orthogonal_selection and orthogonal_dot_selection are two booleans that are read only when selection is None (in classification the parameter file sets selection, so pass selection=None as well). orthogonal_selection=True is the agreement heuristic with the first argument chosen by a tournament on fitness and the functions without the heuristic using the tournament on fitness; orthogonal_dot_selection=True replaces the cosine by the raw dot product of the masked outputs, without the norms and without the absolute value, so the candidate with the smallest signed product wins (if both are on, the agreement takes precedence; for the exact cosine use selection="cosine"). In regression the agreement compares the signs of the outputs.

Random selection

selection="random" chooses every argument at random; it is the default of classification. Another, indirect way is random_generations: while the current generation is not larger than it, every tournament that is not a negative one is replaced by a uniform random draw. With the default selection of classification no argument is chosen by a tournament on fitness, so random_generations has no effect there (the default file sets it to 0).

Example

The default configuration of classification is random arguments, a random choice of the individual that leaves and macro-F1 as fitness, so the first call below only writes it out. The parameters are given to the constructors as any other:

import numpy as np
from EvoDAG import EvoDAGE

rng = np.random.RandomState(0)
X = rng.randn(200, 5)
y = (X[:, 0] + X[:, 1] ** 2 > 1).astype(int) + (X[:, 2] > 1.0)

# rnd-rnd: random arguments, a random choice of the individual that leaves
# and macro-F1 as fitness (the defaults of classification, written out)
default = EvoDAGE(n_estimators=3, popsize=100, early_stopping_rounds=100,
                  selection="random", negative_selection=False,
                  fitness_function="macro-F1", seed=0).fit(X, y)
print((default.predict(X) == y).mean())

# agr-rnd: agreement for the arguments of the sum and of the classifiers
agreement = EvoDAGE(n_estimators=3, popsize=100, early_stopping_rounds=100,
                    selection="agreement", first_selection="random",
                    heuristic_functions="tailored", negative_selection=False,
                    fitness_function="macro-F1", seed=0).fit(X, y)
print((agreement.predict(X) == y).mean())

# another scheme: Pearson's correlation with a random reference
pearson = EvoDAGE(n_estimators=2, popsize=40, early_stopping_rounds=40,
                  selection="pearson", seed=0).fit(X, y)
print((pearson.predict(X) == y).mean())

# the classical selection (fit-fit): fitness tournaments for the arguments
# and for the individual that leaves
classic = EvoDAGE(n_estimators=3, popsize=100, early_stopping_rounds=100,
                  selection="fitness", negative_selection=True,
                  seed=0).fit(X, y)
print((classic.predict(X) == y).mean())

From the command line the same parameters are passed with --kw:

EvoDAG-train -C -n 30 --kw '{"selection": "fitness", "negative_selection": true}' -m model.evodag train.csv

Results

The Performance page gives the average ranks of the combinations of parent and negative selection and of the selection schemes of the table above, on 30 classification problems.

Footnotes

  1. In the program that produced the results of the article, and in EvoDAG up to version 0.18, the first individual of a heuristic was used to compute the measure but was not passed to the function, so the sum of 60 arguments received at most 59 and a function of two arguments, such as the Nearest Centroid, was never built by a heuristic. Version 0.19 corrects it. The results on this site were obtained with the corrected selection, which is why they differ from the numbers of the article.↩︎