org.apache.commons.math3.exception.NoDataException Java Examples
The following examples show how to use
org.apache.commons.math3.exception.NoDataException.
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: AbstractRealMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public RealMatrix getSubMatrix(final int[] selectedRows, final int[] selectedColumns) throws NullArgumentException, NoDataException, OutOfRangeException { MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); final RealMatrix subMatrix = createMatrix(selectedRows.length, selectedColumns.length); subMatrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() { /** {@inheritDoc} */ @Override public double visit(final int row, final int column, final double value) { return getEntry(selectedRows[row], selectedColumns[column]); } }); return subMatrix; }
Example #2
Source File: PiecewiseBicubicSplineInterpolator.java From astor with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public PiecewiseBicubicSplineInterpolatingFunction interpolate( final double[] xval, final double[] yval, final double[][] fval) throws DimensionMismatchException, NullArgumentException, NoDataException, NonMonotonicSequenceException { if ( xval == null || yval == null || fval == null || fval[0] == null ) { throw new NullArgumentException(); } if ( xval.length == 0 || yval.length == 0 || fval.length == 0 ) { throw new NoDataException(); } MathArrays.checkOrder(xval); MathArrays.checkOrder(yval); return new PiecewiseBicubicSplineInterpolatingFunction( xval, yval, fval ); }
Example #3
Source File: ComplexFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create an instance with a custom imaginary character, a custom number * format for the real part, and a custom number format for the imaginary * part. * * @param imaginaryCharacter The custom imaginary character. * @param realFormat the custom format for the real part. * @param imaginaryFormat the custom format for the imaginary part. * @throws NullArgumentException if {@code imaginaryCharacter} is * {@code null}. * @throws NoDataException if {@code imaginaryCharacter} is an * empty string. * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}. * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public ComplexFormat(String imaginaryCharacter, NumberFormat realFormat, NumberFormat imaginaryFormat) throws NullArgumentException, NoDataException { if (imaginaryCharacter == null) { throw new NullArgumentException(); } if (imaginaryCharacter.length() == 0) { throw new NoDataException(); } if (imaginaryFormat == null) { throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } if (realFormat == null) { throw new NullArgumentException(LocalizedFormats.REAL_FORMAT); } this.imaginaryCharacter = imaginaryCharacter; this.imaginaryFormat = imaginaryFormat; this.realFormat = realFormat; }
Example #4
Source File: AbstractRealMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public void copySubMatrix(int[] selectedRows, int[] selectedColumns, double[][] destination) throws OutOfRangeException, NullArgumentException, NoDataException, MatrixDimensionMismatchException { MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw new MatrixDimensionMismatchException(destination.length, destination[0].length, selectedRows.length, selectedColumns.length); } for (int i = 0; i < selectedRows.length; i++) { final double[] destinationI = destination[i]; for (int j = 0; j < selectedColumns.length; j++) { destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]); } } }
Example #5
Source File: StatUtils.java From astor with GNU General Public License v2.0 | 6 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) throws DimensionMismatchException, NoDataException { 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 #6
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 #7
Source File: MapUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Computes the topographic error. * The topographic error is the proportion of data for which first and * second best matching units are not adjacent in the map. * * @param data Feature vectors. * @param net Network. * @param distance Distance function. * @return the error. * @throws NoDataException if {@code data} is empty. */ public static double computeTopographicError(Iterable<double[]> data, Network net, DistanceMeasure distance) { int notAdjacentCount = 0; int count = 0; for (double[] f : data) { ++count; final Pair<Neuron, Neuron> p = findBestAndSecondBest(f, net, distance); if (!net.getNeighbours(p.getFirst()).contains(p.getSecond())) { // Increment count if first and second best matching units // are not neighbours. ++notAdjacentCount; } } if (count == 0) { throw new NoDataException(); } return ((double) notAdjacentCount) / count; }
Example #8
Source File: StepFunction.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Builds a step function from a list of arguments and the corresponding * values. Specifically, returns the function h(x) defined by <pre><code> * h(x) = y[0] for all x < x[1] * y[1] for x[1] <= x < x[2] * ... * y[y.length - 1] for x >= x[x.length - 1] * </code></pre> * The value of {@code x[0]} is ignored, but it must be strictly less than * {@code x[1]}. * * @param x Domain values where the function changes value. * @param y Values of the function. * @throws NonMonotonicSequenceException * if the {@code x} array is not sorted in strictly increasing order. * @throws NullArgumentException if {@code x} or {@code y} are {@code null}. * @throws NoDataException if {@code x} or {@code y} are zero-length. * @throws DimensionMismatchException if {@code x} and {@code y} do not * have the same length. */ public StepFunction(double[] x, double[] y) throws NullArgumentException, NoDataException, DimensionMismatchException, NonMonotonicSequenceException { if (x == null || y == null) { throw new NullArgumentException(); } if (x.length == 0 || y.length == 0) { throw new NoDataException(); } if (y.length != x.length) { throw new DimensionMismatchException(y.length, x.length); } MathArrays.checkOrder(x); abscissa = MathArrays.copyOf(x); ordinate = MathArrays.copyOf(y); }
Example #9
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a column {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param columnData the input column data * @return a columnData x 1 FieldMatrix * @throws NoDataException if {@code data} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createColumnFieldMatrix(final T[] columnData) { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final FieldMatrix<T> m = createFieldMatrix(columnData[0].getField(), nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #10
Source File: AbstractRealMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public RealMatrix getSubMatrix(final int[] selectedRows, final int[] selectedColumns) throws NullArgumentException, NoDataException, OutOfRangeException { MatrixUtils.checkSubMatrixIndex(this, selectedRows, selectedColumns); final RealMatrix subMatrix = createMatrix(selectedRows.length, selectedColumns.length); subMatrix.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() { /** {@inheritDoc} */ @Override public double visit(final int row, final int column, final double value) { return getEntry(selectedRows[row], selectedColumns[column]); } }); return subMatrix; }
Example #11
Source File: MapUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Computes the quantization error. * The quantization error is the average distance between a feature vector * and its "best matching unit" (closest neuron). * * @param data Feature vectors. * @param neurons List of neurons to scan. * @param distance Distance function. * @return the error. * @throws NoDataException if {@code data} is empty. */ public static double computeQuantizationError(Iterable<double[]> data, Iterable<Neuron> neurons, DistanceMeasure distance) { double d = 0; int count = 0; for (double[] f : data) { ++count; d += distance.compute(f, findBest(f, neurons, distance).getFeatures()); } if (count == 0) { throw new NoDataException(); } return d / count; }
Example #12
Source File: WilcoxonSignedRankTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Ensures that the provided arrays fulfills the assumptions. * * @param x first sample * @param y second sample * @throws NullArgumentException if {@code x} or {@code y} are {@code null}. * @throws NoDataException if {@code x} or {@code y} are zero-length. * @throws DimensionMismatchException if {@code x} and {@code y} do not * have the same length. */ private void ensureDataConformance(final double[] x, final double[] y) throws NullArgumentException, NoDataException, DimensionMismatchException { if (x == null || y == null) { throw new NullArgumentException(); } if (x.length == 0 || y.length == 0) { throw new NoDataException(); } if (y.length != x.length) { throw new DimensionMismatchException(y.length, x.length); } }
Example #13
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws NoDataException if {@code rowData} is empty. * @throws NullArgumentException if {@code rowData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) throws NoDataException, NullArgumentException { if (rowData == null) { throw new NullArgumentException(); } final int nCols = rowData.length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; }
Example #14
Source File: ComplexFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create an instance with a custom imaginary character, a custom number * format for the real part, and a custom number format for the imaginary * part. * * @param imaginaryCharacter The custom imaginary character. * @param realFormat the custom format for the real part. * @param imaginaryFormat the custom format for the imaginary part. * @throws NullArgumentException if {@code imaginaryCharacter} is * {@code null}. * @throws NoDataException if {@code imaginaryCharacter} is an * empty string. * @throws NullArgumentException if {@code imaginaryFormat} is {@code null}. * @throws NullArgumentException if {@code realFormat} is {@code null}. */ public ComplexFormat(String imaginaryCharacter, NumberFormat realFormat, NumberFormat imaginaryFormat) throws NullArgumentException, NoDataException { if (imaginaryCharacter == null) { throw new NullArgumentException(); } if (imaginaryCharacter.length() == 0) { throw new NoDataException(); } if (imaginaryFormat == null) { throw new NullArgumentException(LocalizedFormats.IMAGINARY_FORMAT); } if (realFormat == null) { throw new NullArgumentException(LocalizedFormats.REAL_FORMAT); } this.imaginaryCharacter = imaginaryCharacter; this.imaginaryFormat = imaginaryFormat; this.realFormat = realFormat; }
Example #15
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** {@inheritDoc} */ public void copySubMatrix(int[] selectedRows, int[] selectedColumns, T[][] destination) throws MatrixDimensionMismatchException, NoDataException, NullArgumentException, OutOfRangeException { // safety checks checkSubMatrixIndex(selectedRows, selectedColumns); if ((destination.length < selectedRows.length) || (destination[0].length < selectedColumns.length)) { throw new MatrixDimensionMismatchException(destination.length, destination[0].length, selectedRows.length, selectedColumns.length); } // copy entries for (int i = 0; i < selectedRows.length; i++) { final T[] destinationI = destination[i]; for (int j = 0; j < selectedColumns.length; j++) { destinationI[j] = getEntry(selectedRows[i], selectedColumns[j]); } } }
Example #16
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a row {@link FieldMatrix} using the data from the input * array. * * @param <T> the type of the field elements * @param rowData the input row data * @return a 1 x rowData.length FieldMatrix * @throws NoDataException if {@code rowData} is empty. * @throws NullArgumentException if {@code rowData} is {@code null}. */ public static <T extends FieldElement<T>> FieldMatrix<T> createRowFieldMatrix(final T[] rowData) throws NoDataException, NullArgumentException { if (rowData == null) { throw new NullArgumentException(); } final int nCols = rowData.length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } final FieldMatrix<T> m = createFieldMatrix(rowData[0].getField(), 1, nCols); for (int i = 0; i < nCols; ++i) { m.setEntry(0, i, rowData[i]); } return m; }
Example #17
Source File: WilcoxonSignedRankTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Calculates |z[i]| for all i * * @param z sample * @return |z| * @throws NullArgumentException if {@code z} is {@code null} * @throws NoDataException if {@code z} is zero-length. */ private double[] calculateAbsoluteDifferences(final double[] z) throws NullArgumentException, NoDataException { if (z == null) { throw new NullArgumentException(); } if (z.length == 0) { throw new NoDataException(); } final double[] zAbs = new double[z.length]; for (int i = 0; i < z.length; ++i) { zAbs[i] = FastMath.abs(z[i]); } return zAbs; }
Example #18
Source File: Array2DRowFieldMatrix.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Create a new {@code FieldMatrix<T>} using the input array as the underlying * data array. * <p>If an array is built specially in order to be embedded in a * {@code FieldMatrix<T>} and not used directly, the {@code copyArray} may be * set to {@code false}. This will prevent the copying and improve * performance as no new array will be built and no data will be copied.</p> * * @param field Field to which the elements belong. * @param d Data for the new matrix. * @param copyArray Whether to copy or reference the input array. * @throws DimensionMismatchException if {@code d} is not rectangular. * @throws NoDataException if there are not at least one row and one column. * @throws NullArgumentException if {@code d} is {@code null}. * @see #Array2DRowFieldMatrix(FieldElement[][]) */ public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray) throws DimensionMismatchException, NoDataException, NullArgumentException { super(field); if (copyArray) { copyIn(d); } else { MathUtils.checkNotNull(d); final int nRows = d.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = d[0].length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; r++) { if (d[r].length != nCols) { throw new DimensionMismatchException(nCols, d[r].length); } } data = d; } }
Example #19
Source File: ModifiedLoess.java From thunderstorm with GNU General Public License v3.0 | 6 votes |
/** * Compute an interpolating function by performing a loess fit * on the data at the original abscissae and then building a cubic spline * with a * {@link org.apache.commons.math3.analysis.interpolation.SplineInterpolator} * on the resulting fit. * * @param xval the arguments for the interpolation points * @param yval the values for the interpolation points * @return A cubic spline built upon a loess fit to the data at the original abscissae * @throws NonMonotonicSequenceException if {@code xval} not sorted in * strictly increasing order. * @throws DimensionMismatchException if {@code xval} and {@code yval} have * different sizes. * @throws NoDataException if {@code xval} or {@code yval} has zero size. * @throws NotFiniteNumberException if any of the arguments and values are * not finite real numbers. * @throws NumberIsTooSmallException if the bandwidth is too small to * accomodate the size of the input data (i.e. the bandwidth must be * larger than 2/n). */ public final PolynomialSplineFunction interpolate(double[] xval, double[] yval) throws NonMonotonicSequenceException, DimensionMismatchException, NoDataException, NotFiniteNumberException, NumberIsTooSmallException { double[] smoothed = smooth(xval, yval); DoubleList newX = new ArrayDoubleList(); DoubleList newSmoothed = new ArrayDoubleList(); newX.add(xval[0]); newSmoothed.add(smoothed[0]); for(int i = 1; i < xval.length; i++){ if(xval[i] != xval[i-1]){ newX.add(xval[i]); newSmoothed.add(smoothed[i]); } } xval = newX.toArray(); smoothed = newSmoothed.toArray(); return new SplineInterpolator().interpolate(xval, smoothed); }
Example #20
Source File: PolynomialFunction.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Uses Horner's Method to evaluate the polynomial with the given coefficients at * the argument. * * @param coefficients Coefficients of the polynomial to evaluate. * @param argument Input value. * @return the value of the polynomial. * @throws NoDataException if {@code coefficients} is empty. * @throws NullArgumentException if {@code coefficients} is {@code null}. */ protected static double evaluate(double[] coefficients, double argument) throws NullArgumentException, NoDataException { MathUtils.checkNotNull(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } double result = coefficients[n - 1]; for (int j = n - 2; j >= 0; j--) { result = argument * result + coefficients[j]; } return result; }
Example #21
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws DimensionMismatchException, OutOfRangeException, NoDataException, NullArgumentException { if (subMatrix == null) { throw new NullArgumentException(); } final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw new DimensionMismatchException(nCols, subMatrix[r].length); } } checkRowIndex(row); checkColumnIndex(column); checkRowIndex(nRows + row - 1); checkColumnIndex(nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } }
Example #22
Source File: AbstractMultipleLinearRegression.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Loads new y sample data, overriding any previous data. * * @param y the array representing the y sample * @throws NullArgumentException if y is null * @throws NoDataException if y is empty */ protected void newYSampleData(double[] y) { if (y == null) { throw new NullArgumentException(); } if (y.length == 0) { throw new NoDataException(); } this.yVector = new ArrayRealVector(y); }
Example #23
Source File: MathArrays.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution"> * convolution</a> between two sequences. * The solution is obtained via straightforward computation of the * convolution sum (and not via FFT). * Whenever the computation needs an element that would be located * at an index outside the input arrays, the value is assumed to be * zero. * * @param x First sequence. * Typically, this sequence will represent an input signal to a system. * @param h Second sequence. * Typically, this sequence will represent the impulse response of the * system. * @return the convolution of {@code x} and {@code h}. * This array's length will be {@code x.length + h.length - 1}. * @throws NullArgumentException if either {@code x} or {@code h} is * {@code null}. * @throws NoDataException if either {@code x} or {@code h} is empty. * * @since 3.3 */ public static double[] convolve(double[] x, double[] h) throws NullArgumentException, NoDataException { MathUtils.checkNotNull(x); MathUtils.checkNotNull(h); final int xLen = x.length; final int hLen = h.length; if (xLen == 0 || hLen == 0) { throw new NoDataException(); } // initialize the output array final int totalLength = xLen + hLen - 1; final double[] y = new double[totalLength]; // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; int k = FastMath.max(0, n + 1 - xLen); int j = n - k; while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; } y[n] = yn; } return y; }
Example #24
Source File: AbstractRealMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ public void setSubMatrix(final double[][] subMatrix, final int row, final int column) throws NoDataException, DimensionMismatchException, NullArgumentException { MathUtils.checkNotNull(subMatrix); final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw new DimensionMismatchException(nCols, subMatrix[r].length); } } MatrixUtils.checkRowIndex(this, row); MatrixUtils.checkColumnIndex(this, column); MatrixUtils.checkRowIndex(this, nRows + row - 1); MatrixUtils.checkColumnIndex(this, nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } }
Example #25
Source File: MatrixUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Creates a column {@link RealMatrix} using the data from the input * array. * * @param columnData the input column data * @return a columnData x 1 RealMatrix * @throws NoDataException if {@code columnData} is empty. * @throws NullArgumentException if {@code columnData} is {@code null}. */ public static RealMatrix createColumnRealMatrix(double[] columnData) throws NoDataException, NullArgumentException { if (columnData == null) { throw new NullArgumentException(); } final int nRows = columnData.length; final RealMatrix m = createRealMatrix(nRows, 1); for (int i = 0; i < nRows; ++i) { m.setEntry(i, 0, columnData[i]); } return m; }
Example #26
Source File: MathArrays.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Calculates the <a href="http://en.wikipedia.org/wiki/Convolution"> * convolution</a> between two sequences. * <p> * The solution is obtained via straightforward computation of the * convolution sum (and not via FFT). Whenever the computation needs * an element that would be located at an index outside the input arrays, * the value is assumed to be zero. * * @param x First sequence. * Typically, this sequence will represent an input signal to a system. * @param h Second sequence. * Typically, this sequence will represent the impulse response of the system. * @return the convolution of {@code x} and {@code h}. * This array's length will be {@code x.length + h.length - 1}. * @throws NullArgumentException if either {@code x} or {@code h} is {@code null}. * @throws NoDataException if either {@code x} or {@code h} is empty. * * @since 3.3 */ public static double[] convolve(double[] x, double[] h) throws NullArgumentException, NoDataException { MathUtils.checkNotNull(x); MathUtils.checkNotNull(h); final int xLen = x.length; final int hLen = h.length; if (xLen == 0 || hLen == 0) { throw new NoDataException(); } // initialize the output array final int totalLength = xLen + hLen - 1; final double[] y = new double[totalLength]; // straightforward implementation of the convolution sum for (int n = 0; n < totalLength; n++) { double yn = 0; int k = FastMath.max(0, n + 1 - xLen); int j = n - k; while (k < hLen && j >= 0) { yn += x[j--] * h[k++]; } y[n] = yn; } return y; }
Example #27
Source File: AbstractFieldMatrix.java From astor with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} * */ public void setSubMatrix(final T[][] subMatrix, final int row, final int column) throws DimensionMismatchException, NoDataException, NullArgumentException, OutOfRangeException { if (subMatrix == null) { throw new NullArgumentException(); } final int nRows = subMatrix.length; if (nRows == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW); } final int nCols = subMatrix[0].length; if (nCols == 0) { throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN); } for (int r = 1; r < nRows; ++r) { if (subMatrix[r].length != nCols) { throw new DimensionMismatchException(nCols, subMatrix[r].length); } } checkRowIndex(row); checkColumnIndex(column); checkRowIndex(nRows + row - 1); checkColumnIndex(nCols + column - 1); for (int i = 0; i < nRows; ++i) { for (int j = 0; j < nCols; ++j) { setEntry(row + i, column + j, subMatrix[i][j]); } } }
Example #28
Source File: PolynomialFunction.java From astor with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} * @since 3.1 * @throws NoDataException if {@code coefficients} is empty. * @throws NullArgumentException if {@code coefficients} is {@code null}. */ public DerivativeStructure value(final DerivativeStructure t) throws NullArgumentException, NoDataException { MathUtils.checkNotNull(coefficients); int n = coefficients.length; if (n == 0) { throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY); } DerivativeStructure result = new DerivativeStructure(t.getFreeParameters(), t.getOrder(), coefficients[n - 1]); for (int j = n - 2; j >= 0; j--) { result = result.multiply(t).add(coefficients[j]); } return result; }
Example #29
Source File: MannWhitneyUTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Ensures that the provided arrays fulfills the assumptions. * * @param x first sample * @param y second sample * @throws NullArgumentException if {@code x} or {@code y} are {@code null}. * @throws NoDataException if {@code x} or {@code y} are zero-length. */ private void ensureDataConformance(final double[] x, final double[] y) throws NullArgumentException, NoDataException { if (x == null || y == null) { throw new NullArgumentException(); } if (x.length == 0 || y.length == 0) { throw new NoDataException(); } }
Example #30
Source File: TestUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * @see org.apache.commons.math3.stat.inference.TTest#pairedTTest(double[], double[], double) */ public static boolean pairedTTest(final double[] sample1, final double[] sample2, final double alpha) throws NullArgumentException, NoDataException, DimensionMismatchException, NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException { return T_TEST.pairedTTest(sample1, sample2, alpha); }