本文整理汇总了Java中org.apache.commons.math3.analysis.interpolation.SplineInterpolator类的典型用法代码示例。如果您正苦于以下问题:Java SplineInterpolator类的具体用法?Java SplineInterpolator怎么用?Java SplineInterpolator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SplineInterpolator类属于org.apache.commons.math3.analysis.interpolation包,在下文中一共展示了SplineInterpolator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interpolate
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Compute an interpolating function by performing a loess fit
* on the data at the original abscissae and then building a cubic spline
* with a
* {@link org.apache.commons.math3.analysis.interpolation.SplineInterpolator}
* on the resulting fit.
*
* @param xval the arguments for the interpolation points
* @param yval the values for the interpolation points
* @return A cubic spline built upon a loess fit to the data at the original abscissae
* @throws NonMonotonicSequenceException if {@code xval} not sorted in
* strictly increasing order.
* @throws DimensionMismatchException if {@code xval} and {@code yval} have
* different sizes.
* @throws NoDataException if {@code xval} or {@code yval} has zero size.
* @throws NotFiniteNumberException if any of the arguments and values are
* not finite real numbers.
* @throws NumberIsTooSmallException if the bandwidth is too small to
* accomodate the size of the input data (i.e. the bandwidth must be
* larger than 2/n).
*/
public final PolynomialSplineFunction interpolate(double[] xval,
double[] yval)
throws NonMonotonicSequenceException,
DimensionMismatchException,
NoDataException,
NotFiniteNumberException,
NumberIsTooSmallException {
double[] smoothed = smooth(xval, yval);
DoubleList newX = new ArrayDoubleList();
DoubleList newSmoothed = new ArrayDoubleList();
newX.add(xval[0]);
newSmoothed.add(smoothed[0]);
for(int i = 1; i < xval.length; i++){
if(xval[i] != xval[i-1]){
newX.add(xval[i]);
newSmoothed.add(smoothed[i]);
}
}
xval = newX.toArray();
smoothed = newSmoothed.toArray();
return new SplineInterpolator().interpolate(xval, smoothed);
}
示例2: cubicBSplineInterpolation
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
public IDecimalAggregate<E> cubicBSplineInterpolation(final InterpolationConfig config) {
if (values.isEmpty()) {
return DummyDecimalAggregate.getInstance();
}
if (values.size() < 4) {
return parent;
}
final Pair<List<Double>, List<Double>> pair = fillInterpolationPoints(config, null);
final List<Double> xval = pair.getFirst();
final List<Double> yval = pair.getSecond();
final ControlPath cp = new ControlPath();
for (int i = 0; i < xval.size(); i++) {
cp.addPoint(PointFactory.create(xval.get(i), yval.get(i)));
}
final GroupIterator gi = new GroupIterator("0:n-1", cp.numPoints());
final CubicBSpline curve = new CubicBSpline(cp, gi);
curve.setInterpolateEndpoints(true);
calculateCurve(xval, yval, curve);
final UnivariateInterpolator interpolator = new SplineInterpolator();
return interpolate(config, xval, yval, interpolator);
}
示例3: bezierCurveInterpolation
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
public IDecimalAggregate<E> bezierCurveInterpolation(final InterpolationConfig config) {
if (values.isEmpty()) {
return DummyDecimalAggregate.getInstance();
}
final Pair<List<Double>, List<Double>> pair = fillInterpolationPoints(config, BEZIER_CURVE_MAX_SIZE);
final List<Double> xval = pair.getFirst();
final List<Double> yval = pair.getSecond();
final ControlPath cp = new ControlPath();
for (int i = 0; i < xval.size(); i++) {
cp.addPoint(PointFactory.create(xval.get(i), yval.get(i)));
}
final GroupIterator gi = new GroupIterator("0:n-1", cp.numPoints());
final BezierCurve curve = new BezierCurve(cp, gi);
calculateCurve(xval, yval, curve);
final UnivariateInterpolator interpolator = new SplineInterpolator();
return interpolate(config, xval, yval, interpolator);
}
示例4: bSplineInterpolation
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
public IDecimalAggregate<E> bSplineInterpolation(final BSplineInterpolationConfig config) {
if (values.isEmpty()) {
return DummyDecimalAggregate.getInstance();
}
final Pair<List<Double>, List<Double>> pair = fillInterpolationPoints(config, null);
final List<Double> xval = pair.getFirst();
final List<Double> yval = pair.getSecond();
final ControlPath cp = new ControlPath();
for (int i = 0; i < xval.size(); i++) {
cp.addPoint(PointFactory.create(xval.get(i), yval.get(i)));
}
final GroupIterator gi = new GroupIterator("0:n-1", cp.numPoints());
final BSpline curve = new BSpline(cp, gi);
curve.setDegree(config.getDegree());
final int maxDegree = cp.numPoints() - 1;
if (curve.getDegree() > maxDegree) {
curve.setDegree(maxDegree);
}
calculateCurve(xval, yval, curve);
final UnivariateInterpolator interpolator = new SplineInterpolator();
return interpolate(config, xval, yval, interpolator);
}
示例5: addParameterArrayVersionNullModel
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Tests that the correct exception is produced when passing a NULL model.
*/
@Test
public void addParameterArrayVersionNullModel() {
boolean caughtException = false;
setSinData();
try {
SBMLTimeCourseDataHelper.addParameter(
null, "myParam", _times, _values,
new PolynomialInterpolator(new SplineInterpolator()));
}
catch(IllegalArgumentException iae)
{
caughtException = true;
assertEquals("sbmlModel parameter cannot be null", iae.getMessage());
}
if (!caughtException) fail("Expected IllegalArgumentException");
}
示例6: addParameterArrayVersionNullParameterName
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Tests that the correct exception is produced when passing a NULL parameter name.
*/
@Test
public void addParameterArrayVersionNullParameterName() {
boolean caughtException = false;
setSinData();
SBMLDocument doc = new SBMLDocument(3, 1);
Model model = doc.createModel("test_model");
try {
SBMLTimeCourseDataHelper.addParameter(
model, null, _times, _values, new PolynomialInterpolator(new SplineInterpolator()));
}
catch(IllegalArgumentException iae)
{
caughtException = true;
assertEquals("parameterName parameter cannot be null", iae.getMessage());
}
if (!caughtException) fail("Expected IllegalArgumentException");
}
示例7: addParameterArrayVersionNullTimes
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Tests that the correct exception is produced when passing NULL times.
*/
@Test
public void addParameterArrayVersionNullTimes() {
boolean caughtException = false;
setSinData();
SBMLDocument doc = new SBMLDocument(3, 1);
Model model = doc.createModel("test_model");
try {
SBMLTimeCourseDataHelper.addParameter(
model, "myParam", null, _values, new PolynomialInterpolator(new SplineInterpolator()));
}
catch(IllegalArgumentException iae)
{
caughtException = true;
assertEquals("times parameter cannot be null", iae.getMessage());
}
if (!caughtException) fail("Expected IllegalArgumentException");
}
示例8: addParameterArrayVersionNullValues
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Tests that the correct exception is produced when passing NULL values.
*/
@Test
public void addParameterArrayVersionNullValues() {
boolean caughtException = false;
setSinData();
SBMLDocument doc = new SBMLDocument(3, 1);
Model model = doc.createModel("test_model");
try {
SBMLTimeCourseDataHelper.addParameter(
model, "myParam", _times, null, new PolynomialInterpolator(new SplineInterpolator()));
}
catch(IllegalArgumentException iae)
{
caughtException = true;
assertEquals("values parameter cannot be null", iae.getMessage());
}
if (!caughtException) fail("Expected IllegalArgumentException");
}
示例9: splineDerivatives
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* 计算分段插值拟合的导数值
*
* @param input
* @return
*/
private double[] splineDerivatives(double[] input) {
double xStep = 1.0 / input.length;
double[] x = new double[input.length];
double[] y = new double[input.length];
for (int i = 0; i < input.length; i++) {
x[i] = i * xStep;
y[i] = input[i];
}
SplineInterpolator fitter = new SplineInterpolator();
PolynomialSplineFunction func = fitter.interpolate(x, y);
double[] derivatives = new double[input.length];
for (int i = 0; i < derivatives.length; i++) {
derivatives[i] = func.derivative().value(x[i]);
}
return derivatives;
}
示例10: interpolateZeroCrossingPoints
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
@SuppressWarnings("unused")
private void interpolateZeroCrossingPoints()
{
double[] x = new double[zeroCrossingPoints.size()];
double[] y = new double[zeroCrossingPoints.size()];
for (int i = 0; i < x.length; i++)
{
double[] point = zeroCrossingPoints.get(i);
x[i] = point[0];
y[i] = point[1];
}
PolynomialSplineFunction fx = new SplineInterpolator().interpolate(x, y);
double minX = x[0];
double maxX = x[x.length - 1];
double xinc = (maxX - minX) / 50;
for (minX = minX + xinc; minX < maxX; minX += xinc)
{
zeroCrossingPoints.add(new double[] { minX, fx.value(minX) });
}
sortPoints();
}
示例11: InterpolatedData
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
*
* @param wl interpolate N at each wavelength
*/
public void InterpolatedData(double[] wl) throws FileNotFoundException{
if(ReadWavelength!=null && ReadNReal!=null && ReadNImaginary!=null){
SplineInterpolator splineInterp = new SplineInterpolator();
PolynomialSplineFunction polySplineFReal = splineInterp.interpolate(ReadWavelength, ReadNReal);
PolynomialSplineFunction polySplineFImaginary = splineInterp.interpolate(ReadWavelength, ReadNImaginary);
double[] NReal = new double[wl.length];
double[] NImaginary = new double[wl.length];
N = new Complex[wl.length];
theta = new Complex[wl.length];
beta = new Complex[wl.length];
LM = new Matrix[wl.length];
IpM = new Matrix[wl.length];
IsM = new Matrix[wl.length];
for(int j=0; j<=wl.length-1; j++){
NReal[j] = polySplineFReal.value(wl[j]);
NImaginary[j] = polySplineFImaginary.value(wl[j]);
N[j] = new Complex(NReal[j], NImaginary[j]);
}
}
}
示例12: createInterpolator
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
private UnivariateInterpolator createInterpolator()
{
switch(this.gcDepthInterpolation)
{
case loess: return new LoessInterpolator(0.5,4);
case neville: return new NevilleInterpolator();
case difference : return new DividedDifferenceInterpolator();
case linear: return new LinearInterpolator();
case spline : return new SplineInterpolator();
case identity : return new UnivariateInterpolator()
{
@Override
public UnivariateFunction interpolate(double[] arg0, double[] arg1)
throws MathIllegalArgumentException, DimensionMismatchException {
return new Identity();
}
};
default: throw new IllegalStateException("Not implemented");
}
}
示例13: testCurve
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
@Test
public void testCurve() {
final double[] testYValues = new double[] {20, 40, 90};
final PolynomialSplineFunction testFunction = new SplineInterpolator().interpolate(dummyIndex, testYValues);
final double[] coords = spyRouteDrawer.getCoords(testFunction, dummyIndex);
final double stepSize = testFunction.getKnots()[testFunction.getKnots().length - 1] / coords.length;
assertEquals(testYValues[0] * stepSize, coords[(int) Math.round(dummyIndex[0])], 1);
assertEquals(testYValues[1] * stepSize, coords[(int) Math.round(dummyIndex[1])], 1);
assertEquals(testYValues[2] * stepSize, coords[(int) Math.round(dummyIndex[2])], 1);
// TODO change the calculation so that delta = 0;
}
示例14: InterpolatedFrames
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Interpolates the given keyframes and creates a new InterpolatedFrames instance.
*
* @param keyframes keyframes
*/
InterpolatedFrames(List<Keyframe> keyframes) {
Collections.sort(keyframes, new Comparator<Keyframe>() {
@Override
public int compare(Keyframe a, Keyframe b) {
return Double.compare(a.getTime(), b.getTime());
}
});
this.length = keyframes.get(keyframes.size() - 1).getTime();
double[] t = new double[keyframes.size()];
double[] xValues = new double[keyframes.size()];
double[] yValues = new double[keyframes.size()];
double[] zValues = new double[keyframes.size()];
double[] pitchValues = new double[keyframes.size()];
double[] yawValues = new double[keyframes.size()];
int i = 0;
for (Keyframe frame : keyframes) {
t[i] = frame.getTime();
xValues[i] = frame.getX();
yValues[i] = frame.getY();
zValues[i] = frame.getZ();
pitchValues[i] = frame.getPitch();
yawValues[i] = frame.getYaw();
i++;
}
SplineInterpolator interpolator = new SplineInterpolator();
this.x = interpolator.interpolate(t, xValues);
this.y = interpolator.interpolate(t, yValues);
this.z = interpolator.interpolate(t, zValues);
this.pitch = interpolator.interpolate(t, pitchValues);
this.yaw = interpolator.interpolate(t, yawValues);
}
示例15: addParameterArrayVersionDifferentLengthArrays
import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; //导入依赖的package包/类
/**
* Tests that the correct exception is produced when passing times and values arrays of
* different lengths.
*/
@Test
public void addParameterArrayVersionDifferentLengthArrays() {
boolean caughtException = false;
setSinData();
SBMLDocument doc = new SBMLDocument(3, 1);
Model model = doc.createModel("test_model");
// Make longer values array
double[] values = new double[_values.length+1];
System.arraycopy(_values, 0, values, 0, _values.length);
values[values.length-1] = 0.0;
try {
SBMLTimeCourseDataHelper.addParameter(
model, "myParam", _times, values, new PolynomialInterpolator(new SplineInterpolator()));
}
catch(IllegalArgumentException iae)
{
caughtException = true;
assertEquals(
"Number of data points in values parameter differs from times parameter",
iae.getMessage());
}
if (!caughtException) fail("Expected IllegalArgumentException");
}