vstat
Loading...
Searching...
No Matches
Regression metrics

Functions

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto r2_score (I first1, I last1, J first2) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto r2_score (I first1, I last1, J first2, K first3) noexcept -> double
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_squared_error (I first1, I last1, J first2) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_squared_error (I first1, I last1, J first2, K first3) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto normalized_mean_squared_error (I first1, I last1, J first2) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto normalized_mean_squared_error (I first1, I last1, J first2, K first3) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_squared_log_error (I first1, I last1, J first2) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_squared_log_error (I first1, I last1, J first2, K first3) noexcept -> double
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_absolute_error (I first1, I last1, J first2) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_absolute_error (I first1, I last1, J first2, K first3) noexcept -> std::conditional_t< Policy==nan_policy::omit, std::pair< double, std::size_t >, double >
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_absolute_percentage_error (I first1, I last1, J first2) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_absolute_percentage_error (I first1, I last1, J first2, K first3) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto poisson_neg_likelihood_loss (I first1, I last1, J first2) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto poisson_neg_likelihood_loss (I first1, I last1, J first2, K first3) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto gaussian_neg_likelihood_loss (I first1, I last1, J first2, T sigma) noexcept -> double
 
template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto poisson_log_neg_likelihood_loss (I first1, I last1, J first2) noexcept -> double
 

Detailed Description

Regression metrics (R2, MSE, MLSE, MAE).

Function Documentation

◆ gaussian_neg_likelihood_loss()

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto gaussian_neg_likelihood_loss ( first1,
last1,
first2,
sigma 
) -> double
inlinenoexcept

Negative log likelihood loss under a Gaussian with known scalar noise level \(\sigma\).

\[ -\log\mathcal{L}_\text{gaussian}(y, \hat{y}, \sigma) = \frac{n}{2}\log(2\pi) + n\log(\sigma) + \frac{1}{2\sigma^2} \sum_i (y_i - \hat{y}_i)^2 \]

Precondition
sigma > 0. Passing a non-positive value produces NaN/inf silently.

◆ mean_absolute_error() [1/2]

template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_absolute_error ( first1,
last1,
first2 
) -> std::conditional_t<Policy == nan_policy::omit, std::pair<double, std::size_t>, double>
inlinenoexcept

Computes the mean absolute error.

Template Parameters
Policynan_policy::propagate (default): a non-finite value poisons the whole result. nan_policy::omit: rows where either value is non-finite are skipped rather than poisoning the whole result.

\[ \text{MAE}(y, \hat{y}) = \displaystyle \frac{1}{n} {\sum_{i=1}^n |y-\hat{y}|} \]

Returns
nan_policy::propagate: the MAE. nan_policy::omit: the MAE over finite pairs, and the count of skipped (non-finite) pairs.

◆ mean_absolute_error() [2/2]

template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_absolute_error ( first1,
last1,
first2,
first3 
) -> std::conditional_t<Policy == nan_policy::omit, std::pair<double, std::size_t>, double>
inlinenoexcept

Weighted variant of mean_absolute_error.

\[ \text{MAE}(y, \hat{y}) = \displaystyle \frac{1}{\sum_{i=1}^n w_i} \sum_{i=1}^n w_i |y-\hat{y}| \]

◆ mean_absolute_percentage_error() [1/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_absolute_percentage_error ( first1,
last1,
first2 
) -> double
inlinenoexcept

Computes the mean absolute percentage error.

Template Parameters
T

\[ \text{MAPE}(y, \hat{y}) = \frac{1}{n} \sum_{i=1}^{n} \frac{{}\left| y_i - \hat{y}_i \right|}{\max(\epsilon, \left| y_i \right|)} \]

where \(\epsilon\) = std::numeric_limits<T>::epsilon() is an arbitrarily small constant to prevent division by zero.

◆ mean_absolute_percentage_error() [2/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_absolute_percentage_error ( first1,
last1,
first2,
first3 
) -> double
inlinenoexcept

Weighted mean absolute percentage error.

\[ \text{WMAPE}(y, \hat{y}) = \displaystyle \frac{1}{\sum_i^n w_i} \frac{\sum_{i=1}^n w_i |y-\hat{y}|}{\max(\epsilon, \left| y_i \right|)} \]

◆ mean_squared_error() [1/2]

template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_squared_error ( first1,
last1,
first2 
) -> std::conditional_t<Policy == nan_policy::omit, std::pair<double, std::size_t>, double>
inlinenoexcept

Computes the mean squared error.

Template Parameters
Policynan_policy::propagate (default): a non-finite value poisons the whole result. nan_policy::omit: rows where either value is non-finite are skipped rather than poisoning the whole result.

\[ \text{MSE}(y, \hat{y}) = \displaystyle \frac{1}{n} {\sum_{i=1}^n \left(y-\hat{y}\right)^2} \]

Returns
nan_policy::propagate: the MSE. nan_policy::omit: the MSE over finite pairs, and the count of skipped (non-finite) pairs.

◆ mean_squared_error() [2/2]

template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_squared_error ( first1,
last1,
first2,
first3 
) -> std::conditional_t<Policy == nan_policy::omit, std::pair<double, std::size_t>, double>
inlinenoexcept

Weighted variant of mean_squared_error.

\[ \text{MSE}(y, \hat{y}) = {\displaystyle \frac{1}{\sum_{i=1}^n w_i}} \sum_{i=1}^n w_i \left(y-\hat{y}\right)^2 \]

◆ mean_squared_log_error() [1/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto mean_squared_log_error ( first1,
last1,
first2 
) -> double
inlinenoexcept

Computes the mean squared logarithmic error.

\[ \text{MSLE}(y, \hat{y}) = \frac{1}{n} \sum_{i=1}^{n} (\log_e (1 + y_i) - \log_e (1 + \hat{y}_i) )^2 \]

◆ mean_squared_log_error() [2/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto mean_squared_log_error ( first1,
last1,
first2,
first3 
) -> double
inlinenoexcept

Computes the weighted mean squared logarithmic error.

\[ \text{MSLE}(y, \hat{y}) = \frac{1}{\sum_{i=1}^n w_i} \sum_{i=1}^{n} w_i (\log_e (1 + y_i) - \log_e (1 + \hat{y}_i) )^2 \]

◆ normalized_mean_squared_error()

template<std::floating_point T, nan_policy Policy = nan_policy::propagate, std::contiguous_iterator I, std::contiguous_iterator J>
auto normalized_mean_squared_error ( first1,
last1,
first2 
) -> std::conditional_t<Policy == nan_policy::omit, std::pair<double, std::size_t>, double>
inlinenoexcept

Normalized mean squared error over (estimated, target) pairs.

Template Parameters
Policynan_policy::propagate (default): a non-finite value poisons the whole result. nan_policy::omit: rows where either value is non-finite are skipped rather than poisoning the whole result – the target variance is computed over the same finite subset (the mask is shared), keeping the numerator and denominator consistent.

Single pass over the input in both modes: the residual mean and target variance accumulators run in lockstep, instead of composing two independent passes.

\[ \text{NMSE}(y, \hat{y}) = \frac{ \overline{(y - \hat{y})^2} }{ \text{Var}(y) } \]

Returns
nan_policy::propagate: the NMSE (0.0 if the target variance is 0). nan_policy::omit: the NMSE over finite pairs (0.0 if the target variance over that subset is 0), and the count of skipped (non-finite) pairs.

◆ poisson_log_neg_likelihood_loss()

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto poisson_log_neg_likelihood_loss ( first1,
last1,
first2 
) -> double
inlinenoexcept

Negative log likelihood loss with Poisson distribution of target, where the model outputs \(x = \log(\mu)\) (the natural log of the Poisson mean).

\[ -\log\mathcal{L}_\text{poisson-log}(y, x) = \sum_i \left[ e^{x_i} - y_i \cdot x_i + \ln(|\Gamma(y_i + 1)|) \right] \]

◆ poisson_neg_likelihood_loss() [1/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto poisson_neg_likelihood_loss ( first1,
last1,
first2 
) -> double
inlinenoexcept

Negative log likelihood loss with Poisson distribution of target.

\[ -\log\mathcal{L}_\text{poisson}(y, \hat{y}) = \hat{y} - y \cdot \log(\hat{y}) + \ln(|\Gamma(y+1)|) \]

where \(\ln|\Gamma(y+1)| = \log(y!)\) is computed via eve::log_abs_gamma.

◆ poisson_neg_likelihood_loss() [2/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto poisson_neg_likelihood_loss ( first1,
last1,
first2,
first3 
) -> double
inlinenoexcept

Negative log likelihood loss with Poisson distribution of target. The mean in each bin is multiplied by a weight before the Poisson likelihood is applied.

\[ -\log\mathcal{L}_\text{poisson}(y, w \cdot \hat{y}) = w\hat{y} - y \cdot \log(w\hat{y}) + \ln(|\Gamma(y+1)|) \]

where \(\ln|\Gamma(y+1)| = \log(y!)\) is computed via eve::log_abs_gamma.

◆ r2_score() [1/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J>
auto r2_score ( first1,
last1,
first2 
) -> double
inlinenoexcept

Computes the coefficient of determination \(R^2\).

Template Parameters
TThe scalar value type underlying the eve::wide<T> SIMD type used to compute the stats

\begin{align} R^2(y, \hat{y}) &= 1 - \frac{\text{RSS}}{\text{TSS}}\text{, where}\\ \text{RSS} &= \sum_{i=1}^n \left( y - \hat{y} \right)^2\\ \text{TSS} &= \sum_{i=1}^n \left( y - \bar{y} \right)^2\\ \end{align}

◆ r2_score() [2/2]

template<std::floating_point T, std::contiguous_iterator I, std::contiguous_iterator J, std::contiguous_iterator K>
auto r2_score ( first1,
last1,
first2,
first3 
) -> double
inlinenoexcept

Computes the weighted coefficient of determination \(R^2\).

\begin{align} R^2(y, \hat{y}) &= 1 - \frac{\text{RSS}}{\text{TSS}}\text{, where}\\ \text{RSS} &= \sum_{i=1}^n w_i \left( y - \hat{y} \right)^2\\ \text{TSS} &= \sum_{i=1}^n w_i \left( y - \bar{y} \right)^2\\ \end{align}