Filled throws clauses for the analysis package.
JIRA: MATH-854 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1455194 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ad5595706
commit
6f3165670c
|
@ -172,8 +172,11 @@ public class FunctionUtils {
|
|||
return r;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public DerivativeStructure value(final DerivativeStructure t) {
|
||||
/** {@inheritDoc}
|
||||
* @throws DimensionMismatchException if functions are not consistent with each other
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
DerivativeStructure r = f[0].value(t);
|
||||
for (int i = 1; i < f.length; i++) {
|
||||
r = r.add(f[i].value(t));
|
||||
|
@ -418,8 +421,8 @@ public class FunctionUtils {
|
|||
* @throws NotStrictlyPositiveException if the number of sample points
|
||||
* {@code n} is negative.
|
||||
*/
|
||||
public static double[] sample(UnivariateFunction f,
|
||||
double min, double max, int n) {
|
||||
public static double[] sample(UnivariateFunction f, double min, double max, int n)
|
||||
throws NumberIsTooLargeException, NotStrictlyPositiveException {
|
||||
|
||||
if (n <= 0) {
|
||||
throw new NotStrictlyPositiveException(
|
||||
|
@ -609,8 +612,8 @@ public class FunctionUtils {
|
|||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of parameters or derivation
|
||||
* order are higher than 1
|
||||
* @exception NumberIsTooLargeException if derivation order is higher than 1
|
||||
* @exception DimensionMismatchException if numbers of free parameters are inconsistent
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure[] t)
|
||||
throws DimensionMismatchException, NumberIsTooLargeException {
|
||||
|
@ -732,8 +735,8 @@ public class FunctionUtils {
|
|||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of parameters or derivation
|
||||
* order are higher than 1
|
||||
* @exception NumberIsTooLargeException if derivation order is higher than 1
|
||||
* @exception DimensionMismatchException if numbers of free parameters are inconsistent
|
||||
*/
|
||||
public DerivativeStructure[] value(final DerivativeStructure[] t)
|
||||
throws DimensionMismatchException, NumberIsTooLargeException {
|
||||
|
|
|
@ -22,6 +22,9 @@ import java.util.List;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathArithmeticException;
|
||||
import org.apache.commons.math3.exception.MathInternalError;
|
||||
import org.apache.commons.math3.exception.NotPositiveException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math3.util.ArithmeticUtils;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
@ -154,9 +157,11 @@ public class DSCompiler {
|
|||
* @param order derivation order
|
||||
* @param valueCompiler compiler for the value part
|
||||
* @param derivativeCompiler compiler for the derivative part
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
*/
|
||||
private DSCompiler(final int parameters, final int order,
|
||||
final DSCompiler valueCompiler, final DSCompiler derivativeCompiler) {
|
||||
final DSCompiler valueCompiler, final DSCompiler derivativeCompiler)
|
||||
throws NumberIsTooLargeException {
|
||||
|
||||
this.parameters = parameters;
|
||||
this.order = order;
|
||||
|
@ -181,8 +186,10 @@ public class DSCompiler {
|
|||
* @param parameters number of free parameters
|
||||
* @param order derivation order
|
||||
* @return cached rules set
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
*/
|
||||
public static DSCompiler getCompiler(int parameters, int order) {
|
||||
public static DSCompiler getCompiler(int parameters, int order)
|
||||
throws NumberIsTooLargeException {
|
||||
|
||||
// get the cached compilers
|
||||
final DSCompiler[][] cache = compilers.get();
|
||||
|
@ -400,12 +407,14 @@ public class DSCompiler {
|
|||
* @param sizes sizes array
|
||||
* @param derivativesIndirection derivatives indirection array
|
||||
* @return multiplication indirection array
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
*/
|
||||
private static int[][][] compileCompositionIndirection(final int parameters, final int order,
|
||||
final DSCompiler valueCompiler,
|
||||
final DSCompiler derivativeCompiler,
|
||||
final int[][] sizes,
|
||||
final int[][] derivativesIndirection) {
|
||||
final DSCompiler valueCompiler,
|
||||
final DSCompiler derivativeCompiler,
|
||||
final int[][] sizes,
|
||||
final int[][] derivativesIndirection)
|
||||
throws NumberIsTooLargeException {
|
||||
|
||||
if ((parameters == 0) || (order == 0)) {
|
||||
return new int[][][] { { { 1, 0 } } };
|
||||
|
@ -596,10 +605,12 @@ public class DSCompiler {
|
|||
* @param destSizes sizes array for the destination derivative structure
|
||||
* @return index of the partial derivative with the <em>same</em> characteristics
|
||||
* in destination derivative structure
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
*/
|
||||
private static int convertIndex(final int index,
|
||||
final int srcP, final int[][] srcDerivativesIndirection,
|
||||
final int destP, final int destO, final int[][] destSizes) {
|
||||
final int destP, final int destO, final int[][] destSizes)
|
||||
throws NumberIsTooLargeException {
|
||||
int[] orders = new int[destP];
|
||||
System.arraycopy(srcDerivativesIndirection[index], 0, orders, 0, FastMath.min(srcP, destP));
|
||||
return getPartialDerivativeIndex(destP, destO, destSizes, orders);
|
||||
|
@ -1730,15 +1741,23 @@ public class DSCompiler {
|
|||
* @param dsOffset offset of the derivative structure in its array
|
||||
* @param delta parameters offsets (Δx, Δy, ...)
|
||||
* @return value of the Taylor expansion at x + Δx, y + Δy, ...
|
||||
* @throws MathArithmeticException if factorials becomes too large
|
||||
*/
|
||||
public double taylor(final double[] ds, final int dsOffset, final double ... delta) {
|
||||
public double taylor(final double[] ds, final int dsOffset, final double ... delta)
|
||||
throws MathArithmeticException {
|
||||
double value = 0;
|
||||
for (int i = getSize() - 1; i >= 0; --i) {
|
||||
final int[] orders = getPartialDerivativeOrders(i);
|
||||
double term = ds[dsOffset + i];
|
||||
for (int k = 0; k < orders.length; ++k) {
|
||||
if (orders[k] > 0) {
|
||||
term *= FastMath.pow(delta[k], orders[k]) / ArithmeticUtils.factorial(orders[k]);
|
||||
try {
|
||||
term *= FastMath.pow(delta[k], orders[k]) /
|
||||
ArithmeticUtils.factorial(orders[k]);
|
||||
} catch (NotPositiveException e) {
|
||||
// this cannot happen
|
||||
throw new MathInternalError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
value += term;
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.commons.math3.RealFieldElement;
|
|||
import org.apache.commons.math3.Field;
|
||||
import org.apache.commons.math3.FieldElement;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathArithmeticException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooLargeException;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
|
@ -80,8 +81,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
/** Build an instance with all values and derivatives set to 0.
|
||||
* @param parameters number of free parameters
|
||||
* @param order derivation order
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
*/
|
||||
public DerivativeStructure(final int parameters, final int order) {
|
||||
public DerivativeStructure(final int parameters, final int order)
|
||||
throws NumberIsTooLargeException {
|
||||
this(DSCompiler.getCompiler(parameters, order));
|
||||
}
|
||||
|
||||
|
@ -89,9 +92,11 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* @param parameters number of free parameters
|
||||
* @param order derivation order
|
||||
* @param value value of the constant
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
* @see #DerivativeStructure(int, int, int, double)
|
||||
*/
|
||||
public DerivativeStructure(final int parameters, final int order, final double value) {
|
||||
public DerivativeStructure(final int parameters, final int order, final double value)
|
||||
throws NumberIsTooLargeException {
|
||||
this(parameters, order);
|
||||
this.data[0] = value;
|
||||
}
|
||||
|
@ -193,10 +198,11 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* {@link DSCompiler#getPartialDerivativeIndex(int...)}
|
||||
* @exception DimensionMismatchException if derivatives array does not match the
|
||||
* {@link DSCompiler#getSize() size} expected by the compiler
|
||||
* @throws NumberIsTooLargeException if order is too large
|
||||
* @see #getAllDerivatives()
|
||||
*/
|
||||
public DerivativeStructure(final int parameters, final int order, final double ... derivatives)
|
||||
throws DimensionMismatchException {
|
||||
throws DimensionMismatchException, NumberIsTooLargeException {
|
||||
this(parameters, order);
|
||||
if (derivatives.length != data.length) {
|
||||
throw new DimensionMismatchException(derivatives.length, data.length);
|
||||
|
@ -269,7 +275,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return ds;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure add(final DerivativeStructure a)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(a.compiler);
|
||||
|
@ -283,7 +292,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return add(-a);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure subtract(final DerivativeStructure a)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(a.compiler);
|
||||
|
@ -306,7 +318,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return ds;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure multiply(final DerivativeStructure a)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(a.compiler);
|
||||
|
@ -324,7 +339,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return ds;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure divide(final DerivativeStructure a)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(a.compiler);
|
||||
|
@ -340,7 +358,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return ds;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure remainder(final DerivativeStructure a)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(a.compiler);
|
||||
|
@ -412,7 +433,7 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public DerivativeStructure copySign(final double sign){
|
||||
public DerivativeStructure copySign(final double sign) {
|
||||
long m = Double.doubleToLongBits(data[0]);
|
||||
long s = Double.doubleToLongBits(sign);
|
||||
if ((m >= 0 && s >= 0) || (m < 0 && s < 0)) { // Sign is currently OK
|
||||
|
@ -442,7 +463,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return ds;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure hypot(final DerivativeStructure y)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
|
@ -500,7 +524,8 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* @param x a value
|
||||
* @param y a value
|
||||
* @return sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
|
||||
* @exception DimensionMismatchException if number of free parameters or orders are inconsistent
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public static DerivativeStructure hypot(final DerivativeStructure x, final DerivativeStructure y)
|
||||
throws DimensionMismatchException {
|
||||
|
@ -515,7 +540,8 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* @exception DimensionMismatchException if the number of derivatives
|
||||
* in the array is not equal to {@link #getOrder() order} + 1
|
||||
*/
|
||||
public DerivativeStructure compose(final double ... f) {
|
||||
public DerivativeStructure compose(final double ... f)
|
||||
throws DimensionMismatchException {
|
||||
if (f.length != getOrder() + 1) {
|
||||
throw new DimensionMismatchException(f.length, getOrder() + 1);
|
||||
}
|
||||
|
@ -584,7 +610,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
return result;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure pow(final DerivativeStructure e)
|
||||
throws DimensionMismatchException {
|
||||
compiler.checkCompatibility(e.compiler);
|
||||
|
@ -685,7 +714,8 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
* @param y first argument of the arc tangent
|
||||
* @param x second argument of the arc tangent
|
||||
* @return atan2(y, x)
|
||||
* @exception DimensionMismatchException if number of free parameters or orders are inconsistent
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public static DerivativeStructure atan2(final DerivativeStructure y, final DerivativeStructure x)
|
||||
throws DimensionMismatchException {
|
||||
|
@ -759,12 +789,16 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
/** Evaluate Taylor expansion a derivative structure.
|
||||
* @param delta parameters offsets (Δx, Δy, ...)
|
||||
* @return value of the Taylor expansion at x + Δx, y + Δy, ...
|
||||
* @throws MathArithmeticException if factorials becomes too large
|
||||
*/
|
||||
public double taylor(final double ... delta) {
|
||||
public double taylor(final double ... delta) throws MathArithmeticException {
|
||||
return compiler.taylor(data, 0, delta);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final DerivativeStructure[] a, final DerivativeStructure[] b)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
|
@ -792,7 +826,10 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final double[] a, final DerivativeStructure[] b)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
|
@ -816,9 +853,13 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
|
||||
final DerivativeStructure a2, final DerivativeStructure b2) {
|
||||
final DerivativeStructure a2, final DerivativeStructure b2)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1.getValue(), b1.getValue(),
|
||||
|
@ -834,9 +875,13 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
|
||||
final double a2, final DerivativeStructure b2) {
|
||||
final double a2, final DerivativeStructure b2)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1, b1.getValue(),
|
||||
|
@ -852,10 +897,14 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
|
||||
final DerivativeStructure a2, final DerivativeStructure b2,
|
||||
final DerivativeStructure a3, final DerivativeStructure b3) {
|
||||
final DerivativeStructure a3, final DerivativeStructure b3)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1.getValue(), b1.getValue(),
|
||||
|
@ -872,10 +921,14 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
|
||||
final double a2, final DerivativeStructure b2,
|
||||
final double a3, final DerivativeStructure b3) {
|
||||
final double a3, final DerivativeStructure b3)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1, b1.getValue(),
|
||||
|
@ -892,11 +945,15 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final DerivativeStructure a1, final DerivativeStructure b1,
|
||||
final DerivativeStructure a2, final DerivativeStructure b2,
|
||||
final DerivativeStructure a3, final DerivativeStructure b3,
|
||||
final DerivativeStructure a4, final DerivativeStructure b4) {
|
||||
final DerivativeStructure a4, final DerivativeStructure b4)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1.getValue(), b1.getValue(),
|
||||
|
@ -914,11 +971,15 @@ public class DerivativeStructure implements RealFieldElement<DerivativeStructure
|
|||
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
/** {@inheritDoc}
|
||||
* @exception DimensionMismatchException if number of free parameters
|
||||
* or orders do not match
|
||||
*/
|
||||
public DerivativeStructure linearCombination(final double a1, final DerivativeStructure b1,
|
||||
final double a2, final DerivativeStructure b2,
|
||||
final double a3, final DerivativeStructure b3,
|
||||
final double a4, final DerivativeStructure b4) {
|
||||
final double a4, final DerivativeStructure b4)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
// compute an accurate value, taking care of cancellations
|
||||
final double accurateValue = MathArrays.linearCombination(a1, b1.getValue(),
|
||||
|
|
|
@ -39,8 +39,7 @@ public class GradientFunction implements MultivariateVectorFunction {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double[] value(double[] point)
|
||||
throws IllegalArgumentException {
|
||||
public double[] value(double[] point) {
|
||||
|
||||
// set up parameters
|
||||
final DerivativeStructure[] dsX = new DerivativeStructure[point.length];
|
||||
|
|
|
@ -41,8 +41,7 @@ public class JacobianFunction implements MultivariateMatrixFunction {
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double[][] value(double[] point)
|
||||
throws IllegalArgumentException {
|
||||
public double[][] value(double[] point) {
|
||||
|
||||
// set up parameters
|
||||
final DerivativeStructure[] dsX = new DerivativeStructure[point.length];
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.apache.commons.math3.analysis.differentiation;
|
||||
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
|
||||
/** Interface for univariate functions derivatives.
|
||||
* <p>This interface represents a simple function which computes
|
||||
|
@ -35,10 +35,10 @@ public interface UnivariateDifferentiableFunction extends UnivariateFunction {
|
|||
* value and the first derivative of the function.</p>
|
||||
* @param t function input value
|
||||
* @return function result
|
||||
* @exception MathIllegalArgumentException if {@code t} does not
|
||||
* fulfill functions constraints (argument out of bound, or unsupported
|
||||
* derivative order for example)
|
||||
* @exception DimensionMismatchException if t is inconsistent with
|
||||
* function free parameters or order
|
||||
*/
|
||||
DerivativeStructure value(DerivativeStructure t) throws MathIllegalArgumentException;
|
||||
DerivativeStructure value(DerivativeStructure t)
|
||||
throws DimensionMismatchException;
|
||||
|
||||
}
|
||||
|
|
|
@ -209,7 +209,8 @@ public class Gaussian implements UnivariateDifferentiableFunction, Differentiabl
|
|||
/** {@inheritDoc}
|
||||
* @since 3.1
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure t) {
|
||||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
final double u = is * (t.getValue() - mean);
|
||||
double[] f = new double[t.getOrder() + 1];
|
||||
|
|
|
@ -162,7 +162,8 @@ public class HarmonicOscillator implements UnivariateDifferentiableFunction, Dif
|
|||
/** {@inheritDoc}
|
||||
* @since 3.1
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure t) {
|
||||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
final double x = t.getValue();
|
||||
double[] f = new double[t.getOrder() + 1];
|
||||
|
||||
|
|
|
@ -164,7 +164,8 @@ public class Sigmoid implements UnivariateDifferentiableFunction, Differentiable
|
|||
/** {@inheritDoc}
|
||||
* @since 3.1
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure t) {
|
||||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
double[] f = new double[t.getOrder() + 1];
|
||||
final double exp = FastMath.exp(-t.getValue());
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.commons.math3.analysis.FunctionUtils;
|
|||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
/**
|
||||
|
@ -105,7 +106,8 @@ public class Sinc implements UnivariateDifferentiableFunction, DifferentiableUni
|
|||
/** {@inheritDoc}
|
||||
* @since 3.1
|
||||
*/
|
||||
public DerivativeStructure value(final DerivativeStructure t) {
|
||||
public DerivativeStructure value(final DerivativeStructure t)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
final double scaledX = (normalized ? FastMath.PI : 1) * t.getValue();
|
||||
final double scaledX2 = scaledX * scaledX;
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.commons.math3.analysis.function;
|
|||
import java.util.Arrays;
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
|
@ -50,7 +51,7 @@ public class StepFunction implements UnivariateFunction {
|
|||
*
|
||||
* @param x Domain values where the function changes value.
|
||||
* @param y Values of the function.
|
||||
* @throws org.apache.commons.math3.exception.NonMonotonicSequenceException
|
||||
* @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.
|
||||
|
@ -59,9 +60,8 @@ public class StepFunction implements UnivariateFunction {
|
|||
*/
|
||||
public StepFunction(double[] x,
|
||||
double[] y)
|
||||
throws NullArgumentException,
|
||||
NoDataException,
|
||||
DimensionMismatchException {
|
||||
throws NullArgumentException, NoDataException,
|
||||
DimensionMismatchException, NonMonotonicSequenceException {
|
||||
if (x == null ||
|
||||
y == null) {
|
||||
throw new NullArgumentException();
|
||||
|
|
|
@ -107,9 +107,9 @@ public abstract class BaseAbstractUnivariateIntegrator implements UnivariateInte
|
|||
* is lesser than or equal to the minimal number of iterations
|
||||
*/
|
||||
protected BaseAbstractUnivariateIntegrator(final double relativeAccuracy,
|
||||
final double absoluteAccuracy,
|
||||
final int minimalIterationCount,
|
||||
final int maximalIterationCount)
|
||||
final double absoluteAccuracy,
|
||||
final int minimalIterationCount,
|
||||
final int maximalIterationCount)
|
||||
throws NotStrictlyPositiveException, NumberIsTooSmallException {
|
||||
|
||||
// accuracy settings
|
||||
|
|
|
@ -19,10 +19,12 @@ package org.apache.commons.math3.analysis.integration;
|
|||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegratorFactory;
|
||||
import org.apache.commons.math3.analysis.integration.gauss.GaussIntegrator;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.MaxCountExceededException;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.exception.TooManyEvaluationsException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
/**
|
||||
|
@ -52,7 +54,7 @@ public class IterativeLegendreGaussIntegrator
|
|||
* @param minimalIterationCount Minimum number of iterations.
|
||||
* @param maximalIterationCount Maximum number of iterations.
|
||||
* @throws NotStrictlyPositiveException if minimal number of iterations
|
||||
* is not strictly positive.
|
||||
* or number of points are not strictly positive.
|
||||
* @throws NumberIsTooSmallException if maximal number of iterations
|
||||
* is smaller than or equal to the minimal number of iterations.
|
||||
*/
|
||||
|
@ -63,7 +65,10 @@ public class IterativeLegendreGaussIntegrator
|
|||
final int maximalIterationCount)
|
||||
throws NotStrictlyPositiveException, NumberIsTooSmallException {
|
||||
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
|
||||
numberOfPoints = n;
|
||||
if (n <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, n);
|
||||
}
|
||||
numberOfPoints = n;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,10 +77,12 @@ public class IterativeLegendreGaussIntegrator
|
|||
* @param n Number of integration points.
|
||||
* @param relativeAccuracy Relative accuracy of the result.
|
||||
* @param absoluteAccuracy Absolute accuracy of the result.
|
||||
* @throws NotStrictlyPositiveException if {@code n < 1}.
|
||||
*/
|
||||
public IterativeLegendreGaussIntegrator(final int n,
|
||||
final double relativeAccuracy,
|
||||
final double absoluteAccuracy) {
|
||||
final double absoluteAccuracy)
|
||||
throws NotStrictlyPositiveException {
|
||||
this(n, relativeAccuracy, absoluteAccuracy,
|
||||
DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT);
|
||||
}
|
||||
|
@ -90,10 +97,12 @@ public class IterativeLegendreGaussIntegrator
|
|||
* is not strictly positive.
|
||||
* @throws NumberIsTooSmallException if maximal number of iterations
|
||||
* is smaller than or equal to the minimal number of iterations.
|
||||
* @throws NotStrictlyPositiveException if {@code n < 1}.
|
||||
*/
|
||||
public IterativeLegendreGaussIntegrator(final int n,
|
||||
final int minimalIterationCount,
|
||||
final int maximalIterationCount) {
|
||||
final int maximalIterationCount)
|
||||
throws NotStrictlyPositiveException, NumberIsTooSmallException {
|
||||
this(n, DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY,
|
||||
minimalIterationCount, maximalIterationCount);
|
||||
}
|
||||
|
@ -101,7 +110,7 @@ public class IterativeLegendreGaussIntegrator
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected double doIntegrate()
|
||||
throws TooManyEvaluationsException, MaxCountExceededException {
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
|
||||
// Compute first estimate with a single step.
|
||||
double oldt = stage(1);
|
||||
|
||||
|
@ -142,7 +151,8 @@ public class IterativeLegendreGaussIntegrator
|
|||
throws TooManyEvaluationsException {
|
||||
// Function to be integrated is stored in the base class.
|
||||
final UnivariateFunction f = new UnivariateFunction() {
|
||||
public double value(double x) {
|
||||
public double value(double x)
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException {
|
||||
return computeObjectiveValue(x);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -128,6 +128,7 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
* @param absoluteAccuracy absolute accuracy of the result
|
||||
* @param minimalIterationCount minimum number of iterations
|
||||
* @param maximalIterationCount maximum number of iterations
|
||||
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
|
||||
* @exception NotStrictlyPositiveException if minimal number of iterations
|
||||
* is not strictly positive
|
||||
* @exception NumberIsTooSmallException if maximal number of iterations
|
||||
|
@ -138,7 +139,7 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
final double absoluteAccuracy,
|
||||
final int minimalIterationCount,
|
||||
final int maximalIterationCount)
|
||||
throws NotStrictlyPositiveException, NumberIsTooSmallException {
|
||||
throws MathIllegalArgumentException, NotStrictlyPositiveException, NumberIsTooSmallException {
|
||||
super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount);
|
||||
switch(n) {
|
||||
case 2 :
|
||||
|
@ -170,10 +171,12 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
* @param n number of points desired (must be between 2 and 5 inclusive)
|
||||
* @param relativeAccuracy relative accuracy of the result
|
||||
* @param absoluteAccuracy absolute accuracy of the result
|
||||
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
|
||||
*/
|
||||
public LegendreGaussIntegrator(final int n,
|
||||
final double relativeAccuracy,
|
||||
final double absoluteAccuracy) {
|
||||
final double absoluteAccuracy)
|
||||
throws MathIllegalArgumentException {
|
||||
this(n, relativeAccuracy, absoluteAccuracy,
|
||||
DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT);
|
||||
}
|
||||
|
@ -183,6 +186,7 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
* @param n number of points desired (must be between 2 and 5 inclusive)
|
||||
* @param minimalIterationCount minimum number of iterations
|
||||
* @param maximalIterationCount maximum number of iterations
|
||||
* @exception MathIllegalArgumentException if number of points is out of [2; 5]
|
||||
* @exception NotStrictlyPositiveException if minimal number of iterations
|
||||
* is not strictly positive
|
||||
* @exception NumberIsTooSmallException if maximal number of iterations
|
||||
|
@ -190,7 +194,8 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
*/
|
||||
public LegendreGaussIntegrator(final int n,
|
||||
final int minimalIterationCount,
|
||||
final int maximalIterationCount) {
|
||||
final int maximalIterationCount)
|
||||
throws MathIllegalArgumentException {
|
||||
this(n, DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY,
|
||||
minimalIterationCount, maximalIterationCount);
|
||||
}
|
||||
|
@ -198,7 +203,7 @@ public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected double doIntegrate()
|
||||
throws TooManyEvaluationsException, MaxCountExceededException {
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
|
||||
|
||||
// compute first estimate with a single step
|
||||
double oldt = stage(1);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.commons.math3.analysis.integration;
|
||||
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.MaxCountExceededException;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooLargeException;
|
||||
|
@ -144,7 +145,7 @@ public class TrapezoidIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected double doIntegrate()
|
||||
throws TooManyEvaluationsException, MaxCountExceededException {
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException {
|
||||
|
||||
double oldt = stage(this, 0);
|
||||
iterations.incrementCount();
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.TreeMap;
|
|||
import org.apache.commons.math3.util.Pair;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
|
||||
/**
|
||||
* Base class for rules that determines the integration nodes and their
|
||||
|
@ -48,9 +49,17 @@ public abstract class BaseRuleFactory<T extends Number> {
|
|||
* @param numberOfPoints Number of integration points.
|
||||
* @return a copy of the integration rule.
|
||||
* @throws NotStrictlyPositiveException if {@code numberOfPoints < 1}.
|
||||
* @throws DimensionMismatchException if the elements of the rule pair do not
|
||||
* have the same length.
|
||||
*/
|
||||
public Pair<double[], double[]> getRule(int numberOfPoints)
|
||||
throws NotStrictlyPositiveException {
|
||||
throws NotStrictlyPositiveException, DimensionMismatchException {
|
||||
|
||||
if (numberOfPoints <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS,
|
||||
numberOfPoints);
|
||||
}
|
||||
|
||||
// Try to obtain the rule from the cache.
|
||||
Pair<double[], double[]> cached = pointsAndWeightsDouble.get(numberOfPoints);
|
||||
|
||||
|
@ -78,10 +87,11 @@ public abstract class BaseRuleFactory<T extends Number> {
|
|||
*
|
||||
* @param numberOfPoints Order of the rule to be retrieved.
|
||||
* @return the points and weights corresponding to the given order.
|
||||
* @throws NotStrictlyPositiveException if {@code numberOfPoints < 1}.
|
||||
* @throws DimensionMismatchException if the elements of the rule pair do not
|
||||
* have the same length.
|
||||
*/
|
||||
protected synchronized Pair<T[], T[]> getRuleInternal(int numberOfPoints)
|
||||
throws NotStrictlyPositiveException {
|
||||
throws DimensionMismatchException {
|
||||
final Pair<T[], T[]> rule = pointsAndWeights.get(numberOfPoints);
|
||||
if (rule == null) {
|
||||
addRule(computeRule(numberOfPoints));
|
||||
|
@ -98,7 +108,7 @@ public abstract class BaseRuleFactory<T extends Number> {
|
|||
* @throws DimensionMismatchException if the elements of the pair do not
|
||||
* have the same length.
|
||||
*/
|
||||
protected void addRule(Pair<T[], T[]> rule) {
|
||||
protected void addRule(Pair<T[], T[]> rule) throws DimensionMismatchException {
|
||||
if (rule.getFirst().length != rule.getSecond().length) {
|
||||
throw new DimensionMismatchException(rule.getFirst().length,
|
||||
rule.getSecond().length);
|
||||
|
@ -112,8 +122,11 @@ public abstract class BaseRuleFactory<T extends Number> {
|
|||
*
|
||||
* @param numberOfPoints Order of the rule to be computed.
|
||||
* @return the computed rule.
|
||||
* @throws DimensionMismatchException if the elements of the pair do not
|
||||
* have the same length.
|
||||
*/
|
||||
protected abstract Pair<T[], T[]> computeRule(int numberOfPoints);
|
||||
protected abstract Pair<T[], T[]> computeRule(int numberOfPoints)
|
||||
throws DimensionMismatchException;
|
||||
|
||||
/**
|
||||
* Converts the from the actual {@code Number} type to {@code double}
|
||||
|
|
|
@ -45,10 +45,11 @@ public class GaussIntegrator {
|
|||
* @param weights Weights of the corresponding integration nodes.
|
||||
* @throws NonMonotonicSequenceException if the {@code points} are not
|
||||
* sorted in increasing order.
|
||||
* @throws DimensionMismatchException if points and weights don't have the same length
|
||||
*/
|
||||
public GaussIntegrator(double[] points,
|
||||
double[] weights)
|
||||
throws NonMonotonicSequenceException {
|
||||
throws NonMonotonicSequenceException, DimensionMismatchException {
|
||||
if (points.length != weights.length) {
|
||||
throw new DimensionMismatchException(points.length,
|
||||
weights.length);
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.commons.math3.analysis.integration.gauss;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.util.Pair;
|
||||
|
||||
/**
|
||||
|
@ -55,10 +57,12 @@ public class GaussIntegratorFactory {
|
|||
* @param lowerBound Lower bound of the integration interval.
|
||||
* @param upperBound Upper bound of the integration interval.
|
||||
* @return a Gauss-Legendre integrator.
|
||||
* @throws NotStrictlyPositiveException if number of points is not positive
|
||||
*/
|
||||
public GaussIntegrator legendre(int numberOfPoints,
|
||||
double lowerBound,
|
||||
double upperBound) {
|
||||
double upperBound)
|
||||
throws NotStrictlyPositiveException {
|
||||
return new GaussIntegrator(transform(getRule(legendre, numberOfPoints),
|
||||
lowerBound, upperBound));
|
||||
}
|
||||
|
@ -71,8 +75,10 @@ public class GaussIntegratorFactory {
|
|||
*
|
||||
* @param numberOfPoints Order of the integration rule.
|
||||
* @return a Gauss-Legendre integrator.
|
||||
* @throws NotStrictlyPositiveException if number of points is not positive
|
||||
*/
|
||||
public GaussIntegrator legendreHighPrecision(int numberOfPoints) {
|
||||
public GaussIntegrator legendreHighPrecision(int numberOfPoints)
|
||||
throws NotStrictlyPositiveException {
|
||||
return new GaussIntegrator(getRule(legendreHighPrecision, numberOfPoints));
|
||||
}
|
||||
|
||||
|
@ -85,10 +91,12 @@ public class GaussIntegratorFactory {
|
|||
* @param lowerBound Lower bound of the integration interval.
|
||||
* @param upperBound Upper bound of the integration interval.
|
||||
* @return a Gauss-Legendre integrator.
|
||||
* @throws NotStrictlyPositiveException if number of points is not positive
|
||||
*/
|
||||
public GaussIntegrator legendreHighPrecision(int numberOfPoints,
|
||||
double lowerBound,
|
||||
double upperBound) {
|
||||
double upperBound)
|
||||
throws NotStrictlyPositiveException {
|
||||
return new GaussIntegrator(transform(getRule(legendreHighPrecision, numberOfPoints),
|
||||
lowerBound, upperBound));
|
||||
}
|
||||
|
@ -97,9 +105,13 @@ public class GaussIntegratorFactory {
|
|||
* @param factory Integration rule factory.
|
||||
* @param numberOfPoints Order of the integration rule.
|
||||
* @return the integration nodes and weights.
|
||||
* @throws NotStrictlyPositiveException if number of points is not positive
|
||||
* @throws DimensionMismatchException if the elements of the rule pair do not
|
||||
* have the same length.
|
||||
*/
|
||||
private static Pair<double[], double[]> getRule(BaseRuleFactory<? extends Number> factory,
|
||||
int numberOfPoints) {
|
||||
int numberOfPoints)
|
||||
throws NotStrictlyPositiveException, DimensionMismatchException {
|
||||
return factory.getRule(numberOfPoints);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
*/
|
||||
package org.apache.commons.math3.analysis.integration.gauss;
|
||||
|
||||
import java.math.MathContext;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.util.Pair;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
|
||||
/**
|
||||
* Factory that creates Gauss-type quadrature rule using Legendre polynomials.
|
||||
|
@ -60,17 +60,10 @@ public class LegendreHighPrecisionRuleFactory extends BaseRuleFactory<BigDecimal
|
|||
oneHalf = new BigDecimal("0.5", mContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws NotStrictlyPositiveException if {@code numberOfPoints < 1}.
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected Pair<BigDecimal[], BigDecimal[]> computeRule(int numberOfPoints) {
|
||||
if (numberOfPoints <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS,
|
||||
numberOfPoints);
|
||||
}
|
||||
protected Pair<BigDecimal[], BigDecimal[]> computeRule(int numberOfPoints)
|
||||
throws DimensionMismatchException {
|
||||
|
||||
if (numberOfPoints == 1) {
|
||||
// Break recursion.
|
||||
|
|
|
@ -16,9 +16,8 @@
|
|||
*/
|
||||
package org.apache.commons.math3.analysis.integration.gauss;
|
||||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.util.Pair;
|
||||
import org.apache.commons.math3.exception.NotStrictlyPositiveException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
|
||||
/**
|
||||
* Factory that creates Gauss-type quadrature rule using Legendre polynomials.
|
||||
|
@ -32,16 +31,10 @@ import org.apache.commons.math3.exception.util.LocalizedFormats;
|
|||
* @version $Id$
|
||||
*/
|
||||
public class LegendreRuleFactory extends BaseRuleFactory<Double> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected Pair<Double[], Double[]> computeRule(int numberOfPoints)
|
||||
throws NotStrictlyPositiveException {
|
||||
if (numberOfPoints <= 0) {
|
||||
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS,
|
||||
numberOfPoints);
|
||||
}
|
||||
throws DimensionMismatchException {
|
||||
|
||||
if (numberOfPoints == 1) {
|
||||
// Break recursion.
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction;
|
|||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
|
||||
/**
|
||||
|
@ -37,9 +38,8 @@ public class BicubicSplineInterpolator
|
|||
public BicubicSplineInterpolatingFunction interpolate(final double[] xval,
|
||||
final double[] yval,
|
||||
final double[][] fval)
|
||||
throws NoDataException,
|
||||
DimensionMismatchException,
|
||||
NonMonotonicSequenceException {
|
||||
throws NoDataException, DimensionMismatchException,
|
||||
NonMonotonicSequenceException, NumberIsTooSmallException {
|
||||
if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
|
||||
throw new NoDataException();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.commons.math3.analysis.interpolation;
|
|||
import org.apache.commons.math3.analysis.BivariateFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
|
||||
/**
|
||||
* Interface representing a bivariate real interpolating function where the
|
||||
|
@ -39,9 +41,12 @@ public interface BivariateGridInterpolator {
|
|||
* @return a function which interpolates the dataset.
|
||||
* @throws NoDataException if any of the arrays has zero length.
|
||||
* @throws DimensionMismatchException if the array lengths are inconsistent.
|
||||
* @throws NonMonotonicSequenceException if the array is not sorted.
|
||||
* @throws NumberIsTooSmallException if the number of points is too small for
|
||||
* the order of the interpolation
|
||||
*/
|
||||
BivariateFunction interpolate(double[] xval, double[] yval,
|
||||
double[][] fval)
|
||||
throws NoDataException,
|
||||
DimensionMismatchException;
|
||||
throws NoDataException, DimensionMismatchException,
|
||||
NonMonotonicSequenceException, NumberIsTooSmallException;
|
||||
}
|
||||
|
|
|
@ -20,11 +20,14 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.commons.math3.FieldElement;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathArithmeticException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.ZeroException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
||||
/** Polynomial interpolator using both sample values and sample derivatives.
|
||||
* <p>
|
||||
|
@ -82,10 +85,14 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
|
|||
* and a previous point is zero (i.e. the two points are at same abscissa)
|
||||
* @exception MathArithmeticException if the number of derivatives is larger
|
||||
* than 20, which prevents computation of a factorial
|
||||
* @throws DimensionMismatchException if derivative structures are inconsistent
|
||||
* @throws NullArgumentException if x is null
|
||||
*/
|
||||
public void addSamplePoint(final T x, final T[] ... value)
|
||||
throws ZeroException, MathArithmeticException {
|
||||
throws ZeroException, MathArithmeticException,
|
||||
DimensionMismatchException, NullArgumentException {
|
||||
|
||||
MathUtils.checkNotNull(x);
|
||||
T factorial = x.getField().getOne();
|
||||
for (int i = 0; i < value.length; ++i) {
|
||||
|
||||
|
@ -128,10 +135,12 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
|
|||
* @param x interpolation abscissa
|
||||
* @return interpolated value
|
||||
* @exception NoDataException if sample is empty
|
||||
* @throws NullArgumentException if x is null
|
||||
*/
|
||||
public T[] value(T x) throws NoDataException {
|
||||
public T[] value(T x) throws NoDataException, NullArgumentException {
|
||||
|
||||
// safety check
|
||||
MathUtils.checkNotNull(x);
|
||||
if (abscissae.isEmpty()) {
|
||||
throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE);
|
||||
}
|
||||
|
@ -157,10 +166,12 @@ public class FieldHermiteInterpolator<T extends FieldElement<T>> {
|
|||
* @return interpolated value and derivatives (value in row 0,
|
||||
* 1<sup>st</sup> derivative in row 1, ... n<sup>th</sup> derivative in row n)
|
||||
* @exception NoDataException if sample is empty
|
||||
* @throws NullArgumentException if x is null
|
||||
*/
|
||||
public T[][] derivatives(T x, int order) throws NoDataException {
|
||||
public T[][] derivatives(T x, int order) throws NoDataException, NullArgumentException {
|
||||
|
||||
// safety check
|
||||
MathUtils.checkNotNull(x);
|
||||
if (abscissae.isEmpty()) {
|
||||
throw new NoDataException(LocalizedFormats.EMPTY_INTERPOLATION_SAMPLE);
|
||||
}
|
||||
|
|
|
@ -193,8 +193,9 @@ public class MicrosphereInterpolatingFunction
|
|||
/**
|
||||
* @param point Interpolation point.
|
||||
* @return the interpolated value.
|
||||
* @throws DimensionMismatchException if point dimension does not math sample
|
||||
*/
|
||||
public double value(double[] point) {
|
||||
public double value(double[] point) throws DimensionMismatchException {
|
||||
final RealVector p = new ArrayRealVector(point);
|
||||
|
||||
// Reset.
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
package org.apache.commons.math3.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math3.analysis.MultivariateFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
|
||||
/**
|
||||
* Interface representing a univariate real interpolating function.
|
||||
|
@ -36,15 +40,13 @@ public interface MultivariateInterpolator {
|
|||
* point (where {@code d} is thus the dimension of the space).
|
||||
* @param yval the values for the interpolation points
|
||||
* @return a function which interpolates the data set
|
||||
* @throws org.apache.commons.math3.exception.MathIllegalArgumentException
|
||||
* if the arguments violate assumptions made by the interpolation
|
||||
* algorithm.
|
||||
* @throws org.apache.commons.math3.exception.DimensionMismatchException
|
||||
* when the array dimensions are not consistent.
|
||||
* @throws org.apache.commons.math3.exception.NoDataException if an
|
||||
* array has zero-length.
|
||||
* @throws org.apache.commons.math3.exception.NullArgumentException if
|
||||
* the arguments are {@code null}.
|
||||
* @throws MathIllegalArgumentException if the arguments violate assumptions
|
||||
* made by the interpolation algorithm.
|
||||
* @throws DimensionMismatchException when the array dimensions are not consistent.
|
||||
* @throws NoDataException if an array has zero-length.
|
||||
* @throws NullArgumentException if the arguments are {@code null}.
|
||||
*/
|
||||
MultivariateFunction interpolate(double[][] xval, double[] yval);
|
||||
MultivariateFunction interpolate(double[][] xval, double[] yval)
|
||||
throws MathIllegalArgumentException, DimensionMismatchException,
|
||||
NoDataException, NullArgumentException;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@ package org.apache.commons.math3.analysis.interpolation;
|
|||
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NotPositiveException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
import org.apache.commons.math3.util.Precision;
|
||||
import org.apache.commons.math3.optim.nonlinear.vector.jacobian.GaussNewtonOptimizer;
|
||||
|
@ -54,8 +56,10 @@ public class SmoothingPolynomialBicubicSplineInterpolator
|
|||
|
||||
/**
|
||||
* @param degree Degree of the polynomial fitting functions.
|
||||
* @exception NotPositiveException if degree is not positive
|
||||
*/
|
||||
public SmoothingPolynomialBicubicSplineInterpolator(int degree) {
|
||||
public SmoothingPolynomialBicubicSplineInterpolator(int degree)
|
||||
throws NotPositiveException {
|
||||
this(degree, degree);
|
||||
}
|
||||
|
||||
|
@ -64,9 +68,10 @@ public class SmoothingPolynomialBicubicSplineInterpolator
|
|||
* x-dimension.
|
||||
* @param yDegree Degree of the polynomial fitting functions along the
|
||||
* y-dimension.
|
||||
* @exception NotPositiveException if degrees are not positive
|
||||
*/
|
||||
public SmoothingPolynomialBicubicSplineInterpolator(int xDegree,
|
||||
int yDegree) {
|
||||
public SmoothingPolynomialBicubicSplineInterpolator(int xDegree, int yDegree)
|
||||
throws NotPositiveException {
|
||||
if (xDegree < 0) {
|
||||
throw new NotPositiveException(xDegree);
|
||||
}
|
||||
|
@ -91,8 +96,8 @@ public class SmoothingPolynomialBicubicSplineInterpolator
|
|||
public BicubicSplineInterpolatingFunction interpolate(final double[] xval,
|
||||
final double[] yval,
|
||||
final double[][] fval)
|
||||
throws NoDataException,
|
||||
DimensionMismatchException {
|
||||
throws NoDataException, NullArgumentException,
|
||||
DimensionMismatchException, NonMonotonicSequenceException {
|
||||
if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
|
||||
throw new NoDataException();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.commons.math3.analysis.interpolation;
|
|||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +37,8 @@ public class TricubicSplineInterpolator
|
|||
final double[] yval,
|
||||
final double[] zval,
|
||||
final double[][][] fval)
|
||||
throws NoDataException,
|
||||
DimensionMismatchException,
|
||||
NonMonotonicSequenceException {
|
||||
throws NoDataException, NumberIsTooSmallException,
|
||||
DimensionMismatchException, NonMonotonicSequenceException {
|
||||
if (xval.length == 0 || yval.length == 0 || zval.length == 0 || fval.length == 0) {
|
||||
throw new NoDataException();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.commons.math3.analysis.interpolation;
|
|||
import org.apache.commons.math3.analysis.TrivariateFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
|
||||
/**
|
||||
* Interface representing a trivariate real interpolating function where the
|
||||
|
@ -42,9 +44,12 @@ public interface TrivariateGridInterpolator {
|
|||
* @return a function that interpolates the data set.
|
||||
* @throws NoDataException if any of the arrays has zero length.
|
||||
* @throws DimensionMismatchException if the array lengths are inconsistent.
|
||||
* @throws NonMonotonicSequenceException if arrays are not sorted
|
||||
* @throws NumberIsTooSmallException if the number of points is too small for
|
||||
* the order of the interpolation
|
||||
*/
|
||||
TrivariateFunction interpolate(double[] xval, double[] yval, double[] zval,
|
||||
double[][][] fval)
|
||||
throws NoDataException,
|
||||
DimensionMismatchException;
|
||||
throws NoDataException, NumberIsTooSmallException,
|
||||
DimensionMismatchException, NonMonotonicSequenceException;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.commons.math3.analysis.interpolation;
|
||||
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Interface representing a univariate real interpolating function.
|
||||
|
@ -30,9 +32,11 @@ public interface UnivariateInterpolator {
|
|||
* @param xval Arguments for the interpolation points.
|
||||
* @param yval Values for the interpolation points.
|
||||
* @return a function which interpolates the dataset.
|
||||
* @throws org.apache.commons.math3.exception.MathIllegalArgumentException
|
||||
* @throws MathIllegalArgumentException
|
||||
* if the arguments violate assumptions made by the interpolation
|
||||
* algorithm.
|
||||
* @throws DimensionMismatchException if arrays lengthes do not match
|
||||
*/
|
||||
UnivariateFunction interpolate(double xval[], double yval[]);
|
||||
UnivariateFunction interpolate(double xval[], double yval[])
|
||||
throws MathIllegalArgumentException, DimensionMismatchException;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.commons.math3.analysis.interpolation;
|
|||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
|
||||
/**
|
||||
|
@ -82,7 +84,7 @@ public class UnivariatePeriodicInterpolator
|
|||
*/
|
||||
public UnivariateFunction interpolate(double[] xval,
|
||||
double[] yval)
|
||||
throws NumberIsTooSmallException {
|
||||
throws NumberIsTooSmallException, NonMonotonicSequenceException {
|
||||
if (xval.length < extend) {
|
||||
throw new NumberIsTooSmallException(xval.length, extend, true);
|
||||
}
|
||||
|
@ -114,7 +116,7 @@ public class UnivariatePeriodicInterpolator
|
|||
|
||||
final UnivariateFunction f = interpolator.interpolate(x, y);
|
||||
return new UnivariateFunction() {
|
||||
public double value(final double x) {
|
||||
public double value(final double x) throws MathIllegalArgumentException {
|
||||
return f.value(MathUtils.reduce(x, period, offset));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -405,7 +405,8 @@ public class PolynomialFunction implements UnivariateDifferentiableFunction, Dif
|
|||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double value(final double x, final double ... parameters) {
|
||||
public double value(final double x, final double ... parameters)
|
||||
throws NoDataException {
|
||||
return PolynomialFunction.evaluate(parameters, x);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.apache.commons.math3.analysis.UnivariateFunction;
|
|||
import org.apache.commons.math3.util.FastMath;
|
||||
import org.apache.commons.math3.util.MathArrays;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
|
||||
|
@ -65,10 +66,11 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
|
|||
* @param y function values at interpolating points
|
||||
* @throws DimensionMismatchException if the array lengths are different.
|
||||
* @throws NumberIsTooSmallException if the number of points is less than 2.
|
||||
* @throws org.apache.commons.math3.exception.NonMonotonicSequenceException
|
||||
* @throws NonMonotonicSequenceException
|
||||
* if two abscissae have the same value.
|
||||
*/
|
||||
public PolynomialFunctionLagrangeForm(double x[], double y[]) {
|
||||
public PolynomialFunctionLagrangeForm(double x[], double y[])
|
||||
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
|
||||
this.x = new double[x.length];
|
||||
this.y = new double[y.length];
|
||||
System.arraycopy(x, 0, this.x, 0, x.length);
|
||||
|
@ -163,12 +165,13 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
|
|||
* @return the function value.
|
||||
* @throws DimensionMismatchException if {@code x} and {@code y} have
|
||||
* different lengths.
|
||||
* @throws org.apache.commons.math3.exception.NonMonotonicSequenceException
|
||||
* @throws NonMonotonicSequenceException
|
||||
* if {@code x} is not sorted in strictly increasing order.
|
||||
* @throws NumberIsTooSmallException if the size of {@code x} is less
|
||||
* than 2.
|
||||
*/
|
||||
public static double evaluate(double x[], double y[], double z) {
|
||||
public static double evaluate(double x[], double y[], double z)
|
||||
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
|
||||
if (verifyInterpolationArray(x, y, false)) {
|
||||
return evaluateInternal(x, y, z);
|
||||
}
|
||||
|
@ -310,7 +313,8 @@ public class PolynomialFunctionLagrangeForm implements UnivariateFunction {
|
|||
* @see #evaluate(double[], double[], double)
|
||||
* @see #computeCoefficients()
|
||||
*/
|
||||
public static boolean verifyInterpolationArray(double x[], double y[], boolean abort) {
|
||||
public static boolean verifyInterpolationArray(double x[], double y[], boolean abort)
|
||||
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
|
||||
if (x.length != y.length) {
|
||||
throw new DimensionMismatchException(x.length, y.length);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
|
|||
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
import org.apache.commons.math3.exception.NoDataException;
|
||||
import org.apache.commons.math3.exception.NullArgumentException;
|
||||
import org.apache.commons.math3.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math3.util.MathUtils;
|
||||
|
||||
/**
|
||||
* Implements the representation of a real polynomial function in
|
||||
|
@ -69,13 +71,13 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
|
|||
*
|
||||
* @param a Coefficients in Newton form formula.
|
||||
* @param c Centers.
|
||||
* @throws org.apache.commons.math3.exception.NullArgumentException if
|
||||
* any argument is {@code null}.
|
||||
* @throws NullArgumentException if any argument is {@code null}.
|
||||
* @throws NoDataException if any array has zero length.
|
||||
* @throws DimensionMismatchException if the size difference between
|
||||
* {@code a} and {@code c} is not equal to 1.
|
||||
*/
|
||||
public PolynomialFunctionNewtonForm(double a[], double c[]) {
|
||||
public PolynomialFunctionNewtonForm(double a[], double c[])
|
||||
throws NullArgumentException, NoDataException, DimensionMismatchException {
|
||||
|
||||
verifyInputArray(a, c);
|
||||
this.a = new double[a.length];
|
||||
|
@ -172,13 +174,13 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
|
|||
* @param c Centers.
|
||||
* @param z Point at which the function value is to be computed.
|
||||
* @return the function value.
|
||||
* @throws org.apache.commons.math3.exception.NullArgumentException if
|
||||
* any argument is {@code null}.
|
||||
* @throws NullArgumentException if any argument is {@code null}.
|
||||
* @throws NoDataException if any array has zero length.
|
||||
* @throws DimensionMismatchException if the size difference between
|
||||
* {@code a} and {@code c} is not equal to 1.
|
||||
*/
|
||||
public static double evaluate(double a[], double c[], double z) {
|
||||
public static double evaluate(double a[], double c[], double z)
|
||||
throws NullArgumentException, DimensionMismatchException, NoDataException {
|
||||
verifyInputArray(a, c);
|
||||
|
||||
final int n = c.length;
|
||||
|
@ -221,17 +223,18 @@ public class PolynomialFunctionNewtonForm implements UnivariateDifferentiableFun
|
|||
*
|
||||
* @param a the coefficients in Newton form formula
|
||||
* @param c the centers
|
||||
* @throws org.apache.commons.math3.exception.NullArgumentException if
|
||||
* any argument is {@code null}.
|
||||
* @throws NullArgumentException if any argument is {@code null}.
|
||||
* @throws NoDataException if any array has zero length.
|
||||
* @throws DimensionMismatchException if the size difference between
|
||||
* {@code a} and {@code c} is not equal to 1.
|
||||
* @see org.apache.commons.math3.analysis.interpolation.DividedDifferenceInterpolator#computeDividedDifference(double[],
|
||||
* double[])
|
||||
*/
|
||||
protected static void verifyInputArray(double a[], double c[]) {
|
||||
if (a.length == 0 ||
|
||||
c.length == 0) {
|
||||
protected static void verifyInputArray(double a[], double c[])
|
||||
throws NullArgumentException, NoDataException, DimensionMismatchException {
|
||||
MathUtils.checkNotNull(a);
|
||||
MathUtils.checkNotNull(c);
|
||||
if (a.length == 0 || c.length == 0) {
|
||||
throw new NoDataException(LocalizedFormats.EMPTY_POLYNOMIALS_COEFFICIENTS_ARRAY);
|
||||
}
|
||||
if (a.length != c.length + 1) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
|
|||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math3.exception.NonMonotonicSequenceException;
|
||||
import org.apache.commons.math3.exception.OutOfRangeException;
|
||||
import org.apache.commons.math3.exception.NumberIsTooSmallException;
|
||||
import org.apache.commons.math3.exception.DimensionMismatchException;
|
||||
|
@ -95,11 +96,12 @@ public class PolynomialSplineFunction implements UnivariateDifferentiableFunctio
|
|||
* @throws NullArgumentException if either of the input arrays is {@code null}.
|
||||
* @throws NumberIsTooSmallException if knots has length less than 2.
|
||||
* @throws DimensionMismatchException if {@code polynomials.length != knots.length - 1}.
|
||||
* @throws org.apache.commons.math3.exception.NonMonotonicSequenceException if
|
||||
* the {@code knots} array is not strictly increasing.
|
||||
* @throws NonMonotonicSequenceException if the {@code knots} array is not strictly increasing.
|
||||
*
|
||||
*/
|
||||
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[]) {
|
||||
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[])
|
||||
throws NullArgumentException, NumberIsTooSmallException,
|
||||
DimensionMismatchException, NonMonotonicSequenceException{
|
||||
if (knots == null ||
|
||||
polynomials == null) {
|
||||
throw new NullArgumentException();
|
||||
|
|
|
@ -63,8 +63,7 @@ public abstract class AbstractDifferentiableUnivariateSolver
|
|||
*
|
||||
* @param point Point at which the objective function must be evaluated.
|
||||
* @return the objective function value at specified point.
|
||||
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
|
||||
* if the maximal number of evaluations is exceeded.
|
||||
* @throws TooManyEvaluationsException if the maximal number of evaluations is exceeded.
|
||||
*/
|
||||
protected double computeDerivativeObjectiveValue(double point)
|
||||
throws TooManyEvaluationsException {
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.commons.math3.analysis.solvers;
|
|||
|
||||
import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
|
||||
import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
|
||||
import org.apache.commons.math3.exception.TooManyEvaluationsException;
|
||||
|
||||
/**
|
||||
* Provide a default implementation for several functions useful to generic
|
||||
|
@ -61,10 +62,11 @@ public abstract class AbstractUnivariateDifferentiableSolver
|
|||
*
|
||||
* @param point Point at which the objective function must be evaluated.
|
||||
* @return the objective function value and derivative at specified point.
|
||||
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
|
||||
* @throws TooManyEvaluationsException
|
||||
* if the maximal number of evaluations is exceeded.
|
||||
*/
|
||||
protected DerivativeStructure computeObjectiveValueAndDerivative(double point) {
|
||||
protected DerivativeStructure computeObjectiveValueAndDerivative(double point)
|
||||
throws TooManyEvaluationsException {
|
||||
incrementEvaluationCount();
|
||||
return function.value(new DerivativeStructure(1, 1, 0, point));
|
||||
}
|
||||
|
|
|
@ -166,11 +166,13 @@ public abstract class BaseAbstractUnivariateSolver<FUNC extends UnivariateFuncti
|
|||
* @param max Upper bound for the interval.
|
||||
* @param startValue Start value to use.
|
||||
* @param maxEval Maximum number of evaluations.
|
||||
* @exception NullArgumentException if f is null
|
||||
*/
|
||||
protected void setup(int maxEval,
|
||||
FUNC f,
|
||||
double min, double max,
|
||||
double startValue) {
|
||||
double startValue)
|
||||
throws NullArgumentException {
|
||||
// Checks.
|
||||
MathUtils.checkNotNull(f);
|
||||
|
||||
|
|
|
@ -133,8 +133,7 @@ public abstract class BaseSecantSolver
|
|||
*/
|
||||
@Override
|
||||
protected final double doSolve()
|
||||
throws ConvergenceException,
|
||||
MathInternalError {
|
||||
throws ConvergenceException {
|
||||
// Get initial solution
|
||||
double x0 = getMin();
|
||||
double x1 = getMax();
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.commons.math3.analysis.solvers;
|
||||
|
||||
import org.apache.commons.math3.analysis.UnivariateFunction;
|
||||
import org.apache.commons.math3.exception.MathIllegalArgumentException;
|
||||
import org.apache.commons.math3.exception.TooManyEvaluationsException;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -97,12 +99,13 @@ public interface BaseUnivariateSolver<FUNC extends UnivariateFunction> {
|
|||
* @param min Lower bound for the interval.
|
||||
* @param max Upper bound for the interval.
|
||||
* @return a value where the function is zero.
|
||||
* @throws org.apache.commons.math3.exception.MathIllegalArgumentException
|
||||
* @throws MathIllegalArgumentException
|
||||
* if the arguments do not satisfy the requirements specified by the solver.
|
||||
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException if
|
||||
* @throws TooManyEvaluationsException if
|
||||
* the allowed number of evaluations is exceeded.
|
||||
*/
|
||||
double solve(int maxEval, FUNC f, double min, double max);
|
||||
double solve(int maxEval, FUNC f, double min, double max)
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException;
|
||||
|
||||
/**
|
||||
* Solve for a zero in the given interval, start at {@code startValue}.
|
||||
|
@ -116,12 +119,13 @@ public interface BaseUnivariateSolver<FUNC extends UnivariateFunction> {
|
|||
* @param max Upper bound for the interval.
|
||||
* @param startValue Start value to use.
|
||||
* @return a value where the function is zero.
|
||||
* @throws org.apache.commons.math3.exception.MathIllegalArgumentException
|
||||
* @throws MathIllegalArgumentException
|
||||
* if the arguments do not satisfy the requirements specified by the solver.
|
||||
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException if
|
||||
* @throws TooManyEvaluationsException if
|
||||
* the allowed number of evaluations is exceeded.
|
||||
*/
|
||||
double solve(int maxEval, FUNC f, double min, double max, double startValue);
|
||||
double solve(int maxEval, FUNC f, double min, double max, double startValue)
|
||||
throws MathIllegalArgumentException, TooManyEvaluationsException;
|
||||
|
||||
/**
|
||||
* Solve for a zero in the vicinity of {@code startValue}.
|
||||
|
|
|
@ -62,7 +62,7 @@ public class Incrementor {
|
|||
this(max,
|
||||
new MaxCountExceededCallback() {
|
||||
/** {@inheritDoc} */
|
||||
public void trigger(int max) {
|
||||
public void trigger(int max) throws MaxCountExceededException {
|
||||
throw new MaxCountExceededException(max);
|
||||
}
|
||||
});
|
||||
|
@ -76,8 +76,8 @@ public class Incrementor {
|
|||
* @param cb Function to be called when the maximal count has been reached.
|
||||
* @throws NullArgumentException if {@code cb} is {@code null}
|
||||
*/
|
||||
public Incrementor(int max,
|
||||
MaxCountExceededCallback cb) {
|
||||
public Incrementor(int max, MaxCountExceededCallback cb)
|
||||
throws NullArgumentException {
|
||||
if (cb == null){
|
||||
throw new NullArgumentException();
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class Incrementor {
|
|||
* @param value Number of increments.
|
||||
* @throws MaxCountExceededException at counter exhaustion.
|
||||
*/
|
||||
public void incrementCount(int value) {
|
||||
public void incrementCount(int value) throws MaxCountExceededException {
|
||||
for (int i = 0; i < value; i++) {
|
||||
incrementCount();
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ public class Incrementor {
|
|||
* custom {@link MaxCountExceededCallback callback} has been set at
|
||||
* construction.
|
||||
*/
|
||||
public void incrementCount() {
|
||||
public void incrementCount() throws MaxCountExceededException {
|
||||
if (++count > maximalCount) {
|
||||
maxCountCallback.trigger(maximalCount);
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ public class Incrementor {
|
|||
* Function called when the maximal count has been reached.
|
||||
*
|
||||
* @param maximalCount Maximal count.
|
||||
* @throws MaxCountExceededException at counter exhaustion
|
||||
*/
|
||||
void trigger(int maximalCount);
|
||||
void trigger(int maximalCount) throws MaxCountExceededException;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,8 @@ public class MathArrays {
|
|||
* @throws DimensionMismatchException if the array lengths differ.
|
||||
* @since 3.1
|
||||
*/
|
||||
public static double[] ebeAdd(double[] a,
|
||||
double[] b) {
|
||||
public static double[] ebeAdd(double[] a, double[] b)
|
||||
throws DimensionMismatchException {
|
||||
if (a.length != b.length) {
|
||||
throw new DimensionMismatchException(a.length, b.length);
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ public class MathArrays {
|
|||
* @throws DimensionMismatchException if the array lengths differ.
|
||||
* @since 3.1
|
||||
*/
|
||||
public static double[] ebeSubtract(double[] a,
|
||||
double[] b) {
|
||||
public static double[] ebeSubtract(double[] a, double[] b)
|
||||
throws DimensionMismatchException {
|
||||
if (a.length != b.length) {
|
||||
throw new DimensionMismatchException(a.length, b.length);
|
||||
}
|
||||
|
@ -127,8 +127,8 @@ public class MathArrays {
|
|||
* @throws DimensionMismatchException if the array lengths differ.
|
||||
* @since 3.1
|
||||
*/
|
||||
public static double[] ebeMultiply(double[] a,
|
||||
double[] b) {
|
||||
public static double[] ebeMultiply(double[] a, double[] b)
|
||||
throws DimensionMismatchException {
|
||||
if (a.length != b.length) {
|
||||
throw new DimensionMismatchException(a.length, b.length);
|
||||
}
|
||||
|
@ -149,8 +149,8 @@ public class MathArrays {
|
|||
* @throws DimensionMismatchException if the array lengths differ.
|
||||
* @since 3.1
|
||||
*/
|
||||
public static double[] ebeDivide(double[] a,
|
||||
double[] b) {
|
||||
public static double[] ebeDivide(double[] a, double[] b)
|
||||
throws DimensionMismatchException {
|
||||
if (a.length != b.length) {
|
||||
throw new DimensionMismatchException(a.length, b.length);
|
||||
}
|
||||
|
@ -323,9 +323,7 @@ public class MathArrays {
|
|||
* @param strict Whether the order should be strict.
|
||||
* @return {@code true} if sorted, {@code false} otherwise.
|
||||
*/
|
||||
public static boolean isMonotonic(double[] val,
|
||||
OrderDirection dir,
|
||||
boolean strict) {
|
||||
public static boolean isMonotonic(double[] val, OrderDirection dir, boolean strict) {
|
||||
return checkOrder(val, dir, strict, false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue