本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例8: value
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
return FastMath.ceil(x);
}
示例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]));
}
示例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;
}
}