本文整理汇总了Java中org.apache.commons.math3.stat.ranking.NaturalRanking类的典型用法代码示例。如果您正苦于以下问题:Java NaturalRanking类的具体用法?Java NaturalRanking怎么用?Java NaturalRanking使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NaturalRanking类属于org.apache.commons.math3.stat.ranking包,在下文中一共展示了NaturalRanking类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testRankOfRows
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
@Test()
public void testRankOfRows() {
final Random random = new Random();
final DataFrame<String,String> frame = TestDataFrames.random(double.class, 1000, 100);
frame.applyDoubles(v -> random.nextDouble() * 100);
final DataFrame<String,String> rankFrame = frame.rank().ofRows();
Assert.assertEquals(rankFrame.rowCount(), frame.rowCount(), "The row counts match");
Assert.assertEquals(rankFrame.colCount(), frame.colCount(), "The column counts match");
rankFrame.out().print();
rankFrame.rows().forEach(rankRow -> {
final String key = rankRow.key();
final double[] values = frame.row(key).toDoubleStream().toArray();
final NaturalRanking ranking = new NaturalRanking();
final double[] ranks = ranking.rank(values);
for (int i = 0; i < ranks.length; ++i) {
final double value = frame.data().getDouble(key, i);
final double expected = ranks[i];
final double actual = rankFrame.data().getDouble(key, i);
Assert.assertEquals(value, values[i], "The values match for column " + i);
Assert.assertEquals(actual, expected, "The ranks match for " + key + " at column " + i);
}
});
}
开发者ID:zavtech,项目名称:morpheus-core,代码行数:24,代码来源:RankTests.java
示例2: testRankOfColumns
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
@Test()
public void testRankOfColumns() {
final Random random = new Random();
final DataFrame<String,String> frame = TestDataFrames.random(double.class, 1000, 100);
frame.applyDoubles(v -> random.nextDouble() * 100);
final DataFrame<String,String> rankFrame = frame.rank().ofColumns();
Assert.assertEquals(rankFrame.rowCount(), frame.rowCount(), "The row counts match");
Assert.assertEquals(rankFrame.colCount(), frame.colCount(), "The column counts match");
rankFrame.out().print();
rankFrame.cols().forEach(rankColumn -> {
final String key = rankColumn.key();
final double[] values = frame.col(key).toDoubleStream().toArray();
final NaturalRanking ranking = new NaturalRanking();
final double[] ranks = ranking.rank(values);
for (int i=0; i<ranks.length; ++i) {
final double value = frame.data().getDouble(i, key);
final double expected = ranks[i];
final double actual = rankFrame.data().getDouble(i, key);
Assert.assertEquals(value, values[i], "The values match for row " + i);
Assert.assertEquals(actual, expected, "The ranks match for " + key + " at row " + i);
}
});
}
开发者ID:zavtech,项目名称:morpheus-core,代码行数:24,代码来源:RankTests.java
示例3: correlation
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
/**
* Computes the Spearman's rank correlation coefficient between the two arrays.
*
* @param xArray first data array
* @param yArray second data array
* @return Returns Spearman's rank correlation coefficient for the two arrays
* @throws DimensionMismatchException if the arrays lengths do not match
* @throws MathIllegalArgumentException if the array length is less than 2
*/
public double correlation(final double[] xArray, final double[] yArray) {
if (xArray.length != yArray.length) {
throw new DimensionMismatchException(xArray.length, yArray.length);
} else if (xArray.length < 2) {
throw new MathIllegalArgumentException(LocalizedFormats.INSUFFICIENT_DIMENSION,
xArray.length, 2);
} else {
double[] x = xArray;
double[] y = yArray;
if (rankingAlgorithm instanceof NaturalRanking &&
NaNStrategy.REMOVED == ((NaturalRanking) rankingAlgorithm).getNanStrategy()) {
final Set<Integer> nanPositions = new HashSet<Integer>();
nanPositions.addAll(getNaNPositions(xArray));
nanPositions.addAll(getNaNPositions(yArray));
x = removeValues(xArray, nanPositions);
y = removeValues(yArray, nanPositions);
}
return new PearsonsCorrelation().correlation(rankingAlgorithm.rank(x), rankingAlgorithm.rank(y));
}
}
开发者ID:biocompibens,项目名称:SME,代码行数:32,代码来源:SpearmansCorrelation.java
示例4: testMath891Matrix
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
@Test
public void testMath891Matrix() {
final double[] xArray = new double[] { Double.NaN, 1.9, 2, 100, 3 };
final double[] yArray = new double[] { 10, 2, 10, Double.NaN, 4 };
RealMatrix matrix = MatrixUtils.createRealMatrix(xArray.length, 2);
for (int i = 0; i < xArray.length; i++) {
matrix.addToEntry(i, 0, xArray[i]);
matrix.addToEntry(i, 1, yArray[i]);
}
// compute correlation
NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED);
SpearmansCorrelation spearman = new SpearmansCorrelation(matrix, ranking);
Assert.assertEquals(0.5, spearman.getCorrelationMatrix().getEntry(0, 1), Double.MIN_VALUE);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:SpearmansRankCorrelationTest.java
示例5: rank
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
/**
* Returns the rank array for the values specified
* @param values the values to rank
* @return the ranks of input array
*/
static double[] rank(double[] values) {
final NaNStrategy nanStrategy = (NaNStrategy)optionsMap.get(NaNStrategy.class).get(DataFrameOptions.getNanStrategy());
final TiesStrategy tieStrategy = (TiesStrategy)optionsMap.get(TiesStrategy.class).get(DataFrameOptions.getTieStrategy());
if (nanStrategy == null) throw new DataFrameException("Unsupported NaN strategy specified: " + DataFrameOptions.getNanStrategy());
if (tieStrategy == null) throw new DataFrameException("Unsupported tie strategy specified: " + DataFrameOptions.getTieStrategy());
final NaturalRanking ranking = new NaturalRanking(nanStrategy, tieStrategy);
return ranking.rank(values);
}
开发者ID:zavtech,项目名称:morpheus-core,代码行数:14,代码来源:XDataFrameRank.java
示例6: testMath891Array
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
@Test
public void testMath891Array() {
final double[] xArray = new double[] { Double.NaN, 1.9, 2, 100, 3 };
final double[] yArray = new double[] { 10, 2, 10, Double.NaN, 4 };
NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED);
SpearmansCorrelation spearman = new SpearmansCorrelation(ranking);
Assert.assertEquals(0.5, spearman.correlation(xArray, yArray), Double.MIN_VALUE);
}
开发者ID:Quanticol,项目名称:CARMA,代码行数:11,代码来源:SpearmansRankCorrelationTest.java
示例7: rankTransform
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
/**
* Applies rank transform to each of the columns of <code>matrix</code>
* using the current <code>rankingAlgorithm</code>.
*
* @param matrix matrix to transform
* @return a rank-transformed matrix
*/
private RealMatrix rankTransform(final RealMatrix matrix) {
RealMatrix transformed = null;
if (rankingAlgorithm instanceof NaturalRanking &&
((NaturalRanking) rankingAlgorithm).getNanStrategy() == NaNStrategy.REMOVED) {
final Set<Integer> nanPositions = new HashSet<Integer>();
for (int i = 0; i < matrix.getColumnDimension(); i++) {
nanPositions.addAll(getNaNPositions(matrix.getColumn(i)));
}
// if we have found NaN values, we have to update the matrix size
if (!nanPositions.isEmpty()) {
transformed = new BlockRealMatrix(matrix.getRowDimension() - nanPositions.size(),
matrix.getColumnDimension());
for (int i = 0; i < transformed.getColumnDimension(); i++) {
transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions));
}
}
}
if (transformed == null) {
transformed = matrix.copy();
}
for (int i = 0; i < transformed.getColumnDimension(); i++) {
transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
}
return transformed;
}
开发者ID:happyjack27,项目名称:autoredistrict,代码行数:38,代码来源:SpearmansCorrelation.java
示例8: SpearmansCorrelation
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
/**
* Create a SpearmansCorrelation without data.
*/
public SpearmansCorrelation() {
this(new NaturalRanking());
}
开发者ID:biocompibens,项目名称:SME,代码行数:7,代码来源:SpearmansCorrelation.java
示例9: compute
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
public String compute()throws SQLException{
Statement stmt = null;
ResultSet rs = null;
try{
//get data
ResizableDoubleArray data = getData();
//create columns - dao uses its own transaction
int numberOfColumns = dao.getColumnCount(conn, tableName);
int columnNumber = numberOfColumns+1;
String newVariableLabel = "Rank";
if(blom) newVariableLabel = "Blom Normal Score";
if(tukey) newVariableLabel = "Tukey Normal Score";
if(vdw) newVariableLabel = "van der Waerden Normal Score";
if(ntiles) newVariableLabel = "Quantiles: " + numGroups + " groups";
newVariable = new VariableAttributes(newVariableName, newVariableLabel, ItemType.NOT_ITEM, DataType.DOUBLE, columnNumber++, "");
dao.addColumnToDb(conn, tableName, newVariable);
//compute ranks
NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED, tiesStrategy);
double[] ranks = ranking.rank(data.getElements());
//begin transaction
conn.setAutoCommit(false);
//connect to table and update values
SelectQuery select = new SelectQuery();
Table sqlTable = new Table(tableName.getNameForDatabase());
select.addColumn(sqlTable, newVariable.getName().nameForDatabase());
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(select.toString());
int nRanks = ranks.length;
int rankIndex = 0;//array index for ranks (missing values not included)
int dbIndex = 0;//db row position for case (missing values included)
double r = Double.NaN;
boolean missing = false;
String tempName = "";
while(rs.next()){
missing = missingIndex.contains(dbIndex);
if(missing){
rs.updateNull(newVariable.getName().nameForDatabase());
}else{
r = ranks[rankIndex];
if(blom){
rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.blom(r, (double)nRanks));
}else if (tukey){
rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.tukey(r, (double)nRanks));
}else if(vdw){
rs.updateDouble(newVariable.getName().nameForDatabase(), normScore.vanderWaerden(r, (double)nRanks));
}else if(ntiles){
rs.updateDouble(newVariable.getName().nameForDatabase(), getGroup(r, (double)nRanks, (double)numGroups));
}else{
rs.updateDouble(newVariable.getName().nameForDatabase(), r);
}
rankIndex++;
}
rs.updateRow();
updateProgress();
dbIndex++;
}
conn.commit();
return "Ranks computed";
}catch(SQLException ex){
conn.rollback();
throw ex;
}finally{
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
conn.setAutoCommit(true);
}
}
开发者ID:meyerjp3,项目名称:jmetrik,代码行数:76,代码来源:RankingAnalysis.java
示例10: SpearmansCorrelation
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的package包/类
/**
* Create a SpearmansCorrelation without data.
*/
public SpearmansCorrelation() {
data = null;
this.rankingAlgorithm = new NaturalRanking();
rankCorrelation = null;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:SpearmansCorrelation.java
示例11: WilcoxonSignedRankTest
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的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 WilcoxonSignedRankTest() {
naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
TiesStrategy.AVERAGE);
}
开发者ID:biocompibens,项目名称:SME,代码行数:10,代码来源:WilcoxonSignedRankTest.java
示例12: MannWhitneyUTest
import org.apache.commons.math3.stat.ranking.NaturalRanking; //导入依赖的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 MannWhitneyUTest() {
naturalRanking = new NaturalRanking(NaNStrategy.FIXED,
TiesStrategy.AVERAGE);
}
开发者ID:biocompibens,项目名称:SME,代码行数:10,代码来源:MannWhitneyUTest.java
注:本文中的org.apache.commons.math3.stat.ranking.NaturalRanking类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论