org.apache.commons.math3.exception.util.LocalizedFormats Java Examples
The following examples show how to use
org.apache.commons.math3.exception.util.LocalizedFormats.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Math_29_OpenMapRealVector_t.java From coming with MIT License | 6 votes |
/** {@inheritDoc} */ @Override public OpenMapRealVector getSubVector(int index, int n) { checkIndex(index); if (n < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); } checkIndex(index + n - 1); OpenMapRealVector res = new OpenMapRealVector(n); int end = index + n; Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (key >= index && key < end) { res.setEntry(key - index, iter.value()); } } return res; }
Example #2
Source File: BinaryMutation.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Mutate the given chromosome. Randomly changes one gene. * * @param original the original chromosome. * @return the mutated chromosome. * @throws MathIllegalArgumentException if <code>original</code> is not an instance of {@link BinaryChromosome}. */ public Chromosome mutate(Chromosome original) throws MathIllegalArgumentException { if (!(original instanceof BinaryChromosome)) { throw new MathIllegalArgumentException(LocalizedFormats.INVALID_BINARY_CHROMOSOME); } BinaryChromosome origChrom = (BinaryChromosome) original; List<Integer> newRepr = new ArrayList<Integer>(origChrom.getRepresentation()); // randomly select a gene int geneIndex = GeneticAlgorithm.getRandomGenerator().nextInt(origChrom.getLength()); // and change it newRepr.set(geneIndex, origChrom.getRepresentation().get(geneIndex) == 0 ? 1 : 0); Chromosome newChrom = origChrom.newFixedLengthChromosome(newRepr); return newChrom; }
Example #3
Source File: FastMath.java From astor with GNU General Public License v2.0 | 6 votes |
/** Finds q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b > 0. * <p> * This methods returns the same value as integer division when * a and b are same signs, but returns a different value when * they are opposite (i.e. q is negative). * </p> * @param a dividend * @param b divisor * @return q such that a = q b + r with 0 <= r < b if b > 0 and b < r <= 0 if b > 0 * @exception MathArithmeticException if b == 0 * @see #floorMod(long, long) * @since 3.4 */ public static long floorDiv(final long a, final long b) throws MathArithmeticException { if (b == 0l) { throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); } final long m = a % b; if ((a ^ b) >= 0l || m == 0l) { // a an b have same sign, or division is exact return a / b; } else { // a and b have opposite signs and division is not exact return (a / b) - 1l; } }
Example #4
Source File: PolynomialFunction.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example #5
Source File: FieldVector3D.java From astor with GNU General Public License v2.0 | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @param <T> the type of the field elements * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static <T extends RealFieldElement<T>> T angle(final FieldVector3D<T> v1, final Vector3D v2) throws MathArithmeticException { final T normProduct = v1.getNorm().multiply(v2.getNorm()); if (normProduct.getReal() == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } final T dot = dotProduct(v1, v2); final double threshold = normProduct.getReal() * 0.9999; if ((dot.getReal() < -threshold) || (dot.getReal() > threshold)) { // the vectors are almost aligned, compute using the sine FieldVector3D<T> v3 = crossProduct(v1, v2); if (dot.getReal() >= 0) { return v3.getNorm().divide(normProduct).asin(); } return v3.getNorm().divide(normProduct).asin().subtract(FastMath.PI).negate(); } // the vectors are sufficiently separated to use the cosine return dot.divide(normProduct).acos(); }
Example #6
Source File: ParetoDistribution.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a log-normal distribution. * * @param rng Random number generator. * @param scale Scale parameter of this distribution. * @param shape Shape parameter of this distribution. * @param inverseCumAccuracy Inverse cumulative probability accuracy. * @throws NotStrictlyPositiveException if {@code scale <= 0} or {@code shape <= 0}. */ public ParetoDistribution(RandomGenerator rng, double scale, double shape, double inverseCumAccuracy) throws NotStrictlyPositiveException { super(rng); if (scale <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale); } if (shape <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape); } this.scale = scale; this.shape = shape; this.solverAbsoluteAccuracy = inverseCumAccuracy; }
Example #7
Source File: NPEfix_00173_s.java From coming with MIT License | 6 votes |
/** Build an affine line transform from a n {@code AffineTransform}. * @param transform transform to use (must be invertible otherwise * the {@link LineTransform#apply(Hyperplane)} method would work * only for some lines, and fail for other ones) * @exception MathIllegalArgumentException if the transform is non invertible */ public LineTransform(final AffineTransform transform) throws MathIllegalArgumentException { final double[] m = new double[6]; transform.getMatrix(m); cXX = m[0]; cXY = m[2]; cX1 = m[4]; cYX = m[1]; cYY = m[3]; cY1 = m[5]; c1Y = cXY * cY1 - cYY * cX1; c1X = cXX * cY1 - cYX * cX1; c11 = cXX * cYY - cYX * cXY; if (FastMath.abs(c11) < 1.0e-20) { throw new MathIllegalArgumentException(LocalizedFormats.NON_INVERTIBLE_TRANSFORM); } }
Example #8
Source File: GeneticAlgorithm.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a new genetic algorithm. * @param crossoverPolicy The {@link CrossoverPolicy} * @param crossoverRate The crossover rate as a percentage (0-1 inclusive) * @param mutationPolicy The {@link MutationPolicy} * @param mutationRate The mutation rate as a percentage (0-1 inclusive) * @param selectionPolicy The {@link SelectionPolicy} * @throws OutOfRangeException if the crossover or mutation rate is outside the [0, 1] range */ public GeneticAlgorithm(final CrossoverPolicy crossoverPolicy, final double crossoverRate, final MutationPolicy mutationPolicy, final double mutationRate, final SelectionPolicy selectionPolicy) throws OutOfRangeException { if (crossoverRate < 0 || crossoverRate > 1) { throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE, crossoverRate, 0, 1); } if (mutationRate < 0 || mutationRate > 1) { throw new OutOfRangeException(LocalizedFormats.MUTATION_RATE, mutationRate, 0, 1); } this.crossoverPolicy = crossoverPolicy; this.crossoverRate = crossoverRate; this.mutationPolicy = mutationPolicy; this.mutationRate = mutationRate; this.selectionPolicy = selectionPolicy; }
Example #9
Source File: GeneticAlgorithm.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a new genetic algorithm. * @param crossoverPolicy The {@link CrossoverPolicy} * @param crossoverRate The crossover rate as a percentage (0-1 inclusive) * @param mutationPolicy The {@link MutationPolicy} * @param mutationRate The mutation rate as a percentage (0-1 inclusive) * @param selectionPolicy The {@link SelectionPolicy} * @throws OutOfRangeException if the crossover or mutation rate is outside the [0, 1] range */ public GeneticAlgorithm(final CrossoverPolicy crossoverPolicy, final double crossoverRate, final MutationPolicy mutationPolicy, final double mutationRate, final SelectionPolicy selectionPolicy) throws OutOfRangeException { if (crossoverRate < 0 || crossoverRate > 1) { throw new OutOfRangeException(LocalizedFormats.CROSSOVER_RATE, crossoverRate, 0, 1); } if (mutationRate < 0 || mutationRate > 1) { throw new OutOfRangeException(LocalizedFormats.MUTATION_RATE, mutationRate, 0, 1); } this.crossoverPolicy = crossoverPolicy; this.crossoverRate = crossoverRate; this.mutationPolicy = mutationPolicy; this.mutationRate = mutationRate; this.selectionPolicy = selectionPolicy; }
Example #10
Source File: GaussianFitter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Constructs instance with the specified observed points. * * @param observations Observed points from which to guess the * parameters of the Gaussian. * @throws NullArgumentException if {@code observations} is * {@code null}. * @throws NumberIsTooSmallException if there are less than 3 * observations. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (observations.length < 3) { throw new NumberIsTooSmallException(observations.length, 3, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double[] params = basicGuess(sorted); norm = params[0]; mean = params[1]; sigma = params[2]; }
Example #11
Source File: BigFraction.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p> * Subtracts the value of another fraction from the value of this one, * returning the result in reduced form. * </p> * * @param fraction {@link BigFraction} to subtract, must not be {@code null}. * @return a {@link BigFraction} instance with the resulting values * @throws NullArgumentException if the {@code fraction} is {@code null}. */ public BigFraction subtract(final BigFraction fraction) { if (fraction == null) { throw new NullArgumentException(LocalizedFormats.FRACTION); } if (ZERO.equals(fraction)) { return this; } BigInteger num = null; BigInteger den = null; if (denominator.equals(fraction.denominator)) { num = numerator.subtract(fraction.numerator); den = denominator; } else { num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator)); den = denominator.multiply(fraction.denominator); } return new BigFraction(num, den); }
Example #12
Source File: UnivariateSolverUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Check that the endpoints specify an interval and the end points * bracket a root. * * @param function Function. * @param lower Lower endpoint. * @param upper Upper endpoint. * @throws NoBracketingException if the function has the same sign at the * endpoints. * @throws NullArgumentException if {@code function} is {@code null}. */ public static void verifyBracketing(UnivariateFunction function, final double lower, final double upper) throws NullArgumentException, NoBracketingException { if (function == null) { throw new NullArgumentException(LocalizedFormats.FUNCTION); } verifyInterval(lower, upper); if (!isBracketing(function, lower, upper)) { throw new NoBracketingException(lower, upper, function.value(lower), function.value(upper)); } }
Example #13
Source File: Cardumen_0040_s.java From coming with MIT License | 6 votes |
/** Compute the angular separation between two vectors. * <p>This method computes the angular separation between two * vectors using the dot product for well separated vectors and the * cross product for almost aligned vectors. This allows to have a * good accuracy in all cases, even for vectors very close to each * other.</p> * @param v1 first vector * @param v2 second vector * @return angular separation between v1 and v2 * @exception MathArithmeticException if either vector has a null norm */ public static double angle(Vector3D v1, Vector3D v2) { double normProduct = v1.getNorm() * v2.getNorm(); if (normProduct == 0) { throw new MathArithmeticException(LocalizedFormats.ZERO_NORM); } double dot = v1.dotProduct(v2); double threshold = normProduct * 0.9999; if ((dot < -threshold) || (dot > threshold)) { // the vectors are almost aligned, compute using the sine Vector3D v3 = crossProduct(v1, v2); if (dot >= 0) { return FastMath.asin(v3.getNorm() / normProduct); } return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct); } // the vectors are sufficiently separated to use the cosine return FastMath.acos(dot / normProduct); }
Example #14
Source File: Covariance.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Computes the covariance between the two arrays. * * <p>Array lengths must match and the common length must be at least 2.</p> * * @param xArray first data array * @param yArray second data array * @param biasCorrected if true, returned value will be bias-corrected * @return returns the covariance for the two arrays * @throws IllegalArgumentException if the arrays lengths do not match or * there is insufficient data */ public double covariance(final double[] xArray, final double[] yArray, boolean biasCorrected) throws IllegalArgumentException { Mean mean = new Mean(); double result = 0d; int length = xArray.length; if (length != yArray.length) { throw new MathIllegalArgumentException( LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, length, yArray.length); } else if (length < 2) { throw new MathIllegalArgumentException( LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, length, 2); } else { double xMean = mean.evaluate(xArray); double yMean = mean.evaluate(yArray); for (int i = 0; i < length; i++) { double xDev = xArray[i] - xMean; double yDev = yArray[i] - yMean; result += (xDev * yDev - result) / (i + 1); } } return biasCorrected ? result * ((double) length / (double)(length - 1)) : result; }
Example #15
Source File: AbstractUnivariateStatistic.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Set the data array. The input array is copied, not referenced. * * @param values data array to store * @param begin the index of the first element to include * @param length the number of elements to include * @throws MathIllegalArgumentException if values is null or the indices * are not valid * @see #evaluate() */ public void setData(final double[] values, final int begin, final int length) throws MathIllegalArgumentException { if (values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (begin < 0) { throw new NotPositiveException(LocalizedFormats.START_POSITION, begin); } if (length < 0) { throw new NotPositiveException(LocalizedFormats.LENGTH, length); } if (begin + length > values.length) { throw new NumberIsTooLargeException(LocalizedFormats.SUBARRAY_ENDS_AFTER_ARRAY_END, begin + length, values.length, true); } storedData = new double[length]; System.arraycopy(values, begin, storedData, 0, length); }
Example #16
Source File: SparseFieldVector.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); } checkIndex(index); checkIndex(index + n - 1); SparseFieldVector<T> res = new SparseFieldVector<T>(field,n); int end = index + n; OpenIntToFieldHashMap<T>.Iterator iter = entries.iterator(); while (iter.hasNext()) { iter.advance(); int key = iter.key(); if (key >= index && key < end) { res.setEntry(key - index, iter.value()); } } return res; }
Example #17
Source File: BigFractionFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Formats an object and appends the result to a StringBuffer. * <code>obj</code> must be either a {@link BigFraction} object or a * {@link BigInteger} object or a {@link Number} object. Any other type of * object will result in an {@link IllegalArgumentException} being thrown. * * @param obj the object to format. * @param toAppendTo where the text is to be appended * @param pos On input: an alignment field, if desired. On output: the * offsets of the alignment field * @return the value passed in as toAppendTo. * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) * @throws MathIllegalArgumentException if <code>obj</code> is not a valid type. */ @Override public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos) { final StringBuffer ret; if (obj instanceof BigFraction) { ret = format((BigFraction) obj, toAppendTo, pos); } else if (obj instanceof BigInteger) { ret = format(new BigFraction((BigInteger) obj), toAppendTo, pos); } else if (obj instanceof Number) { ret = format(new BigFraction(((Number) obj).doubleValue()), toAppendTo, pos); } else { throw new MathIllegalArgumentException(LocalizedFormats.CANNOT_FORMAT_OBJECT_TO_FRACTION); } return ret; }
Example #18
Source File: StatUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Returns the sum of the (signed) differences between corresponding elements of the * input arrays -- i.e., sum(sample1[i] - sample2[i]). * * @param sample1 the first array * @param sample2 the second array * @return sum of paired differences * @throws DimensionMismatchException if the arrays do not have the same * (positive) length. * @throws NoDataException if the sample arrays are empty. */ public static double sumDifference(final double[] sample1, final double[] sample2) { int n = sample1.length; if (n != sample2.length) { throw new DimensionMismatchException(n, sample2.length); } if (n <= 0) { throw new NoDataException(LocalizedFormats.INSUFFICIENT_DIMENSION); } double result = 0; for (int i = 0; i < n; i++) { result += sample1[i] - sample2[i]; } return result; }
Example #19
Source File: LegendreGaussIntegrator.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Build a Legendre-Gauss integrator with given accuracies and iterations counts. * @param n number of points desired (must be between 2 and 5 inclusive) * @param relativeAccuracy relative accuracy of the result * @param absoluteAccuracy absolute accuracy of the result * @param minimalIterationCount minimum number of iterations * @param maximalIterationCount maximum number of iterations * @exception MathIllegalArgumentException if number of points is out of [2; 5] * @exception NotStrictlyPositiveException if minimal number of iterations * is not strictly positive * @exception NumberIsTooSmallException if maximal number of iterations * is lesser than or equal to the minimal number of iterations */ public LegendreGaussIntegrator(final int n, final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws MathIllegalArgumentException, NotStrictlyPositiveException, NumberIsTooSmallException { super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); switch(n) { case 2 : abscissas = ABSCISSAS_2; weights = WEIGHTS_2; break; case 3 : abscissas = ABSCISSAS_3; weights = WEIGHTS_3; break; case 4 : abscissas = ABSCISSAS_4; weights = WEIGHTS_4; break; case 5 : abscissas = ABSCISSAS_5; weights = WEIGHTS_5; break; default : throw new MathIllegalArgumentException( LocalizedFormats.N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED, n, 2, 5); } }
Example #20
Source File: ArrayFieldVector.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); } ArrayFieldVector<T> out = new ArrayFieldVector<T>(field, n); try { System.arraycopy(data, index, out.data, 0, n); } catch (IndexOutOfBoundsException e) { checkIndex(index); checkIndex(index + n - 1); } return out; }
Example #21
Source File: GammaDistribution.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a Gamma distribution. * * @param rng Random number generator. * @param shape the shape parameter * @param scale the scale parameter * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates (defaults to * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}). * @throws NotStrictlyPositiveException if {@code shape <= 0} or * {@code scale <= 0}. * @since 3.1 */ public GammaDistribution(RandomGenerator rng, double shape, double scale, double inverseCumAccuracy) throws NotStrictlyPositiveException { super(rng); if (shape <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SHAPE, shape); } if (scale <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.SCALE, scale); } this.shape = shape; this.scale = scale; this.solverAbsoluteAccuracy = inverseCumAccuracy; this.shiftedShape = shape + Gamma.LANCZOS_G + 0.5; final double aux = FastMath.E / (2.0 * FastMath.PI * shiftedShape); this.densityPrefactor2 = shape * FastMath.sqrt(aux) / Gamma.lanczos(shape); this.densityPrefactor1 = this.densityPrefactor2 / scale * FastMath.pow(shiftedShape, -shape) * FastMath.exp(shape + Gamma.LANCZOS_G); this.minY = shape + Gamma.LANCZOS_G - FastMath.log(Double.MAX_VALUE); this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0); }
Example #22
Source File: HarmonicFitter.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Simple constructor. * * @param observations Sampled observations. * @throws NumberIsTooSmallException if the sample is too short. * @throws ZeroException if the abscissa range is zero. * @throws MathIllegalStateException when the guessing procedure cannot * produce sensible results. */ public ParameterGuesser(WeightedObservedPoint[] observations) { if (observations.length < 4) { throw new NumberIsTooSmallException(LocalizedFormats.INSUFFICIENT_OBSERVED_POINTS_IN_SAMPLE, observations.length, 4, true); } final WeightedObservedPoint[] sorted = sortObservations(observations); final double aOmega[] = guessAOmega(sorted); a = aOmega[0]; omega = aOmega[1]; phi = guessPhi(sorted); }
Example #23
Source File: ArrayFieldVector.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public FieldVector<T> getSubVector(int index, int n) throws OutOfRangeException, NotPositiveException { if (n < 0) { throw new NotPositiveException(LocalizedFormats.NUMBER_OF_ELEMENTS_SHOULD_BE_POSITIVE, n); } ArrayFieldVector<T> out = new ArrayFieldVector<T>(field, n); try { System.arraycopy(data, index, out.data, 0, n); } catch (IndexOutOfBoundsException e) { checkIndex(index); checkIndex(index + n - 1); } return out; }
Example #24
Source File: BigFraction.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a {@link BigFraction} given the numerator and denominator as * {@code BigInteger}. The {@link BigFraction} is reduced to lowest terms. * * @param num the numerator, must not be {@code null}. * @param den the denominator, must not be {@code null}. * @throws ZeroException if the denominator is zero. * @throws NullArgumentException if either of the arguments is null */ public BigFraction(BigInteger num, BigInteger den) { MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); if (BigInteger.ZERO.equals(den)) { throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); } if (BigInteger.ZERO.equals(num)) { numerator = BigInteger.ZERO; denominator = BigInteger.ONE; } else { // reduce numerator and denominator by greatest common denominator final BigInteger gcd = num.gcd(den); if (BigInteger.ONE.compareTo(gcd) < 0) { num = num.divide(gcd); den = den.divide(gcd); } // move sign to numerator if (BigInteger.ZERO.compareTo(den) > 0) { num = num.negate(); den = den.negate(); } // store the values in the final fields numerator = num; denominator = den; } }
Example #25
Source File: Arja_00103_s.java From coming with MIT License | 5 votes |
/** * {@inheritDoc} * * The default implementation generates the sample by calling * {@link #sample()} in a loop. */ public int[] sample(int sampleSize) { if (sampleSize <= 0) { throw new NotStrictlyPositiveException( LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } int[] out = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
Example #26
Source File: GaussNewtonOptimizer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @throws MathUnsupportedOperationException if bounds were passed to the * {@link #optimize(OptimizationData[]) optimize} method. */ private void checkParameters() { if (getLowerBound() != null || getUpperBound() != null) { throw new MathUnsupportedOperationException(LocalizedFormats.CONSTRAINT); } }
Example #27
Source File: Arja_00123_s.java From coming with MIT License | 5 votes |
/** * {@inheritDoc} * * The default implementation uses the identity * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p> */ public double cumulativeProbability(int x0, int x1) throws NumberIsTooLargeException { if (x1 < x0) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } return cumulativeProbability(x1) - cumulativeProbability(x0); }
Example #28
Source File: jMutRepair_0041_s.java From coming with MIT License | 5 votes |
/** * {@inheritDoc} * * The default implementation generates the sample by calling * {@link #sample()} in a loop. */ public int[] sample(int sampleSize) { if (sampleSize <= 0) { throw new NotStrictlyPositiveException( LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } int[] out = new int[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
Example #29
Source File: BigFraction_s.java From coming with MIT License | 5 votes |
/** * Create a fraction given the double value. * <p> * This constructor behaves <em>differently</em> from * {@link #BigFraction(double, double, int)}. It converts the double value * exactly, considering its internal bits representation. This works for all * values except NaN and infinities and does not requires any loop or * convergence threshold. * </p> * <p> * Since this conversion is exact and since double numbers are sometimes * approximated, the fraction created may seem strange in some cases. For example, * calling <code>new BigFraction(1.0 / 3.0)</code> does <em>not</em> create * the fraction 1/3, but the fraction 6004799503160661 / 18014398509481984 * because the double number passed to the constructor is not exactly 1/3 * (this number cannot be stored exactly in IEEE754). * </p> * @see #BigFraction(double, double, int) * @param value the double value to convert to a fraction. * @exception MathIllegalArgumentException if value is NaN or infinite */ public BigFraction(final double value) throws MathIllegalArgumentException { if (Double.isNaN(value)) { throw new MathIllegalArgumentException(LocalizedFormats.NAN_VALUE_CONVERSION); } if (Double.isInfinite(value)) { throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_VALUE_CONVERSION); } // compute m and k such that value = m * 2^k final long bits = Double.doubleToLongBits(value); final long sign = bits & 0x8000000000000000L; final long exponent = bits & 0x7ff0000000000000L; long m = bits & 0x000fffffffffffffL; if (exponent != 0) { // this was a normalized number, add the implicit most significant bit m |= 0x0010000000000000L; } if (sign != 0) { m = -m; } int k = ((int) (exponent >> 52)) - 1075; while (((m & 0x001ffffffffffffeL) != 0) && ((m & 0x1) == 0)) { m = m >> 1; ++k; } if (k < 0) { numerator = BigInteger.valueOf(m); denominator = BigInteger.ZERO.flipBit(-k); } else { numerator = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k)); denominator = BigInteger.ONE; } }
Example #30
Source File: AbstractFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Modify the denominator format. * @param format the new denominator format value. * @throws NullArgumentException if {@code format} is {@code null}. */ public void setDenominatorFormat(final NumberFormat format) { if (format == null) { throw new NullArgumentException(LocalizedFormats.DENOMINATOR_FORMAT); } this.denominatorFormat = format; }