src/FitnessFunctions.cpp
floatBO EchoBay::Comparator::NRMSE(Eigen::Ref<MatrixBO> predict, Eigen::Ref<MatrixBO> actual, int nOutput, Eigen::Ref<MatrixBO> OutputLabel, const std::string rule)
{
    // Variables
    int i;
    ArrayBO diff_array(predict.rows());
    floatBO RMSE, variance;
    floatBO var_correction;
    ArrayBO NRMSE(predict.cols());

    // Calculate NRMSE
    var_correction = predict.rows() / (floatBO)(predict.rows() - 1);
    for (i = 0; i < nOutput; i++)
    {
        // Calculate difference array
        diff_array = predict.col(i) - actual.col(i);

        RMSE = sqrt(diff_array.pow(2).mean());
        variance = var_correction * (actual.col(i).array().pow(2).mean() - pow(actual.col(i).array().mean(), 2));
        NRMSE(i) = RMSE / sqrt(variance);
    }

    return 100.0 * (1.0 - NRMSE.mean());
}
/**
 * @brief Calculate fitness function as Normalized Root-Mean Square Error
 * 
 * @f[ NRMSE = \frac{\sqrt{\sum_{i=0}^N (predict_i - actual_i)}}{\sqrt{\sigma^2_{actual}}} @f]
 * 
 * @param predict Eigen matrix of predicted values
 * @param actual Eigen matrix of actual values
 * @param nOutput Number of output columns
 * @param OutputLabel [deprecated] return the outputLabel
 * @param rule Unused. Necessary to be compliant with external fitness functions 
 * @return floatBO Value of the fitness function
 */
@brief Calculate fitness function as Normalized Root-Mean Square Error




@brief Calculate fitness function as Normalized Root - Mean Square Error
floatBO EchoBay::Comparator::NRMSE(Eigen::Ref<MatrixBO> predict, Eigen::Ref<MatrixBO> actual, int nOutput, Eigen::Ref<MatrixBO> OutputLabel, const std::string rule)
{
    int i;
    ArrayBO diff_array(predict.rows());
    floatBO RMSE, variance;
    floatBO var_correction;
    ArrayBO NRMSE(predict.cols());
    var_correction = predict.rows() / (floatBO)(predict.rows() - 1);
    for (i = 0; i < nOutput; i++)
    {
        diff_array = predict.col(i) - actual.col(i);
        RMSE = sqrt(diff_array.pow(2).mean());
        variance = var_correction * (actual.col(i).array().pow(2).mean() - pow(actual.col(i).array().mean(), 2));
        NRMSE(i) = RMSE / sqrt(variance);
    }
    return 100.0 * (1.0 - NRMSE.mean());
}
floatBO EchoBay :: Comparator :: NRMSE ( Eigen :: Ref < MatrixBO > predict , Eigen :: Ref < MatrixBO > actual , int nOutput , Eigen :: Ref < MatrixBO > OutputLabel , const std :: string rule ) { int i ; ArrayBO diff_array ( predict . rows ( ) ) ; floatBO RMSE , variance ; floatBO var_correction ; ArrayBO NRMSE ( predict . cols ( ) ) ; var_correction = predict . rows ( ) / ( floatBO ) ( predict . rows ( ) - 1 ) ; for ( i = 0 ; i < nOutput ; i ++ ) { diff_array = predict . col ( i ) - actual . col ( i ) ; RMSE = sqrt ( diff_array . pow ( 2 ) . mean ( ) ) ; variance = var_correction * ( actual . col ( i ) . array ( ) . pow ( 2 ) . mean ( ) - pow ( actual . col ( i ) . array ( ) . mean ( ) , 2 ) ) ; NRMSE ( i ) = RMSE / sqrt ( variance ) ; } return 100.0 * ( 1.0 - NRMSE . mean ( ) ) ; }
@brief Calculate fitness function as Normalized Root-Mean Square Error
@brief Calculate fitness function as Normalized Root - Mean Square Error
// Variables // Calculate NRMSE // Calculate difference array