Example #1
0
        ///<summary>Bound spline min and max values.</summary>
        protected void Bound(ClInt nIterMax, ClDouble overCorrection)
        {
            // Set default argument values.
            if (nIterMax.IsEmpty)
            {
                nIterMax = 100;
            }
            if (overCorrection.IsEmpty)
            {
                overCorrection = 0.01;
            }

            // Iterate while all knots are within bounds or maximum number of iters is reached.
            int nIter;

            for (nIter = 0; nIter < nIterMax; nIter++)
            {
                //Console.WriteLine("Iter = " + nIter.ToString() + "  overCorrection = " + overCorrection.ToString());
                if (!splineMath_.BoundKnots(params_.Min, params_.Max, overCorrection))
                {
                    Console.WriteLine("Bound() completed, nIter = " + nIter);
                    return;
                }
                splineMath_.Solve(params_.SmoothParam);
                overCorrection *= 2;
            }
            Console.WriteLine("Bound() failed, reached nIter = " + nIter + " overCorrection = " + overCorrection);
        }
Example #2
0
        /// <summary>Returns spline values on the grid with a specified step.</summary>
        public ClCsvMatrix ValueOnGrid(double nodeStep)
        {
            ClInt       n      = Convert.ToInt32(Math.Ceiling((Points[PointsNumber - 1] - Points[0]) / nodeStep));
            ClCsvMatrix matrix = new ClCsvMatrix(n, 2);

            for (ClInt i = 0; i < n; i++)
            {
                ClDouble x = Points[0] + i * nodeStep;
                matrix[i, 0] = x.ToVariant();
                matrix[i, 1] = ValueAt(x);
            }
            return(matrix);
        }
Example #3
0
        /// <summary>Return ClCsvMatrix with input data.</summary>
        public ClCsvMatrix GetInputData()
        {
            if (!IsInitialized)
            {
                throw new ClEx("Spline is not initialised.");
            }

            // Build matrix with input data.
            var matrix = new ClCsvMatrix(PointsNumber, 2);

            for (ClInt i = 0; i < PointsNumber; i++)
            {
                matrix[i, 0] = new ClDouble(Points[i]).ToVariant();
                matrix[i, 1] = new ClDouble(Values[i]).ToVariant();
            }
            return(matrix);
        }
Example #4
0
        /// <summary>Return ClCsvMatrix with fitted data.</summary>
        public ClCsvMatrix GetFittedData()
        {
            if (!IsCalculated)
            {
                throw new ClEx("Spline is not calculated.");
            }

            // Build matrix with fitted data.
            var matrix = new ClCsvMatrix(splineMath_.DataNumber, 2);

            for (ClInt i = 0; i < splineMath_.DataNumber; i++)
            {
                var x = Points[i];
                matrix[i, 0] = new ClDouble(x).ToVariant();
                matrix[i, 1] = new ClDouble(ValueAt(x)).ToVariant();
            }
            return(matrix);
        }
Example #5
0
        /// <summary>Calculates spline parameters without spline extension (applying boundary conditions).</summary>
        public void CalculateWithoutExtension()
        {
            if (!IsInitialized)
            {
                throw new ClEx("Spline is not initialised.");
            }
            // Estimate the smoothing parameter
            params_.SmoothParam = BestRigidityEstimate();
            // Solve underlying linear system to find spline coefficients.
            splineMath_.Solve(params_.SmoothParam);

            // Bound spline if needed.
            if (!params_.Max.IsEmpty || !params_.Min.IsEmpty)
            {
                var nIterMax       = new ClInt();
                var overCorrection = new ClDouble();
                Bound(nIterMax, overCorrection);
            }

            IsCalculated = true;
        }