本文整理汇总了Java中org.apache.commons.math3.util.MathUtils类的典型用法代码示例。如果您正苦于以下问题:Java MathUtils类的具体用法?Java MathUtils怎么用?Java MathUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MathUtils类属于org.apache.commons.math3.util包,在下文中一共展示了MathUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logBinomialProbability
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Compute the logarithm of the PMF for a binomial distribution
* using the saddle point expansion.
*
* @param x the value at which the probability is evaluated.
* @param n the number of trials.
* @param p the probability of success.
* @param q the probability of failure (1 - p).
* @return log(p(x)).
*/
static double logBinomialProbability(int x, int n, double p, double q) {
double ret;
if (x == 0) {
if (p < 0.1) {
ret = -getDeviancePart(n, n * q) - n * p;
} else {
ret = n * FastMath.log(q);
}
} else if (x == n) {
if (q < 0.1) {
ret = -getDeviancePart(n, n * p) - n * q;
} else {
ret = n * FastMath.log(p);
}
} else {
ret = getStirlingError(n) - getStirlingError(x) -
getStirlingError(n - x) - getDeviancePart(x, n * p) -
getDeviancePart(n - x, n * q);
double f = (MathUtils.TWO_PI * x * (n - x)) / n;
ret = -0.5 * FastMath.log(f) + ret;
}
return ret;
}
示例2: estimateError
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected T estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {
T error = getField().getZero();
for (int j = 0; j < mainSetDimension; ++j) {
final T errSum = yDotK[0][j].multiply(e1).
add(yDotK[2][j].multiply(e3)).
add(yDotK[3][j].multiply(e4)).
add(yDotK[4][j].multiply(e5)).
add(yDotK[5][j].multiply(e6)).
add(yDotK[6][j].multiply(e7));
final T yScale = MathUtils.max(y0[j].abs(), y1[j].abs());
final T tol = (vecAbsoluteTolerance == null) ?
yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
yScale.multiply(vecRelativeTolerance[j]).add(vecAbsoluteTolerance[j]);
final T ratio = h.multiply(errSum).divide(tol);
error = error.add(ratio.multiply(ratio));
}
return error.divide(mainSetDimension).sqrt();
}
示例3: estimateError
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected T estimateError(final T[][] yDotK, final T[] y0, final T[] y1, final T h) {
T error = getField().getZero();
for (int j = 0; j < mainSetDimension; ++j) {
T errSum = yDotK[0][j].multiply(e[0]);
for (int l = 1; l < e.length; ++l) {
errSum = errSum.add(yDotK[l][j].multiply(e[l]));
}
final T yScale = MathUtils.max(y0[j].abs(), y1[j].abs());
final T tol = (vecAbsoluteTolerance == null) ?
yScale.multiply(scalRelativeTolerance).add(scalAbsoluteTolerance) :
yScale.multiply(vecRelativeTolerance[j]).add(vecAbsoluteTolerance[j]);
final T ratio = h.multiply(errSum).divide(tol);
error = error.add(ratio.multiply(ratio));
}
return error.divide(mainSetDimension).sqrt();
}
示例4: Arc
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** Simple constructor.
* <p>
* If either {@code lower} is equals to {@code upper} or
* the interval exceeds \( 2 \pi \), the arc is considered
* to be the full circle and its initial defining boundaries
* will be forgotten. {@code lower} is not allowed to be
* greater than {@code upper} (an exception is thrown in this case).
* {@code lower} will be canonicalized between 0 and \( 2 \pi \), and
* upper shifted accordingly, so the {@link #getInf()} and {@link #getSup()}
* may not return the value used at instance construction.
* </p>
* @param lower lower angular bound of the arc
* @param upper upper angular bound of the arc
* @param tolerance tolerance below which angles are considered identical
* @exception NumberIsTooLargeException if lower is greater than upper
*/
public Arc(final double lower, final double upper, final double tolerance)
throws NumberIsTooLargeException {
this.tolerance = tolerance;
if (Precision.equals(lower, upper, 0) || (upper - lower) >= MathUtils.TWO_PI) {
// the arc must cover the whole circle
this.lower = 0;
this.upper = MathUtils.TWO_PI;
this.middle = FastMath.PI;
} else if (lower <= upper) {
this.lower = MathUtils.normalizeAngle(lower, FastMath.PI);
this.upper = this.lower + (upper - lower);
this.middle = 0.5 * (this.lower + this.upper);
} else {
throw new NumberIsTooLargeException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL,
lower, upper, true);
}
}
示例5: computeGeometricalProperties
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected void computeGeometricalProperties() {
if (getTree(false).getCut() == null) {
setBarycenter(S1Point.NaN);
setSize(((Boolean) getTree(false).getAttribute()) ? MathUtils.TWO_PI : 0);
} else {
double size = 0.0;
double sum = 0.0;
for (final double[] a : this) {
final double length = a[1] - a[0];
size += length;
sum += length * (a[0] + a[1]);
}
setSize(size);
if (Precision.equals(size, MathUtils.TWO_PI, 0)) {
setBarycenter(S1Point.NaN);
} else if (size >= Precision.SAFE_MIN) {
setBarycenter(new S1Point(sum / (2 * size)));
} else {
final LimitAngle limit = (LimitAngle) getTree(false).getCut().getHyperplane();
setBarycenter(limit.getLocation());
}
}
}
示例6: SubArcsIterator
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** Simple constructor.
*/
SubArcsIterator() {
firstStart = getFirstArcStart();
current = firstStart;
if (firstStart == null) {
// all the leaf tree nodes share the same inside/outside status
if ((Boolean) getFirstLeaf(getTree(false)).getAttribute()) {
// it is an inside node, it represents the full circle
pending = new double[] {
0, MathUtils.TWO_PI
};
} else {
pending = null;
}
} else {
selectPending();
}
}
示例7: anovaStats
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* This method calls the method that actually does the calculations (except
* P-value).
*
* @param categoryData
* <code>Collection</code> of <code>double[]</code> arrays each
* containing data for one category
* @return computed AnovaStats
* @throws NullArgumentException
* if <code>categoryData</code> is <code>null</code>
* @throws DimensionMismatchException
* if the length of the <code>categoryData</code> array is less
* than 2 or a contained <code>double[]</code> array does not
* contain at least two values
*/
private AnovaStats anovaStats(final Collection<double[]> categoryData)
throws NullArgumentException, DimensionMismatchException {
MathUtils.checkNotNull(categoryData);
final Collection<SummaryStatistics> categoryDataSummaryStatistics =
new ArrayList<SummaryStatistics>(categoryData.size());
// convert arrays to SummaryStatistics
for (final double[] data : categoryData) {
final SummaryStatistics dataSummaryStatistics = new SummaryStatistics();
categoryDataSummaryStatistics.add(dataSummaryStatistics);
for (final double val : data) {
dataSummaryStatistics.addValue(val);
}
}
return anovaStats(categoryDataSummaryStatistics, false);
}
示例8: checkParameters
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Performs all dimension checks on the parameters of
* {@link #solve(RealLinearOperator, RealVector, RealVector) solve} and
* {@link #solveInPlace(RealLinearOperator, RealVector, RealVector) solveInPlace},
* and throws an exception if one of the checks fails.
*
* @param a the linear operator A of the system
* @param b the right-hand side vector
* @param x0 the initial guess of the solution
* @throws NullArgumentException if one of the parameters is {@code null}
* @throws NonSquareOperatorException if {@code a} is not square
* @throws DimensionMismatchException if {@code b} or {@code x0} have
* dimensions inconsistent with {@code a}
*/
protected static void checkParameters(final RealLinearOperator a,
final RealVector b, final RealVector x0) throws
NullArgumentException, NonSquareOperatorException,
DimensionMismatchException {
MathUtils.checkNotNull(a);
MathUtils.checkNotNull(b);
MathUtils.checkNotNull(x0);
if (a.getRowDimension() != a.getColumnDimension()) {
throw new NonSquareOperatorException(a.getRowDimension(),
a.getColumnDimension());
}
if (b.getDimension() != a.getRowDimension()) {
throw new DimensionMismatchException(b.getDimension(),
a.getRowDimension());
}
if (x0.getDimension() != a.getColumnDimension()) {
throw new DimensionMismatchException(x0.getDimension(),
a.getColumnDimension());
}
}
示例9: copy
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Copies source to dest.
* <p>Neither source nor dest can be null.</p>
*
* @param source DescriptiveStatistics to copy
* @param dest DescriptiveStatistics to copy to
* @throws NullArgumentException if either source or dest is null
*/
public static void copy(DescriptiveStatistics source, DescriptiveStatistics dest)
throws NullArgumentException {
MathUtils.checkNotNull(source);
MathUtils.checkNotNull(dest);
// Copy data and window size
dest.eDA = source.eDA.copy();
dest.windowSize = source.windowSize;
// Copy implementations
dest.maxImpl = source.maxImpl.copy();
dest.meanImpl = source.meanImpl.copy();
dest.minImpl = source.minImpl.copy();
dest.sumImpl = source.sumImpl.copy();
dest.varianceImpl = source.varianceImpl.copy();
dest.sumsqImpl = source.sumsqImpl.copy();
dest.geometricMeanImpl = source.geometricMeanImpl.copy();
dest.kurtosisImpl = source.kurtosisImpl;
dest.skewnessImpl = source.skewnessImpl;
dest.percentileImpl = source.percentileImpl;
}
示例10: setup
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Prepare for computation.
* Subclasses must call this method if they override any of the
* {@code solve} methods.
*
* @param f Function to solve.
* @param min Lower bound for the interval.
* @param max Upper bound for the interval.
* @param startValue Start value to use.
* @param maxEval Maximum number of evaluations.
* @exception NullArgumentException if f is null
*/
protected void setup(int maxEval,
FUNC f,
double min, double max,
double startValue)
throws NullArgumentException {
// Checks.
MathUtils.checkNotNull(f);
// Reset.
searchMin = min;
searchMax = max;
searchStart = startValue;
function = f;
evaluations = evaluations.withMaximalCount(maxEval).withStart(0);
}
示例11: Array2DRowFieldMatrix
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Create a new {@code FieldMatrix<T>} using the input array as the underlying
* data array.
* <p>If an array is built specially in order to be embedded in a
* {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be
* set to {@code false}. This will prevent the copying and improve
* performance as no new array will be built and no data will be copied.</p>
*
* @param field Field to which the elements belong.
* @param d Data for the new matrix.
* @param copyArray Whether to copy or reference the input array.
* @throws DimensionMismatchException if {@code d} is not rectangular.
* @throws NoDataException if there are not at least one row and one column.
* @throws NullArgumentException if {@code d} is {@code null}.
* @see #Array2DRowFieldMatrix(FieldElement[][])
*/
public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
throws DimensionMismatchException, NoDataException, NullArgumentException {
super(field);
if (copyArray) {
copyIn(d);
} else {
MathUtils.checkNotNull(d);
final int nRows = d.length;
if (nRows == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
}
final int nCols = d[0].length;
if (nCols == 0) {
throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
}
for (int r = 1; r < nRows; r++) {
if (d[r].length != nCols) {
throw new DimensionMismatchException(nCols, d[r].length);
}
}
data = d;
}
}
示例12: differentiate
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* Returns the coefficients of the derivative of the polynomial with the given coefficients.
*
* @param coefficients Coefficients of the polynomial to differentiate.
* @return the coefficients of the derivative or {@code null} if coefficients has length 1.
* @throws NoDataException if {@code coefficients} is empty.
* @throws NullArgumentException if {@code coefficients} is {@code null}.
*/
protected static double[] differentiate(double[] coefficients)
throws NullArgumentException, NoDataException {
MathUtils.checkNotNull(coefficients);
int n = coefficients.length;
if (n == 0) {
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
}
if (n == 1) {
return new double[]{0};
}
double[] result = new double[n - 1];
for (int i = n - 1; i > 0; i--) {
result[i - 1] = i * coefficients[i];
}
return result;
}
示例13: addVariationToIndex
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
public void addVariationToIndex(List<VcfIndexEntry> allEntries, VariantContext context,
Map<String, Chromosome> chromosomeMap,
VcfFilterInfo filterInfo, VCFHeader vcfHeader,
VcfFileReader vcfReader) {
if (chromosomeMap.containsKey(context.getContig())
|| chromosomeMap.containsKey(Utils.changeChromosomeName(context.getContig()))) {
VcfIndexEntry masterEntry = new VcfIndexEntry();
masterEntry.setUuid(UUID.randomUUID());
masterEntry.setFeatureId(context.getID());
masterEntry.setChromosome(Utils.getFromChromosomeMap(chromosomeMap, context.getContig()));
masterEntry.setStartIndex(context.getStart());
masterEntry.setEndIndex(context.getEnd());
masterEntry.setFeatureType(FeatureType.VARIATION);
masterEntry.setInfo(filterInfoByWhiteList(context, filterInfo, vcfHeader));
masterEntry.setVariantContext(context);
double qual = context.getPhredScaledQual();
masterEntry.setQuality(MathUtils.equals(qual, VcfManager.HTSJDK_WRONG_QUALITY) ? 0D : qual);
List<OrganismType> organismTypes = new ArrayList<>();
for (int i = 0; i < context.getAlternateAlleles().size(); i++) {
Variation variation = vcfReader.createVariation(context, vcfHeader, i);
organismTypes.add(variation.getGenotypeData().getOrganismType());
}
if (organismTypes.size() == 1 && organismTypes.get(0) == OrganismType.NO_VARIATION) { // We don't add
// NO_VARIATION variations to index
return;
}
allEntries.add(masterEntry);
}
}
示例14: solve
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @throws NonSelfAdjointOperatorException if {@link #getCheck()} is
* {@code true}, and {@code a} is not self-adjoint
* @throws IllConditionedOperatorException if {@code a} is ill-conditioned
*/
@Override
public RealVector solve(final RealLinearOperator a, final RealVector b)
throws NullArgumentException, NonSquareOperatorException,
DimensionMismatchException, NonSelfAdjointOperatorException,
IllConditionedOperatorException, MaxCountExceededException {
MathUtils.checkNotNull(a);
final RealVector x = new ArrayRealVector(a.getColumnDimension());
x.set(0.);
return solveInPlace(a, null, b, x, false, 0.);
}
示例15: logProbability
import org.apache.commons.math3.util.MathUtils; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public double logProbability(int x) {
double ret;
if (x < 0 || x == Integer.MAX_VALUE) {
ret = Double.NEGATIVE_INFINITY;
} else if (x == 0) {
ret = -mean;
} else {
ret = -SaddlePointExpansion.getStirlingError(x) -
SaddlePointExpansion.getDeviancePart(x, mean) -
0.5 * FastMath.log(MathUtils.TWO_PI) - 0.5 * FastMath.log(x);
}
return ret;
}