• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FastMath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FastMath类属于org.apache.commons.math.util包,在下文中一共展示了FastMath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: testSinFunction

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/**
 * Test of integrator for the sine function.
 */
public void testSinFunction() throws MathException {
    UnivariateRealFunction f = new SinFunction();
    UnivariateRealIntegrator integrator = new SimpsonIntegrator();
    double min, max, expected, result, tolerance;

    min = 0; max = FastMath.PI; expected = 2;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(f, min, max);
    assertEquals(expected, result, tolerance);

    min = -FastMath.PI/3; max = 0; expected = -0.5;
    tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
    result = integrator.integrate(f, min, max);
    assertEquals(expected, result, tolerance);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:SimpsonIntegratorTest.java


示例6: converged

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/**
 * Check if the optimization algorithm has converged considering the
 * last two points.
 * This method may be called several time from the same algorithm
 * iteration with different points. This can be detected by checking the
 * iteration number at each call if needed. Each time this method is
 * called, the previous and current point correspond to points with the
 * same role at each iteration, so they can be compared. As an example,
 * simplex-based algorithms call this method for all points of the simplex,
 * not only for the best or worst ones.
 *
 * @param iteration Index of current iteration
 * @param previous Best point in the previous iteration.
 * @param current Best point in the current iteration.
 * @return {@code true} if the algorithm has converged.
 */
@Override
public boolean converged(final int iteration,
                         final VectorialPointValuePair previous,
                         final VectorialPointValuePair current) {
    final double[] p = previous.getValueRef();
    final double[] c = current.getValueRef();
    for (int i = 0; i < p.length; ++i) {
        final double pi         = p[i];
        final double ci         = c[i];
        final double difference = FastMath.abs(pi - ci);
        final double size       = FastMath.max(FastMath.abs(pi), FastMath.abs(ci));
        if (difference > size * getRelativeThreshold() &&
            difference > getAbsoluteThreshold()) {
            return false;
        }
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:SimpleVectorialValueChecker.java


示例7: testMath341

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/**
 * tests the firstDerivative function by comparison
 *
 * <p>This will test the functions
 * <tt>f(x) = x^3 - 2x^2 + 6x + 3, g(x) = 3x^2 - 4x + 6</tt>
 * and <tt>h(x) = 6x - 4</tt>
 */
@Test
public void testMath341() {
    double[] f_coeff = { 3, 6, -2, 1 };
    double[] g_coeff = { 6, -4, 3 };
    double[] h_coeff = { -4, 6 };

    PolynomialFunction f = new PolynomialFunction(f_coeff);
    PolynomialFunction g = new PolynomialFunction(g_coeff);
    PolynomialFunction h = new PolynomialFunction(h_coeff);

    // compare f' = g
    Assert.assertEquals(f.derivative().value(0), g.value(0), tolerance);
    Assert.assertEquals(f.derivative().value(1), g.value(1), tolerance);
    Assert.assertEquals(f.derivative().value(100), g.value(100), tolerance);
    Assert.assertEquals(f.derivative().value(4.1), g.value(4.1), tolerance);
    Assert.assertEquals(f.derivative().value(-3.25), g.value(-3.25), tolerance);

    // compare g' = h
    Assert.assertEquals(g.derivative().value(FastMath.PI), h.value(FastMath.PI), tolerance);
    Assert.assertEquals(g.derivative().value(FastMath.E),  h.value(FastMath.E),  tolerance);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:PolynomialFunctionTest.java


示例8: walkInOptimizedOrder

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor) {
    visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
    int blockIndex = 0;
    for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
        final int pStart = iBlock * BLOCK_SIZE;
        final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows);
        for (int jBlock = 0; jBlock < blockColumns; ++jBlock) {
            final int qStart = jBlock * BLOCK_SIZE;
            final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns);
            final double[] block = blocks[blockIndex];
            int k = 0;
            for (int p = pStart; p < pEnd; ++p) {
                for (int q = qStart; q < qEnd; ++q) {
                    block[k] = visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
            ++blockIndex;
        }
    }
    return visitor.end();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:BlockRealMatrix.java


示例9: getR

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/** {@inheritDoc} */
public RealMatrix getR() {

    if (cachedR == null) {

        // R is supposed to be m x n
        final int n = qrt.length;
        final int m = qrt[0].length;
        cachedR = MatrixUtils.createRealMatrix(m, n);

        // copy the diagonal from rDiag and the upper triangle of qr
        for (int row = FastMath.min(m, n) - 1; row >= 0; row--) {
            cachedR.setEntry(row, row, rDiag[row]);
            for (int col = row + 1; col < n; col++) {
                cachedR.setEntry(row, col, qrt[col][row]);
            }
        }
    }

    // return the cached matrix
    return cachedR;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:QRDecompositionImpl.java


示例10: testBackward

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

    TestProblem5 pb = new TestProblem5();
    double step = FastMath.abs(pb.getFinalTime() - pb.getInitialTime()) * 0.001;

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

    Assert.assertTrue(handler.getLastError() < 5.0e-10);
    Assert.assertTrue(handler.getMaximalValueError() < 7.0e-10);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-12);
    Assert.assertEquals("3/8", integ.getName());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:ThreeEighthesIntegratorTest.java


示例11: testNoError

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
@Test
public void testNoError() {
    final double a = 0.2;
    final double w = 3.4;
    final double p = 4.1;
    HarmonicOscillator f = new HarmonicOscillator(a, w, p);

    HarmonicFitter fitter =
        new HarmonicFitter(new LevenbergMarquardtOptimizer());
    for (double x = 0.0; x < 1.3; x += 0.01) {
        fitter.addObservedPoint(1, x, f.value(x));
    }

    final double[] fitted = fitter.fit();
    Assert.assertEquals(a, fitted[0], 1.0e-13);
    Assert.assertEquals(w, fitted[1], 1.0e-13);
    Assert.assertEquals(p, MathUtils.normalizeAngle(fitted[2], p), 1e-13);

    HarmonicOscillator ff = new HarmonicOscillator(fitted[0], fitted[1], fitted[2]);

    for (double x = -1.0; x < 1.0; x += 0.01) {
        Assert.assertTrue(FastMath.abs(f.value(x) - ff.value(x)) < 1e-13);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:HarmonicFitterTest.java


示例12: testContains

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
@Test
public void testContains() {
    Vector3D p1 = new Vector3D(0, 0, 1);
    Line l = new Line(p1, new Vector3D(0, 0, 1));
    Assert.assertTrue(l.contains(p1));
    Assert.assertTrue(l.contains(new Vector3D(1.0, p1, 0.3, l.getDirection())));
    Vector3D u = l.getDirection().orthogonal();
    Vector3D v = Vector3D.crossProduct(l.getDirection(), u);
    for (double alpha = 0; alpha < 2 * FastMath.PI; alpha += 0.3) {
        Assert.assertTrue(! l.contains(p1.add(new Vector3D(FastMath.cos(alpha), u,
                                                           FastMath.sin(alpha), v))));
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:LineTest.java


示例13: isSymmetric

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/**
 * Check if a matrix is symmetric.
 *
 * @param matrix Matrix to check.
 * @param raiseException If {@code true}, the method will throw an
 * exception if {@code matrix} is not symmetric.
 * @return {@code true} if {@code matrix} is symmetric.
 * @throws NonSymmetricMatrixException if the matrix is not symmetric and
 * {@code raiseException} is {@code true}.
 */
private boolean isSymmetric(final RealMatrix matrix,
                            boolean raiseException) {
    final int rows = matrix.getRowDimension();
    final int columns = matrix.getColumnDimension();
    final double eps = 10 * rows * columns * MathUtils.EPSILON;
    for (int i = 0; i < rows; ++i) {
        for (int j = i + 1; j < columns; ++j) {
            final double mij = matrix.getEntry(i, j);
            final double mji = matrix.getEntry(j, i);
            if (FastMath.abs(mij - mji) >
                (FastMath.max(FastMath.abs(mij), FastMath.abs(mji)) * eps)) {
                if (raiseException) {
                    throw new NonSymmetricMatrixException(i, j, eps);
                }
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:EigenDecompositionImpl.java


示例14: walkInRowOrder

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor) {
    visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
    for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
        final int pStart = iBlock * BLOCK_SIZE;
        final int pEnd = FastMath.min(pStart + BLOCK_SIZE, rows);
        for (int p = pStart; p < pEnd; ++p) {
            for (int jBlock = 0; jBlock < blockColumns; ++jBlock) {
                final int jWidth = blockWidth(jBlock);
                final int qStart = jBlock * BLOCK_SIZE;
                final int qEnd = FastMath.min(qStart + BLOCK_SIZE, columns);
                final double[] block = blocks[iBlock * blockColumns + jBlock];
                int k = (p - pStart) * jWidth;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
         }
    }
    return visitor.end();
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:BlockRealMatrix.java


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


示例16: getFrobeniusNorm

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/** {@inheritDoc} */
public double getFrobeniusNorm() {
    return walkInOptimizedOrder(new RealMatrixPreservingVisitor() {

        /** Sum of squared entries. */
        private double sum;

        /** {@inheritDoc} */
        public void start(final int rows, final int columns,
                          final int startRow, final int endRow,
                          final int startColumn, final int endColumn) {
            sum = 0;
        }

        /** {@inheritDoc} */
        public void visit(final int row, final int column, final double value) {
            sum += value * value;
        }

        /** {@inheritDoc} */
        public double end() {
            return FastMath.sqrt(sum);
        }
    });
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:AbstractRealMatrix.java


示例17: backward

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

    TestProblem5 pb = new TestProblem5();
    double range = FastMath.abs(pb.getFinalTime() - pb.getInitialTime());

    FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, 0, range, 1.0e-12, 1.0e-12);
    TestProblemHandler handler = new TestProblemHandler(pb, integ);
    integ.addStepHandler(handler);
    integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
                    pb.getFinalTime(), new double[pb.getDimension()]);

    Assert.assertTrue(handler.getLastError() < 1.5e-8);
    Assert.assertTrue(handler.getMaximalValueError() < 1.5e-8);
    Assert.assertEquals(0, handler.getMaximalTimeError(), 1.0e-16);
    Assert.assertEquals("Adams-Bashforth", integ.getName());
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:AdamsBashforthIntegratorTest.java


示例18: testParseBig

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
public void testParseBig() throws ParseException {
    BigFraction f1 =
        improperFormat.parse("167213075789791382630275400487886041651764456874403" +
                             " / " +
                             "53225575123090058458126718248444563466137046489291");
    assertEquals(FastMath.PI, f1.doubleValue(), 0.0);
    BigFraction f2 =
        properFormat.parse("3 " +
                           "7536350420521207255895245742552351253353317406530" +
                           " / " +
                           "53225575123090058458126718248444563466137046489291");
    assertEquals(FastMath.PI, f2.doubleValue(), 0.0);
    assertEquals(f1, f2);
    BigDecimal pi =
        new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068");
    assertEquals(pi, f1.bigDecimalValue(99, BigDecimal.ROUND_HALF_EVEN));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:BigFractionFormatTest.java


示例19: getNextValue

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
/**
 * Generates a random value from this distribution.
 *
 * @return the random value.
 * @throws IllegalStateException if the distribution has not been loaded
 */
public double getNextValue() throws IllegalStateException {

    if (!loaded) {
        throw MathRuntimeException.createIllegalStateException(LocalizedFormats.DISTRIBUTION_NOT_LOADED);
    }

    // Start with a uniformly distributed random number in (0,1)
    double x = FastMath.random();

    // Use this to select the bin and generate a Gaussian within the bin
    for (int i = 0; i < binCount; i++) {
       if (x <= upperBounds[i]) {
           SummaryStatistics stats = binStats.get(i);
           if (stats.getN() > 0) {
               if (stats.getStandardDeviation() > 0) {  // more than one obs
                    return randomData.nextGaussian
                        (stats.getMean(),stats.getStandardDeviation());
               } else {
                   return stats.getMean(); // only one obs in bin
               }
           }
       }
    }
    throw new MathRuntimeException(LocalizedFormats.NO_BIN_SELECTED);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:EmpiricalDistributionImpl.java


示例20: testExactIntegration

import org.apache.commons.math.util.FastMath; //导入依赖的package包/类
@Test
public void testExactIntegration()
    throws ConvergenceException, MathUserException {
    Random random = new Random(86343623467878363l);
    for (int n = 2; n < 6; ++n) {
        LegendreGaussIntegrator integrator =
            new LegendreGaussIntegrator(n, 64);

        // an n points Gauss-Legendre integrator integrates 2n-1 degree polynoms exactly
        for (int degree = 0; degree <= 2 * n - 1; ++degree) {
            for (int i = 0; i < 10; ++i) {
                double[] coeff = new double[degree + 1];
                for (int k = 0; k < coeff.length; ++k) {
                    coeff[k] = 2 * random.nextDouble() - 1;
                }
                PolynomialFunction p = new PolynomialFunction(coeff);
                double result    = integrator.integrate(p, -5.0, 15.0);
                double reference = exactIntegration(p, -5.0, 15.0);
                Assert.assertEquals(n + " " + degree + " " + i, reference, result, 1.0e-12 * (1.0 + FastMath.abs(reference)));
            }
        }

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LatticeViewer类代码示例发布时间:2022-05-23
下一篇:
Java DragEditPartsTrackerEx类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap