本文整理汇总了Java中org.apache.commons.math.stat.ranking.NaNStrategy类的典型用法代码示例。如果您正苦于以下问题:Java NaNStrategy类的具体用法?Java NaNStrategy怎么用?Java NaNStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NaNStrategy类属于org.apache.commons.math.stat.ranking包,在下文中一共展示了NaNStrategy类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.commons.math.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED,
TiesStrategy.MAXIMUM);
double[] data = { 20, 9, 1, 1, 9, 20, 20, 15, 8, 12 };
double[] ranks = ranking.rank(data);
for (int i = 0; i < ranks.length; i++) {
System.out.println("data["+i+"] = " + ranks[i]);
}
double[] newrank = rank(data);
for (int i = 0; i < newrank.length; i++) {
System.out.println("data["+i+"] = " + data[i] + " -> rank = " + newrank[i]);
}
Queue<ScoreRankPair> srp = MatrixUtils.ranking(data);
Iterator<ScoreRankPair> it = srp.iterator();
while(it.hasNext()) {
ScoreRankPair pair = it.next();
System.out.println("score=" + pair.getScore() + " -> rank=" + pair.getRank());
}
}
示例2: rank
import org.apache.commons.math.stat.ranking.NaNStrategy; //导入依赖的package包/类
public static double[] rank(double[] data) {
// Array recording initial positions of data to be ranked
IntDoublePair[] ranks = new IntDoublePair[data.length];
for (int i = 0; i < data.length; i++) {
ranks[i] = new IntDoublePair(data[i], i);
}
// Recode, remove or record positions of NaNs
List<Integer> nanPositions = null;
switch (nanStrategy) {
case MAXIMAL: // Replace NaNs with +INFs
recodeNaNs(ranks, Double.POSITIVE_INFINITY);
break;
case MINIMAL: // Replace NaNs with -INFs
recodeNaNs(ranks, Double.NEGATIVE_INFINITY);
break;
case REMOVED: // Drop NaNs from data
ranks = removeNaNs(ranks);
break;
case FIXED: // Record positions of NaNs
nanPositions = getNanPositions(ranks);
break;
default: // this should not happen unless NaNStrategy enum is changed
throw MathRuntimeException.createInternalError(null);
}
// Sort the IntDoublePairs
Arrays.sort(ranks);
// Walk the sorted array, filling output array using sorted positions,
// resolving ties as we go
double[] out = new double[ranks.length];
int pos = 1; // position in sorted array
out[ranks[0].getPosition()] = pos;
List<Integer> tiesTrace = new ArrayList<Integer>();
tiesTrace.add(ranks[0].getPosition());
for (int i = 1; i < ranks.length; i++) {
if (Double.compare(ranks[i].getValue(), ranks[i - 1].getValue()) > 0) {
// tie sequence has ended (or had length 1)
pos = i + 1;
if (tiesTrace.size() > 1) { // if seq is nontrivial, resolve
resolveTie(out, tiesTrace);
}
tiesTrace = new ArrayList<Integer>();
tiesTrace.add(ranks[i].getPosition());
} else {
// tie sequence continues
tiesTrace.add(ranks[i].getPosition());
}
out[ranks[i].getPosition()] = pos;
}
if (tiesTrace.size() > 1) { // handle tie sequence at end
resolveTie(out, tiesTrace);
}
if (nanStrategy == NaNStrategy.FIXED) {
restoreNaNs(out, nanPositions);
}
return out;
}
示例3: FriedmanTest
import org.apache.commons.math.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
* Set up Friedman family and post-hoc tests given <code>n</code>
* observations for <code>c</code> solver configurations in the n x c data
* matrix.
*
* @param n
* Number of observations for each solver configuration
* @param c
* Number of solver configurations
* @param data
* n x c matrix of the observed values
*/
public FriedmanTest(int n, int c, double[][] data) {
boolean[] missingRow = new boolean[n];
int numMissingRows = 0;
for (int j = 0; j < n; j++) missingRow[j] = false;
for (int j = 0; j < n; j++) {
for (int i = 0; i < c; i++) {
if (Double.isNaN(data[j][i])) {
missingRow[j] = true;
numMissingRows++;
break;
}
}
}
ranks = new double[n - numMissingRows][c];
rankSums = new double[c];
NaturalRanking ranking = new NaturalRanking(NaNStrategy.MAXIMAL, TiesStrategy.AVERAGE);
int row = 0;
for (int i = 0; i < n; i++) {
if (missingRow[i]) continue;
double[] rankedData = ranking.rank(data[i]);
for (int j = 0; j < c; j++) {
ranks[row][j] = rankedData[j];
rankSums[j] += rankedData[j];
}
row++;
}
/*System.out.println("Friedman test will be calculated on:");
StringBuilder out = new StringBuilder();
out.append("\n");
for (int i = 0; i < ranks.length; i++) {
for (int j = 0; j < ranks[i].length; j++) {
out.append(String.format("%5.4f ", ranks[i][j]));
}
out.append("\n");
}
System.out.println(out.toString());*/
m = c;
k = n - numMissingRows;
}
示例4: WilcoxonSignedRankTestImpl
import org.apache.commons.math.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
* Create a test instance where NaN's are left in place and ties get
* the average of applicable ranks. Use this unless you are very sure
* of what you are doing.
*/
public WilcoxonSignedRankTestImpl() {
naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
TiesStrategy.AVERAGE);
}
示例5: MannWhitneyUTestImpl
import org.apache.commons.math.stat.ranking.NaNStrategy; //导入依赖的package包/类
/**
* Create a test instance using where NaN's are left in place and ties get
* the average of applicable ranks. Use this unless you are very sure of
* what you are doing.
*/
public MannWhitneyUTestImpl() {
naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
TiesStrategy.AVERAGE);
}