本文整理汇总了Java中org.apache.commons.math3.util.MathArrays.sortInPlace方法的典型用法代码示例。如果您正苦于以下问题:Java MathArrays.sortInPlace方法的具体用法?Java MathArrays.sortInPlace怎么用?Java MathArrays.sortInPlace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathArrays
的用法示例。
在下文中一共展示了MathArrays.sortInPlace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Evaluate the Lagrange polynomial using
* <a href="http://mathworld.wolfram.com/NevillesAlgorithm.html">
* Neville's Algorithm</a>. It takes O(n^2) time.
*
* @param x Interpolating points array.
* @param y Interpolating values array.
* @param z Point at which the function value is to be computed.
* @return the function value.
* @throws DimensionMismatchException if {@code x} and {@code y} have
* different lengths.
* @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)
throws DimensionMismatchException, NumberIsTooSmallException, NonMonotonicSequenceException {
if (verifyInterpolationArray(x, y, false)) {
return evaluateInternal(x, y, z);
}
// Array is not sorted.
final double[] xNew = new double[x.length];
final double[] yNew = new double[y.length];
System.arraycopy(x, 0, xNew, 0, x.length);
System.arraycopy(y, 0, yNew, 0, y.length);
MathArrays.sortInPlace(xNew, yNew);
// Second check in case some abscissa is duplicated.
verifyInterpolationArray(xNew, yNew, true);
return evaluateInternal(xNew, yNew, z);
}
示例2: sort
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Sort in place given dataset and reorder ancillary datasets too
* @param a dataset to be sorted
* @param b ancillary datasets
*/
public static void sort(Dataset a, Dataset... b) {
if (!DTypeUtils.isDTypeNumerical(a.getDType())) {
throw new UnsupportedOperationException("Sorting non-numerical datasets not supported yet");
}
// gather all datasets as double dataset copies
DoubleDataset s = copy(DoubleDataset.class, a);
int l = b == null ? 0 : b.length;
DoubleDataset[] t = new DoubleDataset[l];
int n = 0;
for (int i = 0; i < l; i++) {
if (b[i] != null) {
if (!DTypeUtils.isDTypeNumerical(b[i].getDType())) {
throw new UnsupportedOperationException("Sorting non-numerical datasets not supported yet");
}
t[i] = copy(DoubleDataset.class, b[i]);
n++;
}
}
double[][] y = new double[n][];
for (int i = 0, j = 0; i < l; i++) {
if (t[i] != null) {
y[j++] = t[i].getData();
}
}
MathArrays.sortInPlace(s.getData(), y);
a.setSlice(s);
for (int i = 0; i < l; i++) {
if (b[i] != null) {
b[i].setSlice(t[i]);
}
}
}
示例3: estimate
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Estimate the quantile for the current marker.
*
* @return estimated quantile
*/
private double estimate() {
final double di = difference();
final boolean isNextHigher =
next.intMarkerPosition - intMarkerPosition > 1;
final boolean isPreviousLower =
previous.intMarkerPosition - intMarkerPosition < -1;
if (di >= 1 && isNextHigher || di <= -1 && isPreviousLower) {
final int d = di >= 0 ? 1 : -1;
final double[] xval =
new double[] { previous.intMarkerPosition,
intMarkerPosition, next.intMarkerPosition };
final double[] yval =
new double[] { previous.markerHeight, markerHeight,
next.markerHeight };
final double xD = intMarkerPosition + d;
UnivariateFunction univariateFunction =
nonLinear.interpolate(xval, yval);
markerHeight = univariateFunction.value(xD);
// If parabolic estimate is bad then turn linear
if (isEstimateBad(yval, markerHeight)) {
int delta = xD - xval[1] > 0 ? 1 : -1;
final double[] xBad =
new double[] { xval[1], xval[1 + delta] };
final double[] yBad =
new double[] { yval[1], yval[1 + delta] };
MathArrays.sortInPlace(xBad, yBad);// since d can be +/- 1
univariateFunction = linear.interpolate(xBad, yBad);
markerHeight = univariateFunction.value(xD);
}
incrementPosition(d);
}
return markerHeight;
}
示例4: PolynomialFunctionLagrangeForm
import org.apache.commons.math3.util.MathArrays; //导入方法依赖的package包/类
/**
* Construct a Lagrange polynomial with the given abscissas and function
* values. The order of interpolating points are not important.
* <p>
* The constructor makes copy of the input arrays and assigns them.</p>
*
* @param x interpolating points
* @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 NonMonotonicSequenceException
* if two abscissae have the same value.
*/
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);
System.arraycopy(y, 0, this.y, 0, y.length);
coefficientsComputed = false;
if (!verifyInterpolationArray(x, y, false)) {
MathArrays.sortInPlace(this.x, this.y);
// Second check in case some abscissa is duplicated.
verifyInterpolationArray(this.x, this.y, true);
}
}