Class Maximizer


  • public final class Maximizer
    extends Object
    Utilities for searching arguments of the maxima of the function.
    • Method Detail

      • alwaysTrue

        public static <T> Predicate<T> alwaysTrue()
        A predicate that is always true.
        Type Parameters:
        T - the type
        Returns:
        the absolute truth
      • alwaysFalse

        public static <T> Predicate<T> alwaysFalse()
        A predicate that is always false.
        Type Parameters:
        T - the type
        Returns:
        the absolute non-truth
      • argmax

        public static <V,​S extends Comparable<S>> Optional<V> argmax​(Iterator<V> it,
                                                                           Predicate<V> checker,
                                                                           Function<V,​S> scorer)
        Find the first argument of the maximum (argmax) of the function.
        Type Parameters:
        V - the argument type
        S - the score type
        Parameters:
        it - the finite iterator
        checker - the predicate that evaluates the suitability of the argument
        scorer - the scoring function
        Returns:
        a non-empty optional that contains the first found argmax, otherwise the empty one
      • argmax

        public static <V,​S extends Comparable<S>> Optional<V> argmax​(Iterator<V> it,
                                                                           Function<V,​S> scorer)
        Find the first argument of the maximum (argmax) of the function.
        Type Parameters:
        V - the argument type
        S - the score type
        Parameters:
        it - the finite iterator
        scorer - the scoring function
        Returns:
        a non-empty optional that contains the first found argmax, otherwise the empty one
        See Also:
        argmax(Iterator, Predicate, Function)
      • argmaxRandom

        public static <V,​S extends Comparable<S>> Optional<V> argmaxRandom​(Iterator<V> it,
                                                                                 Function<V,​S> scorer,
                                                                                 Random random)
        Find the arguments of the maxima (argmax) of the function and randomly choose any of them.
        Type Parameters:
        V - the argument type
        S - the score type
        Parameters:
        it - the finite iterator
        scorer - the scoring function
        random - the random number generator
        Returns:
        a non-empty optional that contains the randomly chosen argmax, otherwise the empty one