• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PolynomialSplineFunction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction的典型用法代码示例。如果您正苦于以下问题:Java PolynomialSplineFunction类的具体用法?Java PolynomialSplineFunction怎么用?Java PolynomialSplineFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PolynomialSplineFunction类属于org.apache.commons.math3.analysis.polynomials包,在下文中一共展示了PolynomialSplineFunction类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:45,代码来源:ModifiedLoess.java


示例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 ;
}
 
开发者ID:cas-bioinf,项目名称:cy-dataseries,代码行数:25,代码来源:LinearSmoothingProvider.java


示例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;
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:17,代码来源:DriftResults.java


示例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();
        }
    }
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:21,代码来源:ResultsDriftCorrection.java


示例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]);
    }
  }
}
 
开发者ID:triplea-game,项目名称:triplea,代码行数:43,代码来源:MapRouteDrawer.java


示例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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:SplineInterpolatorTest.java


示例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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:SplineInterpolatorTest.java


示例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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:17,代码来源:SplineInterpolatorTest.java


示例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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:LinearInterpolatorTest.java


示例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);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:LinearInterpolatorTest.java


示例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;
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:27,代码来源:MarketValueAnalyser.java


示例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;
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:32,代码来源:MarketValueAnalyser.java


示例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;
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:34,代码来源:MarketValueAnalyser.java


示例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);
	
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:30,代码来源:MarketValueAnalyser.java


示例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);
	
}
 
开发者ID:mattmagic149,项目名称:AnSoMia,代码行数:33,代码来源:TestClass.java


示例16: 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 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), interpolationTolerance);
    Assert.assertEquals(0.4,f.value(0.4), interpolationTolerance);
    Assert.assertEquals(1.0,f.value(1.0), interpolationTolerance);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:SplineInterpolatorTest.java


示例17: 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 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), interpolationTolerance);
    Assert.assertEquals(1.4,f.value(1.4), interpolationTolerance);
    Assert.assertEquals(1.5,f.value(1.5), interpolationTolerance);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:SplineInterpolatorTest.java



注:本文中的org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UnknownDependencyException类代码示例发布时间:2022-05-21
下一篇:
Java InputListener类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap