/** {@inheritDoc} */ public double value(double x, double y) { return FastMath.max(x, y); } }
/** * Return the lowest domain value for the given hypergeometric distribution * parameters. * * @param n Population size. * @param m Number of successes in the population. * @param k Sample size. * @return the lowest domain value of the hypergeometric distribution. */ private int getLowerDomain(int n, int m, int k) { return FastMath.max(0, m - (n - k)); }
/** {@inheritDoc} */ @Override public double getLInfNorm() { double max = 0; for (double a : data) { max = FastMath.max(max, FastMath.abs(a)); } return max; }
/** {@inheritDoc} */ public void visit(final int row, final int column, final double value) { columnSum += FastMath.abs(value); if (row == endRow) { maxColSum = FastMath.max(maxColSum, columnSum); columnSum = 0; } }
/** * Computes the L1 norm of the (quasi-)triangular matrix T. * * @return the L1 norm of matrix T */ private double getNorm() { double norm = 0.0; for (int i = 0; i < matrixT.length; i++) { // as matrix T is (quasi-)triangular, also take the sub-diagonal element into account for (int j = FastMath.max(i - 1, 0); j < matrixT.length; j++) { norm += FastMath.abs(matrixT[i][j]); } } return norm; }
/** * 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; }
/** * Returns the index of the bin to which the given value belongs * * @param value the value whose bin we are trying to find * @return the index of the bin containing the value */ private int findBin(double value) { return FastMath.min( FastMath.max((int) FastMath.ceil((value - min) / delta) - 1, 0), binCount - 1); }
/** Compute step grow/shrink factor according to normalized error. * @param error normalized error of the current step * @return grow/shrink factor for next step */ protected double computeStepGrowShrinkFactor(final double error) { return FastMath.min(maxGrowth, FastMath.max(minReduction, safety * FastMath.pow(error, exp))); }
/** {@inheritDoc} */ public double distanceInf(Vector<Euclidean2D> p) { Vector2D p3 = (Vector2D) p; final double dx = FastMath.abs(p3.x - x); final double dy = FastMath.abs(p3.y - y); return FastMath.max(dx, dy); }
/** {@inheritDoc} */ public double getNormInf() { return FastMath.max(FastMath.abs(x), FastMath.abs(y)); }
/** * Calculates the L<sub>∞</sub> (max of abs) distance between two points. * * @param p1 the first point * @param p2 the second point * @return the L<sub>∞</sub> distance between the two points * @throws DimensionMismatchException if the array lengths differ. */ public static int distanceInf(int[] p1, int[] p2) throws DimensionMismatchException { checkEqualLength(p1, p2); int max = 0; for (int i = 0; i < p1.length; i++) { max = FastMath.max(max, FastMath.abs(p1[i] - p2[i])); } return max; }
/** * {@inheritDoc} * * For population size {@code N}, number of successes {@code m}, and sample * size {@code n}, the lower bound of the support is * {@code max(0, n + m - N)}. * * @return lower bound of the support */ public int getSupportLowerBound() { return FastMath.max(0, getSampleSize() + getNumberOfSuccesses() - getPopulationSize()); }
/** * Returns one sample using Cheng's sampling algorithm. * @param random random generator to use * @param alpha distribution first shape parameter * @param beta distribution second shape parameter * @return sampled value */ static double sample(RandomGenerator random, final double alpha, final double beta) { final double a = FastMath.min(alpha, beta); final double b = FastMath.max(alpha, beta); if (a > 1) { return algorithmBB(random, alpha, a, b); } else { return algorithmBC(random, alpha, b, a); } }
/** {@inheritDoc} */ public DerivativeStructure value(final DerivativeStructure t) throws MathIllegalArgumentException { // check we can achieve the requested derivation order with the sample if (t.getOrder() >= nbPoints) { throw new NumberIsTooLargeException(t.getOrder(), nbPoints, false); } // compute sample position, trying to be centered if possible final double t0 = FastMath.max(FastMath.min(t.getValue(), tMax), tMin) - halfSampleSpan; // compute sample points final double[] y = new double[nbPoints]; for (int i = 0; i < nbPoints; ++i) { y[i] = function.value(t0 + i * stepSize); } // evaluate derivatives return evaluate(t, t0, y); }
/** Check the integration span. * @param equations set of differential equations * @param t target time for the integration * @exception NumberIsTooSmallException if integration span is too small * @exception DimensionMismatchException if adaptive step size integrators * tolerance arrays dimensions are not compatible with equations settings */ protected void sanityChecks(final ExpandableStatefulODE equations, final double t) throws NumberIsTooSmallException, DimensionMismatchException { final double threshold = 1000 * FastMath.ulp(FastMath.max(FastMath.abs(equations.getTime()), FastMath.abs(t))); final double dt = FastMath.abs(equations.getTime() - t); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, dt, threshold, false); } }
/** * Check whether the given complex root is actually a real zero * in the given interval, within the solver tolerance level. * * @param min Lower bound for the interval. * @param max Upper bound for the interval. * @param z Complex root. * @return {@code true} if z is a real zero. */ public boolean isRoot(double min, double max, Complex z) { if (isSequence(min, z.getReal(), max)) { double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy()); return (FastMath.abs(z.getImaginary()) <= tolerance) || (z.abs() <= getFunctionValueAccuracy()); } return false; }
/** Check the integration span. * @param eqn set of differential equations * @param t target time for the integration * @exception NumberIsTooSmallException if integration span is too small * @exception DimensionMismatchException if adaptive step size integrators * tolerance arrays dimensions are not compatible with equations settings */ protected void sanityChecks(final FieldODEState<T> eqn, final T t) throws NumberIsTooSmallException, DimensionMismatchException { final double threshold = 1000 * FastMath.ulp(FastMath.max(FastMath.abs(eqn.getTime().getReal()), FastMath.abs(t.getReal()))); final double dt = eqn.getTime().subtract(t).abs().getReal(); if (dt <= threshold) { throw new NumberIsTooSmallException(LocalizedFormats.TOO_SMALL_INTEGRATION_INTERVAL, dt, threshold, false); } }