/// <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="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="CurveExtrapolationLinear"/> class. /// </summary> internal CurveExtrapolationLinear() { FirstDerivative = new Differentiable(GridPointCurve.Extrapolator.BuildingDirection.FromFirstGridPoint); LastDerivative = new Differentiable(GridPointCurve.Extrapolator.BuildingDirection.FromLastGridPoint); SlopeOfFirstTwoGridPoints = new GridpointSlope(GridPointCurve.Extrapolator.BuildingDirection.FromFirstGridPoint); SlopeOfLastTwoGridPoints = new GridpointSlope(GridPointCurve.Extrapolator.BuildingDirection.FromLastGridPoint); }
/// <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<THorizontalLabel,TVerticalLabel>"/> 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(); } }
/// <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<THorizontalLabel,TVerticalLabel>"/> 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)); }
public void GetValue_TestCase2(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 = 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); double actual = surface.GetValue(x, y); Assert.That(actual, Is.EqualTo(expected).Within(1E-7), String.Format("expected: {0}, actual: {1}", expected, actual)); }
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)); } } }
public void GetValue_GridPointArgument_GridPointValue(MklGridPointCurve.Interpolator interpolation, GridPointCurve.Extrapolator leftExtrapolation, GridPointCurve.Extrapolator rightExtrapolation) { var gridPointCurve = GridPointCurve.Create(interpolation, leftExtrapolation, rightExtrapolation); gridPointCurve.Add(1.5, 2.0); gridPointCurve.Add(0.5, 1.25); gridPointCurve.Add(5.75, 9.75); gridPointCurve.Add(4.0, 12.25); gridPointCurve.Add(8.0, 7.5); gridPointCurve.Update(); Assume.That(gridPointCurve.FittingQuality == FittingQuality.Exact); Assert.That(gridPointCurve.IsOperable); for (int j = 0; j < gridPointCurve.GridPointCount; j++) { double expected = gridPointCurve.GridPointValues[j]; double actual = gridPointCurve.GetValue(gridPointCurve.GridPointArguments[j]); Assert.That(actual, Is.EqualTo(expected).Within(1E-6), String.Format("Grid Point argument: {0}; Grid Point value: {1}; null-based Grid Point index {2}.", gridPointCurve.GridPointArguments[j], gridPointCurve.GridPointValues[j], j)); } }