Browse Source

interpolation: assume samples to be sorted (splines-only)

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/2/head
Christoph Ruegg 17 years ago
parent
commit
780493b5ee
  1. 6
      src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs
  2. 22
      src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs
  3. 4
      src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs
  4. 10
      src/Managed/Interpolation/Algorithms/SplineInterpolation.cs
  5. 4
      src/Managed/Interpolation/Interpolation.cs

6
src/Managed/Interpolation/Algorithms/BarycentricInterpolation.cs

@ -64,7 +64,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Initializes a new instance of the BarycentricInterpolation class.
/// </summary>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="samplePoints">Sample Points t (no sorting assumed)</param>
/// <param name="sampleValues">Sample Values x(t)</param>
/// <param name="barycentricWeights">Barycentric weights w(t)</param>
public BarycentricInterpolation(
@ -95,7 +95,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
}
/// <summary>
/// Initialize the interpolation method with the given sample set.
/// Initialize the interpolation method with the given sample set (no sorting assumed).
/// </summary>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="sampleValues">Sample Values x(t)</param>
@ -153,7 +153,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return this.values[0];
}
// evaluate closest point and offset from that point
// evaluate closest point and offset from that point (no sorting assumed)
int closestPoint = 0;
double offset = t - this.points[0];
for (int i = 1; i < this.points.Count; i++)

22
src/Managed/Interpolation/Algorithms/LinearSplineInterpolation.cs

@ -55,8 +55,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Initializes a new instance of the LinearSplineInterpolation class.
/// </summary>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="sampleValues">Sample Values x(samplePoints)</param>
/// <param name="samplePoints">Sample Points t, sorted ascending.</param>
/// <param name="sampleValues">Sample Values x(t)</param>
public LinearSplineInterpolation(
IList<double> samplePoints,
IList<double> sampleValues)
@ -85,9 +85,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
}
/// <summary>
/// Initialize the interpolation method with the given spline coefficients.
/// Initialize the interpolation method with the given spline coefficients (sorted by the sample points t).
/// </summary>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="samplePoints">Sample Points t, sorted ascending.</param>
/// <param name="sampleValues">Sample Values x(t)</param>
public void Initialize(
IList<double> samplePoints,
@ -114,22 +114,16 @@ namespace MathNet.Numerics.Interpolation.Algorithms
}
double[] coefficients = new double[4 * (samplePoints.Count - 1)];
double[] sortedPoints = new double[samplePoints.Count];
samplePoints.CopyTo(sortedPoints, 0);
double[] sortedValues = new double[sampleValues.Count];
sampleValues.CopyTo(sortedValues, 0);
/* TODO: Sorting.Sort(sortedPoints, sortedValues); */
for (int i = 0, j = 0; i < sortedPoints.Length - 1; i++, j += 4)
for (int i = 0, j = 0; i < samplePoints.Count - 1; i++, j += 4)
{
coefficients[j] = sortedValues[i];
coefficients[j + 1] = (sortedValues[i + 1] - sortedValues[i]) / (sortedPoints[i + 1] - sortedPoints[i]);
coefficients[j] = sampleValues[i];
coefficients[j + 1] = (sampleValues[i + 1] - sampleValues[i]) / (samplePoints[i + 1] - samplePoints[i]);
coefficients[j + 2] = 0;
coefficients[j + 3] = 0;
}
this.spline.Initialize(sortedPoints, coefficients);
this.spline.Initialize(samplePoints, coefficients);
}
/// <summary>

4
src/Managed/Interpolation/Algorithms/RationalPoleFreeInterpolation.cs

@ -90,7 +90,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <remarks>
/// The interpolation scheme order will be set to 3.
/// </remarks>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="samplePoints">Sample Points t (no sorting assumed)</param>
/// <param name="sampleValues">Sample Values x(t)</param>
public void Initialize(
IList<double> samplePoints,
@ -100,7 +100,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
}
/// <summary>
/// Initialize the interpolation method with the given sample set.
/// Initialize the interpolation method with the given sample set (no sorting assumed).
/// </summary>
/// <param name="samplePoints">Sample Points t</param>
/// <param name="sampleValues">Sample Values x(t)</param>

10
src/Managed/Interpolation/Algorithms/SplineInterpolation.cs

@ -64,8 +64,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Initializes a new instance of the SplineInterpolation class.
/// </summary>
/// <param name="samplePoints">Sample Points t (length: N)</param>
/// <param name="splineCoefficients">Spline Coefficients (length: 4*(N-1))</param>
/// <param name="samplePoints">Sample Points t (length: N), sorted ascending.</param>
/// <param name="splineCoefficients">Spline Coefficients (length: 4*(N-1)).</param>
public SplineInterpolation(
IList<double> samplePoints,
IList<double> splineCoefficients)
@ -93,10 +93,10 @@ namespace MathNet.Numerics.Interpolation.Algorithms
}
/// <summary>
/// Initialize the interpolation method with the given spline coefficients.
/// Initialize the interpolation method with the given spline coefficients (sorted by the sample points t).
/// </summary>
/// <param name="samplePoints">Sample Points t (length: N)</param>
/// <param name="splineCoefficients">Spline Coefficients (length: 4*(N-1))</param>
/// <param name="samplePoints">Sample Points t (length: N), sorted ascending.</param>
/// <param name="splineCoefficients">Spline Coefficients (length: 4*(N-1)).</param>
public void Initialize(
IList<double> samplePoints,
IList<double> splineCoefficients)

4
src/Managed/Interpolation/Interpolation.cs

@ -54,9 +54,9 @@ namespace MathNet.Numerics.Interpolation
}
/// <summary>
/// Create a linear spline interpolation based on arbitrary points.
/// Create a linear spline interpolation based on arbitrary points (sorted ascending).
/// </summary>
/// <param name="points">The sample points t. Supports both lists and arrays.</param>
/// <param name="points">The sample points t, sorted ascending. Supports both lists and arrays.</param>
/// <param name="values">The sample point values x(t). Supports both lists and arrays.</param>
/// <returns>
/// An interpolation scheme optimized for the given sample points and values,

Loading…
Cancel
Save