|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.commons.math.stat.ranking.NaturalRanking
public class NaturalRanking
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.MAXIMAL 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) |
| Nested Class Summary | |
|---|---|
private static class |
NaturalRanking.IntDoublePair
Represents the position of a double value in an ordering. |
| Field Summary | |
|---|---|
static NaNStrategy |
DEFAULT_NAN_STRATEGY
default NaN strategy |
static TiesStrategy |
DEFAULT_TIES_STRATEGY
default ties strategy |
private NaNStrategy |
nanStrategy
NaN strategy - defaults to NaNs maximal |
private RandomData |
randomData
Source of random data - used only when ties strategy is RANDOM |
private TiesStrategy |
tiesStrategy
Ties strategy - defaults to ties averaged |
| Constructor Summary | |
|---|---|
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,
RandomGenerator randomGenerator)
Create a NaturalRanking with the given NaNStrategy, TiesStrategy.RANDOM and the given source of random data. |
|
NaturalRanking(NaNStrategy nanStrategy,
TiesStrategy tiesStrategy)
Create a NaturalRanking with the given NaNStrategy and TiesStrategy. |
|
NaturalRanking(RandomGenerator randomGenerator)
Create a NaturalRanking with TiesStrategy.RANDOM and the given RandomGenerator as the source of random data. |
|
NaturalRanking(TiesStrategy tiesStrategy)
Create a NaturalRanking with the given TiesStrategy. |
|
| Method Summary | |
|---|---|
private boolean |
containsNaNs(NaturalRanking.IntDoublePair[] ranks)
Checks for presence of NaNs in ranks. |
private void |
fill(double[] data,
List<Integer> tiesTrace,
double value)
Sets data[i] = value for each i in tiesTrace. |
private List<Integer> |
getNanPositions(NaturalRanking.IntDoublePair[] ranks)
Returns a list of indexes where ranks is NaN. |
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. |
private void |
recodeNaNs(NaturalRanking.IntDoublePair[] ranks,
double value)
Recodes NaN values to the given value. |
private NaturalRanking.IntDoublePair[] |
removeNaNs(NaturalRanking.IntDoublePair[] ranks)
Returns an array that is a copy of the input array with IntDoublePairs having NaN values removed. |
private void |
resolveTie(double[] ranks,
List<Integer> tiesTrace)
Resolve a sequence of ties, using the configured TiesStrategy. |
private void |
restoreNaNs(double[] ranks,
List<Integer> nanPositions)
Set ranks[i] = Double.NaN for each i in nanPositions. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final NaNStrategy DEFAULT_NAN_STRATEGY
public static final TiesStrategy DEFAULT_TIES_STRATEGY
private final NaNStrategy nanStrategy
private final TiesStrategy tiesStrategy
private final RandomData randomData
| Constructor Detail |
|---|
public NaturalRanking()
public NaturalRanking(TiesStrategy tiesStrategy)
tiesStrategy - the TiesStrategy to usepublic NaturalRanking(NaNStrategy nanStrategy)
nanStrategy - the NaNStrategy to use
public NaturalRanking(NaNStrategy nanStrategy,
TiesStrategy tiesStrategy)
nanStrategy - NaNStrategy to usetiesStrategy - TiesStrategy to usepublic NaturalRanking(RandomGenerator randomGenerator)
randomGenerator - source of random data
public NaturalRanking(NaNStrategy nanStrategy,
RandomGenerator randomGenerator)
nanStrategy - NaNStrategy to userandomGenerator - source of random data| Method Detail |
|---|
public NaNStrategy getNanStrategy()
public TiesStrategy getTiesStrategy()
public double[] rank(double[] data)
data using the natural ordering on Doubles, with
NaN values handled according to nanStrategy and ties
resolved using tiesStrategy.
rank in interface RankingAlgorithmdata - array to be ranked
private NaturalRanking.IntDoublePair[] removeNaNs(NaturalRanking.IntDoublePair[] ranks)
ranks - input array
private void recodeNaNs(NaturalRanking.IntDoublePair[] ranks,
double value)
ranks - array to recodevalue - the value to replace NaNs withprivate boolean containsNaNs(NaturalRanking.IntDoublePair[] ranks)
ranks.
ranks - array to be searched for NaNs
private void resolveTie(double[] ranks,
List<Integer> tiesTrace)
TiesStrategy.
The input ranks array is expected to take the same value
for all indices in tiesTrace. The common value is recoded
according to the tiesStrategy. For example, if ranks = <5,8,2,6,2,7,1,2>,
tiesTrace = <2,4,7> and tiesStrategy is MINIMUM, ranks will be unchanged.
The same array and trace with tiesStrategy AVERAGE will come out
<5,8,3,6,3,7,1,3>.
ranks - array of rankstiesTrace - list of indices where ranks is constant
-- that is, for any i and j in TiesTrace, ranks[i] == ranks[j]
private void fill(double[] data,
List<Integer> tiesTrace,
double value)
data[i] = value for each i in tiesTrace.
data - array to modifytiesTrace - list of index values to setvalue - value to set
private void restoreNaNs(double[] ranks,
List<Integer> nanPositions)
ranks[i] = Double.NaN for each i in nanPositions.
ranks - array to modifynanPositions - list of index values to set to Double.NaNprivate List<Integer> getNanPositions(NaturalRanking.IntDoublePair[] ranks)
ranks is NaN.
ranks - array to search for NaNs
ranks[i] = NaN
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||