コード例 #1
0
        /// <summary>Creates a new <see cref="IGridPointCurve&lt;TLabel&gt;"/> object with respect to specified interpolation and extrapolation approaches.
        /// </summary>
        /// <param name="curveInterpolator">The curve interpolator.</param>
        /// <param name="leftExtrapolator">The extrapolator on the left side, i.e. from the first grid point to -\infinity.</param>
        /// <param name="rightExtrapolator">The extrapolator on the right side, i.e. from the last grid point to \infinity.</param>
        /// <param name="capacity">The number of elements that the new grid point curve can initially store.</param>
        /// <returns>A <see cref="IGridPointCurve{TLabel}"/> object with respect to the desired interpolation and extrapolation approaches.</returns>
        public static IGridPointCurve <double> Create(Interpolator curveInterpolator, Extrapolator leftExtrapolator, Extrapolator rightExtrapolator, int capacity = 20)
        {
            if (curveInterpolator == null)
            {
                throw new ArgumentException(nameof(curveInterpolator));
            }
            var interpolator = curveInterpolator.Create();

            if (leftExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(leftExtrapolator));
            }
            if (leftExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromFirstGridPoint)
            {
                throw new ArgumentException("Wrong building direction of curve extrapolation", "leftExtrapolator");
            }
            var left = leftExtrapolator.Create(interpolator);

            if (rightExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(rightExtrapolator));
            }
            var right = rightExtrapolator.Create(interpolator);

            if (rightExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromLastGridPoint)
            {
                throw new ArgumentException("Wrong building direction of curve extrapolation", "rightExtrapolation");
            }

            if ((interpolator is IDifferentiableRealValuedCurve) && (left is IDifferentiableRealValuedCurve) && (right is IDifferentiableRealValuedCurve))
            {
                return(new StandardGridPointCurveNoLabels.Differentiable(curveInterpolator, interpolator, leftExtrapolator, left, rightExtrapolator, right, capacity));
            }
            return(new StandardGridPointCurveNoLabels(curveInterpolator, interpolator, leftExtrapolator, left, rightExtrapolator, right, capacity));
        }
コード例 #2
0
        /// <summary>Creates a new read-only <see cref="IGridPointCurve&lt;TLabel&gt;"/> object with respect to specified interpolation and extrapolation approaches.
        /// </summary>
        /// <typeparam name="TLabel">The type of the label.</typeparam>
        /// <param name="curveInterpolator">The curve interpolator.</param>
        /// <param name="leftExtrapolator">The extrapolator on the left side, i.e. from the first grid point to -\infinity.</param>
        /// <param name="rightExtrapolator">The extrapolator on the right side, i.e. from the last grid point to \infinity.</param>
        /// <param name="gridPointCount">The number of grid points, i.e. the number of relevant elements of <paramref name="gridPointLabels"/>, <paramref name="gridPointArguments"/> and <paramref name="gridPointValues"/> to take into account.</param>
        /// <param name="gridPointLabels">The labels of the grid points (the reference will be stored only).</param>
        /// <param name="gridPointArguments">The arguments of the grid points, thus labels of the curve in its <see cref="System.Double"/> representation in ascending order.</param>
        /// <param name="gridPointValues">The values of the grid points corresponding to <paramref name="gridPointArguments"/>.</param>
        /// <param name="gridPointArgumentStartIndex">The null-based start index of <paramref name="gridPointArguments"/> and <paramref name="gridPointLabels"/> to take into account.</param>
        /// <param name="gridPointValueStartIndex">The null-based start index of <paramref name="gridPointValues"/> to take into account.</param>
        /// <param name="gridPointArgumentIncrement">The increment for <paramref name="gridPointArguments"/> and <paramref name="gridPointLabels"/>.</param>
        /// <param name="gridPointValueIncrement">The increment for <paramref name="gridPointValues"/>.</param>
        /// <returns>A read-only <see cref="IGridPointCurve&lt;TLabel&gt;"/> object with respect to the desired interpolation and extrapolation approaches.</returns>
        /// <remarks>This method is mainly used for two-dimensional surface interpolation. Assuming a large grid point matrix, for example 1.000 x 1.000 and one may apply for example a linear interpolation
        /// along horizontal direction and afterwards a linear interpolation along vertical direction. Then we create 1.000 curves in horizontal direction, where the (double) labels and values are constant. The
        /// standard implementation create a copy of 3 * 1.000 x 1.000 = 3.000.000 values and calles the update method of the underlying <see cref="ICurveDataFitting"/> object which again copy 2 * 1.000 * 1.000 = 2.000.000 values, i.e. in total 5 Mio values.
        /// This implementation takes into account references, the underlying <see cref="ICurveDataFitting"/> implementation creates deep copies of double values and grid point values only, i.e. 2 Mio double values.</remarks>
        public static IGridPointCurve <TLabel> Create <TLabel>(Interpolator curveInterpolator, Extrapolator leftExtrapolator, Extrapolator rightExtrapolator, int gridPointCount, IList <TLabel> gridPointLabels, IList <double> gridPointArguments, IList <double> gridPointValues, int gridPointArgumentStartIndex = 0, int gridPointValueStartIndex = 0, int gridPointArgumentIncrement = 1, int gridPointValueIncrement = 1)
            where TLabel : IEquatable <TLabel>
        {
            if (curveInterpolator == null)
            {
                throw new ArgumentException(nameof(curveInterpolator));
            }
            var interpolator = curveInterpolator.Create();

            if (leftExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(leftExtrapolator));
            }
            if (leftExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromFirstGridPoint)
            {
                throw new ArgumentException("Wrong building direction of curve extrapolation", "leftExtrapolator");
            }
            var left = leftExtrapolator.Create(interpolator);

            if (rightExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(rightExtrapolator));
            }
            var right = rightExtrapolator.Create(interpolator);

            if (rightExtrapolator.ExtrapolationBuildingDirection != Extrapolator.BuildingDirection.FromLastGridPoint)
            {
                throw new ArgumentException("Wrong building direction of curve extrapolation", "rightExtrapolation");
            }

            if ((interpolator is IDifferentiableRealValuedCurve) && (left is IDifferentiableRealValuedCurve) && (right is IDifferentiableRealValuedCurve))
            {
                return(new SmartReadOnlyGridPointCurve <TLabel> .Differentiable(interpolator, left, right, gridPointCount, gridPointLabels, gridPointArguments, gridPointValues, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement));
            }
            return(new SmartReadOnlyGridPointCurve <TLabel>(interpolator, left, right, gridPointCount, gridPointLabels, gridPointArguments, gridPointValues, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement));
        }