[MATH-906] Use NaNStrategy.FAILED as default in NaturalRanking.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1411880 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas Neidhart 2012-11-20 21:13:54 +00:00
parent 4577812519
commit 0073facaf9
3 changed files with 27 additions and 11 deletions

View File

@ -52,6 +52,9 @@ If the output is not quite correct, check for invisible trailing spaces!
<body>
<release version="3.1" date="TBD" description="
">
<action dev="tn" type="update" issue="MATH-906" due-to="Patrick Meyer">
Use "NaNStrategy#FAILED" as default strategy in "NaturalRanking".
</action>
<action dev="erans" type="add" issue="MATH-899">
Added a new "SynchronizedRandomGenerator" that wraps another
"RandomGenerator" with all methods being synchronized, thus

View File

@ -35,7 +35,7 @@ import org.apache.commons.math3.util.FastMath;
* <p>NaNs are treated according to the configured {@link NaNStrategy} and ties
* are handled using the selected {@link TiesStrategy}.
* Configuration settings are supplied in optional constructor arguments.
* Defaults are {@link NaNStrategy#MAXIMAL} and {@link TiesStrategy#AVERAGE},
* Defaults are {@link NaNStrategy#FAILED} and {@link TiesStrategy#AVERAGE},
* respectively. When using {@link TiesStrategy#RANDOM}, a
* {@link RandomGenerator} may be supplied as a constructor argument.</p>
* <p>Examples:
@ -72,7 +72,7 @@ import org.apache.commons.math3.util.FastMath;
public class NaturalRanking implements RankingAlgorithm {
/** default NaN strategy */
public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.MAXIMAL;
public static final NaNStrategy DEFAULT_NAN_STRATEGY = NaNStrategy.FAILED;
/** default ties strategy */
public static final TiesStrategy DEFAULT_TIES_STRATEGY = TiesStrategy.AVERAGE;

View File

@ -16,6 +16,8 @@
*/
package org.apache.commons.math3.stat.ranking;
import junit.framework.Assert;
import org.apache.commons.math3.TestUtils;
import org.apache.commons.math3.exception.NotANumberException;
import org.apache.commons.math3.random.JDKRandomGenerator;
@ -40,20 +42,31 @@ public class NaturalRankingTest {
private final double[] allSame = { 0, 0, 0, 0 };
@Test
public void testDefault() { // Ties averaged, NaNs maximal
public void testDefault() { // Ties averaged, NaNs failed
NaturalRanking ranking = new NaturalRanking();
double[] ranks = ranking.rank(exampleData);
double[] correctRanks = { 5, 3, 6, 7, 3, 8, 9, 1, 3 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
double[] ranks;
try {
ranks = ranking.rank(exampleData);
Assert.fail("expected NotANumberException due to NaNStrategy.FAILED");
} catch (NotANumberException e) {
// expected
}
ranks = ranking.rank(tiesFirst);
correctRanks = new double[] { 1.5, 1.5, 4, 3, 5 };
double[] correctRanks = new double[] { 1.5, 1.5, 4, 3, 5 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
ranks = ranking.rank(tiesLast);
correctRanks = new double[] { 3.5, 3.5, 2, 1 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
ranks = ranking.rank(multipleNaNs);
correctRanks = new double[] { 1, 2, 3.5, 3.5 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
try {
ranks = ranking.rank(multipleNaNs);
Assert.fail("expected NotANumberException due to NaNStrategy.FAILED");
} catch (NotANumberException e) {
// expected
}
ranks = ranking.rank(multipleTies);
correctRanks = new double[] { 3, 2, 4.5, 4.5, 6.5, 6.5, 1 };
TestUtils.assertEquals(correctRanks, ranks, 0d);
@ -64,7 +77,7 @@ public class NaturalRankingTest {
@Test
public void testNaNsMaximalTiesMinimum() {
NaturalRanking ranking = new NaturalRanking(TiesStrategy.MINIMUM);
NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL, TiesStrategy.MINIMUM);
double[] ranks = ranking.rank(exampleData);
double[] correctRanks = { 5, 2, 6, 7, 2, 8, 9, 1, 2 };
TestUtils.assertEquals(correctRanks, ranks, 0d);