Package com.opengamma.analytics.math.function

Examples of com.opengamma.analytics.math.function.PiecewisePolynomialFunction1D


    final double[][] yValues = new double[][] { {19., 17., 19., 2., 4., 5., 18. }, {19.0, 15.0, 16.0, 6.0, 12.0, 16.0, 8.0 } };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);

    assertEquals(resultPos.getDimensions(), result.getDimensions());
    assertEquals(resultPos.getNumberOfIntervals(), result.getNumberOfIntervals());
    assertEquals(resultPos.getOrder(), 6);

    final int len = 21;
    double key0 = 5.;
    for (int i = 1; i < len; ++i) {
      final double key = 5. + 1. / (len - 1) * i;
      assertTrue(function.evaluate(resultPos, key).getData()[0] - function.evaluate(resultPos, key0).getData()[0] >= 0.);
      key0 = 5. + 1. / (len - 1) * i;
    }
    key0 = 5.;
    for (int i = 1; i < len; ++i) {
      final double key = 5. + 1. / (len - 1) * i;
      assertTrue(function.evaluate(resultPos, key).getData()[1] - function.evaluate(resultPos, key0).getData()[1] >= 0.);
      key0 = 5. + 1. / (len - 1) * i;
    }

    //    final int nKeys = 61;
    //    for (int i = 0; i < nKeys; ++i) {
View Full Code Here


    final double[][] yValues = new double[][] { {1., 1., 2., 4., 4., 2., 1., 1. }, {10., 10., 6., 4., 4., 6., 10., 10. } };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);

    for (int i = 0; i < 71; ++i) {
      final double key = 1. + 7. / (71 - 1) * i;
      System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
    }

    System.out.println("\n");

    for (int i = 0; i < 701; ++i) {
      final double key = 1. + 7. / (701 - 1) * i;
      System.out.println(key + "\t" + function.differentiateTwice(resultPos, key).getData()[0]);
    }
  }
View Full Code Here

    final double[] yValues = new double[] {35., 22., 20., 25., 30., 25. };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpQuin = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultQuin = interpQuin.interpolate(xValues, yValues);

    PiecewisePolynomialInterpolator interpCube = new MonotonicityPreservingCubicSplineInterpolator(interp);
    PiecewisePolynomialResult resultCube = interpCube.interpolate(xValues, yValues);

    final int nKeys = 1001;
    for (int i = 0; i < nKeys; ++i) {
      final double key = 2. + 11. / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultCube, key).getData()[0] + "\t" + function.evaluate(resultQuin, key).getData()[0]);
    }

    System.out.println("\n");

    for (int i = 0; i < nKeys; ++i) {
      final double key = 8.0 + 0.001 / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.differentiateTwice(resultQuin, key).getData()[0]);
    }
  }
View Full Code Here

    final double[] yValues = new double[] {0.1, 1., 1., 20., 20., 16. };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);
    System.out.println(resultPos.getCoefMatrix());

    final int nKeys = 101;
    for (int i = 0; i < nKeys; ++i) {
      final double key = 1. + 5. / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
    }
    System.out.println("\n");

    for (int i = 0; i < nKeys; ++i) {
      final double key = 3. + 0.5 / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.differentiateTwice(resultPos, key).getData()[0]);
    }
  }
View Full Code Here

    final double[][] yValues = new double[][] {{8.1, 7., 4.4, 7., 4., 3. } };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);
    System.out.println(resultPos.getCoefMatrix());

    final int nKeys = 101;
    for (int i = 0; i < nKeys; ++i) {
      final double key = +30. / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
    }

    for (int i = 0; i < nKeys; ++i) {
      final double key = 2. + 30. / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.differentiateTwice(resultPos, key).getData()[0]);
    }
  }
View Full Code Here

    final double[] yValues = new double[] {2, 4., 6., 8., 10., 12. };

    PiecewisePolynomialInterpolator interp = new CubicSplineInterpolator();
    PiecewisePolynomialResult result = interp.interpolate(xValues, yValues);

    PiecewisePolynomialFunction1D function = new PiecewisePolynomialFunction1D();

    PiecewisePolynomialInterpolator interpPos = new MonotonicityPreservingQuinticSplineInterpolator(interp);
    PiecewisePolynomialResult resultPos = interpPos.interpolate(xValues, yValues);
    System.out.println(resultPos.getCoefMatrix());

    final int nKeys = 101;
    for (int i = 0; i < nKeys; ++i) {
      final double key = 1. + 5. / (nKeys - 1) * i;
      System.out.println(key + "\t" + function.evaluate(result, key).getData()[0] + "\t" + function.evaluate(resultPos, key).getData()[0]);
    }

  }
View Full Code Here

    PiecewisePolynomialResult result = interpolator.interpolate(xValues, yValues);

    System.out.println(result.getCoefMatrix());
    System.out.println(result.getKnots());

    PiecewisePolynomialFunction1D func = new PiecewisePolynomialFunction1D();

    final int nPts = 101;
    for (int i = 0; i < nPts; ++i) {
      final double key = 0. + 5. / (nPts - 1) * i;
      System.out.println(key + "\t" + interpolator.interpolate(xValues, yValues, key) + "\t" + func.integrate(result, 0., key));
    }

    System.out.println("\n");

    for (int i = 0; i < nPts; ++i) {
      final double key = 0. + 5. / (nPts - 1) * i;
      System.out.println(key + "\t" + func.evaluate(result, key).getData()[0]);
    }

  }
View Full Code Here

    double[][] resValues = interp.interpolate(x0Values, x1Values, yValues, x0Values, x1Values).getData();
    final PiecewisePolynomialFunction2D func2D = new PiecewisePolynomialFunction2D();
    double[][] resDiffX0 = func2D.differentiateX0(result, x0Values, x1Values).getData();
    double[][] resDiffX1 = func2D.differentiateX1(result, x0Values, x1Values).getData();

    final PiecewisePolynomialFunction1D func1D = new PiecewisePolynomialFunction1D();
    double[][] expDiffX0 = func1D.differentiate(method.interpolate(x0Values, OG_ALGEBRA.getTranspose(new DoubleMatrix2D(yValues)).getData()), x0Values).getData();
    double[][] expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values).getData();

    for (int i = 0; i < n0Data; ++i) {
      for (int j = 0; j < n1Data; ++j) {
        final double expVal = expDiffX1[i][j];
        final double ref = Math.abs(expVal) == 0. ? 1. : Math.abs(expVal);
View Full Code Here

    double[][] resValues = interp.interpolate(x0Values, x1Values, yValues, x0Values, x1Values).getData();
    final PiecewisePolynomialFunction2D func2D = new PiecewisePolynomialFunction2D();
    double[][] resDiffX0 = func2D.differentiateX0(result, x0Values, x1Values).getData();
    double[][] resDiffX1 = func2D.differentiateX1(result, x0Values, x1Values).getData();

    final PiecewisePolynomialFunction1D func1D = new PiecewisePolynomialFunction1D();
    double[][] expDiffX0 = func1D.differentiate(method.interpolate(x0Values, OG_ALGEBRA.getTranspose(new DoubleMatrix2D(yValues)).getData()), x0Values).getData();
    double[][] expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values).getData();

    for (int i = 0; i < n0Data; ++i) {
      for (int j = 0; j < n1Data; ++j) {
        final double expVal = expDiffX1[i][j];
        final double ref = Math.abs(expVal) == 0. ? 1. : Math.abs(expVal);
View Full Code Here

    double[][] resValues = interp.interpolate(x0Values, x1Values, yValues, x0Values, x1Values).getData();
    final PiecewisePolynomialFunction2D func2D = new PiecewisePolynomialFunction2D();
    double[][] resDiffX0 = func2D.differentiateX0(result, x0Values, x1Values).getData();
    double[][] resDiffX1 = func2D.differentiateX1(result, x0Values, x1Values).getData();

    final PiecewisePolynomialFunction1D func1D = new PiecewisePolynomialFunction1D();
    double[][] expDiffX0 = func1D.differentiate(method.interpolate(x0Values, OG_ALGEBRA.getTranspose(new DoubleMatrix2D(yValues)).getData()), x0Values).getData();
    double[][] expDiffX1 = func1D.differentiate(method.interpolate(x1Values, yValues), x1Values).getData();

    for (int i = 0; i < n0Data; ++i) {
      for (int j = 0; j < n1Data; ++j) {
        final double expVal = expDiffX1[i][j];
        final double ref = Math.abs(expVal) == 0. ? 1. : Math.abs(expVal);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.math.function.PiecewisePolynomialFunction1D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.