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


Java FastMath.max方法代码示例

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


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

示例1: converged

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Check if the optimization algorithm has converged considering the
 * last two points.
 * This method may be called several times 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 arguments satify the convergence criterion.
 */
@Override
public boolean converged(final int iteration,
                         final PointVectorValuePair previous,
                         final PointVectorValuePair current) {
    if (maxIterationCount != ITERATION_CHECK_DISABLED && iteration >= maxIterationCount) {
        return true;
    }

    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:biocompibens,项目名称:SME,代码行数:39,代码来源:SimpleVectorValueChecker.java

示例2: isNonSingular

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Checks whether the decomposed matrix is non-singular.
 *
 * @return true if the decomposed matrix is non-singular.
 */
public boolean isNonSingular() {
    double largestEigenvalueNorm = 0.0;
    // Looping over all values (in case they are not sorted in decreasing
    // order of their norm).
    for (int i = 0; i < realEigenvalues.length; ++i) {
        largestEigenvalueNorm = FastMath.max(largestEigenvalueNorm, eigenvalueNorm(i));
    }
    // Corner case: zero matrix, all exactly 0 eigenvalues
    if (largestEigenvalueNorm == 0.0) {
        return false;
    }
    for (int i = 0; i < realEigenvalues.length; ++i) {
        // Looking for eigenvalues that are 0, where we consider anything much much smaller
        // than the largest eigenvalue to be effectively 0.
        if (Precision.equals(eigenvalueNorm(i) / largestEigenvalueNorm, 0, EPSILON)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:26,代码来源:EigenDecomposition.java

示例3: isSymmetricInternal

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Checks whether a matrix is symmetric, within a given relative tolerance.
 *
 * @param matrix Matrix to check.
 * @param relativeTolerance Tolerance of the symmetry check.
 * @param raiseException If {@code true}, an exception will be raised if
 * the matrix is not symmetric.
 * @return {@code true} if {@code matrix} is symmetric.
 * @throws NonSquareMatrixException if the matrix is not square.
 * @throws NonSymmetricMatrixException if the matrix is not symmetric.
 */
private static boolean isSymmetricInternal(RealMatrix matrix,
                                           double relativeTolerance,
                                           boolean raiseException) {
    final int rows = matrix.getRowDimension();
    if (rows != matrix.getColumnDimension()) {
        if (raiseException) {
            throw new NonSquareMatrixException(rows, matrix.getColumnDimension());
        } else {
            return false;
        }
    }
    for (int i = 0; i < rows; i++) {
        for (int j = i + 1; j < rows; 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)) * relativeTolerance) {
                if (raiseException) {
                    throw new NonSymmetricMatrixException(i, j, relativeTolerance);
                } else {
                    return false;
                }
            }
        }
    }
    return true;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:39,代码来源:MatrixUtils.java

示例4: walkInOptimizedOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor,
                                   final int startRow, final int endRow,
                                   final int startColumn, final int endColumn) {
    checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0     = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd   = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
            final int jWidth = blockWidth(jBlock);
            final int q0     = jBlock * BLOCK_SIZE;
            final int qStart = FastMath.max(startColumn, q0);
            final int qEnd   = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
            final T[] block = blocks[iBlock * blockColumns + jBlock];
            for (int p = pStart; p < pEnd; ++p) {
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
        }
    }
    return visitor.end();
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:29,代码来源:BlockFieldMatrix.java

示例5: TriangularDistribution

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Creates a triangular distribution.
 *
 * @param rng Random number generator.
 * @param a Lower limit of this distribution (inclusive).
 * @param b Upper limit of this distribution (inclusive).
 * @param c Mode of this distribution.
 * @throws NumberIsTooLargeException if {@code a >= b} or if {@code c > b}.
 * @throws NumberIsTooSmallException if {@code c < a}.
 * @since 3.1
 */
public TriangularDistribution(RandomGenerator rng,
                              double a,
                              double c,
                              double b)
    throws NumberIsTooLargeException, NumberIsTooSmallException {
    super(rng);

    if (a >= b) {
        throw new NumberIsTooLargeException(
                        LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND,
                        a, b, false);
    }
    if (c < a) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.NUMBER_TOO_SMALL, c, a, true);
    }
    if (c > b) {
        throw new NumberIsTooLargeException(
                LocalizedFormats.NUMBER_TOO_LARGE, c, b, true);
    }

    this.a = a;
    this.c = c;
    this.b = b;
    solverAbsoluteAccuracy = FastMath.max(FastMath.ulp(a), FastMath.ulp(b));
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:38,代码来源:TriangularDistribution.java

示例6: walkInOptimizedOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor,
                                   final int startRow, final int endRow,
                                   final int startColumn, final int endColumn) {
    MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0 = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
            final int jWidth = blockWidth(jBlock);
            final int q0 = jBlock * BLOCK_SIZE;
            final int qStart = FastMath.max(startColumn, q0);
            final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
            final double[] block = blocks[iBlock * blockColumns + jBlock];
            for (int p = pStart; p < pEnd; ++p) {
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
        }
    }
    return visitor.end();
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:29,代码来源:BlockRealMatrix.java

示例7: calculateMaxMembershipChange

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Calculate the maximum element-by-element change of the membership matrix
 * for the current iteration.
 *
 * @param matrix the membership matrix of the previous iteration
 * @return the maximum membership matrix change
 */
private double calculateMaxMembershipChange(final double[][] matrix) {
    double maxMembership = 0.0;
    for (int i = 0; i < points.size(); i++) {
        for (int j = 0; j < clusters.size(); j++) {
            double v = FastMath.abs(membershipMatrix[i][j] - matrix[i][j]);
            maxMembership = FastMath.max(v, maxMembership);
        }
    }
    return maxMembership;
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:18,代码来源:FuzzyKMeansClusterer.java

示例8: walkInRowOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public T walkInRowOrder(final FieldMatrixPreservingVisitor<T> visitor,
                        final int startRow, final int endRow,
                        final int startColumn, final int endColumn) {
    checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0     = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd   = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int p = pStart; p < pEnd; ++p) {
            for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
                final int jWidth = blockWidth(jBlock);
                final int q0     = jBlock * BLOCK_SIZE;
                final int qStart = FastMath.max(startColumn, q0);
                final int qEnd   = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
                final T[] block = blocks[iBlock * blockColumns + jBlock];
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
         }
    }
    return visitor.end();
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:29,代码来源:BlockFieldMatrix.java

示例9: getLInfNorm

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double getLInfNorm() {
    double max = 0;
    for (double a : data) {
        max = FastMath.max(max, FastMath.abs(a));
    }
    return max;
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:10,代码来源:ArrayRealVector.java

示例10: walkInRowOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
                             final int startRow, final int endRow,
                             final int startColumn, final int endColumn) {
    MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0 = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int p = pStart; p < pEnd; ++p) {
            for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
                final int jWidth = blockWidth(jBlock);
                final int q0 = jBlock * BLOCK_SIZE;
                final int qStart = FastMath.max(startColumn, q0);
                final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
                final double[] block = blocks[iBlock * blockColumns + jBlock];
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
         }
    }
    return visitor.end();
}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:29,代码来源:BlockRealMatrix.java

示例11: walkInOptimizedOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public T walkInOptimizedOrder(final FieldMatrixPreservingVisitor<T> visitor,
                              final int startRow, final int endRow,
                              final int startColumn, final int endColumn)
    throws OutOfRangeException, NumberIsTooSmallException {
    checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0     = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd   = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
            final int jWidth = blockWidth(jBlock);
            final int q0     = jBlock * BLOCK_SIZE;
            final int qStart = FastMath.max(startColumn, q0);
            final int qEnd   = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
            final T[] block = blocks[iBlock * blockColumns + jBlock];
            for (int p = pStart; p < pEnd; ++p) {
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
        }
    }
    return visitor.end();
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:30,代码来源:BlockFieldMatrix.java

示例12: walkInOptimizedOrder

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor,
                                   final int startRow, final int endRow,
                                   final int startColumn,
                                   final int endColumn)
    throws OutOfRangeException, NumberIsTooSmallException {
    MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
    visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
    for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
        final int p0 = iBlock * BLOCK_SIZE;
        final int pStart = FastMath.max(startRow, p0);
        final int pEnd = FastMath.min((iBlock + 1) * BLOCK_SIZE, 1 + endRow);
        for (int jBlock = startColumn / BLOCK_SIZE; jBlock < 1 + endColumn / BLOCK_SIZE; ++jBlock) {
            final int jWidth = blockWidth(jBlock);
            final int q0 = jBlock * BLOCK_SIZE;
            final int qStart = FastMath.max(startColumn, q0);
            final int qEnd = FastMath.min((jBlock + 1) * BLOCK_SIZE, 1 + endColumn);
            final double[] block = blocks[iBlock * blockColumns + jBlock];
            for (int p = pStart; p < pEnd; ++p) {
                int k = (p - p0) * jWidth + qStart - q0;
                for (int q = qStart; q < qEnd; ++q) {
                    block[k] = visitor.visit(p, q, block[k]);
                    ++k;
                }
            }
        }
    }
    return visitor.end();
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:31,代码来源:BlockRealMatrix.java

示例13: Cholesky

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Calculates the Cholesky decomposition of the given matrix.
 * @param matrix the matrix to decompose
 * @param relativeSymmetryThreshold threshold above which off-diagonal
 * elements are considered too different and matrix not symmetric
 * @param absolutePositivityThreshold threshold below which diagonal
 * elements are considered null and matrix not positive definite
 * @throws NonSquareMatrixException if the matrix is not square.
 * @throws NonSymmetricMatrixException if the matrix is not symmetric.
 * @throws NonPositiveDefiniteMatrixException if the matrix is not
 * strictly positive definite.
 * @see #Cholesky(RealMatrix)
 * @see #DEFAULT_RELATIVE_SYMMETRY_THRESHOLD
 * @see #DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD
 */
public Cholesky(final RealMatrix matrix,
                                 final double relativeSymmetryThreshold,
                                 final double absolutePositivityThreshold) {
    if (!matrix.isSquare()) {
        throw new NonSquareMatrixException(matrix.getRowDimension(),
                                           matrix.getColumnDimension());
    }

    final int order = matrix.getRowDimension();
    lTData   = matrix.getData();
    cachedL  = null;
    cachedLT = null;

    // check the matrix before transformation
    for (int i = 0; i < order; ++i) {
        final double[] lI = lTData[i];

        // check off-diagonal elements (and reset them to 0)
        for (int j = i + 1; j < order; ++j) {
            final double[] lJ = lTData[j];
            final double lIJ = lI[j];
            final double lJI = lJ[i];
            final double maxDelta =
                relativeSymmetryThreshold * FastMath.max(FastMath.abs(lIJ), FastMath.abs(lJI));
            if (FastMath.abs(lIJ - lJI) > maxDelta) {
              //double mean = .5*(lIJ+lJI);
              //lTData[j][i] = lTData[i][j] = mean;
              System.out.print("entries: "+lIJ+" "+lJI);
                throw new NonSymmetricMatrixException(i, j, relativeSymmetryThreshold);
            }
            lJ[i] = 0;
       }
    }

    // transform the matrix
    for (int i = 0; i < order; ++i) {

        final double[] ltI = lTData[i];

        // check diagonal element
        if (ltI[i] <= absolutePositivityThreshold) {
            throw new NonPositiveDefiniteMatrixException(ltI[i], i, absolutePositivityThreshold);
        }

        ltI[i] = FastMath.sqrt(ltI[i]);
        final double inverse = 1.0 / ltI[i];

        for (int q = order - 1; q > i; --q) {
            ltI[q] *= inverse;
            final double[] ltQ = lTData[q];
            for (int p = q; p < order; ++p) {
                ltQ[p] -= ltI[q] * ltI[p];
            }
        }
    }
}
 
开发者ID:BigBayes,项目名称:BNPMix.java,代码行数:72,代码来源:Cholesky.java

示例14: run

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
@Override
public void run() {
	mixDens[featureIdx] = new BlockRealMatrix(nBetas,nThetas);
	for(int j = 0; j < nThetas;j++) {
		double theta = thetas.getEntry(j);
		RealVector betaDens = new ArrayRealVector(nBetas);
		for (int k = 0; k < nBetas; k++) {
			double beta = betas.getEntry(k);
			double lowerBound = FastMath.max(0, (beta - 1 + theta) / theta);
			if (Double.isNaN(lowerBound)) lowerBound = 0;
			double upperBound = FastMath.min(1,beta/theta);
			if (Double.isNaN(upperBound)) upperBound = 1;
			double step = (upperBound-lowerBound)/(nPoints-1);
			RealVector dens = new ArrayRealVector(nPoints);
			RealVector points = new ArrayRealVector(nPoints);
			RealVector allTumorDens = new ArrayRealVector(nPoints);
			RealVector allNormalDens = new ArrayRealVector(nPoints);
			RealVector allNormalDensRev = new ArrayRealVector(nPoints);
			// tumor
			for (int l = 0; l < nPoints; l++) {
				double tumorValue = lowerBound + l * step;
				points.setEntry(l, tumorValue);
				if (tumorValue == 0) tumorValue = 0.0001;
				if (tumorValue == 1) tumorValue = 0.9999;
				allTumorDens.setEntry(l,tumorDist.density(tumorValue));
			}
			// adjust the densities
			double calProb = tumorDist.probability(lowerBound,upperBound);
			double estProb = CancerLocator.integSimpson(points,allTumorDens);
			if (estProb!=0)	{
				allTumorDens.mapMultiplyToSelf(calProb/estProb);
			}
			else {
				allTumorDens.mapAddToSelf(1.0/allTumorDens.getDimension());
			}
			// normal
			RealVector normalPoints = new ArrayRealVector(nPoints);
			for (int l = 0; l < nPoints; l++) {
				double normalValue = (beta-theta*points.getEntry(l))/(1-theta);
				normalPoints.setEntry(nPoints-l-1,normalValue);
				if (normalValue == 0) normalValue = 0.0001;
				if (normalValue == 1) normalValue = 0.9999;
				double normalDens = normalDist.density(normalValue);
				allNormalDens.setEntry(l,normalDens);
				allNormalDensRev.setEntry(nPoints-l-1,normalDens);
			}
			calProb = normalDist.probability((beta-theta*upperBound)/(1-theta),(beta-theta*lowerBound)/(1-theta));
			estProb = CancerLocator.integSimpson(normalPoints, allNormalDensRev);
			if (estProb!=0)	{
				allNormalDens.mapMultiplyToSelf(calProb/estProb);
			}
			else {
				allNormalDens.mapAddToSelf(1.0/allNormalDens.getDimension());
			}
			//mixture
			for (int l = 0; l < nPoints; l++) {
				dens.setEntry(l,allTumorDens.getEntry(l)*allNormalDens.getEntry(l));
			}
			betaDens.setEntry(k,CancerLocator.integSimpson(points,dens));
		}
		double normTerm = CancerLocator.integSimpson(betas,betaDens); //normalization term
		if (normTerm!=0) {
			betaDens.mapDivideToSelf(normTerm);
		}
		else {
			betaDens.mapAddToSelf(1.0/betaDens.getDimension());
		}
		mixDens[featureIdx].setColumnVector(j, betaDens);
	}
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:71,代码来源:MixModel.java

示例15: riddersDerivative

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the derivative of a function func at a point x by Ridders’ method of polynomial extrapolation. The
 * value h is input as an estimated initial stepsize; it need not be small, but rather should be an increment in
 * x over which func changes substantially. An estimate of the error in the derivative is returned as err.
 */
IntermediateValue riddersDerivative(CalculatedValue.PartType partType, Complex z, double h)
        throws CancelException
{
    final int NTAB = RIDDER_MAX_ITERATIONS_COUNT;
    final double CON = 1.4;
    final double CON2 = (CON * CON);

    double err = 1.0e30;
    double hh = h;
    double[][] a = new double[NTAB + 1][NTAB + 1];

    final IntermediateValue ans = new IntermediateValue();
    final CalculatedValue leftVal = new CalculatedValue();
    final CalculatedValue rightVal = new CalculatedValue();

    argValue.setComplexValue(z.getReal() + hh, z.getImaginary());
    argTerm.getValue(calculaterTask, leftVal);
    argValue.setComplexValue(z.getReal() - hh, z.getImaginary());
    argTerm.getValue(calculaterTask, rightVal);
    a[1][1] = (leftVal.getPart(partType) - rightVal.getPart(partType)) / (2.0 * hh);
    if (leftVal.isComplex() || rightVal.isComplex())
    {
        ans.complexDetected = true;
    }

    for (int i = 2; i <= NTAB; i++)
    {
        hh /= CON;

        argValue.setComplexValue(z.getReal() + hh, z.getImaginary());
        argTerm.getValue(calculaterTask, leftVal);
        argValue.setComplexValue(z.getReal() - hh, z.getImaginary());
        argTerm.getValue(calculaterTask, rightVal);
        a[1][i] = (leftVal.getPart(partType) - rightVal.getPart(partType)) / (2.0 * hh);
        if (leftVal.isComplex() || rightVal.isComplex())
        {
            ans.complexDetected = true;
        }

        double fac = CON2;
        for (int j = 2; j <= i; j++)
        {
            a[j][i] = (a[j - 1][i] * fac - a[j - 1][i - 1]) / (fac - 1.0);
            fac = CON2 * fac;
            final double errt = FastMath.max(FastMath.abs(a[j][i] - a[j - 1][i]),
                    FastMath.abs(a[j][i] - a[j - 1][i - 1]));
            if (errt <= err)
            {
                err = errt;
                ans.value = a[j][i];
            }
        }
        if (FastMath.abs(a[i][i] - a[i - 1][i - 1]) >= 2.0 * (err))
        {
            break;
        }
    }
    return ans;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:65,代码来源:FormulaTermLoop.java


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