org.apache.commons.math.exception.NotStrictlyPositiveException Java Examples
The following examples show how to use
org.apache.commons.math.exception.NotStrictlyPositiveException.
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: Arja_0083_t.java From coming with MIT License | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #2
Source File: Math_56_MultidimensionalCounter_t.java From coming with MIT License | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #3
Source File: Logistic.java From astor with GNU General Public License v2.0 | 6 votes |
/** * @param k If {@code b > 0}, value of the function for x going towards +∞. * If {@code b < 0}, value of the function for x going towards -∞. * @param m Abscissa of maximum growth. * @param b Growth rate. * @param q Parameter that affects the position of the curve along the * ordinate axis. * @param a If {@code b > 0}, value of the function for x going towards -∞. * If {@code b < 0}, value of the function for x going towards +∞. * @param n Parameter that affects near which asymptote the maximum * growth occurs. * @throws NotStrictlyPositiveException if {@code n <= 0}. */ public Logistic(double k, double m, double b, double q, double a, double n) { if (n <= 0) { throw new NotStrictlyPositiveException(n); } this.k = k; this.m = m; this.b = b; this.q = q; this.a = a; oneOverN = 1 / n; }
Example #4
Source File: PowellOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * The arguments control the behaviour of the default convergence * checking procedure. * * @param rel Relative threshold. * @param abs Absolute threshold. * @throws NotStrictlyPositiveException if {@code abs <= 0}. * @throws NumberIsTooSmallException if {@code rel < 2 * Math.ulp(1d)}. */ public PowellOptimizer(double rel, double abs) { if (rel < MIN_RELATIVE_TOLERANCE) { throw new NumberIsTooSmallException(rel, MIN_RELATIVE_TOLERANCE, true); } if (abs <= 0) { throw new NotStrictlyPositiveException(abs); } relativeThreshold = rel; absoluteThreshold = abs; // Line search tolerances can be much lower than the tolerances // required for the optimizer itself. final double minTol = 1e-4; final double lsRel = Math.min(FastMath.sqrt(relativeThreshold), minTol); final double lsAbs = Math.min(FastMath.sqrt(absoluteThreshold), minTol); line = new LineSearch(lsRel, lsAbs); }
Example #5
Source File: BaseMultiStartMultivariateRealOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a multi-start optimizer from a single-start optimizer. * * @param optimizer Single-start optimizer to wrap. * @param starts Number of starts to perform. If {@code starts == 1}, * the {@link #optimize(int,MultivariateRealFunction,GoalType,double[]) * optimize} will return the same solution as {@code optimizer} would. * @param generator Random vector generator to use for restarts. * @throws NullArgumentException if {@code optimizer} or {@code generator} * is {@code null}. * @throws NotStrictlyPositiveException if {@code starts < 1}. */ protected BaseMultiStartMultivariateRealOptimizer(final BaseMultivariateRealOptimizer<FUNC> optimizer, final int starts, final RandomVectorGenerator generator) { if (optimizer == null || generator == null) { throw new NullArgumentException(); } if (starts < 1) { throw new NotStrictlyPositiveException(starts); } this.optimizer = optimizer; this.starts = starts; this.generator = generator; }
Example #6
Source File: MultiStartUnivariateRealOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a multi-start optimizer from a single-start optimizer. * * @param optimizer Single-start optimizer to wrap. * @param starts Number of starts to perform. If {@code starts == 1}, * the {@code optimize} methods will return the same solution as * {@code optimizer} would. * @param generator Random generator to use for restarts. * @throws NullArgumentException if {@code optimizer} or {@code generator} * is {@code null}. * @throws NotStrictlyPositiveException if {@code starts < 1}. */ public MultiStartUnivariateRealOptimizer(final BaseUnivariateRealOptimizer<FUNC> optimizer, final int starts, final RandomGenerator generator) { if (optimizer == null || generator == null) { throw new NullArgumentException(); } if (starts < 1) { throw new NotStrictlyPositiveException(starts); } this.optimizer = optimizer; this.starts = starts; this.generator = generator; }
Example #7
Source File: MultidimensionalCounter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #8
Source File: MultiStartUnivariateRealOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a multi-start optimizer from a single-start optimizer. * * @param optimizer Single-start optimizer to wrap. * @param starts Number of starts to perform. If {@code starts == 1}, * the {@code optimize} methods will return the same solution as * {@code optimizer} would. * @param generator Random generator to use for restarts. * @throws NullArgumentException if {@code optimizer} or {@code generator} * is {@code null}. * @throws NotStrictlyPositiveException if {@code starts < 1}. */ public MultiStartUnivariateRealOptimizer(final BaseUnivariateRealOptimizer<FUNC> optimizer, final int starts, final RandomGenerator generator) { if (optimizer == null || generator == null) { throw new NullArgumentException(); } if (starts < 1) { throw new NotStrictlyPositiveException(starts); } this.optimizer = optimizer; this.starts = starts; this.generator = generator; }
Example #9
Source File: FDistributionImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create an F distribution using the given degrees of freedom * and inverse cumulative probability accuracy. * @param numeratorDegreesOfFreedom Numerator degrees of freedom. * @param denominatorDegreesOfFreedom Denominator degrees of freedom. * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates. * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} * or {@code denominatorDegreesOfFreedom <= 0}. * @since 2.1 */ public FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom, double inverseCumAccuracy) { if (numeratorDegreesOfFreedom <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM, numeratorDegreesOfFreedom); } if (denominatorDegreesOfFreedom <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM, denominatorDegreesOfFreedom); } this.numeratorDegreesOfFreedom = numeratorDegreesOfFreedom; this.denominatorDegreesOfFreedom = denominatorDegreesOfFreedom; solverAbsoluteAccuracy = inverseCumAccuracy; }
Example #10
Source File: BaseMultiStartMultivariateVectorialOptimizer.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a multi-start optimizer from a single-start optimizer. * * @param optimizer Single-start optimizer to wrap. * @param starts Number of starts to perform. If {@code starts == 1}, * the {@link #optimize(int,MultivariateVectorialFunction,double[],double[],double[]) * optimize} will return the same solution as {@code optimizer} would. * @param generator Random vector generator to use for restarts. * @throws NullArgumentException if {@code optimizer} or {@code generator} * is {@code null}. * @throws NotStrictlyPositiveException if {@code starts < 1}. */ protected BaseMultiStartMultivariateVectorialOptimizer(final BaseMultivariateVectorialOptimizer<FUNC> optimizer, final int starts, final RandomVectorGenerator generator) { if (optimizer == null || generator == null) { throw new NullArgumentException(); } if (starts < 1) { throw new NotStrictlyPositiveException(starts); } this.optimizer = optimizer; this.starts = starts; this.generator = generator; }
Example #11
Source File: JGenProg2017_0029_t.java From coming with MIT License | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #12
Source File: Arja_0036_t.java From coming with MIT License | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #13
Source File: Arja_0036_s.java From coming with MIT License | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #14
Source File: RandomDataImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Uses a 2-cycle permutation shuffle to generate a random permutation. * <strong>Algorithm Description</strong>: Uses a 2-cycle permutation * shuffle to generate a random permutation of <code>c.size()</code> and * then returns the elements whose indexes correspond to the elements of the * generated permutation. This technique is described, and proven to * generate random samples, <a * href="http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html"> * here</a> * * @param c * Collection to sample from. * @param k * sample size. * @return the random sample. * @throws NumberIsTooLargeException if {@code k > c.size()}. * @throws NotStrictlyPositiveException if {@code k <= 0}. */ public Object[] nextSample(Collection<?> c, int k) { int len = c.size(); if (k > len) { throw new NumberIsTooLargeException(LocalizedFormats.SAMPLE_SIZE_EXCEEDS_COLLECTION_SIZE, k, len, true); } if (k <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, k); } Object[] objects = c.toArray(); int[] index = nextPermutation(len, k); Object[] result = new Object[k]; for (int i = 0; i < k; i++) { result[i] = objects[index[i]]; } return result; }
Example #15
Source File: RandomDataImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Uses a 2-cycle permutation shuffle to generate a random permutation. * <strong>Algorithm Description</strong>: Uses a 2-cycle permutation * shuffle to generate a random permutation of <code>c.size()</code> and * then returns the elements whose indexes correspond to the elements of the * generated permutation. This technique is described, and proven to * generate random samples, <a * href="http://www.maths.abdn.ac.uk/~igc/tch/mx4002/notes/node83.html"> * here</a> * * @param c * Collection to sample from. * @param k * sample size. * @return the random sample. * @throws NumberIsTooLargeException if {@code k > c.size()}. * @throws NotStrictlyPositiveException if {@code k <= 0}. */ public Object[] nextSample(Collection<?> c, int k) { int len = c.size(); if (k > len) { throw new NumberIsTooLargeException(LocalizedFormats.SAMPLE_SIZE_EXCEEDS_COLLECTION_SIZE, k, len, true); } if (k <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, k); } Object[] objects = c.toArray(); int[] index = nextPermutation(len, k); Object[] result = new Object[k]; for (int i = 0; i < k; i++) { result[i] = objects[index[i]]; } return result; }
Example #16
Source File: MultidimensionalCounter.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a counter. * * @param size Counter sizes (number of slots in each dimension). * @throws NotStrictlyPositiveException if one of the sizes is * negative or zero. */ public MultidimensionalCounter(int ... size) { dimension = size.length; this.size = MathUtils.copyOf(size); uniCounterOffset = new int[dimension]; last = dimension - 1; int tS = size[last]; for (int i = 0; i < last; i++) { int count = 1; for (int j = i + 1; j < dimension; j++) { count *= size[j]; } uniCounterOffset[i] = count; tS *= size[i]; } uniCounterOffset[last] = 0; if (tS <= 0) { throw new NotStrictlyPositiveException(tS); } totalSize = tS; }
Example #17
Source File: FDistributionImpl.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create an F distribution using the given degrees of freedom * and inverse cumulative probability accuracy. * @param numeratorDegreesOfFreedom Numerator degrees of freedom. * @param denominatorDegreesOfFreedom Denominator degrees of freedom. * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates. * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} * or {@code denominatorDegreesOfFreedom <= 0}. * @since 2.1 */ public FDistributionImpl(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom, double inverseCumAccuracy) { if (numeratorDegreesOfFreedom <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM, numeratorDegreesOfFreedom); } if (denominatorDegreesOfFreedom <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM, denominatorDegreesOfFreedom); } this.numeratorDegreesOfFreedom = numeratorDegreesOfFreedom; this.denominatorDegreesOfFreedom = denominatorDegreesOfFreedom; solverAbsoluteAccuracy = inverseCumAccuracy; }
Example #18
Source File: Logistic.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Validates parameters to ensure they are appropriate for the evaluation of * the {@link #value(double,double[])} and {@link #gradient(double,double[])} * methods. * * @param param Values for {@code k}, {@code m}, {@code b}, {@code q}, * {@code a} and {@code n}. * @throws NullArgumentException if {@code param} is {@code null}. * @throws DimensionMismatchException if the size of {@code param} is * not 6. */ private void validateParameters(double[] param) { if (param == null) { throw new NullArgumentException(); } if (param.length != 6) { throw new DimensionMismatchException(param.length, 6); } if (param[5] <= 0) { throw new NotStrictlyPositiveException(param[5]); } }
Example #19
Source File: AbstractRealMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a new RealMatrix with the supplied row and column dimensions. * * @param rowDimension the number of rows in the new matrix * @param columnDimension the number of columns in the new matrix * @throws NotStrictlyPositiveException if row or column dimension is not positive */ protected AbstractRealMatrix(final int rowDimension, final int columnDimension) { if (rowDimension < 1) { throw new NotStrictlyPositiveException(rowDimension); } if (columnDimension < 1) { throw new NotStrictlyPositiveException(columnDimension); } }
Example #20
Source File: ExponentialDistributionTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testPreconditions() { try { new ExponentialDistributionImpl(0); Assert.fail("Should have generated NotStrictlyPositiveException"); } catch (NotStrictlyPositiveException e) { // Expected. } }
Example #21
Source File: RandomDataImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} * <p> * <strong>Algorithm Description:</strong> hex strings are generated using a * 2-step process. * <ol> * <li> * len/2+1 binary bytes are generated using the underlying Random</li> * <li> * Each binary byte is translated into 2 hex digits</li> * </ol> * </p> * * @param len * the desired string length. * @return the random string. * @throws NotStrictlyPositiveException if {@code len <= 0}. */ public String nextHexString(int len) { if (len <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.LENGTH, len); } // Get a random number generator RandomGenerator ran = getRan(); // Initialize output buffer StringBuffer outBuffer = new StringBuffer(); // Get int(len/2)+1 random bytes byte[] randomBytes = new byte[(len / 2) + 1]; ran.nextBytes(randomBytes); // Convert each byte to 2 hex digits for (int i = 0; i < randomBytes.length; i++) { Integer c = Integer.valueOf(randomBytes[i]); /* * Add 128 to byte value to make interval 0-255 before doing hex * conversion. This guarantees <= 2 hex digits from toHexString() * toHexString would otherwise add 2^32 to negative arguments. */ String hex = Integer.toHexString(c.intValue() + 128); // Make sure we add 2 hex digits for each byte if (hex.length() == 1) { hex = "0" + hex; } outBuffer.append(hex); } return outBuffer.toString().substring(0, len); }
Example #22
Source File: AbstractContinuousDistribution.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generate a random sample from the distribution. The default implementation * generates the sample by calling {@link #sample()} in a loop. * * @param sampleSize Number of random values to generate. * @return an array representing the random sample. * @throws MathException if an error occurs generating the sample. * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive. * @since 2.2 */ public double[] sample(int sampleSize) throws MathException { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, sampleSize); } double[] out = new double[sampleSize]; for (int i = 0; i < sampleSize; i++) { out[i] = sample(); } return out; }
Example #23
Source File: KolmogorovSmirnovDistributionImpl.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @param n Number of observations * @throws NotStrictlyPositiveException * if {@code n <= 0} */ public KolmogorovSmirnovDistributionImpl(int n) { if (n <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NOT_POSITIVE_NUMBER_OF_SAMPLES, n); } this.n = n; }
Example #24
Source File: Gaussian.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Gaussian with given normalization factor, mean and standard deviation. * * @param norm Normalization factor. * @param mean Mean. * @param sigma Standard deviation. * @throws NotStrictlyPositiveException if {@code sigma <= 0}. */ public Gaussian(double norm, double mean, double sigma) { if (sigma <= 0) { throw new NotStrictlyPositiveException(sigma); } this.norm = norm; this.mean = mean; this.i2s2 = 1 / (2 * sigma * sigma); }
Example #25
Source File: WeibullDistributionTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testBeta() { WeibullDistribution dist = new WeibullDistributionImpl(1, 2); assertEquals(2, dist.getScale(), 0); try { dist = new WeibullDistributionImpl(1, 0); fail("NotStrictlyPositiveException expected"); } catch (NotStrictlyPositiveException e) { // Expected. } }
Example #26
Source File: WeibullDistributionTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testAlpha() { WeibullDistribution dist = new WeibullDistributionImpl(1, 2); assertEquals(1, dist.getShape(), 0); try { dist = new WeibullDistributionImpl(0, 2); fail("NotStrictlyPositiveException expected"); } catch (NotStrictlyPositiveException e) { // Expected. } }
Example #27
Source File: PoissonDistributionTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMean() { PoissonDistribution dist; try { dist = new PoissonDistributionImpl(-1); fail("negative mean: NotStrictlyPositiveException expected"); } catch(NotStrictlyPositiveException ex) { // Expected. } dist = new PoissonDistributionImpl(10.0); assertEquals(10.0, dist.getMean(), 0.0); }
Example #28
Source File: AbstractIntegerDistribution.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Generates a random sample from the distribution. The default * implementation generates the sample by calling {@link #sample()} * in a loop. * * @param sampleSize number of random values to generate. * @since 2.2 * @return an array representing the random sample. * @throws MathException if an error occurs generating the sample. * @throws NotStrictlyPositiveException if {@code sampleSize <= 0}. */ public int[] sample(int sampleSize) throws MathException { 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: ExponentialDistributionTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testPreconditions() { try { new ExponentialDistributionImpl(0); fail("Should have generated NotStrictlyPositiveException"); } catch (NotStrictlyPositiveException e) { // Expected. } }
Example #30
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Create a new FieldMatrix<T> with the supplied row and column dimensions. * * @param field Field to which the elements belong. * @param rowDimension Number of rows in the new matrix. * @param columnDimension Number of columns in the new matrix. * @throws NotStrictlyPositiveException if row or column dimension is not * positive. */ protected AbstractFieldMatrix(final Field<T> field, final int rowDimension, final int columnDimension) { if (rowDimension <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION, rowDimension); } if (columnDimension <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DIMENSION, columnDimension); } this.field = field; }