コード例 #1
0
            /// <summary>Updates the current curve fitting object.
            /// </summary>
            /// <param name="gridPointCount">The number of grid points, i.e. the number of relevant elements of <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" /> to take into account.</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="gridPointArgumentHint">Describes the structure of the grid point arguments.</param>
            /// <param name="gridPointValueHint">Describes the structure of the grid point values.</param>
            /// <param name="gridPointValueTransformation">A transformation to apply to the grid point values, i.e. number of grid points and grid point values (mainly used for log-linear interpolation).
            /// Caution: The application of a transformation has an impact on <see cref="Interpolator.GridPointValues"/>.</param>
            /// <param name="state">The state of the grid points, i.e. <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" />, with respect to the previous function call.</param>
            /// <param name="gridPointArgumentStartIndex">The null-based start index of <paramref name="gridPointArguments" /> 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" />.</param>
            /// <param name="gridPointValueIncrement">The increment for <paramref name="gridPointValues" />.</param>
            /// <remarks>
            /// This method should be called if grid points have been changed, added, removed etc. and before evaluating the grid point curve at a specified point.
            /// <para>If no problem occurred, the flag <see cref="IOperable.IsOperable" /> will be set to <c>true</c>.</para>
            /// <para>This method should always store all required data for later use, i.e. creates deep copies of the arguments.</para>
            /// </remarks>
            public void Update(int gridPointCount, IList <double> gridPointArguments, IList <double> gridPointValues, MklGridPointCurve.xHintValue gridPointArgumentHint, MklGridPointCurve.yHintValue gridPointValueHint, Action <int, double[]> gridPointValueTransformation, GridPointCurve.State state = GridPointCurve.State.GridPointChanged, int gridPointArgumentStartIndex = 0, int gridPointValueStartIndex = 0, int gridPointArgumentIncrement = 1, int gridPointValueIncrement = 1)
            {
                if (gridPointCount <= 0)
                {
                    m_GridPointCount = 0;  // i.e. current instance is not operable
                }
                else
                {
                    m_GridPointCount = gridPointCount;
                    bool isInitializedBefore = m_Task != IntPtr.Zero;

                    if (state.HasFlag(GridPointCurve.State.GridPointArgumentChanged))
                    {
                        if (ArrayMemory.Reallocate(ref m_GridPointArguments, gridPointCount, Math.Max(10, gridPointCount / 5)) == true)
                        {
                            m_ReadOnlyGridPointArguments = new ReadOnlyCollection <double>(m_GridPointArguments);
                            if (isInitializedBefore == true)
                            {
                                CheckErrorCode(_dfdEditPtr(m_Task, PtrParameterChangeType.DF_X, m_GridPointArguments), "dfdEditPtr");
                            }
                        }
                        gridPointArguments.CopyTo(m_GridPointArguments, gridPointCount, gridPointArgumentStartIndex, sourceIncrement: gridPointArgumentIncrement);

                        if ((ArrayMemory.Reallocate(ref m_SplineCoefficients, (int)m_MklDataFitting.m_SplineOrder * gridPointCount, Math.Max(10, gridPointCount / 5)) == true) && (isInitializedBefore == true))
                        {
                            CheckErrorCode(_dfdEditPtr(m_Task, PtrParameterChangeType.DF_PP_SCOEFF, m_SplineCoefficients), "dfdEditPtr");
                        }
                        if (isInitializedBefore == true)
                        {
                            CheckErrorCode(_dfiEditVal(m_Task, IntParameterChangeType.DF_XHINT, (int)gridPointArgumentHint), "dfiEditVal");
                        }
                    }

                    if (state.HasFlag(GridPointCurve.State.GridPointValueChanged))
                    {
                        if (ArrayMemory.Reallocate(ref m_GridPointValues, gridPointCount, Math.Max(10, gridPointCount / 5)) == true)
                        {
                            m_ReadOnlyGridPointValues = new ReadOnlyCollection <double>(m_GridPointValues);
                            if (isInitializedBefore == true)
                            {
                                CheckErrorCode(_dfdEditPtr(m_Task, PtrParameterChangeType.DF_Y, m_GridPointValues), "dfdEditPtr");
                            }
                        }
                        gridPointValues.CopyTo(m_GridPointValues, gridPointCount, gridPointValueStartIndex, sourceIncrement: gridPointValueIncrement);

                        gridPointValueTransformation(gridPointCount, m_GridPointValues);  // mainly used for log-linear transformation, i.e. apply logarithm to each grid point value. Caution: The public properties shows transformed values as well!

                        if (isInitializedBefore == true)
                        {
                            CheckErrorCode(_dfiEditVal(m_Task, IntParameterChangeType.DF_NX, gridPointCount), "dfiEditVal");
                            CheckErrorCode(_dfiEditVal(m_Task, IntParameterChangeType.DF_YHINT, (int)gridPointValueHint), "dfiEditVal");
                        }
                        else
                        {
                            CheckErrorCode(_dfdNewTask1D(out m_Task, gridPointCount, m_GridPointArguments, gridPointArgumentHint, 1, m_GridPointValues, gridPointValueHint), "dfdNewTask1D");
                        }
                    }

                    if (state != GridPointCurve.State.NoChangeSinceLastUpdate)
                    {
                        CheckErrorCode(_dfdEditPPSpline1D(m_Task, m_MklDataFitting.m_SplineOrder, m_MklDataFitting.m_SplineType, m_MklDataFitting.m_BoundaryConditionType, m_MklDataFitting.m_BoundaryCondition, m_MklDataFitting.m_InternalConditionTypes, m_MklDataFitting.m_InternalConditions, m_SplineCoefficients, m_MklDataFitting.m_SplineCoefficientHint), "dfdEditPPSpline1D");

                        if (m_MklDataFitting.m_SplineOrder != MklCurveInterpolationSpline.SplineOrder.DF_PP_STD)  // for a 'real' spline interpolation, one has to calculate the spline coefficients
                        {
                            CheckErrorCode(_dfdConstruct1D(m_Task, MklCurveInterpolationSpline.SplineFormat.DF_PP_SPLINE, MklCurveInterpolationSpline.SplineConstructionMethod.DF_METHOD_STD), "dfdConstruct1D");
                        }
                    }
                }
            }
コード例 #2
0
 protected extern static int _dfdNewTask1D(out IntPtr task, int nx, double[] x, MklGridPointCurve.xHintValue xhint, int ny, double[] y, MklGridPointCurve.yHintValue yhint);
コード例 #3
0
 /// <summary>Updates the current curve fitting object.
 /// </summary>
 /// <param name="gridPointCount">The number of grid points, i.e. the number of relevant elements of <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" /> to take into account.</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="gridPointArgumentHint">Describes the structure of the grid point arguments.</param>
 /// <param name="gridPointValueHint">Describes the structure of the grid point values.</param>
 /// <param name="state">The state of the grid points, i.e. <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" />, with respect to the previous function call.</param>
 /// <param name="gridPointArgumentStartIndex">The null-based start index of <paramref name="gridPointArguments" /> 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" />.</param>
 /// <param name="gridPointValueIncrement">The increment for <paramref name="gridPointValues" />.</param>
 /// <remarks>
 /// This method should be called if grid points have been changed, added, removed etc. and before evaluating the grid point curve at a specified point.
 /// <para>If no problem occurred, the flag <see cref="IOperable.IsOperable" /> will be set to <c>true</c>.</para>
 /// <para>This method should always store all required data for later use, i.e. creates deep copies of the arguments.</para>
 /// </remarks>
 public void Update(int gridPointCount, IList <double> gridPointArguments, IList <double> gridPointValues, MklGridPointCurve.xHintValue gridPointArgumentHint, MklGridPointCurve.yHintValue gridPointValueHint, GridPointCurve.State state = GridPointCurve.State.GridPointChanged, int gridPointArgumentStartIndex = 0, int gridPointValueStartIndex = 0, int gridPointArgumentIncrement = 1, int gridPointValueIncrement = 1)
 {
     Update(gridPointCount, gridPointArguments, gridPointValues, gridPointArgumentHint, gridPointValueHint, (n, v) => { }, state, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement);
 }
コード例 #4
0
 /// <summary>Updates the current curve fitting object.
 /// </summary>
 /// <param name="gridPointCount">The number of grid points, i.e. the number of relevant elements of <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" /> to take into account.</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="gridPointArgumentHint">Describes the structure of the grid point arguments.</param>
 /// <param name="gridPointValueHint">Describes the structure of the grid point values.</param>
 /// <param name="state">The state of the grid points, i.e. <paramref name="gridPointArguments" /> and <paramref name="gridPointValues" />, with respect to the previous function call.</param>
 /// <param name="gridPointArgumentStartIndex">The null-based start index of <paramref name="gridPointArguments" /> 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" />.</param>
 /// <param name="gridPointValueIncrement">The increment for <paramref name="gridPointValues" />.</param>
 /// <remarks>
 /// This method should be called if grid points have been changed, added, removed etc. and before evaluating the grid point curve at a specified point.
 /// <para>If no problem occurred, the flag <see cref="IOperable.IsOperable" /> will be set to <c>true</c>.</para>
 /// <para>This method should always store all required data for later use, i.e. creates deep copies of the arguments.</para>
 /// </remarks>
 public void Update(int gridPointCount, IList <double> gridPointArguments, IList <double> gridPointValues, MklGridPointCurve.xHintValue gridPointArgumentHint, MklGridPointCurve.yHintValue gridPointValueHint, GridPointCurve.State state = GridPointCurve.State.GridPointChanged, int gridPointArgumentStartIndex = 0, int gridPointValueStartIndex = 0, int gridPointArgumentIncrement = 1, int gridPointValueIncrement = 1)
 {
     /* lets store a copy of the original grid point values: */
     if (state.HasFlag(GridPointCurve.State.GridPointValueChanged))
     {
         if (ArrayMemory.Reallocate(ref m_OriginalGridPointValues, gridPointCount, Math.Max(10, gridPointCount / 5)) == true)
         {
             m_OriginalGridPointValuesReadOnlyCollection = new ReadOnlyCollection <double>(m_OriginalGridPointValues);
         }
         gridPointValues.CopyTo(m_OriginalGridPointValues, gridPointCount, gridPointValueStartIndex, sourceIncrement: gridPointValueIncrement);
     }
     m_DataFitting.Update(gridPointCount, gridPointArguments, gridPointValues, gridPointArgumentHint, gridPointValueHint, (n, x) => { VectorUnit.Basics.Log(n, x); }, state, gridPointArgumentStartIndex, gridPointValueStartIndex, gridPointArgumentIncrement, gridPointValueIncrement);
 }