Populate "throws" clause.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1379218 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-08-30 23:18:57 +00:00
parent b6bf913d14
commit 8170e47c22
6 changed files with 66 additions and 22 deletions

View File

@ -58,7 +58,8 @@ public class Gaussian implements UnivariateDifferentiable, DifferentiableUnivari
*/
public Gaussian(double norm,
double mean,
double sigma) {
double sigma)
throws NotStrictlyPositiveException {
if (sigma <= 0) {
throw new NotStrictlyPositiveException(sigma);
}
@ -77,7 +78,8 @@ public class Gaussian implements UnivariateDifferentiable, DifferentiableUnivari
* @throws NotStrictlyPositiveException if {@code sigma <= 0}.
*/
public Gaussian(double mean,
double sigma) {
double sigma)
throws NotStrictlyPositiveException {
this(1 / (sigma * FastMath.sqrt(2 * Math.PI)), mean, sigma);
}
@ -122,7 +124,10 @@ public class Gaussian implements UnivariateDifferentiable, DifferentiableUnivari
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
public double value(double x, double ... param) {
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double diff = x - param[1];
@ -144,7 +149,10 @@ public class Gaussian implements UnivariateDifferentiable, DifferentiableUnivari
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
public double[] gradient(double x, double ... param) {
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double norm = param[0];
@ -170,7 +178,10 @@ public class Gaussian implements UnivariateDifferentiable, DifferentiableUnivari
* not 3.
* @throws NotStrictlyPositiveException if {@code param[2]} is negative.
*/
private void validateParameters(double[] param) {
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
if (param == null) {
throw new NullArgumentException();
}

View File

@ -90,7 +90,9 @@ public class HarmonicOscillator implements UnivariateDifferentiable, Differentia
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
public double value(double x, double ... param) {
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
return HarmonicOscillator.value(x * param[1] + param[2], param[0]);
}
@ -108,7 +110,9 @@ public class HarmonicOscillator implements UnivariateDifferentiable, Differentia
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
public double[] gradient(double x, double ... param) {
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
final double amplitude = param[0];
@ -133,7 +137,9 @@ public class HarmonicOscillator implements UnivariateDifferentiable, Differentia
* @throws DimensionMismatchException if the size of {@code param} is
* not 3.
*/
private void validateParameters(double[] param) {
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException {
if (param == null) {
throw new NullArgumentException();
}

View File

@ -67,7 +67,8 @@ public class Logistic implements UnivariateDifferentiable, DifferentiableUnivari
double b,
double q,
double a,
double n) {
double n)
throws NotStrictlyPositiveException {
if (n <= 0) {
throw new NotStrictlyPositiveException(n);
}
@ -113,7 +114,10 @@ public class Logistic implements UnivariateDifferentiable, DifferentiableUnivari
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
*/
public double value(double x, double ... param) {
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
return Logistic.value(param[1] - x, param[0],
param[2], param[3],
@ -134,7 +138,10 @@ public class Logistic implements UnivariateDifferentiable, DifferentiableUnivari
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
*/
public double[] gradient(double x, double ... param) {
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
validateParameters(param);
final double b = param[2];
@ -165,12 +172,15 @@ public class Logistic implements UnivariateDifferentiable, DifferentiableUnivari
* methods.
*
* @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
* {@code a} and {@code n}.
* {@code a} and {@code n}.
* @throws NullArgumentException if {@code param} is {@code null}.
* @throws DimensionMismatchException if the size of {@code param} is
* not 6.
*/
private void validateParameters(double[] param) {
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException,
NotStrictlyPositiveException {
if (param == null) {
throw new NullArgumentException();
}

View File

@ -63,7 +63,8 @@ public class Logit implements UnivariateDifferentiable, DifferentiableUnivariate
}
/** {@inheritDoc} */
public double value(double x) {
public double value(double x)
throws OutOfRangeException {
return value(x, lo, hi);
}
@ -94,7 +95,9 @@ public class Logit implements UnivariateDifferentiable, DifferentiableUnivariate
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double value(double x, double ... param) {
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
return Logit.value(x, param[0], param[1]);
}
@ -112,7 +115,9 @@ public class Logit implements UnivariateDifferentiable, DifferentiableUnivariate
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double[] gradient(double x, double ... param) {
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
final double lo = param[0];
@ -131,7 +136,9 @@ public class Logit implements UnivariateDifferentiable, DifferentiableUnivariate
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
private void validateParameters(double[] param) {
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException {
if (param == null) {
throw new NullArgumentException();
}
@ -149,7 +156,8 @@ public class Logit implements UnivariateDifferentiable, DifferentiableUnivariate
*/
private static double value(double x,
double lo,
double hi) {
double hi)
throws OutOfRangeException {
if (x < lo || x > hi) {
throw new OutOfRangeException(x, lo, hi);
}

View File

@ -96,7 +96,9 @@ public class Sigmoid implements UnivariateDifferentiable, DifferentiableUnivaria
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double value(double x, double ... param) {
public double value(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
return Sigmoid.value(x, param[0], param[1]);
}
@ -114,7 +116,9 @@ public class Sigmoid implements UnivariateDifferentiable, DifferentiableUnivaria
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
public double[] gradient(double x, double ... param) {
public double[] gradient(double x, double ... param)
throws NullArgumentException,
DimensionMismatchException {
validateParameters(param);
final double invExp1 = 1 / (1 + FastMath.exp(-x));
@ -132,7 +136,9 @@ public class Sigmoid implements UnivariateDifferentiable, DifferentiableUnivaria
* @throws DimensionMismatchException if the size of {@code param} is
* not 2.
*/
private void validateParameters(double[] param) {
private void validateParameters(double[] param)
throws NullArgumentException,
DimensionMismatchException {
if (param == null) {
throw new NullArgumentException();
}

View File

@ -58,7 +58,10 @@ public class StepFunction implements UnivariateFunction {
* have the same length.
*/
public StepFunction(double[] x,
double[] y) {
double[] y)
throws NullArgumentException,
NoDataException,
DimensionMismatchException {
if (x == null ||
y == null) {
throw new NullArgumentException();