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 * infis 0,x / 0is infinity for any non-zeroxandnanforx == 0):mul,mul_scalar,divandatan2follow that;dot,SSE,SAEandsumadd 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
ausing the C library, returns a new array.
- acosh(a)¶
Element-wise inverse hyperbolic cosine of
ausing the C library, returns a new array.
- argmax(lst)¶
Position in
lstof the largest value in each position (the first)
- argmin(lst)¶
Position in
lstof the smallest value in each position (the first)
- asin(a)¶
Element-wise arc sine of
ausing the C library, returns a new array.
- asinh(a)¶
Element-wise inverse hyperbolic sine of
ausing the C library, returns a new array.
- atan(a)¶
Element-wise arc tangent of
ausing the C library, returns a new array.
- atan2(a, b)¶
Element-wise arc tangent of
a / busing the quadrant, a zero (also -0.0) in either operand is taken as +0.0.
- atanh(a)¶
Element-wise inverse hyperbolic tangent of
ausing the C library, returns a new array.
- ceil(a)¶
Element-wise ceiling of
ausing the C library, returns a new array.
- cos(a)¶
Element-wise cosine of
ausing the C library, returns a new array.
- cosh(a)¶
Element-wise hyperbolic cosine of
ausing the C library, returns a new array.
- cummax(lst)¶
Element-wise maximum of the vectors in
lst(at least two) ignoringnan, returns a new array.
- cummin(lst)¶
Element-wise minimum of the vectors in
lst(at least two) ignoringnan, returns a new array.
- cummul(lst)¶
Product of the vectors in
lst(at least two) with the semantics ofmul, 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 (
nancounts as not zero)
- div(a, b)¶
a / bwherebis zero: infinity ifais not zero andnanif it is; whereais zero andbis 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
ausing the C library, returns a new array.
- expm1(a)¶
Element-wise exponential minus one of
ausing the C library, returns a new array.
- fabs(a)¶
Element-wise absolute value of
ausing 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
ausing the C library, returns a new array.
- hypot(a, b)¶
Element-wise Euclidean norm of
aandb, i.e. the square root ofa * 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
ausing the C library, returns a new array.
- log10(a)¶
Element-wise base 10 logarithm of
ausing the C library, returns a new array.
- log1p(a)¶
Element-wise natural logarithm of one plus the value of
ausing the C library, returns a new array.
- log2(a)¶
Element-wise base 2 logarithm of
ausing 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 ifwis not finite
- sign(a)¶
-1, 0 or 1;
nangives 0
- sin(a)¶
Element-wise sine of
ausing the C library, returns a new array.
- sinh(a)¶
Element-wise hyperbolic sine of
ausing the C library, returns a new array.
- sq(a)¶
Element-wise square of
ausing the C library, returns a new array.
- sq_sum(a)¶
Sum of the squares, adding in order
- sqrt(a)¶
Element-wise square root of
ausing the C library, returns a new array.
- sum(a)¶
Sum adding in order
- tan(a)¶
Element-wise tangent of
ausing the C library, returns a new array.
- tanh(a)¶
Element-wise hyperbolic tangent of
ausing 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 inindexand 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
indexand for the rest.
- a_precision(y, hy, index)¶
Macro precision, the precision averaged over the classes, as a pair for the positions in
indexand for the rest.
- a_recall(y, hy, index)¶
Macro recall, the recall averaged over the classes, as a pair for the positions in
indexand for the rest.
- accDotMacroF1(y, hy, index)¶
Accuracy times macro F1, as a pair for the positions in
indexand for the rest.
- accuracy(y, hy, index)¶
Accuracy, the fraction of hits, as a pair for the positions in
indexand 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
indexand 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
indexand for the rest.
- g_precision(y, hy, index)¶
Product over the classes of the precision, as a pair for the positions in
indexand for the rest.
- g_recall(y, hy, index)¶
Product over the classes of the recall, as a pair for the positions in
indexand 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 inindexand for the rest.
- macroRecallF1(y, hy, index)¶
Macro recall for the positions in
indexand 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
knumbers 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
varsover the class examples inmask, as a list with one array per class.
- fitness_SAE(_ytr, _hy, _mask)¶
Negative sum of absolute errors between each target in
_ytrand the matching prediction in_hytimes its mask in_mask, averaged over the targets.
- fitness_SSE(_ytr, _hy, _mask)¶
Negative sum of squared errors between each target in
_ytrand the matching prediction in_hytimes_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
vargiven the parameters incoef, 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
varplus the log prior, returned as a list with one array per class.
- naive_bayes_Nc(var, klass, mask, nclass)¶
Multinomial naive Bayes parameters of
varon the positions inmask, 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 thenclassclasses.
- naive_bayes_isfinite_MN(coef, nclass)¶
Whether the first two vectors of
coefare finite in each of thenclassclasses.
- naive_bayes_mean_std2(var, klass, mask, nclass)¶
Per class mean and variance of
varand the class frequency, computed on the positions inmask, 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
- property individual¶
Individual