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


Java FastMath.pow方法代码示例

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


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

示例1: integrate

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Calculate defined integral
 */
public ValueType integrate(int significantDigits, CalculatedValue outValue) throws CancelException
{
    final double absoluteAccuracy = FastMath.pow(10, -1.0 * significantDigits);
    final IntermediateValue re = integrateSimpsons(CalculatedValue.PartType.RE, minValue.getReal(),
            maxValue.getReal(), absoluteAccuracy);
    if (Double.isNaN(re.value))
    {
        return outValue.invalidate(CalculatedValue.ErrorType.NOT_A_NUMBER);
    }
    if (re.complexDetected)
    {
        final IntermediateValue im = integrateSimpsons(CalculatedValue.PartType.IM, minValue.getReal(),
                maxValue.getReal(), absoluteAccuracy);
        return outValue.setComplexValue(re.value, im.value);
    }
    else
    {
        return outValue.setValue(re.value);
    }
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:24,代码来源:FormulaTermLoop.java

示例2: powArray

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
public static double[] powArray(double a[],double pow){
	double[]  apow=new double[a.length];
	for(int i=0;i<a.length;i++){
		apow[i]=FastMath.pow(a[i], pow);
	}
	return apow;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:8,代码来源:MathUtil.java

示例3: powValue2Coeffs

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * 
 * @param val
 * @param pows
 * @return
 */
public static double[] powValue2Coeffs(double val,int pows[]){
	double[]  apow=new double[pows.length];
	for(int i=0;i<pows.length;i++){
		apow[i]=FastMath.pow(val, pows[i]);
	}
	return apow;
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:14,代码来源:MathUtil.java

示例4: hermiteMatrix

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * 
 * @param nPoint
 * @return
 */
public static double[][] hermiteMatrix(int nPoint){
	int np=2*nPoint-1;
	
	List<double[]>matrix=new ArrayList<double[]>();
	
	//loop on rows
	for(int idx=0;idx<=np;idx+=2){
		double row1[]=new double[(np+1)];
		double row2[]=new double[(np+1)];
		
		//loops on columns
		for(int val=np;val>=0;val--){
		  //first two rows contains 1 where we have 0^0
			if(idx==0){
				row1[np-val]=FastMath.pow(0,val);
				row2[np-val]=FastMath.pow(0,FastMath.abs(val-1));
			}
			//
			else{
				int k=idx/2;
				row1[np-val]=FastMath.pow(k,val);
				row2[np-val]=val*FastMath.pow(k,val-1);
			}	
		}
		matrix.add(row1);
		matrix.add(row2);
	}	
	return  (double[][])matrix.toArray(new double[0][]);
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:35,代码来源:HermiteInterpolation.java

示例5: createRadialPolynomial

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Creates and returns a new radial polynomial (R_nm) given two moments.
 *
 * @param n 1st moment (order) of the radial polynomial.
 * @param m 2nd moment (repetition) of the radial polynomial.
 * @return PolynomialFunction representing R_nm
 * @throws ArithmeticException If orders are to large and calculation of binomial coefficients fail.
 */
public static PolynomialFunction createRadialPolynomial(final int n, int m) {
    m = Math.abs(m); /* Make sure that m is positive. */
    String id = n + "-" + m; /* Construct ID for cache lookup. */

    /* Try to retrieve the function from cache. */
    if (RADIAL_FUNCTION_CACHE.containsKey(id)) {
        return RADIAL_FUNCTION_CACHE.get(id);
    }

    /* Initialize coefficients. */
    double[] coefficients = new double[n + 1];

    /* Now check if Polynomial 0 (for n-|m| = odd) .*/
    if ((n - m) % 2 != 0) {
      return new PolynomialFunction(coefficients); /* If (n-m) != even, return 0 function. */
    }
    int s_max = (n - m) / 2;

    double sign = -1.0;
    for (int s = 0; s <= s_max; ++s) {
        int position = n - 2 * s;
        long a = CombinatoricsUtils.binomialCoefficient(n-s, s);
        long b = CombinatoricsUtils.binomialCoefficient(n-2*s, s_max - s);
        coefficients[position] = (FastMath.pow(sign,s) * a * b);
    }

    PolynomialFunction function = new PolynomialFunction(coefficients);
    RADIAL_FUNCTION_CACHE.put(id, function);
    return function;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:39,代码来源:PolynomialFunctionFactory.java

示例6: createInterval

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double modifiedNumberOfTrials = numberOfTrials + zSquared;
    final double modifiedSuccessesRatio = (1.0 / modifiedNumberOfTrials) * (numberOfSuccesses + 0.5 * zSquared);
    final double difference = z *
                              FastMath.sqrt(1.0 / modifiedNumberOfTrials * modifiedSuccessesRatio *
                                            (1 - modifiedSuccessesRatio));
    return new ConfidenceInterval(modifiedSuccessesRatio - difference, modifiedSuccessesRatio + difference,
                                  confidenceLevel);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:16,代码来源:AgrestiCoullInterval.java

示例7: GammaDistribution

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Creates a Gamma distribution.
 *
 * @param rng Random number generator.
 * @param shape the shape parameter
 * @param scale the scale parameter
 * @param inverseCumAccuracy the maximum absolute error in inverse
 * cumulative probability estimates (defaults to
 * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 * @since 3.1
 */
public GammaDistribution(RandomGenerator rng,
                         double shape,
                         double scale,
                         double inverseCumAccuracy)
    throws NotStrictlyPositiveException {
    super(rng);

    if (shape <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape);
    }
    if (scale <= 0) {
        throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale);
    }

    this.shape = shape;
    this.scale = scale;
    this.solverAbsoluteAccuracy = inverseCumAccuracy;
    this.shiftedShape = shape + Gamma.LANCZOS_G + 0.5;
    final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape);
    this.densityPrefactor2 = shape * FastMath.sqrt(aux) / Gamma.lanczos(shape);
    this.logDensityPrefactor2 = FastMath.log(shape) + 0.5 * FastMath.log(aux) -
                                FastMath.log(Gamma.lanczos(shape));
    this.densityPrefactor1 = this.densityPrefactor2 / scale *
            FastMath.pow(shiftedShape, -shape) *
            FastMath.exp(shape + Gamma.LANCZOS_G);
    this.logDensityPrefactor1 = this.logDensityPrefactor2 - FastMath.log(scale) -
            FastMath.log(shiftedShape) * shape +
            shape + Gamma.LANCZOS_G;
    this.minY = shape + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE);
    this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:45,代码来源:GammaDistribution.java

示例8: rootN

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public SparseGradient rootN(final int n) {
    if (n == 2) {
        return sqrt();
    } else if (n == 3) {
        return cbrt();
    } else {
        final double root = FastMath.pow(value, 1.0 / n);
        return new SparseGradient(root, 1.0 / (n * FastMath.pow(root, n - 1)), derivatives);
    }
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:12,代码来源:SparseGradient.java

示例9: density

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double density(final double[] vals) throws DimensionMismatchException {
    final int dim = getDimension();
    if (vals.length != dim) {
        throw new DimensionMismatchException(vals.length, dim);
    }

    return FastMath.pow(2 * FastMath.PI, -0.5 * dim) *
        FastMath.pow(covarianceMatrixDeterminant, -0.5) *
        getExponentTerm(vals);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:12,代码来源:MultivariateNormalDistribution.java

示例10: pow

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** Compute power of a double to a derivative structure.
 * @param a number to exponentiate
 * @param operand array holding the power
 * @param operandOffset offset of the power in its array
 * @param result array where result must be stored (for
 * power the result array <em>cannot</em> be the input
 * array)
 * @param resultOffset offset of the result in its array
 * @since 3.3
 */
public void pow(final double a,
                final double[] operand, final int operandOffset,
                final double[] result, final int resultOffset) {

    // create the function value and derivatives
    // [a^x, ln(a) a^x, ln(a)^2 a^x,, ln(a)^3 a^x, ... ]
    final double[] function = new double[1 + order];
    if (a == 0) {
        if (operand[operandOffset] == 0) {
            function[0] = 1;
            double infinity = Double.POSITIVE_INFINITY;
            for (int i = 1; i < function.length; ++i) {
                infinity = -infinity;
                function[i] = infinity;
            }
        } else if (operand[operandOffset] < 0) {
            Arrays.fill(function, Double.NaN);
        }
    } else {
        function[0] = FastMath.pow(a, operand[operandOffset]);
        final double lnA = FastMath.log(a);
        for (int i = 1; i < function.length; ++i) {
            function[i] = lnA * function[i - 1];
        }
    }


    // apply function composition
    compose(operand, operandOffset, function, result, resultOffset);

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:42,代码来源:DSCompiler.java

示例11: evaluate

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the kurtosis of the entries in the specified portion of the
 * input array.
 * <p>
 * See {@link Kurtosis} for details on the computing algorithm.</p>
 * <p>
 * Throws <code>IllegalArgumentException</code> if the array is null.</p>
 *
 * @param values the input array
 * @param begin index of the first array element to include
 * @param length the number of elements to include
 * @return the kurtosis of the values or Double.NaN if length is less than 4
 * @throws MathIllegalArgumentException if the input array is null or the array
 * index parameters are not valid
 */
@Override
public double evaluate(final double[] values,final int begin, final int length)
throws MathIllegalArgumentException {
    // Initialize the kurtosis
    double kurt = Double.NaN;

    if (test(values, begin, length) && length > 3) {

        // Compute the mean and standard deviation
        Variance variance = new Variance();
        variance.incrementAll(values, begin, length);
        double mean = variance.moment.m1;
        double stdDev = FastMath.sqrt(variance.getResult());

        // Sum the ^4 of the distance from the mean divided by the
        // standard deviation
        double accum3 = 0.0;
        for (int i = begin; i < begin + length; i++) {
            accum3 += FastMath.pow(values[i] - mean, 4.0);
        }
        accum3 /= FastMath.pow(stdDev, 4.0d);

        // Get N
        double n0 = length;

        double coefficientOne =
            (n0 * (n0 + 1)) / ((n0 - 1) * (n0 - 2) * (n0 - 3));
        double termTwo =
            (3 * FastMath.pow(n0 - 1, 2.0)) / ((n0 - 2) * (n0 - 3));

        // Calculate kurtosis
        kurt = (coefficientOne * accum3) - termTwo;
    }
    return kurt;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:51,代码来源:Kurtosis.java

示例12: nthRoot

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Computes the n-th roots of this complex number.
 * The nth roots are defined by the formula:
 * <pre>
 *  <code>
 *   z<sub>k</sub> = abs<sup>1/n</sup> (cos(phi + 2&pi;k/n) + i (sin(phi + 2&pi;k/n))
 *  </code>
 * </pre>
 * for <i>{@code k=0, 1, ..., n-1}</i>, where {@code abs} and {@code phi}
 * are respectively the {@link #abs() modulus} and
 * {@link #getArgument() argument} of this complex number.
 * <p>
 * If one or both parts of this complex number is NaN, a list with just
 * one element, {@link #NaN} is returned.
 * if neither part is NaN, but at least one part is infinite, the result
 * is a one-element list containing {@link #INF}.
 *
 * @param n Degree of root.
 * @return a List of all {@code n}-th roots of {@code this}.
 * @throws NotPositiveException if {@code n <= 0}.
 * @since 2.0
 */
public List<Complex> nthRoot(int n) throws NotPositiveException {

    if (n <= 0) {
        throw new NotPositiveException(LocalizedFormats.CANNOT_COMPUTE_NTH_ROOT_FOR_NEGATIVE_N,
                                       n);
    }

    final List<Complex> result = new ArrayList<Complex>();

    if (isNaN) {
        result.add(NaN);
        return result;
    }
    if (isInfinite()) {
        result.add(INF);
        return result;
    }

    // nth root of abs -- faster / more accurate to use a solver here?
    final double nthRootOfAbs = FastMath.pow(abs(), 1.0 / n);

    // Compute nth roots of complex number with k = 0, 1, ... n-1
    final double nthPhi = getArgument() / n;
    final double slice = 2 * FastMath.PI / n;
    double innerPart = nthPhi;
    for (int k = 0; k < n ; k++) {
        // inner part
        final double realPart = nthRootOfAbs *  FastMath.cos(innerPart);
        final double imaginaryPart = nthRootOfAbs *  FastMath.sin(innerPart);
        result.add(createComplex(realPart, imaginaryPart));
        innerPart += slice;
    }

    return result;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:58,代码来源:Complex.java

示例13: computeInterpolatedStateAndDerivatives

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected void computeInterpolatedStateAndDerivatives(final double theta, final double oneMinusThetaH) {

    final double x = interpolatedTime - referenceTime;
    final double normalizedAbscissa = x / scalingH;

    Arrays.fill(stateVariation, 0.0);
    Arrays.fill(interpolatedDerivatives, 0.0);

    // apply Taylor formula from high order to low order,
    // for the sake of numerical accuracy
    final double[][] nData = nordsieck.getDataRef();
    for (int i = nData.length - 1; i >= 0; --i) {
        final int order = i + 2;
        final double[] nDataI = nData[i];
        final double power = FastMath.pow(normalizedAbscissa, order);
        for (int j = 0; j < nDataI.length; ++j) {
            final double d = nDataI[j] * power;
            stateVariation[j]          += d;
            interpolatedDerivatives[j] += order * d;
        }
    }

    for (int j = 0; j < currentState.length; ++j) {
        stateVariation[j] += scaled[j] * normalizedAbscissa;
        interpolatedState[j] = currentState[j] + stateVariation[j];
        interpolatedDerivatives[j] =
            (interpolatedDerivatives[j] + scaled[j] * normalizedAbscissa) / x;
    }

}
 
开发者ID:biocompibens,项目名称:SME,代码行数:33,代码来源:NordsieckStepInterpolator.java

示例14: 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

示例15: sample

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double sample()  {
    final double n = random.nextDouble();
    return scale / FastMath.pow(n, 1 / shape);
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:7,代码来源:ParetoDistribution.java


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