EvoDAG

Version 0.19.0.

Note

This is the developer reference: the public API with examples that are executed and verified, and a one-line description of every other public name. Using EvoDAG (installation, the command line, the parameters, how the method works) is documented on the user site, mgraffg.github.io/EvoDAG.

EvoDAG is a steady-state semantic genetic programming system for classification and regression. The usual way to use it is through the scikit-learn estimators of EvoDAG.estimators: EnsembleClassifier(EvoDAGClassifier()) (EnsembleRegressor and EvoDAGRegressor for regression) is EvoDAG’s ensemble, and EvoDAGClassifier alone fits one model. They need scikit-learn, an optional dependency (pip install 'EvoDAG[sklearn]'). EvoDAG’s own classes do not need it and are exported by the top-level package: EvoDAGE (the ensemble), Model and Ensemble (what a fit returns), and EvoDAG, RGP and RootGP (the three names of the search engine). Two different classes are called EvoDAG: EvoDAG.EvoDAG is the search engine of EvoDAG.base, whereas EvoDAG.model.EvoDAG is a single model with the fit/predict interface; each docstring says which one it is.

The first page is the scikit-learn estimators; the rest follow the way the data flows through the package:

  1. The scikit-learn estimators: the scikit-learn estimators, one model or an ensemble (EvoDAG.estimators).

  2. The search engine: the search engine (EvoDAG.base), the population and the selection of parents (EvoDAG.population, EvoDAG.function_selection).

  3. Nodes and weights: the individuals and the functions, with the least-squares weights (EvoDAG.node, EvoDAG.naive_bayes).

  4. Fitness and validation masks: the fitness, the training and validation masks (EvoDAG.bagging_fitness).

  5. The model and the ensemble: the fitted model and the ensemble (EvoDAG.model).

  6. Data, parameter search and command line: reading the data files, the random search of parameters and the command line (EvoDAG.utils, EvoDAG.command_line).

  7. Compiled modules and legacy code: the compiled Cython modules and the legacy EvoDAG.gp.

Architecture

The following example runs the engine on a tiny problem and looks at what it leaves behind; it is executed when the documentation is tested.

>>> import numpy as np
>>> from EvoDAG import RGP
>>> rng = np.random.RandomState(0)
>>> X = rng.randn(100, 3)
>>> y = (X[:, 0] > 0).astype(int)
>>> engine = RGP.init(popsize=50, early_stopping_rounds=50, seed=0)
>>> engine = engine.fit(X, y)

An individual is a node. Every individual that the evolution creates is an instance of a class of EvoDAG.node (Variable for an input variable, a subclass of Function for the rest) and is appended to engine.population.hist, the history. A node stores in variable the positions, in that list, of the nodes it was computed from (the index of the column of X for an input variable), its weight (the coefficients), its height and its fitness. As several nodes can point at one node, the set of individuals is a directed acyclic graph. In the example the first node of the history is the one that combines the three input variables, so its variable lists the three columns.

>>> hist = engine.population.hist
>>> hist[0].height
0
>>> hist[0].variable
[0, 1, 2]

Semantics: hy and hy_test. A node holds the values it produces on the training examples in hy and, if a test set was given to fit, on the test examples in hy_test (None otherwise). In classification a node has one array per class. The values are computed when the node is created, from the hy of its arguments, so creating an offspring only costs operations over arrays of the size of the data.

>>> best = engine.population.estopping
>>> len(best.hy), best.hy[0].shape
(2, (100,))
>>> best.hy_test is None
True

Weights and fitness. When an offspring is created, its coefficients are computed by ordinary least squares against the target on the examples of the training mask (compute_weight), and the fitness is computed on the training part and on the validation part (BaggingFitness). The masks are made by EvoDAG.bagging_fitness from tr_fraction and the seed.

From the population to a model. The engine keeps the early stopping individual, the one with the best fitness on the validation part. EvoDAG.base.EvoDAG.model collects the nodes it depends on (EvoDAG.base.EvoDAG.trace), renumbers their positions and builds a Model with only those nodes and their weights. The model evaluates its nodes in order on new inputs and does not keep the training data.

>>> model = engine.model()
>>> model.size <= len(hist)
True
>>> model.nvar
3

The ensemble. EvoDAGE runs the engine n_estimators times with consecutive seeds; each run has its own split of the data, so the models differ. Ensemble aggregates them: the class that most models predict, the median of the outputs for decision_function, and the fraction of votes for predict_proba.