Interface Complexity<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 Complexity<T>
Represents a complexity measure if a given program tree. The program complexity ensures that simpler programs with similar loss function values are preferred. It is part of the overall Error function.
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)
    Calculates the complexity of the current program (possibly) relative to the actual error value.
    static double
    count(Tree<?,?> program, int maxNodes)
    This method uses the node count of a program tree for calculating its complexity.
    static <T> Complexity<T>
    ofNodeCount(int maxNodeCount)
    Return a complexity measure which counts the number of nodes of a program.
  • Method Details

    • apply

      double apply(Tree<? extends Op<T>,?> program)
      Calculates the complexity of the current program (possibly) relative to the actual error value.
      Parameters:
      program - the actual program
      Returns:
      the measure of the program complexity
    • ofNodeCount

      static <T> Complexity<T> ofNodeCount(int maxNodeCount)
      Return a complexity measure which counts the number of nodes of a program.
      Type Parameters:
      T - the sample type
      Parameters:
      maxNodeCount - the maximal node count. The returned complexity will be one of the program node count is greater or equal the given count
      Returns:
      a program node count complexity measure
      Throws:
      IllegalArgumentException - if the max node count is smaller than one
      See Also:
    • count

      static double count(Tree<?,?> program, int maxNodes)
      This method uses the node count of a program tree for calculating its complexity. The returned node count measure is within the range of [0, 1]. If the program contains only one node, zero is returned. If the node count is bigger or equal maxNodes, one is returned.

      The complexity is calculated in the following way:

      final double cc = min(program.size() - 1, maxNodes); return 1.0 - sqrt(1.0 - (cc*cc)/(maxNodes*maxNodes));
      Parameters:
      program - the program used for the complexity measure
      maxNodes - the maximal expected node count
      Returns:
      the complexity measure of the given program
      Throws:
      NullPointerException - if the given program is null
      IllegalArgumentException - if maxNodes is smaller than one
      See Also: