当前位置: 首页>>代码示例>>Java>>正文


Java PolynomialFunction类代码示例

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


PolynomialFunction类属于org.apache.commons.math3.analysis.polynomials包,在下文中一共展示了PolynomialFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMixedDerivatives

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testMixedDerivatives() {
    HermiteInterpolator interpolator = new HermiteInterpolator();
    interpolator.addSamplePoint(0.0, new double[] { 1.0 }, new double[] { 2.0 });
    interpolator.addSamplePoint(1.0, new double[] { 4.0 });
    interpolator.addSamplePoint(2.0, new double[] { 5.0 }, new double[] { 2.0 });
    Assert.assertEquals(4, interpolator.getPolynomials()[0].degree());
    DerivativeStructure y0 = interpolator.value(new DerivativeStructure(1, 1, 0, 0.0))[0];
    Assert.assertEquals(1.0, y0.getValue(), 1.0e-15);
    Assert.assertEquals(2.0, y0.getPartialDerivative(1), 1.0e-15);
    Assert.assertEquals(4.0, interpolator.value(1.0)[0], 1.0e-15);
    DerivativeStructure y2 = interpolator.value(new DerivativeStructure(1, 1, 0, 2.0))[0];
    Assert.assertEquals(5.0, y2.getValue(), 1.0e-15);
    Assert.assertEquals(2.0, y2.getPartialDerivative(1), 1.0e-15);
    checkPolynomial(new PolynomialFunction(new double[] { 1.0, 2.0, 4.0, -4.0, 1.0 }),
                    interpolator.getPolynomials()[0]);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:18,代码来源:HermiteInterpolatorTest.java

示例2: testWikipedia

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testWikipedia() {
    // this test corresponds to the example from Wikipedia page:
    // http://en.wikipedia.org/wiki/Hermite_interpolation
    HermiteInterpolator interpolator = new HermiteInterpolator();
    interpolator.addSamplePoint(-1, new double[] { 2 }, new double[] { -8 }, new double[] { 56 });
    interpolator.addSamplePoint( 0, new double[] { 1 }, new double[] {  0 }, new double[] {  0 });
    interpolator.addSamplePoint( 1, new double[] { 2 }, new double[] {  8 }, new double[] { 56 });
    for (double x = -1.0; x <= 1.0; x += 0.125) {
        DerivativeStructure y = interpolator.value(new DerivativeStructure(1, 1, 0, x))[0];
        double x2 = x * x;
        double x4 = x2 * x2;
        double x8 = x4 * x4;
        Assert.assertEquals(x8 + 1, y.getValue(), 1.0e-15);
        Assert.assertEquals(8 * x4 * x2 * x, y.getPartialDerivative(1), 1.0e-15);
    }
    checkPolynomial(new PolynomialFunction(new double[] { 1, 0, 0, 0, 0, 0, 0, 0, 1 }),
                    interpolator.getPolynomials()[0]);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:20,代码来源:HermiteInterpolatorTest.java

示例3: AssociatedLegendrePolynomial

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
/**
 * Constructor for the AssociatedLegendrePolynomial class.
 *
 * @param l Degree of the associated Legendre polynomial
 * @param m Order of the associated Legendre polynomial
 */
public AssociatedLegendrePolynomial(int l, int m) {

    /* Make some basic, arithmetic checks. */
    if (m > l) {
      throw new IllegalArgumentException("Associated Legendre Polynomials are defined for 0 <= m <= l. You provided m > l!");
    }
    if (m < 0) {
      throw new IllegalArgumentException("Associated Legendre Polynomials are defined for 0 <= m <= l. You provided m < 0!");
    }
    if (l < 0) {
      throw new IllegalArgumentException("Associated Legendre Polynomials are defined for 0 <= m <= l. You provided m < 0!");
    }

    /* Find m-th derivative of Legendre Polynomial of degree l. */
    PolynomialFunction fkt = PolynomialsUtils.createLegendrePolynomial(l);
    for (int i = 0; i < m; i++) {
        fkt = fkt.polynomialDerivative();
    }
    this.legendre = fkt;

    /* Determine sign. */
    this.sign = Math.pow(-1,m);
    this.m = m;
    this.l = l;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:32,代码来源:AssociatedLegendrePolynomial.java

示例4: testOrthogonality

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
/**
 * Tests Orthogonality relation that exists between two radial polynomials.
 */
@Test
@DisplayName("Test Orthogonality")
void testOrthogonality() {
    for (int n1=0;n1<10;n1++) {
        for (int n2=0;n2<10;n2++) {
            int max_m = Math.min(n1, n2);
            for (int m=0;m<=max_m;m++) {
                PolynomialFunction R1 = PolynomialFunctionFactory.createRadialPolynomial(n1, m);
                PolynomialFunction R2 = PolynomialFunctionFactory.createRadialPolynomial(n2, m);
                double result = 0.0;
                double increment = 1e-6;
                for (double d=0.0;d<=1.0f;d+=increment) {
                    result += R1.value(d) * R2.value(d) * d * increment;
                }
                assertEquals((double)MathHelper.kronecker(n1,n2)/(2*n1 + 2) * R1.value(1.0), result, 1e-2);
            }
        }
    }
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:23,代码来源:RadialPolynomialTest.java

示例5: smooth

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Override
public double[] smooth(double[] sourceX, double[] noisyY, double[] estimateX, double parameter) {
	int degree = (int)Math.round(parameter);
	if(degree < 1 || degree > sourceX.length) {
		throw new IllegalArgumentException("Degree must be between 1 and number of data points.");
	}
	if(sourceX.length != noisyY.length) {
		throw new IllegalArgumentException("X and Y input must have the same length.");
	}
	
	
	PolynomialCurveFitter curveFitter = PolynomialCurveFitter.create(degree).withMaxIterations(10000);
	WeightedObservedPoints points = new WeightedObservedPoints();
	for(int i = 0; i < sourceX.length; i++) {
		points.add(sourceX[i], noisyY[i]);
	}
	PolynomialFunction func = new PolynomialFunction(curveFitter.fit(points.toList()));
	
	double[] result = new double[estimateX.length];
	for(int i = 0; i < estimateX.length; i++) {
		result[i] = func.value(estimateX[i]);
	}
	return result;
}
 
开发者ID:cas-bioinf,项目名称:cy-dataseries,代码行数:25,代码来源:PolynomialSmoothingProvider.java

示例6: loadResultsFromFile

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的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

示例7: testPolynomialFit

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testPolynomialFit() {
    final Random randomizer = new Random(53882150042L);
    final RealDistribution rng = new UniformRealDistribution(-100, 100);
    rng.reseedRandomGenerator(64925784252L);

    final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
    final PolynomialFunction f = new PolynomialFunction(coeff);

    // Collect data from a known polynomial.
    final WeightedObservedPoints obs = new WeightedObservedPoints();
    for (int i = 0; i < 100; i++) {
        final double x = rng.sample();
        obs.add(x, f.value(x) + 0.1 * randomizer.nextGaussian());
    }

    final ParametricUnivariateFunction function = new PolynomialFunction.Parametric(); 
    // Start fit from initial guesses that are far from the optimal values.
    final SimpleCurveFitter fitter
        = SimpleCurveFitter.create(function,
                                   new double[] { -1e20, 3e15, -5e25 });
    final double[] best = fitter.fit(obs.toList());

    TestUtils.assertEquals("best != coeff", coeff, best, 2e-2);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:SimpleCurveFitterTest.java

示例8: testFit

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testFit() {
    final RealDistribution rng = new UniformRealDistribution(-100, 100);
    rng.reseedRandomGenerator(64925784252L);

    final LevenbergMarquardtOptimizer optim = new LevenbergMarquardtOptimizer();
    final PolynomialFitter fitter = new PolynomialFitter(optim);
    final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
    final PolynomialFunction f = new PolynomialFunction(coeff);

    // Collect data from a known polynomial.
    for (int i = 0; i < 100; i++) {
        final double x = rng.sample();
        fitter.addObservedPoint(x, f.value(x));
    }

    // Start fit from initial guesses that are far from the optimal values.
    final double[] best = fitter.fit(new double[] { -1e-20, 3e15, -5e25 });

    TestUtils.assertEquals("best != coeff", coeff, best, 1e-12);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:PolynomialFitterTest.java

示例9: testNoError

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testNoError() {
    Random randomizer = new Random(64925784252l);
    for (int degree = 1; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(new LevenbergMarquardtOptimizer());
        for (int i = 0; i <= degree; ++i) {
            fitter.addObservedPoint(1.0, i, p.value(i));
        }

        final double[] init = new double[degree + 1];
        PolynomialFunction fitted = new PolynomialFunction(fitter.fit(init));

        for (double x = -1.0; x < 1.0; x += 0.01) {
            double error = FastMath.abs(p.value(x) - fitted.value(x)) /
                           (1.0 + FastMath.abs(p.value(x)));
            Assert.assertEquals(0.0, error, 1.0e-6);
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:PolynomialFitterTest.java

示例10: testSmallError

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testSmallError() {
    Random randomizer = new Random(53882150042l);
    double maxError = 0;
    for (int degree = 0; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(new LevenbergMarquardtOptimizer());
        for (double x = -1.0; x < 1.0; x += 0.01) {
            fitter.addObservedPoint(1.0, x,
                                    p.value(x) + 0.1 * randomizer.nextGaussian());
        }

        final double[] init = new double[degree + 1];
        PolynomialFunction fitted = new PolynomialFunction(fitter.fit(init));

        for (double x = -1.0; x < 1.0; x += 0.01) {
            double error = FastMath.abs(p.value(x) - fitted.value(x)) /
                          (1.0 + FastMath.abs(p.value(x)));
            maxError = FastMath.max(maxError, error);
            Assert.assertTrue(FastMath.abs(error) < 0.1);
        }
    }
    Assert.assertTrue(maxError > 0.01);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:PolynomialFitterTest.java

示例11: testLargeSample

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testLargeSample() {
    Random randomizer = new Random(0x5551480dca5b369bl);
    double maxError = 0;
    for (int degree = 0; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(new LevenbergMarquardtOptimizer());
        for (int i = 0; i < 40000; ++i) {
            double x = -1.0 + i / 20000.0;
            fitter.addObservedPoint(1.0, x,
                                    p.value(x) + 0.1 * randomizer.nextGaussian());
        }

        final double[] init = new double[degree + 1];
        PolynomialFunction fitted = new PolynomialFunction(fitter.fit(init));

        for (double x = -1.0; x < 1.0; x += 0.01) {
            double error = FastMath.abs(p.value(x) - fitted.value(x)) /
                          (1.0 + FastMath.abs(p.value(x)));
            maxError = FastMath.max(maxError, error);
            Assert.assertTrue(FastMath.abs(error) < 0.01);
        }
    }
    Assert.assertTrue(maxError > 0.001);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:27,代码来源:PolynomialFitterTest.java

示例12: checkUnsolvableProblem

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
private void checkUnsolvableProblem(MultivariateVectorOptimizer optimizer,
                                    boolean solvable) {
    Random randomizer = new Random(1248788532l);
    for (int degree = 0; degree < 10; ++degree) {
        PolynomialFunction p = buildRandomPolynomial(degree, randomizer);

        PolynomialFitter fitter = new PolynomialFitter(optimizer);

        // reusing the same point over and over again does not bring
        // information, the problem cannot be solved in this case for
        // degrees greater than 1 (but one point is sufficient for
        // degree 0)
        for (double x = -1.0; x < 1.0; x += 0.01) {
            fitter.addObservedPoint(1.0, 0.0, p.value(0.0));
        }

        try {
            final double[] init = new double[degree + 1];
            fitter.fit(init);
            Assert.assertTrue(solvable || (degree == 0));
        } catch(ConvergenceException e) {
            Assert.assertTrue((! solvable) && (degree > 0));
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:PolynomialFitterTest.java

示例13: testFit

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testFit() {
    final RealDistribution rng = new UniformRealDistribution(-100, 100);
    rng.reseedRandomGenerator(64925784252L);

    final double[] coeff = { 12.9, -3.4, 2.1 }; // 12.9 - 3.4 x + 2.1 x^2
    final PolynomialFunction f = new PolynomialFunction(coeff);

    // Collect data from a known polynomial.
    final WeightedObservedPoints obs = new WeightedObservedPoints();
    for (int i = 0; i < 100; i++) {
        final double x = rng.sample();
        obs.add(x, f.value(x));
    }

    // Start fit from initial guesses that are far from the optimal values.
    final PolynomialCurveFitter fitter
        = PolynomialCurveFitter.create(0).withStartPoint(new double[] { -1e-20, 3e15, -5e25 });
    final double[] best = fitter.fit(obs.toList());

    TestUtils.assertEquals("best != coeff", coeff, best, 1e-12);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:23,代码来源:PolynomialCurveFitterTest.java

示例14: testNoError

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testNoError() {
    final Random randomizer = new Random(64925784252l);
    for (int degree = 1; degree < 10; ++degree) {
        final PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
        final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);

        final WeightedObservedPoints obs = new WeightedObservedPoints();
        for (int i = 0; i <= degree; ++i) {
            obs.add(1.0, i, p.value(i));
        }

        final PolynomialFunction fitted = new PolynomialFunction(fitter.fit(obs.toList()));

        for (double x = -1.0; x < 1.0; x += 0.01) {
            final double error = FastMath.abs(p.value(x) - fitted.value(x)) /
                (1.0 + FastMath.abs(p.value(x)));
            Assert.assertEquals(0.0, error, 1.0e-6);
        }
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:PolynomialCurveFitterTest.java

示例15: testSmallError

import org.apache.commons.math3.analysis.polynomials.PolynomialFunction; //导入依赖的package包/类
@Test
public void testSmallError() {
    final Random randomizer = new Random(53882150042l);
    double maxError = 0;
    for (int degree = 0; degree < 10; ++degree) {
        final PolynomialFunction p = buildRandomPolynomial(degree, randomizer);
        final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(degree);

        final WeightedObservedPoints obs = new WeightedObservedPoints();
        for (double x = -1.0; x < 1.0; x += 0.01) {
            obs.add(1.0, x, p.value(x) + 0.1 * randomizer.nextGaussian());
        }

        final PolynomialFunction fitted = new PolynomialFunction(fitter.fit(obs.toList()));

        for (double x = -1.0; x < 1.0; x += 0.01) {
            final double error = FastMath.abs(p.value(x) - fitted.value(x)) /
                (1.0 + FastMath.abs(p.value(x)));
            maxError = FastMath.max(maxError, error);
            Assert.assertTrue(FastMath.abs(error) < 0.1);
        }
    }
    Assert.assertTrue(maxError > 0.01);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:PolynomialCurveFitterTest.java


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