当前位置: 首页>>代码示例>>Java>>正文


Java FastMath.floor方法代码示例

本文整理汇总了Java中org.apache.commons.math.util.FastMath.floor方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.floor方法的具体用法?Java FastMath.floor怎么用?Java FastMath.floor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.util.FastMath的用法示例。


在下文中一共展示了FastMath.floor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cumulativeProbability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For a random variable {@code X} whose values are distributed
 * according to this distribution, this method returns
 * {@code P(x0 < X < x1)}.
 *
 * @param x0 Inclusive lower bound.
 * @param x1 Inclusive upper bound.
 * @return the probability that a random variable with this distribution
 * will take a value between {@code x0} and {@code x1},
 * including the endpoints.
 * @throws MathException if the cumulative probability can not be
 * computed due to convergence or other numerical errors.
 * @throws NumberIsTooSmallException if {@code x1 > x0}.
 */
@Override
public double cumulativeProbability(double x0, double x1)
    throws MathException {
    if (x1 < x0) {
        throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x1, x0, true);
    }
    if (FastMath.floor(x0) < x0) {
        return cumulativeProbability(((int) FastMath.floor(x0)) + 1,
           (int) FastMath.floor(x1)); // don't want to count mass below x0
    } else { // x0 is mathematical integer, so use as is
        return cumulativeProbability((int) FastMath.floor(x0),
            (int) FastMath.floor(x1));
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:AbstractIntegerDistribution.java

示例2: cumulativeProbability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For a random variable {@code X} whose values are distributed
 * according to this distribution, this method returns
 * {@code P(x0 <= X <= x1)}.
 *
 * @param x0 Inclusive lower bound.
 * @param x1 Inclusive upper bound.
 * @return the probability that a random variable with this distribution
 * will take a value between {@code x0} and {@code x1},
 * including the endpoints.
 * @throws MathException if the cumulative probability can not be
 * computed due to convergence or other numerical errors.
 * @throws NumberIsTooSmallException if {@code x1 > x0}.
 */
@Override
public double cumulativeProbability(double x0, double x1)
    throws MathException {
    if (x1 < x0) {
        throw new NumberIsTooSmallException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
                                            x1, x0, true);
    }
    if (FastMath.floor(x0) < x0) {
        return cumulativeProbability(((int) FastMath.floor(x0)) + 1,
           (int) FastMath.floor(x1)); // don't want to count mass below x0
    } else { // x0 is mathematical integer, so use as is
        return cumulativeProbability((int) FastMath.floor(x0),
            (int) FastMath.floor(x1));
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:AbstractIntegerDistribution.java

示例3: buildPolynomial

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Get the coefficients array for a given degree.
 * @param degree degree of the polynomial
 * @param coefficients list where the computed coefficients are stored
 * @param generator recurrence coefficients generator
 * @return coefficients array
 */
private static PolynomialFunction buildPolynomial(final int degree,
                                                  final ArrayList<BigFraction> coefficients,
                                                  final RecurrenceCoefficientsGenerator generator) {

    final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1;
    synchronized (PolynomialsUtils.class) {
        if (degree > maxDegree) {
            computeUpToDegree(degree, maxDegree, generator, coefficients);
        }
    }

    // coefficient  for polynomial 0 is  l [0]
    // coefficients for polynomial 1 are l [1] ... l [2] (degrees 0 ... 1)
    // coefficients for polynomial 2 are l [3] ... l [5] (degrees 0 ... 2)
    // coefficients for polynomial 3 are l [6] ... l [9] (degrees 0 ... 3)
    // coefficients for polynomial 4 are l[10] ... l[14] (degrees 0 ... 4)
    // coefficients for polynomial 5 are l[15] ... l[20] (degrees 0 ... 5)
    // coefficients for polynomial 6 are l[21] ... l[27] (degrees 0 ... 6)
    // ...
    final int start = degree * (degree + 1) / 2;

    final double[] a = new double[degree + 1];
    for (int i = 0; i <= degree; ++i) {
        a[i] = coefficients.get(start + i).doubleValue();
    }

    // build the polynomial
    return new PolynomialFunction(a);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:37,代码来源:PolynomialsUtils.java

示例4: evaluate

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns an estimate of the <code>p</code>th percentile of the values
 * in the <code>values</code> array, starting with the element in (0-based)
 * position <code>begin</code> in the array and including <code>length</code>
 * values.
 * <p>
 * Calls to this method do not modify the internal <code>quantile</code>
 * state of this statistic.</p>
 * <p>
 * <ul>
 * <li>Returns <code>Double.NaN</code> if <code>length = 0</code></li>
 * <li>Returns (for any value of <code>p</code>) <code>values[begin]</code>
 *  if <code>length = 1 </code></li>
 * <li>Throws <code>IllegalArgumentException</code> if <code>values</code>
 *  is null , <code>begin</code> or <code>length</code> is invalid, or
 * <code>p</code> is not a valid quantile value (p must be greater than 0
 * and less than or equal to 100)</li>
 * </ul></p>
 * <p>
 * See {@link Percentile} for a description of the percentile estimation
 * algorithm used.</p>
 *
 * @param values array of input values
 * @param p  the percentile to compute
 * @param begin  the first (0-based) element to include in the computation
 * @param length  the number of array elements to include
 * @return  the percentile value
 * @throws IllegalArgumentException if the parameters are not valid or the
 * input array is null
 */
public double evaluate(final double[] values, final int begin,
        final int length, final double p) {

    test(values, begin, length);

    if ((p > 100) || (p <= 0)) {
        throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_QUANTILE_VALUE, p, 0, 100);
    }
    if (length == 0) {
        return Double.NaN;
    }
    if (length == 1) {
        return values[begin]; // always return single value for n = 1
    }
    double n = length;
    double pos = p * (n + 1) / 100;
    double fpos = FastMath.floor(pos);
    int intPos = (int) fpos;
    double dif = pos - fpos;
    double[] work;
    int[] pivotsHeap;
    if (values == getDataRef()) {
        work = getDataRef();
        pivotsHeap = cachedPivots;
    } else {
        work = new double[length];
        System.arraycopy(values, begin, work, 0, length);
        pivotsHeap = new int[(0x1 << MAX_CACHED_LEVELS) - 1];
        Arrays.fill(pivotsHeap, -1);
    }

    if (pos < 1) {
        return select(work, pivotsHeap, 0);
    }
    if (pos >= n) {
        return select(work, pivotsHeap, length - 1);
    }
    double lower = select(work, pivotsHeap, intPos - 1);
    double upper = select(work, pivotsHeap, intPos);
    return lower + dif * (upper - lower);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:72,代码来源:Percentile.java

示例5: value

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
    return FastMath.floor(x);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:5,代码来源:Floor.java

示例6: handleStep

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Handle the last accepted step
 * @param interpolator interpolator for the last accepted step. For
 * efficiency purposes, the various integrators reuse the same
 * object on each call, so if the instance wants to keep it across
 * all calls (for example to provide at the end of the integration a
 * continuous model valid throughout the integration range), it
 * should build a local copy using the clone method and store this
 * copy.
 * @param isLast true if the step is the last one
 * @throws MathUserException this exception is propagated to the
 * caller if the underlying user function triggers one
 */
public void handleStep(final StepInterpolator interpolator,
                       final boolean isLast) throws MathUserException {
    // The first time, update the last state with the start information.
    if (lastState == null) {
        firstTime = interpolator.getPreviousTime();
        lastTime = interpolator.getPreviousTime();
        interpolator.setInterpolatedTime(lastTime);
        lastState = interpolator.getInterpolatedState().clone();
        lastDerivatives = interpolator.getInterpolatedDerivatives().clone();

        // Take the integration direction into account.
        forward = interpolator.getCurrentTime() >= lastTime;
        if (!forward) {
            h = -h;
        }
    }

    // Calculate next normalized step time.
    double nextTime = (mode == StepNormalizerMode.INCREMENT) ?
                      lastTime + h :
                      (FastMath.floor(lastTime / h) + 1) * h;
    if (mode == StepNormalizerMode.MULTIPLES &&
        MathUtils.equals(nextTime, lastTime, 1)) {
        nextTime += h;
    }

    // Process normalized steps as long as they are in the current step.
    boolean nextInStep = isNextInStep(nextTime, interpolator);
    while (nextInStep) {
        // Output the stored previous step.
        doNormalizedStep(false);

        // Store the next step as last step.
        storeStep(interpolator, nextTime);

        // Move on to the next step.
        nextTime += h;
        nextInStep = isNextInStep(nextTime, interpolator);
    }

    if (isLast) {
        // There will be no more steps. The stored one should be given to
        // the handler. We may have to output one more step. Only the last
        // one of those should be flagged as being the last.
        boolean addLast = bounds.lastIncluded() &&
                          lastTime != interpolator.getCurrentTime();
        doNormalizedStep(!addLast);
        if (addLast) {
            storeStep(interpolator, interpolator.getCurrentTime());
            doNormalizedStep(true);
        }
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:67,代码来源:StepNormalizer.java

示例7: probability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For a random variable {@code X} whose values are distributed according
 * to this distribution, this method returns {@code P(X = x)}. In other
 * words, this method represents the probability mass function, or PMF,
 * for the distribution.
 * If {@code x} does not represent an integer value, 0 is returned.
 *
 * @param x Value at which the probability density function is evaluated.
 * @return the value of the probability density function at {@code x}.
 */
public double probability(double x) {
    double fl = FastMath.floor(x);
    if (fl == x) {
        return this.probability((int) x);
    } else {
        return 0;
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:AbstractIntegerDistribution.java


注:本文中的org.apache.commons.math.util.FastMath.floor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。