本文整理汇总了Java中org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction类的典型用法代码示例。如果您正苦于以下问题:Java PolynomialSplineFunction类的具体用法?Java PolynomialSplineFunction怎么用?Java PolynomialSplineFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PolynomialSplineFunction类属于org.apache.commons.math3.analysis.polynomials包,在下文中一共展示了PolynomialSplineFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interpolate
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的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: smooth
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Override
public double[] smooth(double[] sourceX, double[] noisyY, double[] estimateX, double parameter) {
if(sourceX.length < 2)
{
return new double[sourceX.length];
}
LinearInterpolator interpolator = new LinearInterpolator();
PolynomialSplineFunction estimateFunc = interpolator.interpolate(sourceX, noisyY);
double[] result = new double[estimateX.length];
for(int i =0; i < estimateX.length;i++)
{
if(estimateFunc.isValidPoint(estimateX[i]))
{
result[i] = estimateFunc.value(estimateX[i]);
}
else
{
result[i] = Double.NaN;
}
}
return result ;
}
示例3: DriftResults
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
public DriftResults(PolynomialSplineFunction xFunction,
PolynomialSplineFunction yFunction,
double[] driftDataFrame,
double[] driftDataX,
double[] driftDataY,
int minFrame, int maxFrame,
MoleculeDescriptor.Units units) {
this.xFunction = xFunction;
this.yFunction = yFunction;
this.driftDataFrame = driftDataFrame;
this.driftDataX = driftDataX;
this.driftDataY = driftDataY;
this.minFrame = minFrame;
this.maxFrame = maxFrame;
this.units = units;
}
示例4: loadResultsFromFile
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
private DriftResults loadResultsFromFile(String path) throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(path));
Gson gson = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(
UnivariateFunction.class,
new InstanceCreator<PolynomialSplineFunction>() {
@Override
public PolynomialSplineFunction createInstance(Type type) {
return new PolynomialSplineFunction(new double[]{1, 2}, new PolynomialFunction[]{new PolynomialFunction(new double[1])});
}
}).create();
return gson.fromJson(reader, DriftResults.class);
} finally {
if(reader != null) {
reader.close();
}
}
}
示例5: drawCurvedPath
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Draws a smooth curve through the given array of points
*
* <p>
* This algorithm is called Spline-Interpolation
* because the Apache-commons-math library we are using here does not accept
* values but {@code f(x)=y} with x having to increase all the time
* the idea behind this is to use a parameter array - the so called index
* as x array and splitting the points into a x and y coordinates array.
* </p>
*
* <p>
* Finally those 2 interpolated arrays get unified into a single {@linkplain Point2D} array and drawn to the Map
* </p>
*
* @param graphics The {@linkplain Graphics2D} Object to be drawn on
* @param points The Knot Points for the Spline-Interpolator aka the joints
*/
private void drawCurvedPath(final Graphics2D graphics, final Point2D[] points) {
final double[] index = createParameterizedIndex(points);
final PolynomialSplineFunction xcurve =
splineInterpolator.interpolate(index, getValues(points, point -> point.getX()));
final double[] xcoords = getCoords(xcurve, index);
final PolynomialSplineFunction ycurve =
splineInterpolator.interpolate(index, getValues(points, point -> point.getY()));
final double[] ycoords = getCoords(ycurve, index);
final List<Path2D> paths = routeCalculator.getAllNormalizedLines(xcoords, ycoords);
for (final Path2D path : paths) {
drawTransformedShape(graphics, path);
}
// draws the Line to the Cursor on every possible screen, so that the line ends at the cursor no matter what...
final List<Point2D[]> finishingPoints = routeCalculator.getAllPoints(
new Point2D.Double(xcoords[xcoords.length - 1], ycoords[ycoords.length - 1]),
points[points.length - 1]);
final boolean hasArrowEnoughSpace = points[points.length - 2].distance(points[points.length - 1]) > arrowLength;
for (final Point2D[] finishingPointArray : finishingPoints) {
drawTransformedShape(graphics, new Line2D.Double(finishingPointArray[0], finishingPointArray[1]));
if (hasArrowEnoughSpace) {
drawArrow(graphics, finishingPointArray[0], finishingPointArray[1]);
}
}
}
示例6: testInterpolateLinearDegenerateTwoSegment
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Test
public void testInterpolateLinearDegenerateTwoSegment()
{
double tolerance = 1e-15;
double x[] = { 0.0, 0.5, 1.0 };
double y[] = { 0.0, 0.5, 1.0 };
UnivariateInterpolator i = new SplineInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
verifyConsistency((PolynomialSplineFunction) f, x);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 1d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
// Check interpolation
Assert.assertEquals(0.0,f.value(0.0), tolerance);
Assert.assertEquals(0.4,f.value(0.4), tolerance);
Assert.assertEquals(1.0,f.value(1.0), tolerance);
}
示例7: testInterpolateLinearDegenerateThreeSegment
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Test
public void testInterpolateLinearDegenerateThreeSegment()
{
double tolerance = 1e-15;
double x[] = { 0.0, 0.5, 1.0, 1.5 };
double y[] = { 0.0, 0.5, 1.0, 1.5 };
UnivariateInterpolator i = new SplineInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 1d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[2], 1d};
TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance);
// Check interpolation
Assert.assertEquals(0,f.value(0), tolerance);
Assert.assertEquals(1.4,f.value(1.4), tolerance);
Assert.assertEquals(1.5,f.value(1.5), tolerance);
}
示例8: testInterpolateLinear
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Test
public void testInterpolateLinear() {
double x[] = { 0.0, 0.5, 1.0 };
double y[] = { 0.0, 0.5, 0.0 };
UnivariateInterpolator i = new SplineInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
verifyConsistency((PolynomialSplineFunction) f, x);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1.5d, 0d, -2d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 0d, -3d, 2d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
}
示例9: testInterpolateLinearDegenerateTwoSegment
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Test
public void testInterpolateLinearDegenerateTwoSegment()
{
double x[] = { 0.0, 0.5, 1.0 };
double y[] = { 0.0, 0.5, 1.0 };
UnivariateInterpolator i = new LinearInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 1d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
// Check interpolation
Assert.assertEquals(0.0,f.value(0.0), interpolationTolerance);
Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance);
Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance);
}
示例10: testInterpolateLinearDegenerateThreeSegment
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
@Test
public void testInterpolateLinearDegenerateThreeSegment()
{
double x[] = { 0.0, 0.5, 1.0, 1.5 };
double y[] = { 0.0, 0.5, 1.0, 1.5 };
UnivariateInterpolator i = new LinearInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
// Verify coefficients using analytical values
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[1], 1d};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, coefficientTolerance);
target = new double[]{y[2], 1d};
TestUtils.assertEquals(polynomials[2].getCoefficients(), target, coefficientTolerance);
// Check interpolation
Assert.assertEquals(0,f.value(0), interpolationTolerance);
Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance);
Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance);
}
示例11: getMultipleMarketValuesFromCompanies
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Gets the multiple market values from companies.
*
* @param companies the companies
* @param from the from
* @param to the to
* @return the multiple market values from companies
*/
public List<double[]> getMultipleMarketValuesFromCompanies(List<Company> companies,
Calendar from,
Calendar to) {
List<double[]> result = new ArrayList<double[]>();
PolynomialSplineFunction psf;
Company company;
int companies_size = companies.size();
for(int i = 0; i < companies_size; i++) {
company = companies.get(i);
if((psf = this.getMarketValueSplineFromTo(company, from, to)) != null) {
result.add(this.getValuesFromPsf(psf, from, to));
}
}
return result;
}
示例12: getValuesFromPsf
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Gets the values from psf.
*
* @param psf the psf
* @param from the from
* @param to the to
* @return the values from psf
*/
public double[] getValuesFromPsf(PolynomialSplineFunction psf, Calendar from, Calendar to) {
int diff = (int) TimeUnit.DAYS.convert(to.getTimeInMillis()
- from.getTimeInMillis(),
TimeUnit.MILLISECONDS);
double[] result = new double[diff];
Calendar tmp_date = Calendar.getInstance();
tmp_date.setTime(from.getTime());
tmp_date.set(Calendar.DAY_OF_YEAR, from.get(Calendar.DAY_OF_YEAR) + 1);
for(int i = 0; i < result.length; i++) {
result[i] = psf.value(tmp_date.getTimeInMillis());
if(Double.isInfinite(result[i]) || Double.isNaN(result[i])) {
assert false;
}
//increment
tmp_date.set(Calendar.DAY_OF_YEAR, tmp_date.get(Calendar.DAY_OF_YEAR) + 1);
}
return result;
}
示例13: getSharePriceDevelopement
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Gets the share price developement.
*
* @param psf the psf
* @param from the from
* @param to the to
* @return the share price developement
*/
public double[] getSharePriceDevelopement(PolynomialSplineFunction psf, Calendar from, Calendar to) {
int diff = (int) TimeUnit.DAYS.convert(to.getTimeInMillis()
- from.getTimeInMillis(),
TimeUnit.MILLISECONDS);
double[] result = new double[diff];
double reference = psf.value(from.getTimeInMillis());
double tmp;
Calendar tmp_date = Calendar.getInstance();
tmp_date.setTime(from.getTime());
tmp_date.set(Calendar.DAY_OF_YEAR, from.get(Calendar.DAY_OF_YEAR) + 1);
for(int i = 0; i < result.length; i++) {
tmp = psf.value(tmp_date.getTimeInMillis());
result[i] = 100 / reference * (tmp - reference);
//reference = tmp;
//increment
tmp_date.set(Calendar.DAY_OF_YEAR, tmp_date.get(Calendar.DAY_OF_YEAR) + 1);
}
return result;
}
示例14: getMarketValueSplineFromTo
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Gets the market value spline from to.
*
* @param company the company
* @param from the from
* @param to the to
* @return the market value spline from to
*/
public PolynomialSplineFunction getMarketValueSplineFromTo(Company company, Calendar from, Calendar to) {
List<MarketValue> values = company.getMarketValuesBetweenDatesFromDB(from.getTime(), to.getTime());
if(values.size() == 0 || !normalizeMarketValues(company, values, from, to)) {
return null;
}
double[] x = new double[values.size()];
double[] y = new double[values.size()];
Calendar cal = Calendar.getInstance();
for(int i = 0; i < values.size(); i++) {
//System.out.println(values.get(i).getDate() + " " + values.get(i).getHigh());
cal.setTime(values.get(i).getDate());
x[i] = cal.getTimeInMillis();
y[i] = values.get(i).getHigh();
}
return new LinearInterpolator().interpolate(x, y);
}
示例15: getMarketValueSplineFromTo
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入依赖的package包/类
/**
* Gets the market value spline from to.
*
* @param company the company
* @param from the from
* @param to the to
* @return the market value spline from to
*/
public static PolynomialSplineFunction getMarketValueSplineFromTo(Company company,
Calendar from,
Calendar to) {
List<MarketValue> values = company.getMarketValuesBetweenDatesFromDB(from.getTime(), to.getTime());
if(values.size() == 0 || !normalizeMarketValues(company, values, from, to)) {
return null;
}
//System.out.println("NOT NULL");
double[] x = new double[values.size()];
double[] y = new double[values.size()];
Calendar cal = Calendar.getInstance();
for(int i = 0; i < values.size(); i++) {
cal.setTime(values.get(i).getDate());
x[i] = cal.getTimeInMillis();
y[i] = values.get(i).getHigh();
}
return new LinearInterpolator().interpolate(x, y);
}