Class NaturalRanking

java.lang.Object
org.apache.commons.math4.stat.ranking.NaturalRanking
All Implemented Interfaces:
RankingAlgorithm

public class NaturalRanking
extends java.lang.Object
implements RankingAlgorithm
Ranking based on the natural ordering on doubles.

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 random generator may be supplied as a constructor argument.

Examples:

rankings
Input data: (20, 17, 30, 42.3, 17, 50, Double.NaN, Double.NEGATIVE_INFINITY, 17)
NaNStrategyTiesStrategy rank(data)
default (NaNs maximal) default (ties averaged) (5, 3, 6, 7, 3, 8, 9, 1, 3)
default (NaNs 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)
Since:
2.0
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static NaNStrategy DEFAULT_NAN_STRATEGY
    default NaN strategy
    static TiesStrategy DEFAULT_TIES_STRATEGY
    default ties strategy
  • Constructor Summary

    Constructors 
    Constructor Description
    NaturalRanking()
    Create a NaturalRanking with default strategies for handling ties and NaNs.
    NaturalRanking​(NaNStrategy nanStrategy)
    Create a NaturalRanking with the given NaNStrategy.
    NaturalRanking​(NaNStrategy nanStrategy, TiesStrategy tiesStrategy)
    Create a NaturalRanking with the given NaNStrategy and TiesStrategy.
    NaturalRanking​(NaNStrategy nanStrategy, UniformRandomProvider randomGenerator)
    Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM and the given source of random data.
    NaturalRanking​(TiesStrategy tiesStrategy)
    Create a NaturalRanking with the given TiesStrategy.
    NaturalRanking​(UniformRandomProvider randomGenerator)
    Create a NaturalRanking with TiesStrategy.RANDOM and the given random generator as the source of random data.
  • Method Summary

    Modifier and Type Method Description
    NaNStrategy getNanStrategy()
    Return the NaNStrategy
    TiesStrategy getTiesStrategy()
    Return the TiesStrategy
    double[] rank​(double[] data)
    Rank data using the natural ordering on Doubles, with NaN values handled according to nanStrategy and ties resolved using tiesStrategy.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • NaturalRanking

      public NaturalRanking()
      Create a NaturalRanking with default strategies for handling ties and NaNs.
    • NaturalRanking

      public NaturalRanking​(TiesStrategy tiesStrategy)
      Create a NaturalRanking with the given TiesStrategy.
      Parameters:
      tiesStrategy - the TiesStrategy to use
    • NaturalRanking

      public NaturalRanking​(NaNStrategy nanStrategy)
      Create a NaturalRanking with the given NaNStrategy.
      Parameters:
      nanStrategy - the NaNStrategy to use
    • NaturalRanking

      public NaturalRanking​(NaNStrategy nanStrategy, TiesStrategy tiesStrategy)
      Create a NaturalRanking with the given NaNStrategy and TiesStrategy.
      Parameters:
      nanStrategy - NaNStrategy to use
      tiesStrategy - TiesStrategy to use
    • NaturalRanking

      public NaturalRanking​(UniformRandomProvider randomGenerator)
      Create a NaturalRanking with TiesStrategy.RANDOM and the given random generator as the source of random data.
      Parameters:
      randomGenerator - source of random data
    • NaturalRanking

      public NaturalRanking​(NaNStrategy nanStrategy, UniformRandomProvider randomGenerator)
      Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM and the given source of random data.
      Parameters:
      nanStrategy - NaNStrategy to use
      randomGenerator - source of random data
  • Method Details

    • getNanStrategy

      public NaNStrategy getNanStrategy()
      Return the NaNStrategy
      Returns:
      returns the NaNStrategy
    • getTiesStrategy

      public TiesStrategy getTiesStrategy()
      Return the TiesStrategy
      Returns:
      the TiesStrategy
    • rank

      public double[] rank​(double[] data)
      Rank data using the natural ordering on Doubles, with NaN values handled according to nanStrategy and ties resolved using tiesStrategy.
      Specified by:
      rank in interface RankingAlgorithm
      Parameters:
      data - array to be ranked
      Returns:
      array of ranks
      Throws:
      NotANumberException - if the selected NaNStrategy is FAILED and a Double.NaN is encountered in the input data