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
RandomGenerator may be supplied as a constructor argument.
Examples:
| Input data: (20, 17, 30, 42.3, 17, 50, Double.NaN, Double.NEGATIVE_INFINITY, 17) | ||
|---|---|---|
| NaNStrategy | TiesStrategy | 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) |
| Modifier and Type | Class and Description |
|---|---|
| private static class | NaturalRanking.
Represents the position of a double value in an ordering. |
| Modifier and Type | Field and Description |
|---|---|
| public static final NaNStrategy | DEFAULT_NAN_STRATEGY
default NaN strategy |
| public static final TiesStrategy | DEFAULT_TIES_STRATEGY
default ties strategy |
| private final NaNStrategy | nanStrategy
NaN strategy - defaults to NaNs maximal |
| private final RandomDataGenerator | randomData
Deprecated
as a consequence of Source of random data - used only when ties strategy is RANDOM
RandomDataGenerator being deprecated.
|
| private final TiesStrategy | tiesStrategy
Ties strategy - defaults to ties averaged |
| Access | Constructor and Description |
|---|---|
| public | |
| public | NaturalRanking(TiesStrategy
the TiesStrategy to use tiesStrategy)Create a NaturalRanking with the given TiesStrategy. |
| public | NaturalRanking(NaNStrategy
the NaNStrategy to use nanStrategy)Create a NaturalRanking with the given NaNStrategy. |
| public | NaturalRanking(NaNStrategy
NaNStrategy to use nanStrategy, TiesStrategy TiesStrategy to use tiesStrategy)Create a NaturalRanking with the given NaNStrategy and TiesStrategy. |
| public | NaturalRanking(RandomGenerator
source of random data randomGenerator)Create a NaturalRanking with TiesStrategy.RANDOM and the given RandomGenerator as the source of random data. |
| public | NaturalRanking(NaNStrategy
NaNStrategy to use nanStrategy, RandomGenerator source of random data randomGenerator)Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM and the given source of random data. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | Returns: true iff ranks contains one or more NaNsarray to be searched for NaNs ranksChecks for presence of NaNs in |
| private void | |
| private List | Returns: list of indexes i such thatranks[i] = NaNarray to search for ranksNaNsReturns a list of indexes where |
| public NaNStrategy | |
| public TiesStrategy | |
| public double[] | Returns: array of ranksarray to be ranked data)Implements org. Rank |
| private void | recodeNaNs(NaturalRanking.
array to recode ranks,the value to replace NaNs with value)Recodes NaN values to the given value. |
| private NaturalRanking. | Returns: array with NaN-valued entries removedinput array ranksReturns an array that is a copy of the input array with IntDoublePairs having NaN values removed. |
| private void | resolveTie(double[]
array of ranks ranks, List<Integer> list of indices where tiesTrace)ranks is constant
-- that is, for any i and j in TiesTrace, ranks[i] == ranks[j]
Resolve a sequence of ties, using the configured |
| private void | restoreNaNs(double[]
array to modify ranks, List<Integer> list of index values to set to nanPositions)Double.NaNSet |
| DEFAULT_NAN_STRATEGY | back to summary |
|---|---|
| public static final NaNStrategy DEFAULT_NAN_STRATEGY default NaN strategy | |
| DEFAULT_TIES_STRATEGY | back to summary |
|---|---|
| public static final TiesStrategy DEFAULT_TIES_STRATEGY default ties strategy | |
| nanStrategy | back to summary |
|---|---|
| private final NaNStrategy nanStrategy NaN strategy - defaults to NaNs maximal | |
| randomData | back to summary |
|---|---|
| private final RandomDataGenerator randomData
Deprecated as a consequence of Source of random data - used only when ties strategy is RANDOM | |
| tiesStrategy | back to summary |
|---|---|
| private final TiesStrategy tiesStrategy Ties strategy - defaults to ties averaged | |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking() Create a NaturalRanking with default strategies for handling ties and NaNs. | |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking(TiesStrategy tiesStrategy) Create a NaturalRanking with the given TiesStrategy.
| |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking(NaNStrategy nanStrategy) Create a NaturalRanking with the given NaNStrategy.
| |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking(NaNStrategy nanStrategy, TiesStrategy tiesStrategy) Create a NaturalRanking with the given NaNStrategy and TiesStrategy.
| |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking(RandomGenerator randomGenerator) Create a NaturalRanking with TiesStrategy.RANDOM and the given RandomGenerator as the source of random data.
| |
| NaturalRanking | back to summary |
|---|---|
| public NaturalRanking(NaNStrategy nanStrategy, RandomGenerator randomGenerator) Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM and the given source of random data.
| |
| containsNaNs | back to summary |
|---|---|
| private boolean containsNaNs(NaturalRanking. Checks for presence of NaNs in
| |
| fill | back to summary |
|---|---|
| private void fill(double[] data, List<Integer> tiesTrace, double value) Sets | |
| getNanPositions | back to summary |
|---|---|
| private List Returns a list of indexes where
| |
| getNanStrategy | back to summary |
|---|---|
| public NaNStrategy getNanStrategy() Return the NaNStrategy
| |
| getTiesStrategy | back to summary |
|---|---|
| public TiesStrategy getTiesStrategy() Return the TiesStrategy
| |
| rank | back to summary |
|---|---|
| public double[] rank(double[] data) Implements org. Rank
| |
| recodeNaNs | back to summary |
|---|---|
| private void recodeNaNs(NaturalRanking. Recodes NaN values to the given value.
| |
| removeNaNs | back to summary |
|---|---|
| private NaturalRanking. Returns an array that is a copy of the input array with IntDoublePairs having NaN values removed.
| |
| resolveTie | back to summary |
|---|---|
| private void resolveTie(double[] ranks, List<Integer> tiesTrace) Resolve a sequence of ties, using the configured | |
| restoreNaNs | back to summary |
|---|---|
| private void restoreNaNs(double[] ranks, List<Integer> nanPositions) Set | |
| Modifier and Type | Field and Description |
|---|---|
| private final int | position
Original position of the pair |
| private final double | value
Value of the pair |
| Access | Constructor and Description |
|---|---|
| pack-priv | IntDoublePair(double
the value of the pair value, int the original position position)Construct an IntDoublePair with the given value and position. |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: result ofDouble.compare(value, other.value)the other pair to compare this to otherImplements java. Compare this IntDoublePair to another pair. |
| public int | |
| public double |
| position | back to summary |
|---|---|
| private final int position Original position of the pair | |
| value | back to summary |
|---|---|
| private final double value Value of the pair | |
| IntDoublePair | back to summary |
|---|---|
| pack-priv IntDoublePair(double value, int position) Construct an IntDoublePair with the given value and position.
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(NaturalRanking. Implements java. Compare this IntDoublePair to another pair. Only the values are compared.
| |
| getPosition | back to summary |
|---|---|
| public int getPosition() Returns the original position of the pair.
| |
| getValue | back to summary |
|---|---|
| public double getValue() Returns the value of the pair.
| |