List of usage examples for java.lang StrictMath floor
public static double floor(double a)
From source file:Main.java
public static void main(String[] args) { double d1 = 5.3, d2 = 7.8, d3 = 1.5; System.out.println("Floor value of " + d1 + " = " + StrictMath.floor(d1)); System.out.println("Floor value of " + d2 + " = " + StrictMath.floor(d2)); System.out.println("Floor value of " + d3 + " = " + StrictMath.floor(d3)); }
From source file:org.cirdles.calamari.algorithms.WeightedMeanCalculators.java
/** * Adapted from Simon Bodorkos interpretation of Ludwig: * https://github.com/CIRDLES/ET_Redux/wiki/SHRIMP:-Sub-wtdLinCorr. Note the * logic is simplified and output values are stored in object of type * WtdLinCorrResults. Indexing in Java is 0-based, hence the use of i-1 and * minIndex - 1 in the calls to deletePoint. * * @param y//from w w w . j a v a 2 s.c o m * @param sigRho * @param x * @return */ public static WtdLinCorrResults wtdLinCorr(double[] y, double[][] sigRho, double[] x) { WtdLinCorrResults wtdLinCorrResults = new WtdLinCorrResults(); boolean linReg = (y.length == x.length); int avg1LinRegr2 = linReg ? 2 : 1; int n = y.length; double[] mswdRatList = new double[] { 0.0, 0.1, 0.15, 0.2, 0.2, 0.25 }; double mswdRatToler = (n > 7) ? 0.3 : mswdRatList[n - avg1LinRegr2 - 1]; // int maxRej = (int) StrictMath.ceil((n - avg1LinRegr2) / 8.0); // incorrect statement found by Griffin Hiers Feb 2017 int maxRej = 1 + (int) StrictMath.floor((n - avg1LinRegr2) / 8.0); // boolean[] rej = new boolean[n]; // not used double minProb = 0.1; // double wLrej = 0; int pass = 0; int minIndex = -1; double minMSWD = 0.0; double maxProb = 0.0; double[] y1 = y.clone(); double[] y2 = y.clone(); double[] x1 = x.clone(); double[] x2 = x.clone(); double[][] sigRho1 = sigRho.clone(); double[][] sigRho2 = sigRho.clone(); double[] sigmaY = new double[n]; for (int i = 0; i < n; i++) { sigmaY[i] = sigRho[i][i]; } double f = StrictMath.max(TukeyBiweight.calculateMedian(sigmaY), 1e-10); for (int i = 0; i < n; i++) { sigRho1[i][i] = StrictMath.max(sigRho1[i][i], f); sigRho2[i][i] = sigRho1[i][i]; } boolean doContinue = true; int nw = n; DeletePointResults deletePointResults; double[] probW = new double[n + 1]; double[] mswdW = new double[n + 1]; double[] sigmaInterW = new double[n + 1]; double[] interW = new double[n + 1]; double[] slopeW = new double[n + 1]; double[] sigmaSlopeW = new double[n + 1]; double[] covSlopeInterW = new double[n + 1]; do { for (int i = 0; i < (n + 1); i++) { if (i > 0) { deletePointResults = deletePoint(i - 1, y1, sigRho1, x1); y2 = deletePointResults.getY2(); sigRho2 = deletePointResults.getSigRho2(); x2 = deletePointResults.getX2(); nw = n - 1; } if ((nw == 1) && !linReg) { probW[i] = 1.0; mswdW[i] = 0.0; sigmaInterW[i] = 1.0; interW[i] = 1.0; } else if (linReg) { WeightedLinearCorrResults weightedLinearCorrResults = weightedLinearCorr(y2, x2, sigRho2); slopeW[i] = weightedLinearCorrResults.getSlope(); interW[i] = weightedLinearCorrResults.getIntercept(); mswdW[i] = weightedLinearCorrResults.getMswd(); probW[i] = weightedLinearCorrResults.getProb(); sigmaSlopeW[i] = weightedLinearCorrResults.getSlopeSig(); sigmaInterW[i] = weightedLinearCorrResults.getInterceptSig(); covSlopeInterW[i] = weightedLinearCorrResults.getSlopeInterceptCov(); // bad is never used } else { WtdAvCorrResults wtdAvCorrResults = wtdAvCorr(y2, convertCorrelationsToCovariances(sigRho2)); interW[i] = wtdAvCorrResults.getMeanVal(); sigmaInterW[i] = wtdAvCorrResults.getSigmaMeanVal(); mswdW[i] = wtdAvCorrResults.getMswd(); probW[i] = wtdAvCorrResults.getProb(); } if (i == 0) { if (probW[0] > 0.1) { minIndex = 0; // minMSWD = mswdW[0]; // assignment never used // exit for loop of i break; } maxProb = probW[0]; } } // for loop of i if (minIndex == 0) { doContinue = false; } else { minIndex = 0; minMSWD = mswdW[0]; for (int i = 1; i < (n + 1); i++) { double mswdRat = mswdW[i] / StrictMath.max(1e-32, mswdW[0]); if ((mswdRat < mswdRatToler) && (mswdW[i] < minMSWD) && (probW[i] > minProb)) { // rej[i] = true; not used // wLrej++; not used minIndex = i; maxProb = probW[i]; minMSWD = mswdW[i]; } } pass++; // note check for pass > 0 in original code is redundant if ((minIndex == 0) || (pass == maxRej) || (maxProb > 0.1)) { doContinue = false; } else { deletePointResults = deletePoint(minIndex - 1, y1, sigRho1, x1); y2 = deletePointResults.getY2(); sigRho2 = deletePointResults.getSigRho2(); x2 = deletePointResults.getX2(); n -= 1; y1 = new double[n]; if (linReg) { x1 = new double[n]; } sigRho1 = new double[n][n]; for (int i = 0; i < n; i++) { y1[i] = y2[i]; if (linReg) { x1[i] = x2[i]; } System.arraycopy(sigRho2[i], 0, sigRho1[i], 0, n); } } } } while (doContinue); double intercept = interW[minIndex]; double sigmaIntercept = sigmaInterW[minIndex]; double mswd = mswdW[minIndex]; double probfit = probW[minIndex]; if (linReg && (minIndex > 0)) { wtdLinCorrResults.setSlope(slopeW[minIndex]); wtdLinCorrResults.setSigmaSlope(sigmaSlopeW[minIndex]); wtdLinCorrResults.setCovSlopeInter(covSlopeInterW[minIndex]); } if (probfit < 0.05) { sigmaIntercept *= StrictMath.sqrt(mswd); if (linReg) { wtdLinCorrResults.setSigmaSlope(wtdLinCorrResults.getSigmaSlope() * StrictMath.sqrt(mswd)); } } wtdLinCorrResults.setBad(false); wtdLinCorrResults.setIntercept(intercept); wtdLinCorrResults.setSigmaIntercept(sigmaIntercept); wtdLinCorrResults.setMswd(mswd); wtdLinCorrResults.setProbFit(probfit); wtdLinCorrResults.setMinIndex(minIndex); return wtdLinCorrResults; }
From source file:org.esa.beam.framework.datamodel.TiePointGrid.java
public InterpInput calcInterp(final float x, final float y) { final float fi = (x - offsetX) / subSamplingX; final float fj = (y - offsetY) / subSamplingY; final int i = MathUtils.crop((int) StrictMath.floor(fi), 0, rasterWidthMinus2); final int j = MathUtils.crop((int) StrictMath.floor(fj), 0, rasterHeightMinus2); return new InterpInput(fi - i, fj - j, i, j); }