Examples of CubicInterpolation


Examples of flanagan.interpolation.CubicInterpolation

        if(this.nAnalyteConcns<2)throw new IllegalArgumentException("Method cubicInterpolation requres at least 2 data points; only " + this.nAnalyteConcns + " were supplied");
        this.methodUsed = 1;
        this.sampleErrorFlag = false;
        this.titleOne = "Cubic interpolation ";
        if(!this.setDataOneDone)this.setDataOne();
        this.ci = new CubicInterpolation(this.analyteConcns, this.responses, 0);
        for(int i=0; i<this.nInterp; i++)this.calculatedResponses[i] = ci.interpolate(this.interpolationConcns[i]);
        if(!this.supressPlot)this.plott();
        this.curveCheck(this.methodIndices[this.methodUsed]);
    }
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        double interpolated, error;
        final int n = generic_x.size();
        final double[] x35 = new double[3];

        // Natural spline
        CubicInterpolation f = new CubicInterpolation(
                generic_x, generic_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.SecondDerivative, generic_natural_y2.first(),
                CubicInterpolation.BoundaryCondition.SecondDerivative, generic_natural_y2.last());
        f.update();

        checkValues("Natural spline", f, generic_x, generic_y);
        // cached second derivative
        for (int i=0; i<n; i++) {
            interpolated = f.secondDerivative(generic_x.get(i));
            error = interpolated - generic_natural_y2.get(i);
            assertFalse("Natural spline interpolation "
                  +"second derivative failed at x="+generic_x.get(i)
                  +"\n interpolated value: "+interpolated
                  +"\n expected value:     "+generic_natural_y2.get(i)
                  +"\n error:              "+error,
                  abs(error) > 3e-16);
        }
        x35[1] = f.op(3.5);


        // Clamped spline
        final double y1a = 0.0;
        final double y1b = 0.0;
        f = new CubicInterpolation(
                generic_x, generic_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.FirstDerivative, y1a,
                CubicInterpolation.BoundaryCondition.FirstDerivative, y1b);
        f.update();

        checkValues("Clamped spline", f, generic_x, generic_y);
        check1stDerivativeValue("Clamped spline", f, generic_x.first(), 0.0);
        check1stDerivativeValue("Clamped spline", f, generic_x.last()0.0);
        x35[0] = f.op(3.5);


        // Not-a-knot spline
        f = new CubicInterpolation(
                generic_x, generic_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();

        checkValues("Not-a-knot spline", f, generic_x, generic_y);
        checkNotAKnotCondition("Not-a-knot spline", f);
        x35[2] = f.op(3.5);

        assertFalse("Spline interpolation failure"
            +"\n at x = "+3.5
            +"\n clamped spline    "+x35[0]
            +"\n natural spline    "+x35[1]
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        final Array x = xRange(-1.8, 1.8, n);
        final Array y = gaussian(x);

        // Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();

        checkValues("Not-a-knot spline", f, x, y);
        checkNotAKnotCondition("Not-a-knot spline", f);
        checkSymmetry("Not-a-knot spline", f, x.first());


        // MC not-a-knot spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();

        checkValues("MC not-a-knot spline", f, x, y);
        checkSymmetry("MC not-a-knot spline", f, x.first());
    }
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        final int n = 4;
        final Array x = xRange(-2.0, 2.0, n);
        final Array y = parabolic(x);

        // Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();
        checkValues("Not-a-knot spline", f, x, y);
        check1stDerivativeValue("Not-a-knot spline", f, x.get(0), 4.0);
        check1stDerivativeValue("Not-a-knot spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("Not-a-knot spline", f, x.get(0), -2.0);
        check2ndDerivativeValue("Not-a-knot spline", f, x.get(n-1), -2.0);


        // Clamped spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.FirstDerivative,  4.0,
                CubicInterpolation.BoundaryCondition.FirstDerivative, -4.0);
        f.update();
        checkValues("Clamped spline", f, x, y);
        check1stDerivativeValue("Clamped spline", f, x.get(0), 4.0);
        check1stDerivativeValue("Clamped spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("Clamped spline", f, x.get(0), -2.0);
        check2ndDerivativeValue("Clamped spline", f, x.get(n-1), -2.0);


        // SecondDerivative spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0);
        f.update();
        checkValues("SecondDerivative spline", f, x, y);
        check1stDerivativeValue("SecondDerivative spline", f, x.get(0), 4.0);
        check1stDerivativeValue("SecondDerivative spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("SecondDerivative spline", f, x.get(0), -2.0);
        check2ndDerivativeValue("SecondDerivative spline", f, x.get(n-1), -2.0);

        // MC Not-a-knot spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();
        checkValues("MC Not-a-knot spline", f, x, y);
        check1stDerivativeValue("MC Not-a-knot spline", f, x.get(0), 4.0);
        check1stDerivativeValue("MC Not-a-knot spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("MC Not-a-knot spline", f, x.get(0), -2.0);
        check2ndDerivativeValue("MC Not-a-knot spline", f, x.get(n-1), -2.0);


        // MC Clamped spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.FirstDerivative,  4.0,
                CubicInterpolation.BoundaryCondition.FirstDerivative, -4.0);
        f.update();
        checkValues("MC Clamped spline", f, x, y);
        check1stDerivativeValue("MC Clamped spline", f, x.get(0), 4.0);
        check1stDerivativeValue("MC Clamped spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("MC Clamped spline", f, x.get(0), -2.0);
        check2ndDerivativeValue("MC Clamped spline", f, x.get(n-1), -2.0);


        // MC SecondDerivative spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0);
        f.update();
        checkValues("MC SecondDerivative spline", f, x, y);
        check1stDerivativeValue("MC SecondDerivative spline", f, x.get(0), 4.0);
        check1stDerivativeValue("MC SecondDerivative spline", f, x.get(n-1), -4.0);
        check2ndDerivativeValue("SecondDerivative spline",    f, x.get(0), -2.0);
        check2ndDerivativeValue("MC SecondDerivative spline", f, x.get(n-1), -2.0);
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

          final Array x = xRange(-1.7, 1.9, n);
          final Array y = gaussian(x);
          double result;

          // Not-a-knot
          CubicInterpolation f = new CubicInterpolation(
                  x, y,
                    CubicInterpolation.DerivativeApprox.Spline, false,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

          result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse("Not-a-knot spline interpolation "
                    +"\n    sample points:      "+n
                    +"\n    norm of difference: "+result
                    +"\n    it should be:       "+tabulatedErrors[i],
                    abs(result-tabulatedErrors[i]) > toleranceOnTabErr[i]);

          // MC not-a-knot
          f = new CubicInterpolation(
                  x, y,
                    CubicInterpolation.DerivativeApprox.Spline, true,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                    CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
          f.update();

            result = Math.sqrt(integral.op(makeErrorFunction(f), -1.7, 1.9));
          result /= scaleFactor;
            assertFalse ("MC Not-a-knot spline interpolation "
                    + "\n    sample points:      "
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

    double interpolated;


      // Natural spline
      CubicInterpolation f = new CubicInterpolation(
                                RPN15A_x, RPN15A_y,
                                CubicInterpolation.DerivativeApprox.Spline, false,
                                CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                                CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
      f.update();

      checkValues("Natural spline", f, RPN15A_x, RPN15A_y);
      check2ndDerivativeValue("Natural spline", f, RPN15A_x.first(), 0.0);
      check2ndDerivativeValue("Natural spline", f, RPN15A_x.last()0.0);

      // poor performance
      final double x_bad = 11.0;
      interpolated = f.op(x_bad);
        assertFalse("Natural spline interpolation poor performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated<1.0);


      // Clamped spline
      f = new CubicInterpolation(
                RPN15A_x, RPN15A_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.FirstDerivative, 0.0,
                CubicInterpolation.BoundaryCondition.FirstDerivative, 0.0);
      f.update();

      checkValues("Clamped spline", f, RPN15A_x, RPN15A_y);
      check1stDerivativeValue("Clamped spline", f, RPN15A_x.first(), 0.0);
      check1stDerivativeValue("Clamped spline", f, RPN15A_x.last()0.0);

      // poor performance
      interpolated = f.op(x_bad);
        assertFalse("Clamped spline interpolation poor performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated<1.0);


      // Not-a-knot spline
        f = new CubicInterpolation(
                RPN15A_x, RPN15A_y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
      f.update();

      checkValues("Not-a-knot spline", f, RPN15A_x, RPN15A_y);
      checkNotAKnotCondition("Not-a-knot spline", f);

      // poor performance
      interpolated = f.op(x_bad);
        assertFalse("Not-a-knot spline interpolation poor performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated<1.0);



      // MC natural spline values
        f = new CubicInterpolation(
                RPN15A_x, RPN15A_y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0,
                CubicInterpolation.BoundaryCondition.SecondDerivative, 0.0);
      f.update();

      checkValues("MC natural spline", f, RPN15A_x, RPN15A_y);

      // good performance
      interpolated = f.op(x_bad);
        assertFalse("MC natural spline interpolation good performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated>1.0);


      // MC clamped spline values
        f = new CubicInterpolation(
                RPN15A_x, RPN15A_y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.FirstDerivative, 0.0,
                CubicInterpolation.BoundaryCondition.FirstDerivative, 0.0);
      f.update();

      checkValues("MC clamped spline", f, RPN15A_x, RPN15A_y);
      check1stDerivativeValue("MC clamped spline", f, RPN15A_x.first(), 0.0);
      check1stDerivativeValue("MC clamped spline", f, RPN15A_x.last()0.0);

      // good performance
      interpolated = f.op(x_bad);
        assertFalse("MC clamped spline interpolation good performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated>1.0);


      // MC not-a-knot spline values
        f = new CubicInterpolation(
                RPN15A_x, RPN15A_y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
      f.update();

      checkValues("MC not-a-knot spline", f, RPN15A_x, RPN15A_y);

      // good performance
      interpolated = f.op(x_bad);
        assertFalse("MC clamped spline interpolation good performance unverified"
                +"\n    at x = "+x_bad
                +"\n    interpolated value: "+interpolated
                +"\n    expected value > 1.0",
                interpolated>1.0);
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        for (double start = -1.9, j=0; j<2; start+=0.2, j++) {
            x = xRange(start, start+3.6, n);
            y = gaussian(x);

            // Not-a-knot spline
            CubicInterpolation f = new CubicInterpolation(
                    x, y,
                    CubicInterpolation.DerivativeApprox.Spline, false,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0);

            checkValues("Not-a-knot spline", f, x, y);
            checkNotAKnotCondition("Not-a-knot spline", f);
            // bad performance
            interpolated  = f.op(x1_bad);
            interpolated2 = f.op(x2_bad);
            assertFalse("Not-a-knot spline interpolation bad performance unverified"
                    +"\n    at x = "+x1_bad
                    +"\n    interpolated value: "+interpolated
                    +"\n    at x = "+x2_bad
                    +"\n    interpolated value: "+interpolated2
                    +"\n    at least one of them was expected to be < 0.0",
                    interpolated>0.0 && interpolated2>0.0);

            // MC not-a-knot spline
            f = new CubicInterpolation(
                    x, y,
                    CubicInterpolation.DerivativeApprox.Spline, true,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0);
            f.update();

            checkValues("MC not-a-knot spline", f, x, y);

            // bad performance
            interpolated  = f.op(x1_bad);
            interpolated2 = f.op(x2_bad);
            assertFalse("Not-a-knot spline interpolation "
                        + "bad performance unverified"
                        + "\nat x = " + x1_bad
                        + " interpolated value: " + interpolated
                        + "\nat x = " + x2_bad
                        + " interpolated value: " + interpolated
                        + "\n at least one of them was expected to be < 0.0",
                        interpolated<=0.0 || interpolated2<=0.0);
        }


        QL.info("Testing spline interpolation on a Gaussian data set...");

        for (double start = -1.9, j=0; j<2; start+=0.2, j++) {
            x = xRange(start, start+3.6, n);
            y = gaussian(x);

            // MC not-a-knot spline
            final CubicInterpolation interpolation = new CubicInterpolation(
                    x, y,
                    CubicInterpolation.DerivativeApprox.Spline, true,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0,
                    CubicInterpolation.BoundaryCondition.NotAKnot, 0.0);
            interpolation.update();

            checkValues("MC not-a-knot spline", interpolation, x, y);

            // bad performance
            interpolated  = interpolation.op(x1_bad);
            interpolated2 = interpolation.op(x2_bad);
            if (interpolated>0.0 && interpolated2>0.0 ) {
                assertFalse("Not-a-knot spline interpolation "
                            + "bad performance unverified"
                            + "\nat x = " + x1_bad
                            + " interpolated value: " + interpolated
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        final double zero=0.0;
        double interpolated;
        final double expected=0.0;

        // MC Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.NotAKnot, 0.0,
                CubicInterpolation.BoundaryCondition.NotAKnot, 0.0);

        interpolated = f.op(zero);
        assertFalse("MC not-a-knot spline interpolation failed at x = "+zero
                    +"\n    interpolated value: "+interpolated
                    +"\n    expected value:     "+expected
                    +"\n    error:              "+abs(interpolated-expected),
                    abs(interpolated-expected) > 1e-15);


        // MC Clamped spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.FirstDerivative,  4.0,
                CubicInterpolation.BoundaryCondition.FirstDerivative, -4.0);

        interpolated =  f.op(zero);
        assertFalse("MC clamped spline interpolation failed at x = "+zero
                +"\n    interpolated value: "+interpolated
                +"\n    expected value:     "+expected
                +"\n    error:              "+abs(interpolated-expected),
                abs(interpolated-expected) > 1e-15);


        // MC SecondDerivative spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0,
                CubicInterpolation.BoundaryCondition.SecondDerivative, -2.0);

        interpolated =  f.op(zero);
        assertFalse("MC SecondDerivative spline interpolation failed at x = "+zero
                +"\n    interpolated value: "+interpolated
                +"\n    expected value:     "+expected
                +"\n    error:              "+abs(interpolated-expected),
                abs(interpolated-expected) > 1e-15);
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        } else {
            transformed = this.grid.clone().transform(f);
            newValues = newGrid.clone().transform(f);
        }

        final CubicInterpolation priceSpline = new NaturalCubicInterpolation(transformed, values);

        priceSpline.update();
        for (int i=0; i<newValues.size(); i++) {
            newValues.set(i, priceSpline.op(newValues.get(i), true) );
        }

        this.grid.swap(newGrid);
        this.values.swap(newValues);
    }
View Full Code Here

Examples of org.jquantlib.math.interpolations.CubicInterpolation

        final Array x = xRange(-1.8, 1.8, n);
        final Array y = gaussian(x);

        // Not-a-knot spline
        CubicInterpolation f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, false,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();

        checkValues("Not-a-knot spline", f, x, y);
        checkNotAKnotCondition("Not-a-knot spline", f);
        checkSymmetry("Not-a-knot spline", f, x.first());


        // MC not-a-knot spline
        f = new CubicInterpolation(
                x, y,
                CubicInterpolation.DerivativeApprox.Spline, true,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL,
                CubicInterpolation.BoundaryCondition.NotAKnot, Constants.NULL_REAL);
        f.update();

        checkValues("MC not-a-knot spline", f, x, y);
        checkSymmetry("MC not-a-knot spline", f, x.first());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.