Class NaturalRanking

  • All Implemented Interfaces:
    Function<double[],​double[]>, UnaryOperator<double[]>, RankingAlgorithm

    public class NaturalRanking
    extends Object
    implements RankingAlgorithm
    Ranking based on the natural ordering on floating-point values.

    NaNs are treated according to the configured NaNStrategy and ties are handled using the selected TiesStrategy. Configuration settings are supplied in optional constructor arguments. Defaults are NaNStrategy.FAILED and TiesStrategy.AVERAGE, respectively.

    When using TiesStrategy.RANDOM, a generator of random values in [0, x) can be supplied as a IntUnaryOperator argument; otherwise a default is created on-demand. The source of randomness can be supplied using a method reference. The following example creates a ranking with NaN values with the highest ranking and ties resolved randomly:

     NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL,
                                                 new SplittableRandom()::nextInt);
     

    Note: Using TiesStrategy.RANDOM is not thread-safe due to the mutable generator of randomness. Instances not using random resolution of ties are thread-safe.

    Examples:

    Examples
    Input data: [20, 17, 30, 42.3, 17, 50, Double.NaN, Double.NEGATIVE_INFINITY, 17]
    NaNStrategyTiesStrategy rank(data)
    MAXIMAL default (ties averaged) [5, 3, 6, 7, 3, 8, 9, 1, 3]
    MAXIMAL MINIMUM [5, 2, 6, 7, 2, 8, 9, 1, 2]
    MINIMAL default (ties averaged] [6, 4, 7, 8, 4, 9, 1.5, 1.5, 4]
    REMOVED SEQUENTIAL [5, 2, 6, 7, 3, 8, 1, 4]
    MINIMAL MAXIMUM [6, 5, 7, 8, 5, 9, 2, 2, 5]
    MINIMAL MAXIMUM [6, 5, 7, 8, 5, 9, 2, 2, 5]
    Since:
    1.1