List of usage examples for org.apache.commons.math3.exception NotPositiveException NotPositiveException
public NotPositiveException(Number value)
From source file:DBScan.java
public DBScan(final double eps, final int minPts) throws NotPositiveException { if (eps < 0.0d) { throw new NotPositiveException(eps); }//from w w w . j a v a2 s. com if (minPts < 0) { throw new NotPositiveException(minPts); } this.eps = eps; this.epsSqr = eps * eps; this.minPts = minPts; }
From source file:gedi.util.math.stat.distributions.NormalMixtureDistribution.java
public NormalMixtureDistribution(NormalDistribution[] components, double[] mixing) { super(new Well19937c()); this.components = components; this.mixing = mixing; if (ArrayUtils.min(mixing) < 0) throw new NotPositiveException(ArrayUtils.min(mixing)); if (components.length != mixing.length) throw new DimensionMismatchException(mixing.length, components.length); double sum = ArrayUtils.sum(mixing); if (Double.isInfinite(sum)) throw new NotFiniteNumberException(sum); ArrayUtils.mult(mixing, 1 / sum);//from ww w .j a v a 2s .c o m this.mixingSum = mixing.clone(); ArrayUtils.cumSumInPlace(mixingSum, 1); }
From source file:com.yahoo.egads.utilities.DBSCANClusterer.java
/** * Creates a new instance of a DBSCANClusterer. * * @param eps maximum radius of the neighborhood to be considered * @param minPts minimum number of points needed for a cluster * @param measure the distance measure to use * @throws NotPositiveException if {@code eps < 0.0} or {@code minPts < 0} *///w w w . j a v a2s . com public DBSCANClusterer(final double eps, final int minPts, final DistanceMeasure measure) throws NotPositiveException { super(measure); if (eps < 0.0d) { throw new NotPositiveException(eps); } if (minPts < 0) { throw new NotPositiveException(minPts); } this.eps = eps; this.minPts = minPts; }
From source file:hivemall.utils.math.StatsUtils.java
/** * @param observed means non-negative vector * @param expected means positive vector * @return chi2 value/*from ww w. j a v a2 s .c om*/ */ public static double chiSquare(@Nonnull final double[] observed, @Nonnull final double[] expected) { if (observed.length < 2) { throw new DimensionMismatchException(observed.length, 2); } if (expected.length != observed.length) { throw new DimensionMismatchException(observed.length, expected.length); } MathArrays.checkPositive(expected); for (double d : observed) { if (d < 0.d) { throw new NotPositiveException(d); } } double sumObserved = 0.d; double sumExpected = 0.d; for (int i = 0; i < observed.length; i++) { sumObserved += observed[i]; sumExpected += expected[i]; } double ratio = 1.d; boolean rescale = false; if (FastMath.abs(sumObserved - sumExpected) > 10e-6) { ratio = sumObserved / sumExpected; rescale = true; } double sumSq = 0.d; for (int i = 0; i < observed.length; i++) { if (rescale) { final double dev = observed[i] - ratio * expected[i]; sumSq += dev * dev / (ratio * expected[i]); } else { final double dev = observed[i] - expected[i]; sumSq += dev * dev / expected[i]; } } return sumSq; }
From source file:org.gitools.analysis.groupcomparison.format.math33Preview.CombinatoricsUtils.java
/** * Returns the <a// ww w.j av a 2s. c o m * href="http://mathworld.wolfram.com/StirlingNumberoftheSecondKind.html"> * Stirling number of the second kind</a>, "{@code S(n, k)}", the number of * ways of partitioning an {@code n}-element set into {@code k} non-empty * subsets. * <p> * The preconditions are {@code 0 <= k <= n } (otherwise * {@code NotPositiveException} is thrown) * </p> * * @param n the size of the set * @param k the number of non-empty subsets * @return {@code S(n, k)} * @throws NotPositiveException if {@code k < 0}. * @throws NumberIsTooLargeException if {@code k > n}. * @throws MathArithmeticException if some overflow happens, typically for n exceeding 25 and * k between 20 and n-2 (S(n,n-1) is handled specifically and does not overflow) * @since 3.1 */ public static long stirlingS2(final int n, final int k) throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { if (k < 0) { throw new NotPositiveException(k); } if (k > n) { throw new NumberIsTooLargeException(k, n, true); } long[][] stirlingS2 = STIRLING_S2.get(); if (stirlingS2 == null) { // the cache has never been initialized, compute the first numbers // by direct recurrence relation // as S(26,9) = 11201516780955125625 is larger than Long.MAX_VALUE // we must stop computation at row 26 final int maxIndex = 26; stirlingS2 = new long[maxIndex][]; stirlingS2[0] = new long[] { 1l }; for (int i = 1; i < stirlingS2.length; ++i) { stirlingS2[i] = new long[i + 1]; stirlingS2[i][0] = 0; stirlingS2[i][1] = 1; stirlingS2[i][i] = 1; for (int j = 2; j < i; ++j) { stirlingS2[i][j] = j * stirlingS2[i - 1][j] + stirlingS2[i - 1][j - 1]; } } // atomically save the cache STIRLING_S2.compareAndSet(null, stirlingS2); } if (n < stirlingS2.length) { // the number is in the small cache return stirlingS2[n][k]; } else { // use explicit formula to compute the number without caching it if (k == 0) { return 0; } else if (k == 1 || k == n) { return 1; } else if (k == 2) { return (1l << (n - 1)) - 1l; } else if (k == n - 1) { return binomialCoefficient(n, 2); } else { // definition formula: note that this may trigger some overflow long sum = 0; long sign = ((k & 0x1) == 0) ? 1 : -1; for (int j = 1; j <= k; ++j) { sign = -sign; sum += sign * binomialCoefficient(k, j) * ArithmeticUtils.pow(j, n); if (sum < 0) { // there was an overflow somewhere throw new MathArithmeticException(LocalizedFormats.ARGUMENT_OUTSIDE_DOMAIN, n, 0, stirlingS2.length - 1); } } return sum / factorial(k); } } }
From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java
/** * Check that all entries of the input array are >= 0. * * @param in Array to be tested//from w w w . ja v a 2 s. c o m * @throws NotPositiveException if any array entries are less than 0. * @since 3.1 */ public static void checkNonNegative(final long[] in) throws NotPositiveException { for (int i = 0; i < in.length; i++) { if (in[i] < 0) { throw new NotPositiveException(in[i]); } } }
From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java
/** * Check all entries of the input array are >= 0. * * @param in Array to be tested//w w w. j a va2 s . c om * @throws NotPositiveException if any array entries are less than 0. * @since 3.1 */ public static void checkNonNegative(final long[][] in) throws NotPositiveException { for (int i = 0; i < in.length; i++) { for (int j = 0; j < in[i].length; j++) { if (in[i][j] < 0) { throw new NotPositiveException(in[i][j]); } } } }
From source file:ro.hasna.ts.math.type.TesparSymbol.java
/** * Create a TESPAR symbol.//from w w w .jav a 2 s . c o m * * @param duration the number of samples between two successive real zeros (one epoch) * @param shape the number of local minimums (for a positive epoch) or * the number of local maximums (for a negative epoch) * @param amplitude the amplitude of the epoch */ public TesparSymbol(int duration, int shape, double amplitude) { this.duration = duration; this.shape = shape; if (amplitude < 0) { throw new NotPositiveException(amplitude); } this.amplitude = amplitude; }
From source file:utils.DBSCAN.TrajDbscan.java
/** * Creates a new instance of a DBSCANClusterer. * * @param eps maximum radius of the neighborhood to be considered * @param minPts minimum number of points needed for a cluster * @param measure the distance measure to use * @throws NotPositiveException if {@code eps < 0.0} or {@code minPts < 0} *///from www.j a va 2 s .com public TrajDbscan(final double eps, final int minPts, final DistanceMeasure measure) throws NotPositiveException { super(measure); if (eps < 0.0d) { throw new NotPositiveException(eps); } if (minPts < 0) { throw new NotPositiveException(minPts); } this.eps = eps; this.minPts = minPts; }