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


Java FastMath.pow方法代码示例

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


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

示例1: SimpleNoiseDistribution

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param peakList the peak list
 * 
 * @throws MathException thrown if a math error occurs
 */
public SimpleNoiseDistribution(HashMap<Double, Peak> peakList) throws MathException {

    ArrayList<Double> intensitiesLog = new ArrayList<Double>(peakList.size());
    for (Peak peak : peakList.values()) {
        double log = FastMath.log10(peak.intensity);
        intensitiesLog.add(log);
    }
    Collections.sort(intensitiesLog);
    intensityLogDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistributionFromSortedList(intensitiesLog);

    orderedBins = new int[nBins - 1];
    pLog = new double[nBins - 1];
    binSize = 1.0 / nBins;

    for (int i = 1; i < nBins; i++) {
        double p = binSize * i;
        double x = intensityLogDistribution.getValueAtDescendingCumulativeProbability(p);
        orderedBins[i - 1] = (int) FastMath.pow(10, x);
        pLog[i - 1] = FastMath.log10(p);
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:29,代码来源:SimpleNoiseDistribution.java

示例2: getAssumptionFromLine

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns a Peptide Assumption from an Andromeda line.
 *
 * @param line the line to parse
 * @param rank the rank of the assumption
 *
 * @return the corresponding assumption
 */
private PeptideAssumption getAssumptionFromLine(String line, int rank) {

    String[] temp = line.trim().split("\t");

    String[] temp1 = temp[4].split(",");
    ArrayList<ModificationMatch> modMatches = new ArrayList<ModificationMatch>();

    for (int aa = 0; aa < temp1.length; aa++) {
        String mod = temp1[aa];
        if (!mod.equals("A")) {
            modMatches.add(new ModificationMatch(mod, true, aa));
        }
    }

    String sequence = temp[0];
    Peptide peptide = new Peptide(sequence, modMatches, true);

    Charge charge = new Charge(Charge.PLUS, new Integer(temp[6]));
    Double score = new Double(temp[1]);
    Double p = FastMath.pow(10, -(score / 10));
    PeptideAssumption peptideAssumption = new PeptideAssumption(peptide, rank, Advocate.andromeda.getIndex(), charge, p, fileName);
    peptideAssumption.setRawScore(score);
    return peptideAssumption;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:33,代码来源:AndromedaIdfileReader.java

示例3: testLn

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Tests the ln function
 */
public void testLn() {

    for (int i = -100; i <= 100; i++) {
        double x = FastMath.pow(10, i);
        double fastMathResult = FastMath.log(x);
        BigDecimal fastMathResultBD = new BigDecimal(fastMathResult);

        BigDecimal xBD = new BigDecimal(x);
        BigDecimal utilitiesResult = BigFunctions.ln(xBD, mathContext);

        BigDecimal error = utilitiesResult.subtract(fastMathResultBD);

        Assert.assertEquals(-1, error.abs().compareTo(tolerance));
    }

}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:20,代码来源:TestBigFunctions.java

示例4: testLnBD

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Tests the lnBD function
 */
public void testLnBD() {

    for (int i = -100; i <= 100; i++) {
        double x = FastMath.pow(10, i);
        double fastMathResult = FastMath.log(x);
        BigDecimal fastMathResultBD = new BigDecimal(fastMathResult);

        BigDecimal xDB = new BigDecimal(x);
        BigDecimal utilitiesResult = BigFunctions.lnBD(xDB, mathContext);

        BigDecimal error = utilitiesResult.subtract(fastMathResultBD);

        Assert.assertEquals(-1, error.abs().compareTo(tolerance));
    }

}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:20,代码来源:TestBigFunctions.java

示例5: testGradientComponent1Component2Component3

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testGradientComponent1Component2Component3() {
    final double m = 1.2;
    final double k = 3.4;
    final double a = 2.3;
    final double b = 0.567;
    final double q = 1 / FastMath.exp(b * m);
    final double n = 3.4;

    final Logistic.Parametric f = new Logistic.Parametric();
    
    final double x = 0;
    final double qExp1 = 2;

    final double[] gf = f.gradient(x, new double[] {k, m, b, q, a, n});

    final double factor = (a - k) / (n * FastMath.pow(qExp1, 1 / n + 1));
    Assert.assertEquals(factor * b, gf[1], EPS);
    Assert.assertEquals(factor * m, gf[2], EPS);
    Assert.assertEquals(factor / q, gf[3], EPS);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:LogisticTest.java

示例6: ln

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the natural logarithm of a big decimal. FastMath method is used
 * when possible. Results are not rounded.
 *
 * @param bigDecimal the big decimal to estimate the log on
 * @param mathContext the math context to use for the calculation
 *
 * @return the log of a big decimal
 */
public static BigDecimal ln(BigDecimal bigDecimal, MathContext mathContext) {
    if (bigDecimal.compareTo(BigDecimal.ZERO) != 1) {
        throw new IllegalArgumentException("Attempting to estimate the log of 0.");
    } else if (bigDecimal.compareTo(BigDecimal.ONE) == 0) {
        // log(1)=0
        return BigDecimal.ZERO;
    } else if (bigDecimal.compareTo(BigMathUtils.E) == 0) {
        // log(1)=0
        return BigDecimal.ZERO;
    }

    int precision = mathContext.getPrecision();
    boolean inRange = false;
    double deltaInf = FastMath.pow(10, -precision - 1); // one order of magnitude as margin
    if (precision < 300) {
        double deltaSup = FastMath.pow(10, -precision + 1);
        // try to find the range where FastMath methods can be used
        if (bigDecimal.compareTo(BigDecimal.ONE) == 1) {
            BigDecimal maxValue = new BigDecimal(Double.MAX_VALUE * (1 - deltaSup));
            if (bigDecimal.compareTo(maxValue) == -1) {
                inRange = true;
            }
        } else {
            BigDecimal minValue = new BigDecimal(Double.MIN_NORMAL * (1 + deltaSup));
            if (bigDecimal.compareTo(minValue) == 1) {
                inRange = true;
            }
        }
    }
    if (inRange) {
        double doubleValue = bigDecimal.doubleValue();
        double log = FastMath.log(doubleValue);
        double resolution = Math.abs(FastMath.pow(2, -60) / log);
        if (resolution < deltaInf) {
            return new BigDecimal(log);
        }
    }
    return lnBD(bigDecimal, mathContext);
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:49,代码来源:BigFunctions.java

示例7: evaluate

import org.apache.commons.math.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 IllegalArgumentException 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) {
    // 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:SpoonLabs,项目名称:astor,代码行数:51,代码来源:Kurtosis.java

示例8: inverseCumulativeProbability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For this distribution, {@code X}, this method returns the critical
 * point {@code x}, such that {@code P(X < x) = p}.
 * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and
 * {@code Double.POSITIVE_INFINITY} when p = 1.
 *
 * @param p Desired probability.
 * @return {@code x}, such that {@code P(X < x) = p}.
 * @throws OutOfRangeException if {@code p} is not a valid probability.
 */
@Override
public double inverseCumulativeProbability(double p) {
    double ret;
    if (p < 0.0 || p > 1.0) {
        throw new OutOfRangeException(p, 0.0, 1.0);
    } else if (p == 0) {
        ret = 0.0;
    } else  if (p == 1) {
        ret = Double.POSITIVE_INFINITY;
    } else {
        ret = scale * FastMath.pow(-FastMath.log(1.0 - p), 1.0 / shape);
    }
    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:WeibullDistributionImpl.java

示例9: probability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For this distribution, {@code X}, this method returns {@code P(X = x)}.
 *
 * @param x Value at which the PMF is evaluated.
 * @return PMF for this distribution.
 */
public double probability(int x) {
    double ret;
    if (x < 0) {
        ret = 0.0;
    } else {
        ret = MathUtils.binomialCoefficientDouble(x +
              numberOfSuccesses - 1, numberOfSuccesses - 1) *
              FastMath.pow(probabilityOfSuccess, numberOfSuccesses) *
              FastMath.pow(1.0 - probabilityOfSuccess, x);
    }
    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:PascalDistributionImpl.java

示例10: probability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * The probability mass function {@code P(X = x)} for a Zipf distribution.
 *
 * @param x Value at which the probability density function is evaluated.
 * @return the value of the probability mass function at {@code x}.
 */
public double probability(final int x) {
    if (x <= 0 || x > numberOfElements) {
        return 0.0;
    }

    return (1.0 / FastMath.pow(x, exponent)) / generalizedHarmonic(numberOfElements, exponent);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:ZipfDistributionImpl.java

示例11: testIncreasingTolerance

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testIncreasingTolerance()
  throws MathUserException, IntegratorException {

  int previousCalls = Integer.MAX_VALUE;
  AdaptiveStepsizeIntegrator integ =
      new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY,
                                     Double.NaN, Double.NaN);
  for (int i = -12; i < -2; ++i) {
    TestProblem1 pb = new TestProblem1();
    double minStep = 0;
    double maxStep = pb.getFinalTime() - pb.getInitialTime();
    double scalAbsoluteTolerance = FastMath.pow(10.0, i);
    double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;
    integ.setStepSizeControl(minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance);

    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    // the 1.3 factor is only valid for this test
    // and has been obtained from trial and error
    // there is no general relation between local and global errors
    Assert.assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

    int calls = pb.getCalls();
    Assert.assertEquals(integ.getEvaluations(), calls);
    Assert.assertTrue(calls <= previousCalls);
    previousCalls = calls;

  }

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

示例12: computeInterpolatedStateAndDerivatives

import org.apache.commons.math.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:SpoonLabs,项目名称:astor,代码行数:33,代码来源:NordsieckStepInterpolator.java

示例13: density

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    if (x < 0) {
        return 0;
    }
    return FastMath.pow(x / beta, alpha - 1) / beta *
           FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:GammaDistributionImpl.java

示例14: testIncreasingTolerance

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testIncreasingTolerance()
  throws MathUserException, IntegratorException {

  int previousCalls = Integer.MAX_VALUE;
  for (int i = -12; i < -2; ++i) {
    TestProblem1 pb = new TestProblem1();
    double minStep = 0;
    double maxStep = pb.getFinalTime() - pb.getInitialTime();
    double scalAbsoluteTolerance = FastMath.pow(10.0, i);
    double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

    FirstOrderIntegrator integ = new HighamHall54Integrator(minStep, maxStep,
                                                            scalAbsoluteTolerance,
                                                            scalRelativeTolerance);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb,
                    pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    // the 1.3 factor is only valid for this test
    // and has been obtained from trial and error
    // there is no general relation between local and global errors
    Assert.assertTrue(handler.getMaximalValueError() < (1.3 * scalAbsoluteTolerance));
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);

    int calls = pb.getCalls();
    Assert.assertEquals(integ.getEvaluations(), calls);
    Assert.assertTrue(calls <= previousCalls);
    previousCalls = calls;

  }

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

示例15: testIncreasingTolerance

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testIncreasingTolerance()
    throws MathUserException, IntegratorException {

    int previousCalls = Integer.MAX_VALUE;
    for (int i = -12; i < -5; ++i) {
        TestProblem1 pb = new TestProblem1();
        double minStep = 0;
        double maxStep = pb.getFinalTime() - pb.getInitialTime();
        double scalAbsoluteTolerance = FastMath.pow(10.0, i);
        double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance;

        FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, minStep, maxStep,
                                                                  scalAbsoluteTolerance,
                                                                  scalRelativeTolerance);
        TestProblemHandler handler = new TestProblemHandler(pb, integ);
        integ.addStepHandler(handler);
        integ.integrate(pb,
                        pb.getInitialTime(), pb.getInitialState(),
                        pb.getFinalTime(), new double[pb.getDimension()]);

        // the 31 and 36 factors are only valid for this test
        // and has been obtained from trial and error
        // there is no general relation between local and global errors
        assertTrue(handler.getMaximalValueError() > (31.0 * scalAbsoluteTolerance));
        assertTrue(handler.getMaximalValueError() < (36.0 * scalAbsoluteTolerance));
        assertEquals(0, handler.getMaximalTimeError(), 1.0e-16);

        int calls = pb.getCalls();
        assertEquals(integ.getEvaluations(), calls);
        assertTrue(calls <= previousCalls);
        previousCalls = calls;

    }

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


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