Package io.jenetics.prog.regression
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 overallErrorfunction.final Error<Double> error = Error.of(LossFunction::mse, Complexity.ofMaxNodeCount(50));- Since:
- 5.0
- Version:
- 5.0
- Author:
- Franz Wilhelmstötter
- See Also:
LossFunction,Error
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description doubleapply(Tree<? extends Op<T>,?> program)Calculates the complexity of the current program (possibly) relative to the actual error value.static doublecount(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 Detail
-
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 if the program node count is greater or equal the givencount- Returns:
- a program node count complexity measure
- Throws:
IllegalArgumentException- if the max nodecountis smaller than one- See Also:
count(Tree, int)
-
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 equalmaxNodes, 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 measuremaxNodes- the maximal expected node count- Returns:
- the complexity measure of the given
program - Throws:
NullPointerException- if the givenprogramisnullIllegalArgumentException- ifmaxNodesis smaller than one- See Also:
ofNodeCount(int)
-
-