Interface LossFunction<T>

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface LossFunction<T>
    This function evaluates how well an evolved program tree fits the given sample data set. If the predictions are totally off, the loss function will output a higher value. If they’re pretty good, it’ll output a lower number. It is the essential part of the overall Error function.
    final Error<Double> error = Error.of(LossFunction::mse);
    Since:
    5.0
    Version:
    5.0
    See Also:
    Loss function
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      double apply​(T[] calculated, T[] expected)
      Calculates the error between the expected function values and the values calculated by the actual ProgramGene.
      static double mae​(Double[] calculated, Double[] expected)
      Mean absolute error is measured as the average of sum of absolute differences between predictions and actual observations.
      static double mse​(Double[] calculated, Double[] expected)
      Mean square error is measured as the average of squared difference between predictions and actual observations.
      static double rmse​(Double[] calculated, Double[] expected)
      Root mean square error is measured as the average of squared difference between predictions and actual observations.
    • Method Detail

      • apply

        double apply​(T[] calculated,
                     T[] expected)
        Calculates the error between the expected function values and the values calculated by the actual ProgramGene.
        Parameters:
        calculated - the currently calculated function value
        expected - the expected function values
        Returns:
        the error value
        Throws:
        IllegalArgumentException - if the length of the two arrays are not equal
        NullPointerException - if one of the double[] arrays is null
      • mse

        static double mse​(Double[] calculated,
                          Double[] expected)
        Mean square error is measured as the average of squared difference between predictions and actual observations.
        Parameters:
        calculated - the function values calculated with the current program tree
        expected - the expected function value as given by the sample points
        Returns:
        the mean square error
        Throws:
        IllegalArgumentException - if the length of the two arrays are not equal
        NullPointerException - if one of the double[] arrays is null
        See Also:
        rmse(Double[], Double[])
      • rmse

        static double rmse​(Double[] calculated,
                           Double[] expected)
        Root mean square error is measured as the average of squared difference between predictions and actual observations.
        Parameters:
        calculated - the function values calculated with the current program tree
        expected - the expected function value as given by the sample points
        Returns:
        the mean square error
        Throws:
        IllegalArgumentException - if the length of the two arrays are not equal
        NullPointerException - if one of the double[] arrays is null
        See Also:
        mse(Double[], Double[])
      • mae

        static double mae​(Double[] calculated,
                          Double[] expected)
        Mean absolute error is measured as the average of sum of absolute differences between predictions and actual observations.
        Parameters:
        calculated - the function values calculated with the current program tree
        expected - the expected function value as given by the sample points
        Returns:
        the mean absolute error
        Throws:
        IllegalArgumentException - if the length of the two arrays are not equal
        NullPointerException - if one of the double[] arrays is null