Interface Error<T>

Type Parameters:
T - the sample type
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 Error<T>
This function calculates the overall error of a given program tree. The error is calculated from the LossFunction and, if desired, the program Complexity.
final Error<Double> error = Error.of(LossFunction::mse, Complexity.ofNodeCount(50));
Since:
5.0
Version:
5.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    apply(Tree<? extends Op<T>,?> program, T[] calculated, T[] expected)
    Calculates the overall error of a given program tree.
    static <T> Error<T>
    of(LossFunction<T> loss)
    Creates an error function which only uses the given loss function for calculating the program error
    static <T> Error<T>
    of(LossFunction<T> loss, Complexity<T> complexity)
    Creates an error function by combining the given loss function and program complexity.
    static <T> Error<T>
    of(LossFunction<T> loss, Complexity<T> complexity, DoubleBinaryOperator compose)
    Creates an error function by combining the given loss function and program complexity.
  • Method Details

    • apply

      double apply(Tree<? extends Op<T>,?> program, T[] calculated, T[] expected)
      Calculates the overall error of a given program tree. The error is calculated from the LossFunction and, if desired, the program Complexity.
      Parameters:
      program - the program tree which calculated the calculated values
      calculated - the calculated function values
      expected - the expected function values
      Returns:
      the overall program error
      Throws:
      NullPointerException - if one of the arguments is null
    • of

      static <T> Error<T> of(LossFunction<T> loss)
      Creates an error function which only uses the given loss function for calculating the program error
      Type Parameters:
      T - the sample type
      Parameters:
      loss - the loss function to use for calculating the program error
      Returns:
      an error function which uses the loss function for error calculation
      Throws:
      NullPointerException - if the given loss function is null
    • of

      static <T> Error<T> of(LossFunction<T> loss, Complexity<T> complexity)
      Creates an error function by combining the given loss function and program complexity. The loss function and program complexity is combined in the following way: error = loss + loss*complexity. The complexity function penalizes programs which grows to big.
      Type Parameters:
      T - the sample type
      Parameters:
      loss - the loss function
      complexity - the program complexity measure
      Returns:
      a new error function by combining the given loss and complexity function
      Throws:
      NullPointerException - if one of the functions is null
    • of

      static <T> Error<T> of(LossFunction<T> loss, Complexity<T> complexity, DoubleBinaryOperator compose)
      Creates an error function by combining the given loss function and program complexity. The loss function and program complexity is combined in the following way: error = loss + loss*complexity. The complexity function penalizes programs which grows to big.
      Type Parameters:
      T - the sample type
      Parameters:
      loss - the loss function
      complexity - the program complexity measure
      compose - the function which composes the loss and complexity function
      Returns:
      a new error function by combining the given loss and complexity function
      Throws:
      NullPointerException - if one of the functions is null