List of usage examples for org.apache.commons.math.util FastMath log10
public static double log10(final double x)
From source file:com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore.java
/** * Returns the interpolation values for the given score histogram in the * form {a, b}.//from w ww . ja v a2 s . co m * * @param scoreHistogram the score histogram * @param useCache if true the interpolation values will be stored in the * histograms in cache * * @return the interpolation values for the given score histogram */ public double[] getInterpolationValues(HashMap<Integer, Integer> scoreHistogram, boolean useCache) { ArrayList<Integer> bins = new ArrayList<Integer>(scoreHistogram.keySet()); Collections.sort(bins, Collections.reverseOrder()); ArrayList<Double> evalueFunctionX = new ArrayList<Double>(scoreHistogram.size()); ArrayList<Double> evalueFunctionY = new ArrayList<Double>(scoreHistogram.size()); Integer currentSum = 0; for (Integer bin : bins) { Integer nInBin = scoreHistogram.get(bin); if (nInBin != null) { currentSum += nInBin; } if (currentSum > 0) { Double xValue = new Double(bin); xValue = FastMath.log10(xValue); evalueFunctionX.add(xValue); Double yValue = new Double(currentSum); yValue = FastMath.log10(yValue); evalueFunctionY.add(yValue); } } if (evalueFunctionX.size() <= 1) { return null; } RegressionStatistics regressionStatistics = LinearRegression.getSimpleLinearRegression(evalueFunctionX, evalueFunctionY); if (useCache) { Double roundedA = Util.roundDouble(regressionStatistics.a, 2); Double roundedB = Util.roundDouble(regressionStatistics.b, 2); Integer nA = as.get(roundedA); if (nA == null) { as.put(roundedA, 1); } else { as.put(roundedA, nA + 1); } Integer nB = bs.get(roundedB); if (nB == null) { bs.put(roundedB, 1); } else { bs.put(roundedB, nB + 1); } } return new double[] { regressionStatistics.a, regressionStatistics.b }; }
From source file:com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore.java
/** * Returns the interpolation of a list of hyperscores using a linear * interpolation of the form result = a * log(score) + b. If the score is * null, returns the number of hyperscores. The value at every score is * returned in a map./*from w w w . j av a 2s . c o m*/ * * @param hyperScores a list of hyperscores * @param a the slope of the interpolation * @param b the offset of the interpolation * * @return the interpolation for every score in a map. */ public HashMap<Double, Double> getInterpolation(ArrayList<Double> hyperScores, Double a, Double b) { HashMap<Double, Double> result = new HashMap<Double, Double>(); for (Double hyperScore : hyperScores) { if (!result.containsKey(hyperScore)) { if (hyperScore > 0) { double logScore = FastMath.log10(hyperScore); double eValue = getInterpolation(logScore, a, b); result.put(hyperScore, eValue); } else { Double eValue = new Double(hyperScores.size()); result.put(hyperScore, eValue); } } } return result; }