List of usage examples for org.apache.commons.math3.exception MathIllegalArgumentException MathIllegalArgumentException
public MathIllegalArgumentException(Localizable pattern, Object... args)
From source file:com.github.gerbsen.math.Frequency.java
/** * Adds 1 to the frequency count for v.//from w w w .j ava 2 s .c om * <p> * If other objects have already been added to this Frequency, v must * be comparable to those that have already been added. * </p> * * @param v the value to add. * @throws IllegalArgumentException if <code>v</code> is not comparable with previous entries */ public void addValue(Comparable<?> v) { Comparable<?> obj = v; if (v instanceof Integer) { obj = Long.valueOf(((Integer) v).longValue()); } try { Long count = freqTable.get(obj); if (count == null) { freqTable.put(obj, Long.valueOf(1)); } else { freqTable.put(obj, Long.valueOf(count.longValue() + 1)); } } catch (ClassCastException ex) { //TreeMap will throw ClassCastException if v is not comparable throw new MathIllegalArgumentException(LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES, v.getClass().getName()); } }
From source file:com.juliazozulia.wordusage.Utils.Frequency.java
/** * Increments the frequency count for v. * <p>//from w w w . j av a 2 s .c om * If other objects have already been added to this Frequency, v must * be comparable to those that have already been added. * </p> * * @param v the value to add. * @param increment the amount by which the value should be incremented * @throws MathIllegalArgumentException if <code>v</code> is not comparable with previous entries * @since 3.1 */ public void incrementValue(String v, Integer increment) throws MathIllegalArgumentException { String obj = v; try { Integer count = freqTable.get(obj); if (count == null) { freqTable.put(obj, Integer.valueOf(increment)); } else { freqTable.put(obj, Integer.valueOf(count + increment)); } } catch (ClassCastException ex) { //TreeMap will throw ClassCastException if v is not comparable throw new MathIllegalArgumentException(LocalizedFormats.INSTANCES_NOT_COMPARABLE_TO_EXISTING_VALUES, v.getClass().getName()); } }
From source file:experiment.FastCosineTransformer_bug.java
/** * Perform the FCT algorithm (including inverse). * * @param f the real data array to be transformed * @return the real transformed array/*from w ww . j a v a 2 s . c o m*/ * @throws MathIllegalArgumentException if the length of the data array is * not a power of two plus one */ protected double[] fct(double[] f) throws MathIllegalArgumentException { final double[] transformed = new double[f.length]; final int n = f.length - 1; if (!ArithmeticUtils.isPowerOfTwo(n)) { throw new MathIllegalArgumentException(LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE, Integer.valueOf(f.length)); } if (n == 1) { // trivial case transformed[0] = 0.5 * (f[0] + f[1]); transformed[1] = 0.5 * (f[0] - f[1]); return transformed; } // construct a new array and perform FFT on it final double[] x = new double[n]; x[0] = 0.5 * (f[0] + f[n]); String funname = "cosh/"; double tempexpression = 0; double[] data1 = { x[0], f[0], f[n] }; String expressionname = "x[0]"; log.add(1, data1, funname + expressionname); x[n >> 1] = f[n >> 1]; double[] data2 = { x[n >> 1], f[n >> 1] }; expressionname = "x[n>>1]"; log.add(2, data2, funname + expressionname); // temporary variable for transformed[1] double t1 = 0.5 * (f[0] - f[n]); double[] data3 = { t1, f[0], f[n] }; expressionname = "t1"; log.add(3, data3, funname + expressionname); double[] data4 = { f[0] - f[n], f[0], f[n] }; expressionname = "f[0]-f[n]"; log.add(4, data4, funname + expressionname); for (int i = 1; i < (n >> 1); i++) { final double a = 0.5 * (f[i] + f[n - i]); double[] data5 = { a, f[i], f[n - i] }; expressionname = "a"; log.add(5, data5, funname + expressionname); final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n - i]); double[] data6 = { b, FastMath.sin(i * FastMath.PI / n), (f[i] - f[n - i]) }; expressionname = "b"; log.add(6, data6, funname + expressionname); /*****bug2 store in Data2 FastMath.sin(i * FastMath.PI / n) to FastMath.sin(2*i * FastMath.PI / n)*******/ double[] data7 = { FastMath.sin(i * FastMath.PI / n), i * FastMath.PI, n }; expressionname = "FastMath.sin(i * FastMath.PI / n)"; log.add(7, data7, funname + expressionname); double[] data8 = { (f[i] - f[n - i]), f[i], f[n - i] }; expressionname = "f[i] - f[n - i]"; log.add(8, data8, funname + expressionname); final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n - i]); double[] data9 = { c, FastMath.cos(i * FastMath.PI / n), (f[i] - f[n - i]) }; expressionname = "c"; log.add(9, data9, funname + expressionname); double[] data10 = { FastMath.cos(i * FastMath.PI / n), i * FastMath.PI, n }; expressionname = "FastMath.cos(i * FastMath.PI / n)"; log.add(10, data10, funname + expressionname); double[] data11 = { (f[i] - f[n - i]), f[i], f[n - i] }; expressionname = "c"; log.add(11, data11, funname + expressionname); x[i] = a + b; double[] data12 = { x[i], a, b }; expressionname = "x[i]"; log.add(12, data12, funname + expressionname); x[n - i] = a - b; double[] data13 = { x[n - i], a, b }; expressionname = "x[n-i]"; log.add(13, data13, funname + expressionname); tempexpression = t1; t1 += c; double[] data14 = { t1, tempexpression, c }; expressionname = "t1"; log.add(14, data14, funname + expressionname); } FastFourierTransformer transformer; transformer = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] y = transformer.transform(x, TransformType.FORWARD); // reconstruct the FCT result for the original array transformed[0] = y[0].getReal(); double[] data15 = { transformed[0] }; expressionname = "transformed[0]"; log.add(15, data15, funname + expressionname); transformed[1] = t1; double[] data16 = { transformed[1] }; expressionname = "transformed[1]"; log.add(16, data16, funname + expressionname); for (int i = 1; i < (n >> 1); i++) { transformed[2 * i] = y[i].getReal(); double[] data17 = { transformed[2 * i] }; expressionname = "transformed[2 * i]"; log.add(17, data17, funname + expressionname); /***bug 1, store in Data1, add Math.abs() on transformed[2 * i - 1] - y[i].getImaginary()***/ transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary(); double[] data18 = { transformed[2 * i + 1], transformed[2 * i - 1], y[i].getImaginary() }; expressionname = "transformed[2 * i+1]"; log.add(18, data18, funname + expressionname); double[] data20 = { transformed[2 * i - 1] - y[i].getImaginary(), transformed[2 * i - 1], y[i].getImaginary() }; expressionname = "transformed[2 * i - 1] - y[i].getImaginary()"; log.add(20, data20, funname + expressionname); } transformed[n] = y[n >> 1].getReal(); double[] data19 = { transformed[n] }; expressionname = "transformed[n]"; log.add(19, data19, funname + expressionname); log.logFile(); log.clear(); return transformed; }
From source file:experiment.FastSineTransformer_bug.java
/** * Perform the FST algorithm (including inverse). The first element of the * data set is required to be {@code 0}. * * @param f the real data array to be transformed * @return the real transformed array//from www . j a va2s. c om * @throws MathIllegalArgumentException if the length of the data array is * not a power of two, or the first element of the data array is not zero */ protected double[] fst(double[] f) throws MathIllegalArgumentException { final double[] transformed = new double[f.length]; if (!ArithmeticUtils.isPowerOfTwo(f.length)) { throw new MathIllegalArgumentException(LocalizedFormats.NOT_POWER_OF_TWO_CONSIDER_PADDING, Integer.valueOf(f.length)); } if (f[0] != 0.0) { throw new MathIllegalArgumentException(LocalizedFormats.FIRST_ELEMENT_NOT_ZERO, Double.valueOf(f[0])); } final int n = f.length; if (n == 1) { // trivial case transformed[0] = 0.0; return transformed; } // construct a new array and perform FFT on it final double[] x = new double[n]; x[0] = 0.0; x[n >> 1] = 2.0 * f[n >> 1]; double[] data1 = { x[n >> 1], f[n >> 1] }; log.add(1, data1, "x[n>>1] f[n>>1]");//x[n>>1] f[n>>1] exp1 double[] data2 = { f[n >> 1] }; log.add(2, data2, "f[n>>1]");//f[n>>1] exp2 double tempa = 0; double tempb = 0; int tempi = 0; /*Bug2 change FastMath.PI/n to FastMath.PI/(n-1)+1E-10 store in Data1 * Bug 3 change 0.5 to 0.499 for b store in Data2 */ /*Bug1 add a small value*/ for (int i = 1; i < (n >> 1); i++) { final double a = FastMath.sin(i * FastMath.PI / n) * (f[i] + f[n - i]); final double b = 0.499 * (f[i] - f[n - i]); x[i] = a + b; x[n - i] = a - b; tempa = a; tempb = b; tempi = i; } double[] data3 = { tempa, FastMath.sin(tempi * FastMath.PI / n), f[tempi] + f[n - tempi] }; log.add(3, data3, "a");// a FastMath.sin(i*FastMath.PI/n) (f[i]+f[n-i]) double[] data4 = { FastMath.sin(tempi * FastMath.PI / n), (double) tempi };// FastMath.sin(i * FastMath.PI / n) i log.add(4, data4, "FastMath.sin(temp * FastMath.PI / n)"); double[] data5 = { f[tempi] + f[n - tempi], f[tempi], f[n - tempi] }; log.add(5, data5, "f[temp] + f[n - temp]");// (f[i] + f[n - i]) f[i] f[n-i] double[] data6 = { f[tempi] }; log.add(6, data6, "f[temp]");//f[i] double[] data7 = { f[n - tempi] }; log.add(7, data7, "f[n-temp]");//f[n-i] double[] data8 = { x[tempi], tempa, tempb }; log.add(8, data8, "x[i]");//x[i] a b double[] data9 = { x[n - tempi], tempa, tempb }; log.add(9, data9, "x[n-i]");//x[n-i] a b double[] data10 = { tempa }; log.add(10, data10, "a");//a double[] data11 = { tempb, f[tempi], f[n - tempi] }; log.add(11, data11, "b");//b FastFourierTransformer transformer; transformer = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] y = transformer.transform(x, TransformType.FORWARD); // reconstruct the FST result for the original array transformed[0] = 0.0; /*Bug 1 add a small number 0.03 to transformed[1] */ transformed[1] = 0.5 * y[0].getReal(); double[] data12 = { transformed[1], y[0].getReal() }; log.add(12, data12, "transformed[1]");//transformed[1] y[0].getReal() double[] data13 = { y[0].getReal() }; log.add(13, data13, "y[0].getReal()");//y[0].getReal() for (int i = 1; i < (n >> 1); i++) { /*Bug 4 add abs to y[i].getImaginary */ transformed[2 * i] = -y[i].getImaginary(); /*Bug 5 change 2*i-1 to 2*i */ transformed[2 * i + 1] = y[i].getReal() + transformed[2 * i - 1]; tempi = i; } double[] data14 = { transformed[2 * tempi] }; log.add(14, data14, "transformed[2*i]");// transformed[2*i] -y[i].getImaginary(); double[] data15 = { transformed[2 * tempi + 1], y[tempi].getReal(), transformed[2 * tempi - 1] };// transformed[2*i+1] y[i].getReal() transformed[2 * i - 1] log.add(15, data15, "transformed[2*ti+1]"); double[] data16 = { y[tempi].getReal() }; log.add(16, data16, "y[i].getReal()");// y[i].getReal() double[] data17 = { transformed[2 * tempi - 1] }; log.add(17, data17, "transformed[2 * i - 1]");// transformed[2 * i - 1] log.logFile(); log.clear(); return transformed; }
From source file:experiment.FastCosineTransformer_bug2.java
/** * Perform the FCT algorithm (including inverse). * //from w w w . jav a 2s.com * @param f * the real data array to be transformed * @return the real transformed array * @throws MathIllegalArgumentException * if the length of the data array is not a power of two plus * one */ protected double[] fct(double[] f) throws MathIllegalArgumentException { final double[] transformed = new double[f.length]; final int n = f.length - 1; if (!ArithmeticUtils.isPowerOfTwo(n)) { throw new MathIllegalArgumentException(LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE, Integer.valueOf(f.length)); } if (n == 1) { // trivial case transformed[0] = 0.5 * (f[0] + f[1]); transformed[1] = 0.5 * (f[0] - f[1]); return transformed; } test test1 = new test(); // construct a new array and perform FFT on it final double[] x = new double[n]; x[0] = 0.5 * (f[0] + f[n]); String funname = "cosh/"; double tempexpression = 0; double ta = 3.24, tb = 2.31, tc = 7.86, td = 5.12; int te = 2; boolean tf = false; x[n >> 1] = f[n >> 1]; ta = tb + tc + mid((int) ta + 1, (int) tb, (int) tc) + td; // temporary variable for transformed[1] double t1 = 0.5 * (f[0] - f[n]); ta = (te >> 2) + tc % tb + td; ta = tb + tc + td; ta = tb + tc - td; ta = tb + tc + td + te; ta = tb * tc * td; ta = tb * tc / td; ta = tb * tc * td * te; ta = ta * ta + tb * tb + tc * tc; ta = tc - (td + te); ta = tc + tb - (td + te + tc); ta = tc * tb / tc + test1.a + 3; ta = tc + tb / td - test1.f.a; ta = td + Math.cos(ta + tc - td - te * tb) + tb; ta = Math.min(tc, td + 1) + 1; for (int i = 1; i < (n >> 1); i++) { final double a = 0.5 * (f[i] + f[n - i]); final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n - i]); /***** * bug2 store in Data2 FastMath.sin(i * FastMath.PI / n) to * FastMath.sin(2*i * FastMath.PI / n) *******/ final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n - i]); x[i] = a + b; x[n - i] = a - b; tempexpression = t1; t1 = t1 + c; } FastFourierTransformer transformer; transformer = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] y = transformer.transform(x, TransformType.FORWARD); // reconstruct the FCT result for the original array transformed[0] = y[0].getReal(); transformed[1] = t1; for (int i = 1; i < (n >> 1); i++) { transformed[2 * i] = y[i].getReal(); /*** * bug 1, store in Data1, add Math.abs() on transformed[2 * i - 1] - * y[i].getImaginary() ***/ transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary(); } transformed[n] = y[n >> 1].getReal(); return transformed; }
From source file:org.gitools.analysis.groupcomparison.format.math33Preview.MathArrays.java
/** * This method is used// w w w . j av a2s . co m * to verify that the begin and length parameters designate a subarray of positive length * and the weights are all non-negative, non-NaN, finite, and not all zero. * <p> * <ul> * <li>returns <code>true</code> iff the parameters designate a subarray of * non-negative length and the weights array contains legitimate values.</li> * <li>throws <code>MathIllegalArgumentException</code> if any of the following are true: * <ul><li>the values array is null</li> * <li>the weights array is null</li> * <li>the weights array does not have the same length as the values array</li> * <li>the weights array contains one or more infinite values</li> * <li>the weights array contains one or more NaN values</li> * <li>the weights array contains negative values</li> * <li>the start and length arguments do not determine a valid array</li></ul> * </li> * <li>returns <code>false</li> if the array is non-null, but * <code>length</code> is 0 unless <code>allowEmpty</code> is <code>true</code>. * </ul></p> * * @param values the input array. * @param weights the weights array. * @param begin index of the first array element to include. * @param length the number of elements to include. * @param allowEmpty if {@code true} than allow zero length arrays to pass. * @return {@code true} if the parameters are valid. * @throws NullArgumentException if either of the arrays are null * @throws MathIllegalArgumentException if the array indices are not valid, * the weights array contains NaN, infinite or negative elements, or there * are no positive weights. * @since 3.3 */ public static boolean verifyValues(final double[] values, final double[] weights, final int begin, final int length, final boolean allowEmpty) throws MathIllegalArgumentException { if (weights == null || values == null) { throw new NullArgumentException(LocalizedFormats.INPUT_ARRAY); } if (weights.length != values.length) { throw new DimensionMismatchException(weights.length, values.length); } boolean containsPositiveWeight = false; for (int i = begin; i < begin + length; i++) { final double weight = weights[i]; if (Double.isNaN(weight)) { throw new MathIllegalArgumentException(LocalizedFormats.NAN_ELEMENT_AT_INDEX, Integer.valueOf(i)); } if (Double.isInfinite(weight)) { throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_ARRAY_ELEMENT, Double.valueOf(weight), Integer.valueOf(i)); } if (weight < 0) { throw new MathIllegalArgumentException(LocalizedFormats.NEGATIVE_ELEMENT_AT_INDEX, Integer.valueOf(i), Double.valueOf(weight)); } if (!containsPositiveWeight && weight > 0.0) { containsPositiveWeight = true; } } if (!containsPositiveWeight) { throw new MathIllegalArgumentException(LocalizedFormats.WEIGHT_AT_LEAST_ONE_NON_ZERO); } return verifyValues(values, begin, length, allowEmpty); }