當前位置: 首頁>>代碼示例>>Java>>正文


Java FastMath.ceil方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.util.FastMath.ceil方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.ceil方法的具體用法?Java FastMath.ceil怎麽用?Java FastMath.ceil使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.util.FastMath的用法示例。


在下文中一共展示了FastMath.ceil方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exactK

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Calculates the exact value of {@code P(D_n < d)} using method described
 * in [1] and {@link org.apache.commons.math3.fraction.BigFraction} (see
 * above).
 *
 * @param d statistic
 * @return the two-sided probability of {@code P(D_n < d)}
 * @throws MathArithmeticException if algorithm fails to convert {@code h}
 * to a {@link org.apache.commons.math3.fraction.BigFraction} in expressing
 * {@code d} as {@code (k - h) / m} for integer {@code k, m} and
 * {@code 0 <= h < 1}.
 */
private double exactK(double d) throws MathArithmeticException {

    final int k = (int) FastMath.ceil(n * d);

    final FieldMatrix<BigFraction> H = this.createH(d);
    final FieldMatrix<BigFraction> Hpower = H.power(n);

    BigFraction pFrac = Hpower.getEntry(k - 1, k - 1);

    for (int i = 1; i <= n; ++i) {
        pFrac = pFrac.multiply(i).divide(n);
    }

    /*
     * BigFraction.doubleValue converts numerator to double and the
     * denominator to double and divides afterwards. That gives NaN quite
     * easy. This does not (scale is the number of digits):
     */
    return pFrac.bigDecimalValue(20, BigDecimal.ROUND_HALF_UP).doubleValue();
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:33,代碼來源:KolmogorovSmirnovDistribution.java

示例2: getNumberOfPoints

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
private int getNumberOfPoints(double min, double max, double delta)
{
    int N = (int) FastMath.ceil(((max - min) / delta));
    if (N > 0 && min + delta * (double) N > max + delta / 2)
    {
        N--;
    }
    return N;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:10,代碼來源:FormulaTermInterval.java

示例3: roundedK

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Calculates {@code P(D_n < d)} using method described in [1] and doubles
 * (see above).
 *
 * @param d statistic
 * @return the two-sided probability of {@code P(D_n < d)}
 * @throws MathArithmeticException if algorithm fails to convert {@code h}
 * to a {@link org.apache.commons.math3.fraction.BigFraction} in expressing
 * {@code d} as {@code (k - h) / m} for integer {@code k, m} and
 * {@code 0 <= h < 1}.
 */
private double roundedK(double d) throws MathArithmeticException {

    final int k = (int) FastMath.ceil(n * d);
    final FieldMatrix<BigFraction> HBigFraction = this.createH(d);
    final int m = HBigFraction.getRowDimension();

    /*
     * Here the rounding part comes into play: use
     * RealMatrix instead of FieldMatrix<BigFraction>
     */
    final RealMatrix H = new Array2DRowRealMatrix(m, m);

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            H.setEntry(i, j, HBigFraction.getEntry(i, j).doubleValue());
        }
    }

    final RealMatrix Hpower = H.power(n);

    double pFrac = Hpower.getEntry(k - 1, k - 1);

    for (int i = 1; i <= n; ++i) {
        pFrac *= (double) i / (double) n;
    }

    return pFrac;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:40,代碼來源:KolmogorovSmirnovDistribution.java

示例4: estimate

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * {@inheritDoc}This method in particular for R_1 uses ceil(pos-0.5)
 */
@Override
protected double estimate(final double[] values,
                          final int[] pivotsHeap, final double pos,
                          final int length, final KthSelector selector) {
    return super.estimate(values, pivotsHeap, FastMath.ceil(pos - 0.5), length, selector);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:10,代碼來源:Percentile.java

示例5: readAndDecimateTile

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
public int[] readAndDecimateTile(int x, int y, int width, int height, double scalingFactor, boolean filter, int band) {
    int outWidth = (int) (width * scalingFactor);
    int outHeight = (int) (height * scalingFactor);
    double deltaPixelsX = (double) width / outWidth;
    double deltaPixelsY = (double) height / outHeight;
    double tileHeight = height / (((double) (width * height) / MAXTILESIZE));
    int[] outData = new int[outWidth * outHeight];
    if (height / outHeight > 4) {
        double a = width*1.0 / outWidth;  //moltiplico per 1.0 per avere un risultato con i decimali
        double b = height*1.0 / outHeight;
        for (int i = 0; i < outHeight; i++) {
            for (int j = 0; j < outWidth; j++) {
                try {
                    outData[i * outWidth + j] = readTile((int) (x + j * a), (int) (y + i * b), 1, 1,band)[0];
                    if(outData.length==0)
                    	outData[i * outWidth + j] = readTile((int) (x + j * a), (int) (y + i * b), 1, 1,band)[0];
                } catch (Exception e) {
                }
            }
        }
        return outData;
    }
    // load first tile
    int currentY = 0;
    int[] tile = readTile(0, currentY, width, (int) FastMath.ceil(tileHeight),band);
    double posY = 0.0;
    for (int j = 0; j < outHeight; j++, posY += deltaPixelsY) {
        // update progress bar
        if (j / 100 - FastMath.floor(j / 100) == 0) {
        }
        if (posY > (int) FastMath.ceil(tileHeight)) {
            tile = readTile(0, currentY + (int) FastMath.ceil(tileHeight), width, (int) FastMath.ceil(tileHeight),band);
            posY -= (int) FastMath.ceil(tileHeight);
            currentY += (int) FastMath.ceil(tileHeight);

        }

        double posX = 0.0;
        for (int i = 0; i < outWidth; i++, posX += deltaPixelsX) {
            //System.out.println("i = " + i + ", j = " + j + ", posX = " + posX + ", posY = " + posY);
            outData[i + j * outWidth] = tile[(int) posX * (int) posY];
        }
        //System.gc();
    }

    return outData;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:48,代碼來源:SarImageReader.java

示例6: roundToNumberOfSignificantDigits

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Procedure rounds the given value to the given number of significant digits see
 * http://stackoverflow.com/questions/202302
 *
 * Note: The maximum double value in Java is on the order of 10^308, while the minimum value is on the order of
 * 10^-324. Therefore, you can run into trouble when applying the function roundToSignificantFigures to something
 * that's within a few powers of ten of Double.MIN_VALUE.
 *
 * Consequently, the variable magnitude may become Infinity, and it's all garbage from then on out. Fortunately,
 * this is not an insurmountable problem: it is only the factor magnitude that's overflowing. What really matters is
 * the product num * magnitude, and that does not overflow. One way of resolving this is by breaking up the
 * multiplication by the factor magintude into two steps.
 */
public static double roundToNumberOfSignificantDigits(double num, int n)
{
    final double maxPowerOfTen = FastMath.floor(FastMath.log10(Double.MAX_VALUE));

    if (num == 0)
    {
        return 0;
    }

    try
    {
        return new BigDecimal(num).round(new MathContext(n, RoundingMode.HALF_EVEN)).doubleValue();
    }
    catch (ArithmeticException ex)
    {
        // nothing to do
    }

    final double d = FastMath.ceil(FastMath.log10(num < 0 ? -num : num));
    final int power = n - (int) d;

    double firstMagnitudeFactor = 1.0;
    double secondMagnitudeFactor = 1.0;
    if (power > maxPowerOfTen)
    {
        firstMagnitudeFactor = FastMath.pow(10.0, maxPowerOfTen);
        secondMagnitudeFactor = FastMath.pow(10.0, (double) power - maxPowerOfTen);
    }
    else
    {
        firstMagnitudeFactor = FastMath.pow(10.0, (double) power);
    }

    double toBeRounded = num * firstMagnitudeFactor;
    toBeRounded *= secondMagnitudeFactor;

    final long shifted = FastMath.round(toBeRounded);
    double rounded = ((double) shifted) / firstMagnitudeFactor;
    rounded /= secondMagnitudeFactor;
    return rounded;
}
 
開發者ID:mkulesh,項目名稱:microMathematics,代碼行數:55,代碼來源:ViewUtils.java

示例7: inverseCumulativeProbability

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 *
 * The default implementation returns
 * <ul>
 * <li>{@link #getSupportLowerBound()} for {@code p = 0},</li>
 * <li>{@link #getSupportUpperBound()} for {@code p = 1}, and</li>
 * <li>{@link #solveInverseCumulativeProbability(double, int, int)} for
 *     {@code 0 < p < 1}.</li>
 * </ul>
 */
public int inverseCumulativeProbability(final double p) throws OutOfRangeException {
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0, 1);
    }

    int lower = getSupportLowerBound();
    if (p == 0.0) {
        return lower;
    }
    if (lower == Integer.MIN_VALUE) {
        if (checkedCumulativeProbability(lower) >= p) {
            return lower;
        }
    } else {
        lower -= 1; // this ensures cumulativeProbability(lower) < p, which
                    // is important for the solving step
    }

    int upper = getSupportUpperBound();
    if (p == 1.0) {
        return upper;
    }

    // use the one-sided Chebyshev inequality to narrow the bracket
    // cf. AbstractRealDistribution.inverseCumulativeProbability(double)
    final double mu = getNumericalMean();
    final double sigma = FastMath.sqrt(getNumericalVariance());
    final boolean chebyshevApplies = !(Double.isInfinite(mu) || Double.isNaN(mu) ||
            Double.isInfinite(sigma) || Double.isNaN(sigma) || sigma == 0.0);
    if (chebyshevApplies) {
        double k = FastMath.sqrt((1.0 - p) / p);
        double tmp = mu - k * sigma;
        if (tmp > lower) {
            lower = ((int) FastMath.ceil(tmp)) - 1;
        }
        k = 1.0 / k;
        tmp = mu + k * sigma;
        if (tmp < upper) {
            upper = ((int) FastMath.ceil(tmp)) - 1;
        }
    }

    return solveInverseCumulativeProbability(p, lower, upper);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:56,代碼來源:AbstractIntegerDistribution.java

示例8: value

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.ceil(x);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:5,代碼來源:Ceil.java

示例9: ceil

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc}
 * @since 3.2
 */
public DerivativeStructure ceil() {
    return new DerivativeStructure(compiler.getFreeParameters(),
                                   compiler.getOrder(),
                                   FastMath.ceil(data[0]));
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:9,代碼來源:DerivativeStructure.java

示例10: calculateIntegralD

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Given a d-statistic in the range [0, 1] and the two sample sizes n and m,
 * an integral d-statistic in the range [0, n*m] is calculated, that can be used for
 * comparison with other integral d-statistics. Depending whether {@code strict} is
 * {@code true} or not, the returned value divided by (n*m) is greater than
 * (resp greater than or equal to) the given d value (allowing some tolerance).
 *
 * @param d a d-statistic in the range [0, 1]
 * @param n first sample size
 * @param m second sample size
 * @param strict whether the returned value divided by (n*m) is allowed to be equal to d
 * @return the integral d-statistic in the range [0, n*m]
 */
private static long calculateIntegralD(double d, int n, int m, boolean strict) {
    final double tol = 1e-12;  // d-values within tol of one another are considered equal
    long nm = n * (long)m;
    long upperBound = (long)FastMath.ceil((d - tol) * nm);
    long lowerBound = (long)FastMath.floor((d + tol) * nm);
    if (strict && lowerBound == upperBound) {
        return upperBound + 1l;
    }
    else {
        return upperBound;
    }
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:26,代碼來源:KolmogorovSmirnovTest.java


注:本文中的org.apache.commons.math3.util.FastMath.ceil方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。