List of usage examples for org.apache.commons.math.stat.regression SimpleRegression getN
public long getN()
From source file:com.discursive.jccook.math.SimpleRegressionExample.java
public static void main(String[] args) throws MathException { SimpleRegression sr = new SimpleRegression(); // Add data points sr.addData(0, 0);/* w w w .j a va 2s.co m*/ sr.addData(1, 1.2); sr.addData(2, 2.6); sr.addData(3, 3.2); sr.addData(4, 4); sr.addData(5, 5); NumberFormat format = NumberFormat.getInstance(); // Print the value of y when line intersects the y axis System.out.println("Intercept: " + format.format(sr.getIntercept())); // Print the number of data points System.out.println("N: " + sr.getN()); // Print the Slope and the Slop Confidence System.out.println("Slope: " + format.format(sr.getSlope())); System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval())); // Print RSquare a measure of relatedness System.out.println("RSquare: " + format.format(sr.getRSquare())); sr.addData(400, 100); sr.addData(300, 105); sr.addData(350, 70); sr.addData(200, 50); sr.addData(150, 300); sr.addData(50, 500); System.out.println("Intercept: " + format.format(sr.getIntercept())); System.out.println("N: " + sr.getN()); System.out.println("Slope: " + format.format(sr.getSlope())); System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval())); System.out.println("RSquare: " + format.format(sr.getRSquare())); }
From source file:ch.usi.inf.lidr.merging.SSL.java
/** * <b>IMPORTANT:</b> {@link #setSampleDocuments(List)} must be called before running normalization. * //from w w w . j av a 2 s . c om * @see ch.usi.inf.lidr.norm.ScoreNormalization#normalize(List<ScoredEntity<T>>) * @see #setSampleDocuments(List) */ @Override public <T> List<ScoredEntity<T>> normalize(List<ScoredEntity<T>> unnormScoredDocs) { if (unnormScoredDocs == null) { throw new NullPointerException("The list of scored documents is null."); } SimpleRegression regression = getRegression(unnormScoredDocs); //TODO: backup with CORI if (regression.getN() < 3) { return new ArrayList<ScoredEntity<T>>(); } List<ScoredEntity<T>> normScoredDocs = new ArrayList<ScoredEntity<T>>(unnormScoredDocs.size()); for (int i = 0; i < unnormScoredDocs.size(); i++) { ScoredEntity<T> normScoredDoc = new ScoredEntity<T>(unnormScoredDocs.get(i).getEntity(), regression.getSlope() * unnormScoredDocs.get(i).getScore() + regression.getIntercept()); normScoredDocs.add(normScoredDoc); } return normScoredDocs; }
From source file:ch.usi.inf.lidr.merging.SSL.java
/** * Creates and returns a {@link SimpleRegression} * for a given list of scored documents <code>scoredDocs</code>. * This regression maps unnormalized scores in <code>scoredDocs</code> * to normalized/centralized scores in <code>centrScores</code>. * Documents that appear both in <code>scoredDocs</code> * and <code>centrScores</code> are used as a training for the regression. * According to the original paper, only first 10 * documents are considered for training. * // ww w. ja va 2s . com * @param scoredDocs The list of scored documents. * * @return The {@link SimpleRegression} with filled-in training data. */ private <T> SimpleRegression getRegression(List<ScoredEntity<T>> scoredDocs) { SimpleRegression regression = new SimpleRegression(); Set<Double> xData = new HashSet<Double>(); for (ScoredEntity<T> scoredDocument : scoredDocs) { Object docId = scoredDocument.getEntity(); double specificScore = scoredDocument.getScore(); if (centrScores.containsKey(docId) && !xData.contains(specificScore)) { regression.addData(specificScore, centrScores.get(docId)); xData.add(specificScore); if (regression.getN() >= 10) { return regression; } } } return regression; }
From source file:com.joliciel.jochre.graphics.SourceImageImpl.java
@Override public double getMeanHorizontalSlope() { if (!meanHorizontalSlopeCalculated) { // Calculate the average regression to be used for analysis Mean meanForSlope = new Mean(); StandardDeviation stdDevForSlope = new StandardDeviation(); List<SimpleRegression> regressions = new ArrayList<SimpleRegression>(); for (RowOfShapes row : this.getRows()) { SimpleRegression regression = row.getRegression(); // only include rows for which regression was really calculated (more than 2 points) if (regression.getN() > 2) { meanForSlope.increment(regression.getSlope()); stdDevForSlope.increment(regression.getSlope()); regressions.add(regression); }/* w w w . j a va 2s . com*/ } double slopeMean = 0.0; double slopeStdDev = 0.0; if (meanForSlope.getN() > 0) { slopeMean = meanForSlope.getResult(); slopeStdDev = stdDevForSlope.getResult(); } LOG.debug("slopeMean: " + slopeMean); LOG.debug("slopeStdDev: " + slopeStdDev); if (regressions.size() > 0) { double minSlope = slopeMean - slopeStdDev; double maxSlope = slopeMean + slopeStdDev; meanForSlope = new Mean(); for (SimpleRegression regression : regressions) { if (minSlope <= regression.getSlope() && regression.getSlope() <= maxSlope) meanForSlope.increment(regression.getSlope()); } meanHorizontalSlope = meanForSlope.getResult(); } else { meanHorizontalSlope = 0.0; } LOG.debug("meanHorizontalSlope: " + meanHorizontalSlope); meanHorizontalSlopeCalculated = true; } return meanHorizontalSlope; }
From source file:net.sf.mzmine.modules.peaklistmethods.identification.metamsecorrelate.MetaMSEcorrelateTask.java
/** * feature shape correlation//from w w w .j av a 2s . c o m * @param f1 * @param f2 * @return feature shape correlation * or null if not possible * not enough data points for a correlation * @throws Exception */ public static FeatureShapeCorrelationData corrFeatureShape(Feature f1, Feature f2, boolean sameRawFile) throws Exception { //Range<Double> rt1 = f1.getRawDataPointsRTRange(); //Range<Double> rt2 = f2.getRawDataPointsRTRange(); if (sameRawFile) { // scan numbers (not necessary 1,2,3...) int[] sn1 = f1.getScanNumbers(); int[] sn2 = f2.getScanNumbers(); int offsetI1 = 0; int offsetI2 = 0; // find corresponding value if (sn2[0] > sn1[0]) { for (int i = 1; i < sn1.length; i++) { if (sn1[i] == sn2[0]) { offsetI1 = i; break; } } // peaks are not overlapping if (offsetI1 == 0) return null; } if (sn2[0] < sn1[0]) { for (int i = 1; i < sn2.length; i++) { if (sn1[0] == sn2[i]) { offsetI2 = i; break; } } // peaks are not overlapping if (offsetI2 == 0) return null; } // only correlate intercepting areas 0-max int max = 0; if (sn1.length - offsetI1 <= sn2.length - offsetI2) max = sn1.length - offsetI1; if (sn1.length - offsetI1 > sn2.length - offsetI2) max = sn2.length - offsetI2; if (max - offsetI1 > minCorrelatedDataPoints && max - offsetI2 > minCorrelatedDataPoints) { RawDataFile raw = f1.getDataFile(); SimpleRegression reg = new SimpleRegression(); // save max and min of intensity of val1(x) double maxX = 0; double minX = Double.POSITIVE_INFINITY; Vector<Double> I1 = new Vector<Double>(); Vector<Double> I2 = new Vector<Double>(); // add all data points over a given threshold // raw data (not smoothed) for (int i = 0; i < max; i++) { if (sn1[i + offsetI1] != sn2[i + offsetI2]) throw new Exception("Scans are not the same for peak shape corr"); double val1 = f1.getDataPoint(sn1[i + offsetI1]).getIntensity(); double val2 = f2.getDataPoint(sn2[i + offsetI2]).getIntensity(); if (val1 >= noiseLevelShapeCorr && val2 >= noiseLevelShapeCorr) { reg.addData(val1, val2); if (val1 < minX) minX = val1; if (val1 > maxX) maxX = val1; I1.add(val1); I2.add(val2); } } // return pearson r if (reg.getN() >= minCorrelatedDataPoints) { Double[][] data = new Double[][] { I1.toArray(new Double[I1.size()]), I2.toArray(new Double[I2.size()]) }; return new FeatureShapeCorrelationData(reg, data, minX, maxX); } } } else { // TODO if different raw file search for same rt // impute rt/I values if between 2 data points } return null; }