本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.checkOrder方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.checkOrder方法的具体用法?Java MathArrays.checkOrder怎么用?Java MathArrays.checkOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathArrays
的用法示例。
在下文中一共展示了MathArrays.checkOrder方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BilinearInterpolatingFunction
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
public BilinearInterpolatingFunction(double[] xval, double[] yval, double[][] fval)
throws DimensionMismatchException, NoDataException, NonMonotonicSequenceException {
if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
throw new NoDataException();
}
if (xval.length != fval.length) {
throw new DimensionMismatchException(xval.length, fval.length);
}
if (yval.length != fval[0].length) {
throw new DimensionMismatchException(yval.length, fval[0].length);
}
MathArrays.checkOrder(xval);
MathArrays.checkOrder(yval);
this.xval = xval;
this.yval = yval;
this.fval = fval;
}
示例2: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
@Override
public BilinearInterpolatingFunction interpolate(double[] xval, double[] yval, double[][] fval)
throws NoDataException, DimensionMismatchException, NonMonotonicSequenceException {
if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
throw new NoDataException();
}
if (xval.length != fval.length) {
throw new DimensionMismatchException(xval.length, fval.length);
}
if (yval.length != fval[0].length) {
throw new DimensionMismatchException(yval.length, fval[0].length);
}
MathArrays.checkOrder(xval);
MathArrays.checkOrder(yval);
return new BilinearInterpolatingFunction(xval, yval, fval);
}
示例3: StepFunction
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* 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);
}
示例4: PolynomialSplineFunction
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Construct a polynomial spline function with the given segment delimiters
* and interpolating polynomials.
* The constructor copies both arrays and assigns the copies to the knots
* and polynomials properties, respectively.
*
* @param knots Spline segment interval delimiters.
* @param polynomials Polynomial functions that make up the spline.
* @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 NonMonotonicSequenceException if the {@code knots} array is not strictly increasing.
*
*/
public PolynomialSplineFunction(double knots[], PolynomialFunction polynomials[])
throws NullArgumentException, NumberIsTooSmallException,
DimensionMismatchException, NonMonotonicSequenceException{
if (knots == null ||
polynomials == null) {
throw new NullArgumentException();
}
if (knots.length < 2) {
throw new NumberIsTooSmallException(LocalizedFormats.NOT_ENOUGH_POINTS_IN_SPLINE_PARTITION,
2, knots.length, false);
}
if (knots.length - 1 != polynomials.length) {
throw new DimensionMismatchException(polynomials.length, knots.length);
}
MathArrays.checkOrder(knots);
this.n = knots.length -1;
this.knots = new double[n + 1];
System.arraycopy(knots, 0, this.knots, 0, n + 1);
this.polynomials = new PolynomialFunction[n];
System.arraycopy(polynomials, 0, this.polynomials, 0, n);
}
示例5: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* {@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 );
}
示例6: GaussIntegrator
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Creates an integrator from the given {@code points} and {@code weights}.
* The integration interval is defined by the first and last value of
* {@code points} which must be sorted in increasing order.
*
* @param points Integration points.
* @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, DimensionMismatchException {
if (points.length != weights.length) {
throw new DimensionMismatchException(points.length,
weights.length);
}
MathArrays.checkOrder(points, MathArrays.OrderDirection.INCREASING, true, true);
this.points = points.clone();
this.weights = weights.clone();
}
示例7: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Computes a linear interpolating function for the data set.
*
* @param x the arguments for the interpolation points
* @param y the values for the interpolation points
* @return a function which interpolates the data set
* @throws DimensionMismatchException if {@code x} and {@code y}
* have different sizes.
* @throws NonMonotonicSequenceException if {@code x} is not sorted in
* strict increasing order.
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
* than 2.
*/
public PolynomialSplineFunction interpolate(double x[], double y[])
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {
if (x.length != y.length) {
throw new DimensionMismatchException(x.length, y.length);
}
if (x.length < 2) {
throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS,
x.length, 2, true);
}
// Number of intervals. The number of data points is n + 1.
int n = x.length - 1;
MathArrays.checkOrder(x);
// Slope of the lines between the datapoints.
final double m[] = new double[n];
for (int i = 0; i < n; i++) {
m[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i]);
}
final PolynomialFunction polynomials[] = new PolynomialFunction[n];
final double coefficients[] = new double[2];
for (int i = 0; i < n; i++) {
coefficients[0] = y[i];
coefficients[1] = m[i];
polynomials[i] = new PolynomialFunction(coefficients);
}
return new PolynomialSplineFunction(x, polynomials);
}
示例8: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public BicubicInterpolatingFunction interpolate(final double[] xval,
final double[] yval,
final double[][] fval)
throws NoDataException, DimensionMismatchException,
NonMonotonicSequenceException, NumberIsTooSmallException {
if (xval.length == 0 || yval.length == 0 || fval.length == 0) {
throw new NoDataException();
}
if (xval.length != fval.length) {
throw new DimensionMismatchException(xval.length, fval.length);
}
MathArrays.checkOrder(xval);
MathArrays.checkOrder(yval);
final int xLen = xval.length;
final int yLen = yval.length;
// Approximation to the partial derivatives using finite differences.
final double[][] dFdX = new double[xLen][yLen];
final double[][] dFdY = new double[xLen][yLen];
final double[][] d2FdXdY = new double[xLen][yLen];
for (int i = 1; i < xLen - 1; i++) {
final int nI = i + 1;
final int pI = i - 1;
final double nX = xval[nI];
final double pX = xval[pI];
final double deltaX = nX - pX;
for (int j = 1; j < yLen - 1; j++) {
final int nJ = j + 1;
final int pJ = j - 1;
final double nY = yval[nJ];
final double pY = yval[pJ];
final double deltaY = nY - pY;
dFdX[i][j] = (fval[nI][j] - fval[pI][j]) / deltaX;
dFdY[i][j] = (fval[i][nJ] - fval[i][pJ]) / deltaY;
final double deltaXY = deltaX * deltaY;
d2FdXdY[i][j] = (fval[nI][nJ] - fval[nI][pJ] - fval[pI][nJ] + fval[pI][pJ]) / deltaXY;
}
}
// Create the interpolating function.
return new BicubicInterpolatingFunction(xval, yval, fval,
dFdX, dFdY, d2FdXdY) {
/** {@inheritDoc} */
@Override
public boolean isValidPoint(double x, double y) {
if (x < xval[1] ||
x > xval[xval.length - 2] ||
y < yval[1] ||
y > yval[yval.length - 2]) {
return false;
} else {
return true;
}
}
};
}
示例9: PiecewiseBicubicSplineInterpolatingFunction
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* @param x Sample values of the x-coordinate, in increasing order.
* @param y Sample values of the y-coordinate, in increasing order.
* @param f Values of the function on every grid point. the expected number
* of elements.
* @throws NonMonotonicSequenceException if {@code x} or {@code y} are not
* strictly increasing.
* @throws NullArgumentException if any of the arguments are null
* @throws NoDataException if any of the arrays has zero length.
* @throws DimensionMismatchException if the length of x and y don't match the row, column
* height of f
*/
public PiecewiseBicubicSplineInterpolatingFunction(double[] x,
double[] y,
double[][] f)
throws DimensionMismatchException,
NullArgumentException,
NoDataException,
NonMonotonicSequenceException {
if (x == null ||
y == null ||
f == null ||
f[0] == null) {
throw new NullArgumentException();
}
final int xLen = x.length;
final int yLen = y.length;
if (xLen == 0 ||
yLen == 0 ||
f.length == 0 ||
f[0].length == 0) {
throw new NoDataException();
}
if (xLen < MIN_NUM_POINTS ||
yLen < MIN_NUM_POINTS ||
f.length < MIN_NUM_POINTS ||
f[0].length < MIN_NUM_POINTS) {
throw new InsufficientDataException();
}
if (xLen != f.length) {
throw new DimensionMismatchException(xLen, f.length);
}
if (yLen != f[0].length) {
throw new DimensionMismatchException(yLen, f[0].length);
}
MathArrays.checkOrder(x);
MathArrays.checkOrder(y);
xval = x.clone();
yval = y.clone();
fval = f.clone();
}
示例10: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Computes an interpolating function for the data set.
*
* @param xvals the arguments for the interpolation points
* @param yvals the values for the interpolation points
* @return a function which interpolates the data set
* @throws DimensionMismatchException if {@code xvals} and {@code yvals} have
* different sizes.
* @throws NonMonotonicSequenceException if {@code xvals} is not sorted in
* strict increasing order.
* @throws NumberIsTooSmallException if the size of {@code xvals} is smaller
* than 5.
*/
public PolynomialSplineFunction interpolate(double[] xvals,
double[] yvals)
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {
if (xvals == null ||
yvals == null) {
throw new NullArgumentException();
}
if (xvals.length != yvals.length) {
throw new DimensionMismatchException(xvals.length, yvals.length);
}
if (xvals.length < MINIMUM_NUMBER_POINTS) {
throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS,
xvals.length,
MINIMUM_NUMBER_POINTS, true);
}
MathArrays.checkOrder(xvals);
final int numberOfDiffAndWeightElements = xvals.length - 1;
final double[] differences = new double[numberOfDiffAndWeightElements];
final double[] weights = new double[numberOfDiffAndWeightElements];
for (int i = 0; i < differences.length; i++) {
differences[i] = (yvals[i + 1] - yvals[i]) / (xvals[i + 1] - xvals[i]);
}
for (int i = 1; i < weights.length; i++) {
weights[i] = FastMath.abs(differences[i] - differences[i - 1]);
}
// Prepare Hermite interpolation scheme.
final double[] firstDerivatives = new double[xvals.length];
for (int i = 2; i < firstDerivatives.length - 2; i++) {
final double wP = weights[i + 1];
final double wM = weights[i - 1];
if (Precision.equals(wP, 0.0) &&
Precision.equals(wM, 0.0)) {
final double xv = xvals[i];
final double xvP = xvals[i + 1];
final double xvM = xvals[i - 1];
firstDerivatives[i] = (((xvP - xv) * differences[i - 1]) + ((xv - xvM) * differences[i])) / (xvP - xvM);
} else {
firstDerivatives[i] = ((wP * differences[i - 1]) + (wM * differences[i])) / (wP + wM);
}
}
firstDerivatives[0] = differentiateThreePoint(xvals, yvals, 0, 0, 1, 2);
firstDerivatives[1] = differentiateThreePoint(xvals, yvals, 1, 0, 1, 2);
firstDerivatives[xvals.length - 2] = differentiateThreePoint(xvals, yvals, xvals.length - 2,
xvals.length - 3, xvals.length - 2,
xvals.length - 1);
firstDerivatives[xvals.length - 1] = differentiateThreePoint(xvals, yvals, xvals.length - 1,
xvals.length - 3, xvals.length - 2,
xvals.length - 1);
return interpolateHermiteSorted(xvals, yvals, firstDerivatives);
}
示例11: interpolate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Computes an interpolating function for the data set.
* @param x the arguments for the interpolation points
* @param y the values for the interpolation points
* @return a function which interpolates the data set
* @throws DimensionMismatchException if {@code x} and {@code y}
* have different sizes.
* @throws NonMonotonicSequenceException if {@code x} is not sorted in
* strict increasing order.
* @throws NumberIsTooSmallException if the size of {@code x} is smaller
* than 3.
*/
public PolynomialSplineFunction interpolate(double x[], double y[])
throws DimensionMismatchException,
NumberIsTooSmallException,
NonMonotonicSequenceException {
if (x.length != y.length) {
throw new DimensionMismatchException(x.length, y.length);
}
if (x.length < 3) {
throw new NumberIsTooSmallException(LocalizedFormats.NUMBER_OF_POINTS,
x.length, 3, true);
}
// Number of intervals. The number of data points is n + 1.
final int n = x.length - 1;
MathArrays.checkOrder(x);
// Differences between knot points
final double h[] = new double[n];
for (int i = 0; i < n; i++) {
h[i] = x[i + 1] - x[i];
}
final double mu[] = new double[n];
final double z[] = new double[n + 1];
mu[0] = 0d;
z[0] = 0d;
double g = 0;
for (int i = 1; i < n; i++) {
g = 2d * (x[i+1] - x[i - 1]) - h[i - 1] * mu[i -1];
mu[i] = h[i] / g;
z[i] = (3d * (y[i + 1] * h[i - 1] - y[i] * (x[i + 1] - x[i - 1])+ y[i - 1] * h[i]) /
(h[i - 1] * h[i]) - h[i - 1] * z[i - 1]) / g;
}
// cubic spline coefficients -- b is linear, c quadratic, d is cubic (original y's are constants)
final double b[] = new double[n];
final double c[] = new double[n + 1];
final double d[] = new double[n];
z[n] = 0d;
c[n] = 0d;
for (int j = n -1; j >=0; j--) {
c[j] = z[j] - mu[j] * c[j + 1];
b[j] = (y[j + 1] - y[j]) / h[j] - h[j] * (c[j + 1] + 2d * c[j]) / 3d;
d[j] = (c[j + 1] - c[j]) / (3d * h[j]);
}
final PolynomialFunction polynomials[] = new PolynomialFunction[n];
final double coefficients[] = new double[4];
for (int i = 0; i < n; i++) {
coefficients[0] = y[i];
coefficients[1] = b[i];
coefficients[2] = c[i];
coefficients[3] = d[i];
polynomials[i] = new PolynomialFunction(coefficients);
}
return new PolynomialSplineFunction(x, polynomials);
}
示例12: StepFunction
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* 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 org.apache.commons.math3.exception.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) {
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);
}
示例13: verifyInterpolationArray
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Check that the interpolation arrays are valid.
* The arrays features checked by this method are that both arrays have the
* same length and this length is at least 2.
*
* @param x Interpolating points array.
* @param y Interpolating values array.
* @param abort Whether to throw an exception if {@code x} is not sorted.
* @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
* if {@code x} is not sorted in strictly increasing order and {@code abort}
* is {@code true}.
* @return {@code false} if the {@code x} is not sorted in increasing order,
* {@code true} otherwise.
* @see #evaluate(double[], double[], double)
* @see #computeCoefficients()
*/
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);
}
if (x.length < 2) {
throw new NumberIsTooSmallException(LocalizedFormats.WRONG_NUMBER_OF_POINTS, 2, x.length, true);
}
return MathArrays.checkOrder(x, MathArrays.OrderDirection.INCREASING, true, abort);
}