List of usage examples for org.apache.commons.math3.stat.descriptive.moment Mean Mean
public Mean()
From source file:com.itemanalysis.psychometrics.rasch.JMLE.java
/** * Computes PROX starting values fro items, thresholds, and persons. *///ww w. ja v a2 s . c o m public void prox() { Mean m = new Mean(); RatingScaleItem rsi = null; for (VariableName v : items.keySet()) { rsi = items.get(v); rsi.prox(MPRIS(v), adjustedRIS(v)); m.increment(rsi.getDifficulty()); } for (VariableName v : items.keySet()) { rsi = items.get(v); rsi.recenter(m.getResult()); rsi.recenterProposalDifficulty(m.getResult()); } RatingScaleThresholds rst = null; for (String s : thresholds.keySet()) { rst = thresholds.get(s); if (!rst.extremeThreshold()) { rst.categoryProx(Spj(rst.getGroupId())); rst.recenterProposalThresholds(); rst.recenterThresholds(); } } for (int i = 0; i < nPeople; i++) { theta[i] = prox(data[i]); } }
From source file:com.itemanalysis.psychometrics.rasch.JMLE.java
public void linearTransformation(DefaultLinearTransformation lt, int precision) { Mean pMean = new Mean(); StandardDeviation pSd = new StandardDeviation(); //set transformation and rescale persons double newScale = lt.getScale(); double newMean = lt.getIntercept(); double oldPersonMean = pMean.evaluate(theta); double oldPersonSd = pSd.evaluate(theta); lt.setScaleAndIntercept(oldPersonMean, newMean, oldPersonSd, newScale); for (int i = 0; i < theta.length; i++) { theta[i] = lt.transform(theta[i]); }/*from w ww . ja v a2 s . c o m*/ //set transformation and rescale items Mean iMean = new Mean(); StandardDeviation iSd = new StandardDeviation(); double tempDifficulty = 0.0; for (VariableName v : items.keySet()) { tempDifficulty = items.get(v).getDifficulty(); iMean.increment(tempDifficulty); iSd.increment(tempDifficulty); } lt.setScaleAndIntercept(iMean.getResult(), newMean, iSd.getResult(), newScale); for (VariableName v : items.keySet()) { items.get(v).linearTransformation(lt, precision); } //set transformation and rescale thresholds RatingScaleThresholds tempThresholds = null; for (String s : thresholds.keySet()) { tempThresholds = thresholds.get(s); lt.setScaleAndIntercept(tempThresholds.getThresholdMean(), newMean, tempThresholds.getThresholdStandardDeviation(), newScale); thresholds.get(s).linearTransformation(lt, precision); } }
From source file:nl.systemsgenetics.genenetworkbackend.div.CalculateGenePredictability.java
/** * @param args the command line arguments *//* w w w.j a v a2 s.c o m*/ public static void main(String[] args) throws IOException { File predictionMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\reactome_predictions.txt.gz"); File annotationMatrixFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\Ensembl2Reactome_All_Levels.txt_matrix.txt.gz"); File significantTermsFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\reactome_predictions_bonSigTerms_alsoInGoP.txt"); File outputFile = new File( "C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\reactome_predictions_genePredictability_alsoInGoP.txt"); // File predictionMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions.txt.gz"); // 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"); // File significantTermsFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_bonSigTerms.txt"); // File outputFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\hpo_predictions_genePredictability.txt"); // // File predictionMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\go_F_predictions.txt.gz"); // File annotationMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\goa_human.gaf_F_matrix.txt.gz"); // File significantTermsFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\go_F_predictions_bonSigTerms.txt"); // File outputFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\go_F_predictions_genePredictability.txt"); // // File predictionMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\kegg_predictions.txt.gz"); // File annotationMatrixFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\PathwayMatrix\\c2.cp.kegg.v6.1.entrez.gmt_matrix.txt.gz"); // File significantTermsFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\kegg_predictions_bonSigTerms.txt"); // File outputFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\Data31995Genes05-12-2017\\PCA_01_02_2018\\predictions\\kegg_predictions_genePredictability.txt"); // // File predictionMatrixFile = new File("/groups/umcg-wijmenga/tmp04/umcg-svandam/GeneNetwork/Data31995Genes05-12-2017/GeneNetwork_V2_01-02-2018/Covariates/PCA/predictions/go_P_predictions.txt.gz"); // File annotationMatrixFile = new File("/groups/umcg-wijmenga/tmp04/umcg-svandam/GeneNetwork/Data31995Genes05-12-2017/GeneNetwork_V2_01-02-2018/Covariates/PCA/PathwayMatrix/goa_human.gaf_P_matrix.txt.gz"); // File significantTermsFile = new File("/groups/umcg-wijmenga/tmp04/umcg-svandam/GeneNetwork/Data31995Genes05-12-2017/GeneNetwork_V2_01-02-2018/Covariates/PCA/predictions/go_P_predictions_bonSigTerms_alsoInReactome.txt"); // File outputFile = new File("/groups/umcg-wijmenga/tmp04/umcg-svandam/GeneNetwork/Data31995Genes05-12-2017/GeneNetwork_V2_01-02-2018/Covariates/PCA/predictions/go_P_predictions_genePredictability_alsoInReactome.txt"); LinkedHashSet<String> significantTerms = loadSignificantTerms(significantTermsFile); DoubleMatrixDataset<String, String> predictionMatrix = DoubleMatrixDataset .loadDoubleData(predictionMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> annotationMatrix = DoubleMatrixDataset .loadDoubleData(annotationMatrixFile.getAbsolutePath()); DoubleMatrixDataset<String, String> predictionMatrixSignificant = predictionMatrix .viewColSelection(significantTerms); DoubleMatrixDataset<String, String> annotationMatrixSignificant = annotationMatrix .viewColSelection(significantTerms); if (!predictionMatrixSignificant.getColObjects().equals(annotationMatrixSignificant.getColObjects())) { System.err.println("Differnce in terms"); return; } if (!predictionMatrixSignificant.getRowObjects().equals(annotationMatrixSignificant.getRowObjects())) { System.err.println("Differnce in genes"); return; } MannWhitneyUTest2 uTest = new MannWhitneyUTest2(); Kurtosis kurtosisCalculator = new Kurtosis(); Skewness skewnessCalculator = new Skewness(); Mean annotatedMeanCalculator = new Mean(); Mean notAnnotatedMeanCalculator = new Mean(); double[] genePredictabilityZscores = new double[predictionMatrixSignificant.rows()]; int[] pathwayCount = new int[predictionMatrixSignificant.rows()]; double[] geneKurtosis = new double[predictionMatrixSignificant.rows()]; double[] geneSkewness = new double[predictionMatrixSignificant.rows()]; double[] geneAnnotatedMean = new double[predictionMatrixSignificant.rows()]; double[] geneNotAnnotatedMean = new double[predictionMatrixSignificant.rows()]; for (int g = 0; g < predictionMatrixSignificant.rows(); g++) { kurtosisCalculator.clear(); skewnessCalculator.clear(); annotatedMeanCalculator.clear(); notAnnotatedMeanCalculator.clear(); DoubleMatrix1D geneAnnotations = annotationMatrixSignificant.getRow(g); int geneAnnotationCount = geneAnnotations.cardinality(); pathwayCount[g] = geneAnnotationCount; double[] zScoresAnnotatedPathways = new double[geneAnnotationCount]; double[] zScoresOtherPathways = new double[annotationMatrixSignificant.columns() - geneAnnotationCount]; int x = 0; int y = 0; for (int p = 0; p < geneAnnotations.size(); p++) { double z = predictionMatrixSignificant.getElementQuick(g, p); if (geneAnnotations.getQuick(p) != 0) { annotatedMeanCalculator.increment(z); zScoresAnnotatedPathways[x++] = z; } else { notAnnotatedMeanCalculator.increment(z); zScoresOtherPathways[y++] = z; } kurtosisCalculator.increment(z); skewnessCalculator.increment(z); } if (geneAnnotationCount >= 10) { uTest.setData(zScoresOtherPathways, zScoresAnnotatedPathways); genePredictabilityZscores[g] = uTest.getZ(); } else { genePredictabilityZscores[g] = Double.NaN; } geneKurtosis[g] = kurtosisCalculator.getResult(); geneSkewness[g] = skewnessCalculator.getResult(); geneAnnotatedMean[g] = annotatedMeanCalculator.getResult(); geneNotAnnotatedMean[g] = notAnnotatedMeanCalculator.getResult(); } CSVWriter writer = new CSVWriter(new FileWriter(outputFile), '\t', '\0', '\0', "\n"); String[] outputLine = new String[7]; int c = 0; outputLine[c++] = "Gene"; outputLine[c++] = "Z-score"; outputLine[c++] = "Skewness"; outputLine[c++] = "Kurtosis"; outputLine[c++] = "MeanNotAnnotated"; outputLine[c++] = "MeanAnnotated"; outputLine[c++] = "Annoted_pathways"; writer.writeNext(outputLine); ArrayList<String> geneNames = predictionMatrixSignificant.getRowObjects(); for (int g = 0; g < predictionMatrixSignificant.rows(); g++) { c = 0; outputLine[c++] = geneNames.get(g); outputLine[c++] = String.valueOf(genePredictabilityZscores[g]); outputLine[c++] = String.valueOf(geneSkewness[g]); outputLine[c++] = String.valueOf(geneKurtosis[g]); outputLine[c++] = String.valueOf(geneNotAnnotatedMean[g]); outputLine[c++] = String.valueOf(geneAnnotatedMean[g]); outputLine[c++] = String.valueOf(pathwayCount[g]); writer.writeNext(outputLine); } writer.close(); }
From source file:nl.systemsgenetics.genenetworkbackend.hpo.TestDiseaseGenePerformance.java
/** * @param args the command line arguments * @throws java.lang.Exception// www .j a va 2 s . 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:nl.systemsgenetics.genenetworkbackend.hpo.TestDiseaseGenePerformance.java
private static HashMap<String, MeanSd> calculatePathayMeansOfAnnotatedGenes( DoubleMatrixDataset<String, String> predictionMatrixSignificant, DoubleMatrixDataset<String, String> annotationMatrixSignificant) { HashMap<String, MeanSd> pathwayMeanSdMap = new HashMap<>(predictionMatrixSignificant.columns()); Mean meanCalculator = new Mean(); Variance varianceCalculator = new Variance(); for (String pathway : predictionMatrixSignificant.getColObjects()) { meanCalculator.clear();//from w w w.j av a2 s .c o m varianceCalculator.clear(); DoubleMatrix1D pathwayPredictions = predictionMatrixSignificant.getCol(pathway); DoubleMatrix1D pathwayAnnotations = annotationMatrixSignificant.getCol(pathway); for (int g = 0; g < pathwayPredictions.size(); ++g) { if (pathwayAnnotations.get(g) != 0) { meanCalculator.increment(pathwayPredictions.getQuick(g)); varianceCalculator.increment(pathwayPredictions.getQuick(g)); } } double v = varianceCalculator.getResult(); pathwayMeanSdMap.put(pathway, new MeanSd(meanCalculator.getResult(), v * v)); } return pathwayMeanSdMap; }
From source file:org.apache.mahout.classifier.ConfusionMatrix.java
public double getWeightedPrecision() { double[] precisions = new double[numLabels()]; double[] weights = new double[numLabels()]; int index = 0; for (String label : labelMap.keySet()) { precisions[index] = getPrecision(label); weights[index] = getActualNumberOfTestExamplesForClass(label); index++;/*w w w . j a v a 2 s.co m*/ } return new Mean().evaluate(precisions, weights); }
From source file:org.apache.mahout.classifier.ConfusionMatrix.java
public double getWeightedRecall() { double[] recalls = new double[numLabels()]; double[] weights = new double[numLabels()]; int index = 0; for (String label : labelMap.keySet()) { recalls[index] = getRecall(label); weights[index] = getActualNumberOfTestExamplesForClass(label); index++;//from www. jav a2 s. c o m } return new Mean().evaluate(recalls, weights); }
From source file:org.apache.mahout.classifier.ConfusionMatrix.java
public double getWeightedF1score() { double[] f1Scores = new double[numLabels()]; double[] weights = new double[numLabels()]; int index = 0; for (String label : labelMap.keySet()) { f1Scores[index] = getF1score(label); weights[index] = getActualNumberOfTestExamplesForClass(label); index++;//from w w w .j a v a 2s . com } return new Mean().evaluate(f1Scores, weights); }
From source file:org.briljantframework.data.vector.DoubleVector.java
@Override public double mean() { Mean mean = new Mean(); for (int i = 0, size = size(); i < size; i++) { double v = getAsDoubleAt(i); if (!Is.NA(v)) { mean.increment(v);//from w w w .java 2 s . co m } } return mean.getN() > 0 ? mean.getResult() : Na.DOUBLE; }
From source file:org.drugis.mtc.parameterization.AbstractDataStartingValueGenerator.java
public double getStandardDeviation() { double[] errors = new double[d_cGraph.getEdgeCount()]; int i = 0;//w w w .j ava2 s.com for (FoldedEdge<Treatment, Study> edge : d_cGraph.getEdges()) { final Pair<Treatment> v = edge.getVertices(); errors[i++] = getPooledEffect(new BasicParameter(v.getFirst(), v.getSecond())).getStandardError(); } if (d_rng == null) { return new Mean().evaluate(errors); } else { return errors[d_rng.nextInt(errors.length)]; } }