/** * Check that the endpoints specify an interval. * * @param lower Lower endpoint. * @param upper Upper endpoint. * @throws NumberIsTooLargeException if {@code lower >= upper}. */ public static void verifyInterval(final double lower, final double upper) throws NumberIsTooLargeException { if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.ENDPOINTS_NOT_AN_INTERVAL, lower, upper, false); } }
/** * Creates a uniform distribution. * * @param rng Random number generator. * @param lower Lower bound of this distribution (inclusive). * @param upper Upper bound of this distribution (exclusive). * @throws NumberIsTooLargeException if {@code lower >= upper}. * @since 3.1 */ public UniformDistribution(org.nd4j.linalg.api.rng.Random rng, double lower, double upper) throws NumberIsTooLargeException { super(rng); if (lower >= upper) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } this.lower = lower; this.upper = upper; }
/** * Build a Romberg integrator with given iteration counts. * @param minimalIterationCount minimum number of iterations * @param maximalIterationCount maximum number of iterations * (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT}) * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT} */ public RombergIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(minimalIterationCount, maximalIterationCount); if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, ROMBERG_MAX_ITERATIONS_COUNT, false); } }
/** * Build a Simpson integrator with given iteration counts. * @param minimalIterationCount minimum number of iterations * @param maximalIterationCount maximum number of iterations * (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT}) * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT} */ public SimpsonIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(minimalIterationCount, maximalIterationCount); if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, SIMPSON_MAX_ITERATIONS_COUNT, false); } }
/** * Build a midpoint integrator with given iteration counts. * @param minimalIterationCount minimum number of iterations * @param maximalIterationCount maximum number of iterations * (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT} * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT} */ public MidPointIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(minimalIterationCount, maximalIterationCount); if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, MIDPOINT_MAX_ITERATIONS_COUNT, false); } }
/** * Creates a uniform distribution. * * @param rng Random number generator. * @param lower Lower bound of this distribution (inclusive). * @param upper Upper bound of this distribution (exclusive). * @throws NumberIsTooLargeException if {@code lower >= upper}. * @since 3.1 */ public UniformRealDistribution(RandomGenerator rng, double lower, double upper) throws NumberIsTooLargeException { super(rng); if (lower >= upper) { throw new NumberIsTooLargeException( LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, false); } this.lower = lower; this.upper = upper; }
/** * Build a trapezoid integrator with given iteration counts. * @param minimalIterationCount minimum number of iterations * @param maximalIterationCount maximum number of iterations * (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} */ public TrapezoidIntegrator(final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(minimalIterationCount, maximalIterationCount); if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, TRAPEZOID_MAX_ITERATIONS_COUNT, false); } }
/** * Creates a new uniform integer distribution using the given lower and * upper bounds (both inclusive). * * @param rng Random number generator. * @param lower Lower bound (inclusive) of this distribution. * @param upper Upper bound (inclusive) of this distribution. * @throws NumberIsTooLargeException if {@code lower > upper}. * @since 3.1 */ public UniformIntegerDistribution(RandomGenerator rng, int lower, int upper) throws NumberIsTooLargeException { super(rng); if (lower > upper) { throw new NumberIsTooLargeException( LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper, true); } this.lower = lower; this.upper = upper; }
/** * Build a Romberg integrator with given accuracies and iterations counts. * @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 * (must be less than or equal to {@link #ROMBERG_MAX_ITERATIONS_COUNT}) * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #ROMBERG_MAX_ITERATIONS_COUNT} */ public RombergIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); if (maximalIterationCount > ROMBERG_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, ROMBERG_MAX_ITERATIONS_COUNT, false); } }
/** * Build a trapezoid integrator with given accuracies and iterations counts. * @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 * (must be less than or equal to {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #TRAPEZOID_MAX_ITERATIONS_COUNT} */ public TrapezoidIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); if (maximalIterationCount > TRAPEZOID_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, TRAPEZOID_MAX_ITERATIONS_COUNT, false); } }
/** * Build a Simpson integrator with given accuracies and iterations counts. * @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 * (must be less than or equal to {@link #SIMPSON_MAX_ITERATIONS_COUNT}) * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #SIMPSON_MAX_ITERATIONS_COUNT} */ public SimpsonIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); if (maximalIterationCount > SIMPSON_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, SIMPSON_MAX_ITERATIONS_COUNT, false); } }
/** * Build a midpoint integrator with given accuracies and iterations counts. * @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 * (must be less than or equal to {@link #MIDPOINT_MAX_ITERATIONS_COUNT} * @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 * @exception NumberIsTooLargeException if maximal number of iterations * is greater than {@link #MIDPOINT_MAX_ITERATIONS_COUNT} */ public MidPointIntegrator(final double relativeAccuracy, final double absoluteAccuracy, final int minimalIterationCount, final int maximalIterationCount) throws NotStrictlyPositiveException, NumberIsTooSmallException, NumberIsTooLargeException { super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); if (maximalIterationCount > MIDPOINT_MAX_ITERATIONS_COUNT) { throw new NumberIsTooLargeException(maximalIterationCount, MIDPOINT_MAX_ITERATIONS_COUNT, false); } }
/** * Add the given chromosome to the population. * * @param chromosome the chromosome to add. * @throws NumberIsTooLargeException if the population would exceed the {@code populationLimit} after * adding this chromosome */ public void addChromosome(final Chromosome chromosome) throws NumberIsTooLargeException { if (chromosomes.size() >= populationLimit) { throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE, chromosomes.size(), populationLimit, false); } this.chromosomes.add(chromosome); }
/** * Add a {@link Collection} of chromosomes to this {@link Population}. * @param chromosomeColl a {@link Collection} of chromosomes * @throws NumberIsTooLargeException if the population would exceed the population limit when * adding this chromosome * @since 3.1 */ public void addChromosomes(final Collection<Chromosome> chromosomeColl) throws NumberIsTooLargeException { if (chromosomes.size() + chromosomeColl.size() > populationLimit) { throw new NumberIsTooLargeException(LocalizedFormats.LIST_OF_CHROMOSOMES_BIGGER_THAN_POPULATION_SIZE, chromosomes.size(), populationLimit, false); } this.chromosomes.addAll(chromosomeColl); }
/** * {@inheritDoc} */ @Override public double probability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } final double denom = standardDeviation * SQRT2; final double v0 = (x0 - mean) / denom; final double v1 = (x1 - mean) / denom; return 0.5 * Erf.erf(v0, v1); }
/** * {@inheritDoc} */ @Override public double probability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } final double denom = standardDeviation * SQRT2; final double v0 = (x0 - mean) / denom; final double v1 = (x1 - mean) / denom; return 0.5 * Erf.erf(v0, v1); }
/** * {@inheritDoc} */ @Override public double probability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } final double denom = standardDeviation * SQRT2; final double v0 = (x0 - mean) / denom; final double v1 = (x1 - mean) / denom; return 0.5 * Erf.erf(v0, v1); }
/** {@inheritDoc} */ @Override public double probability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); } final double denom = standardDeviation * SQRT2; final double v0 = (x0 - mean) / denom; final double v1 = (x1 - mean) / denom; return 0.5 * Erf.erf(v0, v1); }
/** * Check binomial preconditions. * * @param n Size of the set. * @param k Size of the subsets to be counted. * @throws NotPositiveException if {@code n < 0}. * @throws NumberIsTooLargeException if {@code k > n}. */ public static void checkBinomial(final int n, final int k) throws NumberIsTooLargeException, NotPositiveException { if (n < k) { throw new NumberIsTooLargeException(LocalizedFormats.BINOMIAL_INVALID_PARAMETERS_ORDER, k, n, true); } if (n < 0) { throw new NotPositiveException(LocalizedFormats.BINOMIAL_NEGATIVE_PARAMETER, n); } } }
/** * @param lo Lower bound. * @param hi Upper bound. * @param init Start value. * @throws NumberIsTooLargeException if {@code lo >= hi}. * @throws OutOfRangeException if {@code init < lo} or {@code init > hi}. */ public SearchInterval(double lo, double hi, double init) { if (lo >= hi) { throw new NumberIsTooLargeException(lo, hi, false); } if (init < lo || init > hi) { throw new OutOfRangeException(init, lo, hi); } lower = lo; upper = hi; start = init; }