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


Java FastMath.signum方法代碼示例

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


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

示例1: doSolve

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected double doSolve()
    throws TooManyEvaluationsException,
           NoBracketingException {
    double min = getMin();
    double max = getMax();
    // [x1, x2] is the bracketing interval in each iteration
    // x3 is the midpoint of [x1, x2]
    // x is the new root approximation and an endpoint of the new interval
    double x1 = min;
    double y1 = computeObjectiveValue(x1);
    double x2 = max;
    double y2 = computeObjectiveValue(x2);

    // check for zeros before verifying bracketing
    if (y1 == 0) {
        return min;
    }
    if (y2 == 0) {
        return max;
    }
    verifyBracketing(min, max);

    final double absoluteAccuracy = getAbsoluteAccuracy();
    final double functionValueAccuracy = getFunctionValueAccuracy();
    final double relativeAccuracy = getRelativeAccuracy();

    double oldx = Double.POSITIVE_INFINITY;
    while (true) {
        // calculate the new root approximation
        final double x3 = 0.5 * (x1 + x2);
        final double y3 = computeObjectiveValue(x3);
        if (FastMath.abs(y3) <= functionValueAccuracy) {
            return x3;
        }
        final double delta = 1 - (y1 * y2) / (y3 * y3);  // delta > 1 due to bracketing
        final double correction = (FastMath.signum(y2) * FastMath.signum(y3)) *
                                  (x3 - x1) / FastMath.sqrt(delta);
        final double x = x3 - correction;                // correction != 0
        final double y = computeObjectiveValue(x);

        // check for convergence
        final double tolerance = FastMath.max(relativeAccuracy * FastMath.abs(x), absoluteAccuracy);
        if (FastMath.abs(x - oldx) <= tolerance) {
            return x;
        }
        if (FastMath.abs(y) <= functionValueAccuracy) {
            return x;
        }

        // prepare the new interval for next iteration
        // Ridders' method guarantees x1 < x < x2
        if (correction > 0.0) {             // x1 < x < x3
            if (FastMath.signum(y1) + FastMath.signum(y) == 0.0) {
                x2 = x;
                y2 = y;
            } else {
                x1 = x;
                x2 = x3;
                y1 = y;
                y2 = y3;
            }
        } else {                            // x3 < x < x2
            if (FastMath.signum(y2) + FastMath.signum(y) == 0.0) {
                x1 = x;
                y1 = y;
            } else {
                x1 = x3;
                x2 = x;
                y1 = y3;
                y2 = y;
            }
        }
        oldx = x;
    }
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:80,代碼來源:RiddersSolver.java

示例2: value

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

示例3: signum

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


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