List of usage examples for org.apache.commons.math3.stat.ranking NaturalRanking rank
public double[] rank(double[] data)
data
using the natural ordering on Doubles, with NaN values handled according to nanStrategy
and ties resolved using tiesStrategy.
From source file:ch.unil.genescore.vegas.GeneDataFakePhenotype.java
private void addSignal(double[] fakePheno) { for (int i = 0; i < fakePheno.length; i++) { fakePheno[i] = fakePheno[i] + fakeSignal_[i]; }// www.ja v a2s.c o m NaturalRanking ranking = new NaturalRanking(NaNStrategy.MINIMAL, TiesStrategy.MAXIMUM); double[] ranks = ranking.rank(fakePheno); for (int i = 0; i < fakePheno.length; i++) { //fakePheno[i]=myNormal.inverseCumulativeProbability(ranks[i]/(ranks.length+1)); fakePheno[i] = DistributionMethods.normalInverseCumulativeProbability(ranks[i] / (ranks.length + 1)); } }
From source file:com.itemanalysis.jmetrik.stats.ranking.RankingAnalysis.java
public String compute() throws SQLException { Statement stmt = null;//from w ww .j a v a2s. c o m 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); } }
From source file:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.TestEQTLDatasetForInteractions.java
private ExpressionDataset correctCovariateDataPCA(String[] covsToCorrect2, String[] covsToCorrect, ExpressionDataset datasetGenotypes, ExpressionDataset datasetCovariatesPCAForceNormal) throws Exception { int nrCompsToCorrectFor = 25; System.out.println("Preparing data for testing eQTL effects of SNPs on covariate data:"); System.out.println("Correcting covariate data for cohort specific effects:"); ExpressionDataset datasetCovariatesToCorrectFor = new ExpressionDataset( covsToCorrect2.length + covsToCorrect.length + nrCompsToCorrectFor, datasetGenotypes.nrSamples); datasetCovariatesToCorrectFor.sampleNames = datasetGenotypes.sampleNames; // add covariates from the first list HashMap hashCovsToCorrect = new HashMap(); // add covariates from the second list for (int i = 0; i < covsToCorrect2.length; ++i) { String cov = covsToCorrect2[i]; hashCovsToCorrect.put(cov, null); Integer c = datasetCovariatesPCAForceNormal.hashProbes.get(cov); if (c == null) { throw new Exception("Covariate not found: " + cov); }//from w w w .j a v a2s .com for (int s = 0; s < datasetGenotypes.nrSamples; s++) { datasetCovariatesToCorrectFor.rawData[i][s] = datasetCovariatesPCAForceNormal.rawData[c][s]; } } int[] covsToCorrectIndex = new int[covsToCorrect.length]; for (int c = 0; c < covsToCorrect.length; c++) { hashCovsToCorrect.put(covsToCorrect[c], null); covsToCorrectIndex[c] = ((Integer) datasetCovariatesPCAForceNormal.hashProbes.get(covsToCorrect[c])) .intValue(); for (int s = 0; s < datasetGenotypes.nrSamples; s++) { datasetCovariatesToCorrectFor.rawData[covsToCorrect2.length + c][s] = datasetCovariatesPCAForceNormal.rawData[covsToCorrectIndex[c]][s]; } } // add PCs if (nrCompsToCorrectFor > 0) { for (int comp = 0; comp < nrCompsToCorrectFor; comp++) { for (int s = 0; s < datasetGenotypes.nrSamples; s++) { datasetCovariatesToCorrectFor.rawData[covsToCorrect2.length + covsToCorrect.length + comp][s] = datasetCovariatesPCAForceNormal.rawData[datasetCovariatesPCAForceNormal.nrProbes - 51 + comp][s]; } } } datasetCovariatesToCorrectFor.transposeDataset(); datasetCovariatesToCorrectFor.save(inputDir + "/CovariatesToCorrectFor.txt"); orthogonalizeDataset(inputDir + "/CovariatesToCorrectFor.txt"); datasetCovariatesToCorrectFor = new ExpressionDataset( inputDir + "/CovariatesToCorrectFor.txt.PrincipalComponents.txt"); datasetCovariatesToCorrectFor.transposeDataset(); ExpressionDataset datasetCovariatesToCorrectForEigenvalues = new ExpressionDataset( inputDir + "/CovariatesToCorrectFor.txt.Eigenvalues.txt"); for (int p = 0; p < datasetCovariatesPCAForceNormal.nrProbes; p++) { if (!hashCovsToCorrect.containsKey(datasetCovariatesPCAForceNormal.probeNames[p])) { for (int cov = 0; cov < datasetCovariatesToCorrectFor.nrProbes; cov++) { if (datasetCovariatesToCorrectForEigenvalues.rawData[cov][0] > 1E-5) { double[] rc = getLinearRegressionCoefficients(datasetCovariatesToCorrectFor.rawData[cov], datasetCovariatesPCAForceNormal.rawData[p]); for (int s = 0; s < datasetGenotypes.nrSamples; s++) { datasetCovariatesPCAForceNormal.rawData[p][s] -= rc[0] * datasetCovariatesToCorrectFor.rawData[cov][s]; } } } /*double stdev = JSci.maths.ArrayMath.standardDeviation(datasetCovariates.rawData[p]); double mean = JSci.maths.ArrayMath.mean(datasetCovariates.rawData[p]); if (stdev < 1E-5) { for (int s = 0; s < datasetGenotypes.nrSamples; s++) { datasetCovariatesPCAForceNormal.rawData[p][s] = mean; } }*/ } } System.out.println("Enforcing normal distribution on covariates"); NaturalRanking ranker = new NaturalRanking(); for (int p = 0; p < datasetCovariatesPCAForceNormal.nrProbes; p++) { //Rank order the expression values: double[] values = new double[datasetCovariatesPCAForceNormal.nrSamples]; for (int s = 0; s < datasetGenotypes.nrSamples; s++) { values[s] = datasetCovariatesPCAForceNormal.rawData[p][s]; } double[] rankedValues = ranker.rank(values); //Replace the original expression value with the standard distribution enforce: for (int s = 0; s < datasetGenotypes.nrSamples; s++) { //Convert the rank to a proportion, with range <0, 1> double pValue = (0.5d + rankedValues[s] - 1d) / (double) (rankedValues.length); //Convert the pValue to a Z-Score: double zScore = cern.jet.stat.tdouble.Probability.normalInverse(pValue); datasetCovariatesPCAForceNormal.rawData[p][s] = zScore; //Replace original expression value with the Z-Score } } return datasetCovariatesPCAForceNormal; }
From source file:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.TestEQTLDatasetForInteractions.java
private void forceNormalCovariates(ExpressionDataset datasetCovariates, ExpressionDataset datasetGenotypes) throws ArithmeticException { System.out.println("Enforcing normal distribution on covariates"); NaturalRanking ranker = new NaturalRanking(); for (int p = 0; p < datasetCovariates.nrProbes; p++) { //Rank order the expression values: double[] values = new double[datasetCovariates.nrSamples]; for (int s = 0; s < datasetGenotypes.nrSamples; s++) { values[s] = datasetCovariates.rawData[p][s]; }/*from w ww. j a v a 2 s . c o m*/ double[] rankedValues = ranker.rank(values); //Replace the original expression value with the standard distribution enforce: for (int s = 0; s < datasetGenotypes.nrSamples; s++) { //Convert the rank to a proportion, with range <0, 1> double pValue = (0.5d + rankedValues[s] - 1d) / (double) (rankedValues.length); //Convert the pValue to a Z-Score: double zScore = cern.jet.stat.tdouble.Probability.normalInverse(pValue); datasetCovariates.rawData[p][s] = zScore; //Replace original expression value with the Z-Score } } }
From source file:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.TestEQTLDatasetForInteractions.java
private void forceNormalExpressionData(ExpressionDataset datasetExpression) throws ArithmeticException { System.out.println("Enforcing normal distribution on expression data:"); NaturalRanking ranker = new NaturalRanking(); for (int p = 0; p < datasetExpression.nrProbes; p++) { //Rank order the expression values: double[] values = new double[datasetExpression.nrSamples]; for (int s = 0; s < datasetExpression.nrSamples; s++) { values[s] = datasetExpression.rawData[p][s]; }/*from ww w. j a va 2 s . c o m*/ double[] rankedValues = ranker.rank(values); //Replace the original expression value with the standard distribution enforce: for (int s = 0; s < datasetExpression.nrSamples; s++) { //Convert the rank to a proportion, with range <0, 1> double pValue = (0.5d + rankedValues[s] - 1d) / (double) (rankedValues.length); //Convert the pValue to a Z-Score: double zScore = cern.jet.stat.tdouble.Probability.normalInverse(pValue); datasetExpression.rawData[p][s] = zScore; //Replace original expression value with the Z-Score } } System.out.println("Expression data now force normal"); }
From source file:nl.systemsgenetics.genenetworkbackend.hpo.TestDiseaseGenePerformance.java
/** * @param args the command line arguments * @throws java.lang.Exception// www . j a v a 2s . c o m */ public static void main(String[] args) throws Exception { final File diseaseGeneHpoFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\HPO\\135\\ALL_SOURCES_ALL_FREQUENCIES_diseases_to_genes_to_phenotypes.txt"); final File ncbiToEnsgMapFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\ensgNcbiId.txt"); final File hgncToEnsgMapFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\ensgHgnc.txt"); final File ensgSymbolMappingFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\ensgHgnc.txt"); final File predictionMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_zscores.txt.gz"); final File predictionMatrixCorrelationFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_pathwayCorrelation.txt"); final File significantTermsFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_bonSigTerms.txt"); final double correctedPCutoff = 0.05; final File hpoOboFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\HPO\\135\\hp.obo"); final File hpoPredictionInfoFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_auc_bonferroni.txt"); final File hposToExcludeFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\hpoToExclude.txt"); final File skewnessFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\skewnessSummary.txt"); final boolean randomize = true; final File annotationMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\ALL_SOURCES_ALL_FREQUENCIES_phenotype_to_genes.txt_matrix.txt.gz"); final File backgroundForRandomize = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\Ensembl2Reactome_All_Levels.txt_genesInPathways.txt"); //final File backgroundForRandomize = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\expressedReactomeGenes.txt"); final boolean randomizeCustomBackground = true; Map<String, String> ensgSymbolMapping = loadEnsgToHgnc(ensgSymbolMappingFile); final File outputFile; final ArrayList<String> backgroundGenes; if (randomize) { if (randomizeCustomBackground) { System.err.println("First need to fix so ranking list contains all genes in background list"); return; // backgroundGenes = loadBackgroundGenes(backgroundForRandomize); // outputFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\hpoDiseaseBenchmarkRandomizedCustomBackground.txt"); } else { backgroundGenes = null; outputFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\hpoDiseaseBenchmarkRandomizedExtraNorm.txt"); } } else { backgroundGenes = null; outputFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\hpoDiseaseBenchmarkExtraNorm.txt"); } final HashMap<String, ArrayList<String>> ncbiToEnsgMap = loadNcbiToEnsgMap(ncbiToEnsgMapFile); final HashMap<String, ArrayList<String>> hgncToEnsgMap = loadHgncToEnsgMap(hgncToEnsgMapFile); final HashSet<String> exludedHpo = loadHpoExclude(hposToExcludeFile); final SkewnessInfo skewnessInfo = new SkewnessInfo(skewnessFile); LinkedHashSet<String> significantTerms = loadSignificantTerms(significantTermsFile); DoubleMatrixDataset<String, String> predictionMatrix = DoubleMatrixDataset .loadDoubleData(predictionMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> predictionMatrixSignificant = predictionMatrix .viewColSelection(significantTerms); DoubleMatrixDataset<String, String> predictionMatrixSignificantCorrelationMatrix = DoubleMatrixDataset .loadDoubleData(predictionMatrixCorrelationFile.getAbsolutePath()); DiseaseGeneHpoData diseaseGeneHpoData = new DiseaseGeneHpoData(diseaseGeneHpoFile, ncbiToEnsgMap, hgncToEnsgMap, exludedHpo, new HashSet(predictionMatrix.getHashRows().keySet()), "OMIM"); //NOTE if one would use a differnt background this needs to be updated HashSet<String> diseaseGenes = new HashSet<>(diseaseGeneHpoData.getDiseaseGenes()); if (randomize) { diseaseGeneHpoData = diseaseGeneHpoData.getPermutation(1, backgroundGenes); } for (String gene : diseaseGenes) { if (!predictionMatrixSignificant.containsRow(gene)) { throw new Exception("Error: " + gene); } } int[] mapGeneIndexToDiseaseGeneIndex = new int[predictionMatrix.rows()]; ArrayList<String> predictedGenes = predictionMatrix.getRowObjects(); int g2 = 0; for (int g = 0; g < predictedGenes.size(); ++g) { mapGeneIndexToDiseaseGeneIndex[g] = diseaseGenes.contains(predictedGenes.get(g)) ? g2++ : -1; } DoubleMatrixDataset<String, String> annotationnMatrix = DoubleMatrixDataset .loadDoubleData(annotationMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> annotationMatrixSignificant = annotationnMatrix .viewColSelection(significantTerms); HashMap<String, MeanSd> hpoMeanSds = calculatePathayMeansOfAnnotatedGenes(predictionMatrixSignificant, annotationMatrixSignificant); Map<String, PredictionInfo> predictionInfo = HpoFinder.loadPredictionInfo(hpoPredictionInfoFile); Ontology hpoOntology = HpoFinder.loadHpoOntology(hpoOboFile); HpoFinder hpoFinder = new HpoFinder(hpoOntology, predictionInfo); final int totalGenes = predictionMatrixSignificant.rows(); final int totalDiseaseGenes = diseaseGenes.size(); final double[] geneScores = new double[totalGenes]; final double[] geneScoresDiseaseGenes = new double[totalDiseaseGenes]; final NaturalRanking naturalRanking = new NaturalRanking(NaNStrategy.FAILED, TiesStrategy.MAXIMUM); CSVWriter writer = new CSVWriter(new FileWriter(outputFile), '\t', '\0', '\0', "\n"); String[] outputLine = new String[16]; int c = 0; outputLine[c++] = "Disease"; outputLine[c++] = "Gene"; outputLine[c++] = "Hgnc"; outputLine[c++] = "Rank"; outputLine[c++] = "RankAmongDiseaseGenes"; outputLine[c++] = "Z-score"; outputLine[c++] = "HPO_skewness"; outputLine[c++] = "Other_mean_skewness"; outputLine[c++] = "Other_max_skewness"; outputLine[c++] = "HPO_phenotypic_match_score"; outputLine[c++] = "HPO_count"; outputLine[c++] = "HPO_sum_auc"; outputLine[c++] = "HPO_mean_auc"; outputLine[c++] = "HPO_median_auc"; outputLine[c++] = "HPO_terms"; outputLine[c++] = "HPO_terms_match_score"; writer.writeNext(outputLine); Random random = new Random(1); Mean meanCalculator = new Mean(); Median medianCalculator = new Median(); for (DiseaseGeneHpoData.DiseaseGene diseaseGene : diseaseGeneHpoData.getDiseaseGeneHpos()) { String gene = diseaseGene.getGene(); String disease = diseaseGene.getDisease(); if (!predictionMatrixSignificant.containsRow(gene)) { continue; } Set<String> geneHpos = diseaseGeneHpoData.getDiseaseEnsgHpos(diseaseGene); LinkedHashSet<String> geneHposPredictable = new LinkedHashSet<>(); for (String hpo : geneHpos) { geneHposPredictable .addAll(hpoFinder.getTermsToNames(hpoFinder.getPredictableTerms(hpo, correctedPCutoff))); } if (geneHposPredictable.isEmpty()) { continue; } // if(geneHposPredictable.size() > 1){ // String hpoSelected = geneHposPredictable.toArray(new String[geneHposPredictable.size()])[random.nextInt(geneHposPredictable.size())]; // geneHposPredictable = new LinkedHashSet<>(1); // geneHposPredictable.add(hpoSelected); // } DoubleMatrixDataset<String, String> predictionCaseTerms = predictionMatrixSignificant .viewColSelection(geneHposPredictable); DoubleMatrix2D predictionCaseTermsMatrix = predictionCaseTerms.getMatrix(); double denominator = Math.sqrt(geneHposPredictable.size()); for (int g = 0; g < totalGenes; ++g) { geneScores[g] = predictionCaseTermsMatrix.viewRow(g).zSum() / denominator; if (Double.isNaN(geneScores[g])) { geneScores[g] = 0; } g2 = mapGeneIndexToDiseaseGeneIndex[g]; if (g2 >= 0) { geneScoresDiseaseGenes[g2] = geneScores[g]; } } double[] geneRanks = naturalRanking.rank(geneScores); int diseaseGeneIndex = predictionMatrixSignificant.getRowIndex(gene); double[] geneRanksDiseaseGenes = naturalRanking.rank(geneScoresDiseaseGenes); int diseaseGeneIndexInDiseaseGenesOnly = mapGeneIndexToDiseaseGeneIndex[diseaseGeneIndex]; double zscore = geneScores[diseaseGeneIndex]; double rank = (totalGenes - geneRanks[diseaseGeneIndex]) + 1; double rankAmongDiseaseGenes = (totalDiseaseGenes - geneRanksDiseaseGenes[diseaseGeneIndexInDiseaseGenesOnly]) + 1; double hpoPhenotypicMatchScore = 0; StringBuilder individualMatchScore = new StringBuilder(); boolean notFirst = false; int usedHpos = 0; double[] aucs = new double[geneHposPredictable.size()]; double sumAucs = 0; int i = 0; for (String hpo : geneHposPredictable) { usedHpos++; MeanSd hpoMeanSd = hpoMeanSds.get(hpo); double hpoPredictionZ = predictionMatrixSignificant.getElement(gene, hpo); double hpoPredictionOutlierScore = ((hpoPredictionZ - hpoMeanSd.getMean()) / hpoMeanSd.getSd()); if (notFirst) { individualMatchScore.append(';'); } notFirst = true; individualMatchScore.append(hpoPredictionOutlierScore); hpoPhenotypicMatchScore += hpoPredictionOutlierScore; aucs[i++] = predictionInfo.get(hpo).getAuc(); sumAucs += predictionInfo.get(hpo).getAuc(); } double meanAuc = meanCalculator.evaluate(aucs); double medianAuc = medianCalculator.evaluate(aucs); if (usedHpos == 0) { hpoPhenotypicMatchScore = Double.NaN; } else { hpoPhenotypicMatchScore = hpoPhenotypicMatchScore / usedHpos; } String symbol = ensgSymbolMapping.get(gene); if (symbol == null) { symbol = ""; } c = 0; outputLine[c++] = disease; outputLine[c++] = gene; outputLine[c++] = symbol; outputLine[c++] = String.valueOf(rank); outputLine[c++] = String.valueOf(rankAmongDiseaseGenes); outputLine[c++] = String.valueOf(zscore); outputLine[c++] = String.valueOf(skewnessInfo.getHpoSkewness(gene)); outputLine[c++] = String.valueOf(skewnessInfo.getMeanSkewnessExHpo(gene)); outputLine[c++] = String.valueOf(skewnessInfo.getMaxSkewnessExHpo(gene)); outputLine[c++] = String.valueOf(hpoPhenotypicMatchScore); outputLine[c++] = String.valueOf(geneHposPredictable.size()); outputLine[c++] = String.valueOf(sumAucs); outputLine[c++] = String.valueOf(meanAuc); outputLine[c++] = String.valueOf(medianAuc); outputLine[c++] = String.join(";", geneHposPredictable); outputLine[c++] = individualMatchScore.toString(); writer.writeNext(outputLine); } writer.close(); }
From source file:org.apache.solr.client.solrj.io.eval.RankEvaluator.java
@Override public Object doWork(Object value) { if (null == value) { return null; } else if (value instanceof List) { NaturalRanking rank = new NaturalRanking(); return Arrays .stream(rank.rank(((List<?>) value).stream() .mapToDouble(innerValue -> ((Number) innerValue).doubleValue()).toArray())) .mapToObj(Double::new).collect(Collectors.toList()); } else {/* ww w . j a v a 2 s . com*/ return doWork(Arrays.asList((BigDecimal) value)); } }
From source file:org.apache.solr.client.solrj.io.stream.RankEvaluator.java
public List<Number> evaluate(Tuple tuple) throws IOException { StreamEvaluator colEval = subEvaluators.get(0); List<Number> numbers = (List<Number>) colEval.evaluate(tuple); double[] values = new double[numbers.size()]; for (int i = 0; i < numbers.size(); i++) { values[i] = numbers.get(i).doubleValue(); }/*from w w w . ja va2 s . c o m*/ NaturalRanking rank = new NaturalRanking(); double[] ranked = rank.rank(values); List<Number> rankedList = new ArrayList(); for (int i = 0; i < numbers.size(); i++) { rankedList.add(ranked[i]); } return rankedList; }