Compiled modules and legacy code

The numerical kernels are written in Cython; they are compiled when the package is installed (python setup.py build_ext --inplace in a checkout). Their functions work on arrays of float64.

EvoDAG.array_utils

Operations over one-dimensional arrays: elementwise operations that keep the conventions of the evolution (a zero stays zero), reductions, and counts.

Operations on vectors, i.e. 1-D C-contiguous float64 numpy arrays.

The vectors of EvoDAG are dense arrays with the semantics of sparse vectors, which only store the entries that are not zero:

  • the C library’s math functions are used (not numpy’s, whose SIMD versions can differ in the last bit), through typed memoryviews;

  • where one operand is zero nothing is computed (e.g. 0 * inf is 0, x / 0 is infinity for any non-zero x and nan for x == 0): mul, mul_scalar, div and atan2 follow that;

  • dot, SSE, SAE and sum add sequentially in index order and not pairwise, which changes the last bits and, with them, the search trajectory.

SAE(a, b)

Sum of absolute errors, adding in order

SSE(a, b)

Sum of squared errors, adding in order

acos(a)

Element-wise arc cosine of a using the C library, returns a new array.

acosh(a)

Element-wise inverse hyperbolic cosine of a using the C library, returns a new array.

argmax(lst)

Position in lst of the largest value in each position (the first)

argmin(lst)

Position in lst of the smallest value in each position (the first)

asin(a)

Element-wise arc sine of a using the C library, returns a new array.

asinh(a)

Element-wise inverse hyperbolic sine of a using the C library, returns a new array.

atan(a)

Element-wise arc tangent of a using the C library, returns a new array.

atan2(a, b)

Element-wise arc tangent of a / b using the quadrant, a zero (also -0.0) in either operand is taken as +0.0.

atanh(a)

Element-wise inverse hyperbolic tangent of a using the C library, returns a new array.

ceil(a)

Element-wise ceiling of a using the C library, returns a new array.

cos(a)

Element-wise cosine of a using the C library, returns a new array.

cosh(a)

Element-wise hyperbolic cosine of a using the C library, returns a new array.

cummax(lst)

Element-wise maximum of the vectors in lst (at least two) ignoring nan, returns a new array.

cummin(lst)

Element-wise minimum of the vectors in lst (at least two) ignoring nan, returns a new array.

cummul(lst)

Product of the vectors in lst (at least two) with the semantics of mul, returns a new array.

cumsum(lst)

Sum of the vectors in lst (at least two) added in order, returns a new array.

density(a)

Fraction of entries that are not zero (nan counts as not zero)

div(a, b)

a / b where b is zero: infinity if a is not zero and nan if it is; where a is zero and b is not: 0

dot(a, b)

Sum of the products of the positions where both are not zero, in order

exp(a)

Element-wise exponential of a using the C library, returns a new array.

expm1(a)

Element-wise exponential minus one of a using the C library, returns a new array.

fabs(a)

Element-wise absolute value of a using the C library, returns a new array.

finite(a)

Sets to zero, in place, the entries that are not finite; returns a

floor(a)

Element-wise floor of a using the C library, returns a new array.

hypot(a, b)

Element-wise Euclidean norm of a and b, i.e. the square root of a * a + b * b.

isfinite(a)

Whether every entry is finite

lgamma(a)

Log of the absolute value of gamma (the C library’s, numpy has none)

log(a)

Element-wise natural logarithm of a using the C library, returns a new array.

log10(a)

Element-wise base 10 logarithm of a using the C library, returns a new array.

log1p(a)

Element-wise natural logarithm of one plus the value of a using the C library, returns a new array.

log2(a)

Element-wise base 2 logarithm of a using the C library, returns a new array.

mul(a, b)

a * b; it is 0 wherever one of them is, also if the other is inf

mul_scalar(a, w)

a * w; zeros stay zero, also if w is not finite

sign(a)

-1, 0 or 1; nan gives 0

sin(a)

Element-wise sine of a using the C library, returns a new array.

sinh(a)

Element-wise hyperbolic sine of a using the C library, returns a new array.

sq(a)

Element-wise square of a using the C library, returns a new array.

sq_sum(a)

Sum of the squares, adding in order

sqrt(a)

Element-wise square root of a using the C library, returns a new array.

sum(a)

Sum adding in order

tan(a)

Element-wise tangent of a using the C library, returns a new array.

tanh(a)

Element-wise hyperbolic tangent of a using the C library, returns a new array.

EvoDAG.cython_utils

Naive Bayes, centroids and the classification scores used as fitness.

class Score

Per class precision and recall of a prediction, on the positions in an index and on the rest, and the scores built from them.

F1(i, y, hy, index)

F1 of class i, as a pair for the positions in index and for the rest.

classmethod __new__(*args, **kwargs)
a_F1(y, hy, index)

Macro F1, the F1 averaged over the classes, as a pair for the positions in index and for the rest.

a_precision(y, hy, index)

Macro precision, the precision averaged over the classes, as a pair for the positions in index and for the rest.

a_recall(y, hy, index)

Macro recall, the recall averaged over the classes, as a pair for the positions in index and for the rest.

accDotMacroF1(y, hy, index)

Accuracy times macro F1, as a pair for the positions in index and for the rest.

accuracy(y, hy, index)

Accuracy, the fraction of hits, as a pair for the positions in index and for the rest.

g_F1(y, hy, index)

Product over the classes of the F1, 0 if the F1 of a class is zero, as a pair for the positions in index and for the rest.

g_g_recall_precision(y, hy, index)

Product over the classes of the precision times the recall, as a pair for the positions in index and for the rest.

g_precision(y, hy, index)

Product over the classes of the precision, as a pair for the positions in index and for the rest.

g_recall(y, hy, index)

Product over the classes of the recall, as a pair for the positions in index and for the rest.

g_recall_precision(i, y, hy, index)

Product of the precision and the recall of class i, as a pair for the positions in index and for the rest.

macroRecallF1(y, hy, index)

Macro recall for the positions in index and macro F1 for the rest, as a pair, each averaged over the classes.

class SelectNumbers

Hands out the numbers of a list, shuffled, in consecutive groups without repeating any.

classmethod __new__(*args, **kwargs)
empty()

Whether all the numbers have been handed out.

get(k)

Return the next k numbers that have not been handed out (fewer if there are not enough).

get_one()

Return the next number that has not been handed out.

centroid_coef(vars, klass, mask, nclass)

Per class coefficients, minus the mean of each variable in vars over the class examples in mask, as a list with one array per class.

fitness_SAE(_ytr, _hy, _mask)

Negative sum of absolute errors between each target in _ytr and the matching prediction in _hy times its mask in _mask, averaged over the targets.

fitness_SSE(_ytr, _hy, _mask)

Negative sum of squared errors between each target in _ytr and the matching prediction in _hy times _mask, averaged over the targets.

naive_bayes(var, coef, nclass)

Gaussian naive Bayes, for each class the log prior plus the log likelihood of the variables in var given the parameters in coef, returned as a list with one array per class.

naive_bayes_MN(var, coef, nclass)

Multinomial naive Bayes, for each class the exponential of the weighted sum of the variables in var plus the log prior, returned as a list with one array per class.

naive_bayes_Nc(var, klass, mask, nclass)

Multinomial naive Bayes parameters of var on the positions in mask, the log of the share of its positive mass in each class and the log of the class frequency.

naive_bayes_isfinite(coef, nclass)

Whether the variances and the class priors (positions 1 and 2 of coef) are not zero for any of the nclass classes.

naive_bayes_isfinite_MN(coef, nclass)

Whether the first two vectors of coef are finite in each of the nclass classes.

naive_bayes_mean_std2(var, klass, mask, nclass)

Per class mean and variance of var and the class frequency, computed on the positions in mask, returned as a list of three arrays.

EvoDAG.linalg_solve

The least-squares solver that computes the weights of a node.

compute_weight(r, ytr, mask)

Returns the weight (w) using OLS of r * w = gp._ytr

EvoDAG.gp

Individuals written in prefix notation; this module is not used by the engine.

class Individual[source]

Object to store in individual on prefix notation

__init__(ind, classifier=True, labels=None)[source]
property individual

Individual

decision_function(X)[source]

Decision function i.e. the raw data of the prediction

class Population[source]

Population of a tree-based GP system

__init__(function_set=None, nterminals=None, seed=0)[source]
random_function()[source]

Return a node of a randomly chosen function with the first positions as arguments and unit weights.

random_terminal()[source]

Return a variable node on a randomly chosen input with weight one.

create_random_ind_full(depth=0)[source]

Random individual using full method

grow_use_function(depth=0)[source]

Select either function or terminal in grow method

create_random_ind_grow(depth=0)[source]

Random individual using grow method

create_population(popsize=1000, min_depth=2, max_depth=4, X=None)[source]

Creates random population using ramped half-and-half method