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


Java FastMath类代码示例

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


FastMath类属于org.apache.commons.math.util包,在下文中一共展示了FastMath类的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: 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


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