Package com.gengoai.math
Enum Optimum
- java.lang.Object
-
- java.lang.Enum<Optimum>
-
- com.gengoai.math.Optimum
-
- All Implemented Interfaces:
Serializable
,Comparable<Optimum>
,Comparator<Double>
public enum Optimum extends Enum<Optimum> implements Comparator<Double>
Defines methodologies for comparing, testing, and selecting values and indexes based on optimizing values in a specific direction, i.e. MAXIMUM or MINIMUM
- Author:
- David B. Bracewell
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract int
compare(double v1, double v2)
Compares two values such that the most optimum value would result in being sorted to the front.int
compare(Double o1, Double o2)
Tuple2<Integer,Double>
optimum(double[] array)
Select the best index and value from the given array.<T> Optional<T>
optimum(MStream<T> stream, SerializableToDoubleFunction<T> function)
Optimum optional.<T> Optional<T>
optimum(Stream<T> stream, SerializableToDoubleFunction<T> function)
Optimum optional.int
optimumIndex(double[] array)
Selects the index of the best value in the given arrayint
optimumIndex(float[] array)
Selects the index of the best value in the given arrayint
optimumIndex(int[] array)
Selects the index of the best value in the given arraydouble
optimumValue(@lombok.NonNull double[] array)
Selects the best value from the given arraydouble
optimumValue(@lombok.NonNull float[] array)
Selects the best value from the given arrayabstract double
startingValue()
Gets a value that will also be the worst possible solution.abstract boolean
test(double value, double threshold)
Test if the given value passes the given threshold based on the direction of the optimum.static Optimum
valueOf(String name)
Returns the enum constant of this type with the specified name.static Optimum[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.-
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
-
-
-
Method Detail
-
values
public static Optimum[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Optimum c : Optimum.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Optimum valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
compare
public int compare(Double o1, Double o2)
- Specified by:
compare
in interfaceComparator<Double>
-
compare
public abstract int compare(double v1, double v2)
Compares two values such that the most optimum value would result in being sorted to the front.- Parameters:
v1
- the first valuev2
- the second value- Returns:
- the result of comparison (optimum value should be
<
0)
-
optimum
public Tuple2<Integer,Double> optimum(double[] array)
Select the best index and value from the given array.- Parameters:
array
- the array to select from- Returns:
- the index and value of the best entry
-
optimum
public <T> Optional<T> optimum(MStream<T> stream, SerializableToDoubleFunction<T> function)
Optimum optional.- Type Parameters:
T
- the type parameter- Parameters:
stream
- the streamfunction
- the function- Returns:
- the optional
-
optimum
public <T> Optional<T> optimum(Stream<T> stream, SerializableToDoubleFunction<T> function)
Optimum optional.- Type Parameters:
T
- the type parameter- Parameters:
stream
- the streamfunction
- the function- Returns:
- the optional
-
optimumIndex
public int optimumIndex(double[] array)
Selects the index of the best value in the given array- Parameters:
array
- the array to select from- Returns:
- the index of the optimum value
-
optimumIndex
public int optimumIndex(float[] array)
Selects the index of the best value in the given array- Parameters:
array
- the array to select from- Returns:
- the index of the optimum value
-
optimumIndex
public int optimumIndex(int[] array)
Selects the index of the best value in the given array- Parameters:
array
- the array to select from- Returns:
- the index of the optimum value
-
optimumValue
public double optimumValue(@NonNull @lombok.NonNull double[] array)
Selects the best value from the given array- Parameters:
array
- the array to select from- Returns:
- the most optimum value
-
optimumValue
public double optimumValue(@NonNull @lombok.NonNull float[] array)
Selects the best value from the given array- Parameters:
array
- the array to select from- Returns:
- the most optimum value
-
startingValue
public abstract double startingValue()
Gets a value that will also be the worst possible solution.- Returns:
- the double
-
test
public abstract boolean test(double value, double threshold)
Test if the given value passes the given threshold based on the direction of the optimum. ForMINIMUM
this uses a less than equal to operator and forMAXIMUM
this uses a greater than equal to operator.- Parameters:
value
- the valuethreshold
- the threshold- Returns:
- the boolean
-
-