Losses and criteria#

Losses, scores, complexity measures and information criteria.

All losses are to be minimized. Non-finite predictions give an infinite loss, so that invalid expressions are never selected.

Examples#

>>> import numpy as np
>>> from eqdisco.fitness import mse, r2, complexity
>>> from eqdisco.expr import Expression
>>> y = np.array([1.0, 2.0, 3.0]); yhat = np.array([1.1, 1.9, 3.2])
>>> round(mse(y, yhat), 4), round(r2(y, yhat), 4)
(0.02, 0.97)
>>> e = Expression.from_string("7*x0^2 + 3*x0 + 5")
>>> complexity(e, "size"), complexity(e, "recursive")
(10, 17.0)

Losses, complexity measures, information criteria and description length.

Functions#

mse(y, yhat[, sample_weight])

Mean squared error \(\frac1N\sum_k (y_k-\hat y_k)^2\).

rmse(y, yhat[, sample_weight])

Root mean squared error.

nmse(y, yhat[, sample_weight])

MSE normalized by the variance of y (1 for the constant mean model).

mae(y, yhat[, sample_weight])

Mean absolute error.

r2(y, yhat[, sample_weight])

Coefficient of determination \(R^2 = 1 - \mathrm{SSE}/\mathrm{SST}\).

max_error(y, yhat[, sample_weight])

Largest absolute residual.

huber(y, yhat[, sample_weight, delta])

Huber loss; delta defaults to 1.345 times the MAD of y (robust regression).

log_loss(y, p[, sample_weight, eps])

Binary cross-entropy of probabilities p for labels y in {0, 1}.

misclassification(y, yhat[, sample_weight])

Share of wrongly classified samples (labels compared directly).

balanced_error(y, yhat[, sample_weight])

One minus the balanced accuracy (mean recall over the classes).

get_loss(loss)

Resolve a loss given by name or as a callable loss(y, yhat, sample_weight).

complexity(expr[, kind])

Complexity \(C(f)\) of an expression.

gaussian_loglik(rss, n)

Maximized Gaussian log-likelihood for residual sum of squares rss.

aic(rss, n, k)

Akaike information criterion \(2k - 2\ln\hat L\) (Gaussian errors).

aicc(rss, n, k)

AIC with the small-sample correction of Hurvich and Tsai.

bic(rss, n, k)

Bayesian information criterion \(k\ln N - 2\ln\hat L\) (Gaussian errors).

information_criterion(name, y, yhat, k)

"aic", "aicc" or "bic" of a prediction with k parameters.

description_length(expr, y, yhat[, ...])

Two-part description length (in nats) of data and model.

per_case_errors(y, yhat)

Absolute errors per sample (the cases of lexicase selection); inf if invalid.

Constants#

LOSSES

Regression losses available by name.

COMPLEXITY_KINDS

Names accepted by complexity().