void Number(out ClDouble d) { Expect(13); double tmpVal = double.Parse(t.val, new CultureInfo("en-US").NumberFormat); d = new ClDouble(tmpVal); }
/// <summary> Spline initialisation from X, Y input arrays and boundary conditions (slopes and values at end points) /// X must be in ascending order. </summary> public override void Load(ClWeightedPoint[] data, Spline1DBuilder parameters) { // if left or right end value is not set take value from first or last point if (parameters.ValueRight.IsEmpty) { valueRight_ = data[data.Length - 1].Value; } else { valueRight_ = parameters.ValueRight; } if (parameters.ValueLeft.IsEmpty) { valueLeft_ = data[0].Value; } else { valueLeft_ = parameters.ValueLeft; } base.Load(data); // Number of unknown b_i. equationSize_ = pointsNumber_; }
///<summary> Bound spline knots.</summary> public bool BoundKnots(ClDouble min, ClDouble max, ClDouble overCorrection) { // Set default argument value. if (overCorrection.IsEmpty) { overCorrection = 0; } // Check knots, correct data if needed. bool flagModified = false; for (int i = 0; i < pointsNumber_; i++) { double fitValue = (i == pointsNumber_ - 1) ? GetSplineValueInSection(i - 1, h_.Last(), 0) : splineSections_[i].D; if (!min.IsEmpty && fitValue < min) { splineSections_[i].Y = min + overCorrection * splineSections_[i].Weight; flagModified = true; } if (!max.IsEmpty && fitValue > max) { splineSections_[i].Y = max - overCorrection * splineSections_[i].Weight; flagModified = true; } } // Re-initialise spline if modified. if (flagModified) { CalculateQ(); } return(flagModified); }
/// <summary> Spline initialisation from X, Y input arrays and boundary conditions (slopes at end points) /// X must be in ascending order. </summary> public override void Load(ClWeightedPoint[] data, Spline1DBuilder parameters) { // if left or right slope is not set calculate it from first or last two points if (parameters.SlopeRight.IsEmpty) { slopeRight_ = (data[data.Length - 1].Value - data[data.Length - 2].Value) / (data[data.Length - 1].X[0] - data[data.Length - 2].X[0]); } else { slopeRight_ = parameters.SlopeRight; } if (parameters.SlopeLeft.IsEmpty) { slopeLeft_ = (data[1].Value - data[0].Value) / (data[1].X[0] - data[0].X[0]); } else { slopeLeft_ = parameters.SlopeLeft; } base.Load(data); // Number of unknown b_i. equationSize_ = pointsNumber_; }
///<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); }
public Spline1DBuilder() { SmoothParam = 0.9; min_ = ClDouble.Empty; max_ = ClDouble.Empty; slopeLeft_ = ClDouble.Empty; slopeRight_ = ClDouble.Empty; valueLeft_ = ClDouble.Empty; valueRight_ = ClDouble.Empty; }
/// <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); }
/// <summary> Return ClCsvMatrix with all spline coefficients. </summary> public ClCsvMatrix GetCoefficients() { ClCsvMatrix matrix = new ClCsvMatrix(splineSections_.Length - 1, 6); for (int i = 0; i < splineSections_.Length - 1; i++) { matrix[i, 0] = new ClDouble(splineSections_[i].X).ToVariant(); matrix[i, 1] = new ClDouble(splineSections_[i + 1].X).ToVariant(); matrix[i, 2] = new ClDouble(splineSections_[i].A).ToVariant(); matrix[i, 3] = new ClDouble(splineSections_[i].B).ToVariant(); matrix[i, 4] = new ClDouble(splineSections_[i].C).ToVariant(); matrix[i, 5] = new ClDouble(splineSections_[i].D).ToVariant(); } return(matrix); }
/// <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); }
/// <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); }
/// <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; }
/// <summary>Returns spline values on grid with a specified number of nodes.</summary> public ClCsvMatrix ValueOnGrid(int nodeCount) { ClDouble knotStep = (Points[PointsNumber - 1] - Points[0]) / (nodeCount - 1); return(ValueOnGrid(knotStep)); }