예제 #1
0
            /// <summary>Initializes a new instance of the <see cref="VInterpolation"/> class.
            /// </summary>
            /// <param name="gridPointMatrix">The grid point matrix.</param>
            /// <param name="horizontalCurveFactory">A factory for grid point curves along horizontal direction, i.e. taken into account a specified interpolation, parametrization etc.</param>
            /// <param name="verticalInterpolator">The interpolation approach along vertical direction.</param>
            /// <param name="verticalAboveExtrapolator">The extrapolation approach in vertical direction above the grid points.</param>
            /// <param name="verticalBelowExtrapolator">The extrapolation approach in vertical direction below the grid points.</param>
            internal VInterpolation(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPointMatrix, Func <TVerticalLabel, IGridPointCurveFactory <THorizontalLabel> > horizontalCurveFactory, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator)
                : base(gridPointMatrix, horizontalCurveFactory)
            {
                m_VerticalInterpolatorFactory = verticalInterpolator ?? throw new NullReferenceException(nameof(verticalInterpolator));
                m_VerticalInterpolator        = verticalInterpolator.Create();

                if (verticalAboveExtrapolator == null)
                {
                    throw new NullReferenceException(nameof(verticalAboveExtrapolator));
                }
                if (verticalAboveExtrapolator.ExtrapolationBuildingDirection != GridPointCurve.Extrapolator.BuildingDirection.FromFirstGridPoint)
                {
                    throw new ArgumentException(String.Format("Invalid building direction of extrapolation above grid points."), nameof(verticalAboveExtrapolator));
                }
                m_VerticalAboveExtrapolatorFactory = verticalAboveExtrapolator;
                m_VerticalAboveExtrapolator        = verticalAboveExtrapolator.Create(m_VerticalInterpolator);

                if (verticalBelowExtrapolator == null)
                {
                    throw new NullReferenceException(nameof(verticalBelowExtrapolator));
                }
                if (verticalBelowExtrapolator.ExtrapolationBuildingDirection != GridPointCurve.Extrapolator.BuildingDirection.FromLastGridPoint)
                {
                    throw new ArgumentException(String.Format("Invalid building direction of extrapolation below grid points."), nameof(verticalBelowExtrapolator));
                }
                m_VerticalBelowExtrapolatorFactory = verticalBelowExtrapolator;
                m_VerticalBelowExtrapolator        = verticalBelowExtrapolator.Create(m_VerticalInterpolator);

                m_TempValuesForVerticalEvaluation = new double[m_VerticalDoubleLabels.Length];
                m_TempVerticalDoubleLabels        = new double[m_GridPointMatrix.RowCount];
            }
            /// <summary>Initializes a new instance of the <see cref="HInterpolation"/> class.
            /// </summary>
            /// <param name="gridPointMatrix">The grid point matrix.</param>
            /// <param name="verticalCurveFactory">A factory for grid point curves along vertical direction, i.e. taken into account a specified interpolation, parametrization etc.</param>
            /// <param name="horizontalInterpolator">The interpolation approach along horizontal direction.</param>
            /// <param name="horizontalLeftExtrapolator">The extrapolation approach in horizontal direction on the left side of the grid points.</param>
            /// <param name="horizontalRightExtrapolator">The extrapolation approach in horizontal direction on the right side of the grid points.</param>
            internal HInterpolation(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPointMatrix, Func <THorizontalLabel, IGridPointCurveFactory <TVerticalLabel> > verticalCurveFactory, GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator)
                : base(gridPointMatrix, verticalCurveFactory)
            {
                m_HorizontalInterpolatorFactory = horizontalInterpolator ?? throw new NullReferenceException(nameof(horizontalInterpolator));
                m_HorizontalInterpolator        = horizontalInterpolator.Create();

                if (horizontalLeftExtrapolator == null)
                {
                    throw new NullReferenceException(nameof(horizontalLeftExtrapolator));
                }
                if (horizontalLeftExtrapolator.ExtrapolationBuildingDirection != GridPointCurve.Extrapolator.BuildingDirection.FromFirstGridPoint)
                {
                    throw new ArgumentException(String.Format("Invalid building direction of extrapolation on left side of the grid points."), nameof(horizontalLeftExtrapolator));
                }
                m_HorizontalLeftExtrapolatorFactory = horizontalLeftExtrapolator;
                m_HorizontalLeftExtrapolator        = horizontalLeftExtrapolator.Create(m_HorizontalInterpolator);

                if (horizontalRightExtrapolator == null)
                {
                    throw new NullReferenceException(nameof(horizontalRightExtrapolator));
                }
                if (horizontalRightExtrapolator.ExtrapolationBuildingDirection != GridPointCurve.Extrapolator.BuildingDirection.FromLastGridPoint)
                {
                    throw new ArgumentException(String.Format("Invalid building direction of extrapolation on the right side of the grid points."), nameof(horizontalRightExtrapolator));
                }
                m_HorizontalRightExtrapolatorFactory = horizontalRightExtrapolator;
                m_HorizontalRightExtrapolator        = horizontalRightExtrapolator.Create(m_HorizontalInterpolator);

                m_TempValuesForHorizontalEvaluation = new double[m_HorizontalDoubleLabels.Length];
                m_TempHorizontalDoubleLabels        = new double[m_GridPointMatrix.ColumnCount];
            }
 /// <summary>Initializes a new instance of the <see cref="NearestAlongXAxisReplenishment"/> class.
 /// </summary>
 /// <param name="horizontalInterpolator">The (curve) interpolator along x-axis.</param>
 internal NearestAlongXAxisReplenishment(GridPointCurve.Interpolator horizontalInterpolator)
     : base(MissingValueReplenishmentResource.AnnotationAlongXAxis)
 {
     m_HorizontalInterpolator = horizontalInterpolator ?? throw new ArgumentNullException(nameof(horizontalInterpolator));
     m_Name     = new IdentifierString("X-Axis Replenishment");
     m_LongName = new IdentifierString(MissingValueReplenishmentResource.LongNameAlongXAxis);
 }
예제 #4
0
        /// <summary>Initializes a new instance of the <see cref="CurveInterpolationSpline"/> class.
        /// </summary>
        internal CurveInterpolationSpline()
        {
            var naturalCondition = new NaturalCubicSplineBoundaryCondition();

            NaturalCubicSpline = new CurveInterpolationCommonCubicSpline(naturalCondition, "Natural Cubic Spline", CurveResource.LongNameInterpolationNaturalCubicSpline, CurveResource.AnnotationInterpolationNaturalCubicSpline);

            BesselCubicSpline = new CurveInterpolationBesselCubicSpline();
        }
 /// <summary>Initializes a new instance of the <see cref="NearestWeightedReplenishment"/> class.
 /// </summary>
 /// <param name="horizontalInterpolator">The (curve) interpolator along x-axis.</param>
 /// <param name="verticalInterpolator">The (curve) interpolator along y-axis.</param>
 /// <param name="weight">The weight for the convex combination of the interpolated values which are the result of a linear interpolation in horizontal and vertical direction.</param>
 /// <remarks>The estimated value of a missing grid point is specified by (1.0 - Weight) * estimatedValueInXDirection + Weight * estimatedValueInYDirection.</remarks>
 internal NearestWeightedReplenishment(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Interpolator verticalInterpolator, double weight = 0.5)
     : base(MissingValueReplenishmentResource.AnnotationNearestWeighted)
 {
     m_HorizontalInterpolator = horizontalInterpolator ?? throw new ArgumentNullException(nameof(horizontalInterpolator));
     m_VerticalInterpolator   = verticalInterpolator ?? throw new ArgumentNullException(nameof(verticalInterpolator));
     m_Name     = new IdentifierString("WeightedInterpolation");
     m_LongName = new IdentifierString(String.Format(MissingValueReplenishmentResource.LongNameNearestWeighted, horizontalInterpolator.Name.String, verticalInterpolator.Name.String, weight));
     m_Weight   = weight;
 }
        public void GetValue_TestCase1(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, GridPointSurface2d.ConstructionOrder constructionOrder, double x, double y, double expected)
        {
            int rowCount    = 3;
            int columnCount = 3;
            var xLabels     = new double[] { 1.1, 2.12, 3.4 };
            var yLabels     = new double[] { 1.05, 2.07, 3.65 };

            double[] matrixEntries = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // matrix is provided column-by-column

            var labelMatrix = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels);

            var surface = GridPointSurface2d.Create(labelMatrix, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator, constructionOrder);

            double actual = surface.GetValue(x, y);

            Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("expected: {0}, actual: {1}", expected, actual));
        }
예제 #7
0
        public void GetValue_AtGridPoint_GridPointValue_TestCase2(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, GridPointSurface2d.ConstructionOrder constructionOrder)
        {
            int rowCount    = 2;
            int columnCount = 5;

            var xLabels = new double[] { 1.05, 2.6, 3, 4, 5 };
            var yLabels = new double[] { 1.3, 2.8 };

            var matrixEntries = new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // matrix is provided column-by-column
            var labelMatrix   = LabelMatrix.Create(rowCount, columnCount, matrixEntries, xLabels, yLabels);

            var surface = GridPointSurface2d.Create(labelMatrix, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator, constructionOrder);

            for (int j = 0; j < rowCount; j++)
            {
                for (int k = 0; k < columnCount; k++)
                {
                    double expected = labelMatrix[j, k];

                    double actual = surface.GetValue(x: labelMatrix.HorizontalDoubleLabels[k], y: labelMatrix.VerticalDoubleLabels[j]);
                    Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("Row: {0}, Column: {1}, expected: {2}, actual: {3}", j, k, expected, actual));
                }
            }
        }
예제 #8
0
        /// <summary>Creates a specified two-dimensional surface.
        /// </summary>
        /// <typeparam name="THorizontalLabel">The type of the horizontal label.</typeparam>
        /// <typeparam name="TVerticalLabel">The type of the vertical label.</typeparam>
        /// <param name="gridPoints">The grid points in its <see cref="LabelMatrix&lt;THorizontalLabel,TVerticalLabel&gt;"/> representation.</param>
        /// <param name="horizontalInterpolator">The interpolation approach along horizontal direction.</param>
        /// <param name="horizontalLeftExtrapolator">The extrapolation approach in horizontal direction on the left.</param>
        /// <param name="horizontalRightExtrapolator">The extrapolation approach in horizontal direction on the right.</param>
        /// <param name="verticalInterpolator">The interpolation approach along vertical direction.</param>
        /// <param name="verticalAboveExtrapolator">The extrapolation approach in vertical direction above the grid points.</param>
        /// <param name="verticalBelowExtrapolator">The extrapolation approach in vertical direction below the grid points.</param>
        /// <param name="constructionOrder">A value indicating the order of the vertical and horizontal interpolation, extrapolation etc.</param>
        /// <returns>An object that repesents the two-dimensional surface with respect to the specified grid points and interpolation/extrapolation.</returns>
        public static IGridPointSurface2d <THorizontalLabel, TVerticalLabel> Create <THorizontalLabel, TVerticalLabel>(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPoints, GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, ConstructionOrder constructionOrder = ConstructionOrder.HorizontalVertical)
            where THorizontalLabel : IComparable <THorizontalLabel>, IEquatable <THorizontalLabel>
            where TVerticalLabel : IComparable <TVerticalLabel>, IEquatable <TVerticalLabel>
        {
            if (gridPoints == null)
            {
                throw new ArgumentNullException(nameof(gridPoints));
            }
            if (horizontalInterpolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalInterpolator));
            }
            if (horizontalLeftExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalLeftExtrapolator));
            }
            if (horizontalRightExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalRightExtrapolator));
            }
            switch (constructionOrder)
            {
            case ConstructionOrder.HorizontalVertical:
                var horizontalCurveFactory = GridPointCurve.Factory.Create <THorizontalLabel>(horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator);
                return(new HorizontalVerticalWiseSurface2d <THorizontalLabel, TVerticalLabel> .VInterpolation(gridPoints, verticalLabel => horizontalCurveFactory, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator));

            case ConstructionOrder.VerticalHorizontal:
                var verticalCurveFactory = GridPointCurve.Factory.Create <TVerticalLabel>(verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator);
                return(new VerticalHorizontalWiseSurface2d <THorizontalLabel, TVerticalLabel> .HInterpolation(gridPoints, horizontalLabel => verticalCurveFactory, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator));

            default:
                throw new NotImplementedException();
            }
        }
예제 #9
0
 /// <summary>Creates a specified two-dimensional surface, where the interpolation, parametrization etc. takes place first in vertical direction and then in horizontal direction.
 /// </summary>
 /// <typeparam name="THorizontalLabel">The type of the horizontal label.</typeparam>
 /// <typeparam name="TVerticalLabel">The type of the vertical label.</typeparam>
 /// <param name="gridPoints">The grid points in its <see cref="LabelMatrix&lt;THorizontalLabel,TVerticalLabel&gt;"/> representation.</param>
 /// <param name="verticalCurveFactory">A factory for horizontal grid point curves.</param>
 /// <param name="horizontalInterpolator">The interpolation approach along horizontal direction.</param>
 /// <param name="horizontalLeftExtrapolator">The extrapolation approach in horizontal direction on the left.</param>
 /// <param name="horizontalRightExtrapolator">The extrapolation approach in horizontal direction on the right.</param>
 /// <returns>An object that repesents the two-dimensional surface with respect to the specified grid points and interpolation/extrapolation.</returns>
 public static IGridPointSurface2d <THorizontalLabel, TVerticalLabel> Create <THorizontalLabel, TVerticalLabel>(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPoints, Func <THorizontalLabel, IGridPointCurveFactory <TVerticalLabel> > verticalCurveFactory, GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator)
     where THorizontalLabel : IComparable <THorizontalLabel>, IEquatable <THorizontalLabel>
     where TVerticalLabel : IComparable <TVerticalLabel>, IEquatable <TVerticalLabel>
 {
     if (gridPoints == null)
     {
         throw new ArgumentNullException(nameof(gridPoints));
     }
     if (verticalCurveFactory == null)
     {
         throw new ArgumentNullException(nameof(verticalCurveFactory));
     }
     return(new VerticalHorizontalWiseSurface2d <THorizontalLabel, TVerticalLabel> .HInterpolation(gridPoints, verticalCurveFactory, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator));
 }
 /// <summary>Initializes a new instance of the <see cref="Replenishment"/> class.
 /// </summary>
 /// <param name="horizontalInterpolator">The (curve) interpolator along x-axis.</param>
 internal Replenishment(GridPointCurve.Interpolator horizontalInterpolator)
 {
     m_HorizontalInterpolator = horizontalInterpolator.Create();
 }
예제 #11
0
 /// <summary>Initializes a new instance of the <see cref="Replenishment"/> class.
 /// </summary>
 /// <param name="verticalInterpolator">The (curve) interpolator along y-axis.</param>
 internal Replenishment(GridPointCurve.Interpolator verticalInterpolator)
 {
     m_VerticalInterpolator = verticalInterpolator.Create();
 }
예제 #12
0
 /// <summary>Creates a new <see cref="LabelMatrix.MissingValueReplenishment"/> object.
 /// </summary>
 /// <param name="horizontalInterpolator">The (curve) interpolator along x-axis.</param>
 /// <param name="verticalInterpolator">The (curve) interpolator along y-axis.</param>
 /// <param name="weight">The weight for the convex combination of the interpolated values along x-axis and y-axis; (1.0 - <paramref name="weight"/>) * estimatedValueInXDirection + <paramref name="weight"/> * estimatedValueInYDirection.</param>
 /// <returns>A <see cref="LabelMatrix.MissingValueReplenishment"/> object that replenish missing values via
 /// <para>(1.0 - <paramref name="weight"/>) * estimatedValueInXDirection + <paramref name="weight"/> * estimatedValueInYDirection,</para>
 /// where <c>estimatedValueInXDirection</c> is the result of a interpolation along x-axis w.r.t. nearest (valid) grid points and
 /// <c>estimatedValueInYDirection</c> is the result of a interpolation along y-axis w.r.t. nearest (valid) grid points.</returns>
 public LabelMatrix.MissingValueReplenishment Create(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Interpolator verticalInterpolator, double weight = 0.5)
 {
     return(new NearestWeightedReplenishment(horizontalInterpolator, verticalInterpolator, weight));
 }
 /// <summary>Initializes a new instance of the <see cref="Replenishment"/> class.
 /// </summary>
 /// <param name="horizontalInterpolator">The (curve) interpolator along x-axis.</param>
 /// <param name="verticalInterpolator"></param>
 /// <param name="weight">The weight for the convex combination of the interpolated values which are the result of a linear interpolation in horizontal and vertical direction.</param>
 internal Replenishment(GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Interpolator verticalInterpolator, double weight)
 {
     m_HorizontalInterpolator = horizontalInterpolator.Create();
     m_VerticalInterpolator   = verticalInterpolator.Create();
     m_Weight = weight;
 }