Browse Source

Interpolation: simplify namespaces, minor formatting

optimization-1
Christoph Ruegg 13 years ago
parent
commit
893a5c48c7
  1. 1
      src/Examples/Interpolation/AkimaSpline.cs
  2. 1
      src/Examples/Interpolation/LinearBetweenPoints.cs
  3. 1
      src/Examples/Interpolation/RationalWithPoles.cs
  4. 1
      src/Examples/Interpolation/RationalWithoutPoles.cs
  5. 8
      src/Numerics/Interpolate.cs
  6. 38
      src/Numerics/Interpolation/AkimaSplineInterpolation.cs
  7. 24
      src/Numerics/Interpolation/BarycentricInterpolation.cs
  8. 24
      src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs
  9. 24
      src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs
  10. 38
      src/Numerics/Interpolation/CubicSplineInterpolation.cs
  11. 14
      src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs
  12. 16
      src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs
  13. 2
      src/Numerics/Interpolation/IInterpolation.cs
  14. 18
      src/Numerics/Interpolation/LinearSplineInterpolation.cs
  15. 28
      src/Numerics/Interpolation/NevillePolynomialInterpolation.cs
  16. 2
      src/Numerics/Interpolation/SplineBoundaryCondition.cs
  17. 64
      src/Numerics/Interpolation/SplineInterpolation.cs
  18. 22
      src/Numerics/Numerics.csproj
  19. 1
      src/UnitTests/InterpolationTests/AkimaSplineTest.cs
  20. 1
      src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs
  21. 1
      src/UnitTests/InterpolationTests/CubicSplineTest.cs
  22. 1
      src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs
  23. 1
      src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs
  24. 1
      src/UnitTests/InterpolationTests/LinearSplineTest.cs
  25. 1
      src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

1
src/Examples/Interpolation/AkimaSpline.cs

@ -26,7 +26,6 @@
using System;
using MathNet.Numerics.Interpolation;
using MathNet.Numerics.Interpolation.Algorithms;
using MathNet.Numerics.Random;
using MathNet.Numerics.Signals;

1
src/Examples/Interpolation/LinearBetweenPoints.cs

@ -25,6 +25,7 @@
// </copyright>
using System;
using MathNet.Numerics;
using MathNet.Numerics.Interpolation;
using MathNet.Numerics.Random;
using MathNet.Numerics.Signals;

1
src/Examples/Interpolation/RationalWithPoles.cs

@ -25,6 +25,7 @@
// </copyright>
using System;
using MathNet.Numerics;
using MathNet.Numerics.Interpolation;
using MathNet.Numerics.Random;
using MathNet.Numerics.Signals;

1
src/Examples/Interpolation/RationalWithoutPoles.cs

@ -25,6 +25,7 @@
// </copyright>
using System;
using MathNet.Numerics;
using MathNet.Numerics.Interpolation;
using MathNet.Numerics.Random;
using MathNet.Numerics.Signals;

8
src/Numerics/Interpolation/Interpolate.cs → src/Numerics/Interpolate.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation
{
using System.Collections.Generic;
using Algorithms;
using System.Collections.Generic;
using MathNet.Numerics.Interpolation;
namespace MathNet.Numerics
{
/// <summary>
/// Interpolation Factory.
/// </summary>

38
src/Numerics/Interpolation/Algorithms/AkimaSplineInterpolation.cs → src/Numerics/Interpolation/AkimaSplineInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Akima Spline Interpolation Algorithm.
/// </summary>
@ -45,7 +45,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Spline Interpolation
/// </summary>
private readonly CubicHermiteSplineInterpolation _spline;
readonly CubicHermiteSplineInterpolation _spline;
/// <summary>
/// Initializes a new instance of the AkimaSplineInterpolation class.
@ -147,7 +147,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
for (int i = 0; i < differences.Length; i++)
{
differences[i] = (sampleValues[i + 1] - sampleValues[i]) / (samplePoints[i + 1] - samplePoints[i]);
differences[i] = (sampleValues[i + 1] - sampleValues[i])/(samplePoints[i + 1] - samplePoints[i]);
}
for (int i = 1; i < weights.Length; i++)
@ -163,16 +163,16 @@ namespace MathNet.Numerics.Interpolation.Algorithms
{
derivatives[i] =
weights[i - 1].AlmostEqual(0.0) && weights[i + 1].AlmostEqual(0.0)
? (((samplePoints[i + 1] - samplePoints[i]) * differences[i - 1])
+ ((samplePoints[i] - samplePoints[i - 1]) * differences[i]))
/ (samplePoints[i + 1] - samplePoints[i - 1])
: ((weights[i + 1] * differences[i - 1])
+ (weights[i - 1] * differences[i]))
/ (weights[i + 1] + weights[i - 1]);
? (((samplePoints[i + 1] - samplePoints[i])*differences[i - 1])
+ ((samplePoints[i] - samplePoints[i - 1])*differences[i]))
/(samplePoints[i + 1] - samplePoints[i - 1])
: ((weights[i + 1]*differences[i - 1])
+ (weights[i - 1]*differences[i]))
/(weights[i + 1] + weights[i - 1]);
}
derivatives[0] = DifferentiateThreePoint(samplePoints, sampleValues, 0, 0, 1, 2);
derivatives[1] = DifferentiateThreePoint(samplePoints, sampleValues, 1, 0, 1, 2);
derivatives[1] = DifferentiateThreePoint(samplePoints, sampleValues, 1, 0, 1, 2);
derivatives[n - 2] = DifferentiateThreePoint(samplePoints, sampleValues, n - 2, n - 3, n - 2, n - 1);
derivatives[n - 1] = DifferentiateThreePoint(samplePoints, sampleValues, n - 1, n - 3, n - 2, n - 1);
@ -212,7 +212,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <param name="index1">Index of the second sample.</param>
/// <param name="index2">Index of the third sample.</param>
/// <returns>The derivative approximation.</returns>
private static double DifferentiateThreePoint(
static double DifferentiateThreePoint(
IList<double> samplePoints,
IList<double> sampleValues,
int indexT,
@ -228,9 +228,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
double t1 = samplePoints[index1] - samplePoints[index0];
double t2 = samplePoints[index2] - samplePoints[index0];
double a = (x2 - x0 - (t2 / t1 * (x1 - x0))) / ((t2 * t2) - (t1 * t2));
double b = (x1 - x0 - (a * t1 * t1)) / t1;
return (2 * a * t) + b;
double a = (x2 - x0 - (t2/t1*(x1 - x0)))/((t2*t2) - (t1*t2));
double b = (x1 - x0 - (a*t1*t1))/t1;
return (2*a*t) + b;
}
/// <summary>
@ -283,4 +283,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return _spline.Integrate(t);
}
}
}
}

24
src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs → src/Numerics/Interpolation/BarycentricInterpolation.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Barycentric Interpolation Algorithm.
/// </summary>
@ -44,17 +44,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Sample Points t.
/// </summary>
private IList<double> _points;
IList<double> _points;
/// <summary>
/// Sample Values x(t).
/// </summary>
private IList<double> _values;
IList<double> _values;
/// <summary>
/// Barycentric Weights w(t).
/// </summary>
private IList<double> _weights;
IList<double> _weights;
/// <summary>
/// Initializes a new instance of the BarycentricInterpolation class.
@ -187,19 +187,19 @@ namespace MathNet.Numerics.Interpolation.Algorithms
{
if (i != closestPoint)
{
double v = offset * _weights[i] / (t - _points[i]);
s1 = s1 + (v * _values[i]);
double v = offset*_weights[i]/(t - _points[i]);
s1 = s1 + (v*_values[i]);
s2 = s2 + v;
}
else
{
double v = _weights[i];
s1 = s1 + (v * _values[i]);
s1 = s1 + (v*_values[i]);
s2 = s2 + v;
}
}
return s1 / s2;
return s1/s2;
}
/// <summary>
@ -242,4 +242,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
throw new NotSupportedException();
}
}
}
}

24
src/Numerics/Interpolation/Algorithms/BulirschStoerRationalInterpolation.cs → src/Numerics/Interpolation/BulirschStoerRationalInterpolation.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Rational Interpolation (with poles) using Roland Bulirsch and Josef Stoer's Algorithm.
/// </summary>
@ -46,12 +46,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Sample Points t.
/// </summary>
private IList<double> _points;
IList<double> _points;
/// <summary>
/// Spline Values x(t).
/// </summary>
private IList<double> _values;
IList<double> _values;
/// <summary>
/// Initializes a new instance of the BulirschStoerRationalInterpolation class.
@ -165,7 +165,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
for (int i = 0; i < n - level; i++)
{
double hp = _points[i + level] - t;
double ho = (_points[i] - t) * d[i] / hp;
double ho = (_points[i] - t)*d[i]/hp;
double den = ho - c[i + 1];
if (den.AlmostEqual(0.0))
@ -173,12 +173,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return double.NaN; // zero-div, singularity
}
den = (c[i + 1] - d[i]) / den;
d[i] = c[i + 1] * den;
c[i] = ho * den;
den = (c[i + 1] - d[i])/den;
d[i] = c[i + 1]*den;
c[i] = ho*den;
}
x += (2 * nearestIndex) < (n - level)
x += (2*nearestIndex) < (n - level)
? c[nearestIndex]
: d[--nearestIndex];
}
@ -226,4 +226,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
throw new NotSupportedException();
}
}
}
}

24
src/Numerics/Interpolation/Algorithms/CubicHermiteSplineInterpolation.cs → src/Numerics/Interpolation/CubicHermiteSplineInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Cubic Hermite Spline Interpolation Algorithm.
/// </summary>
@ -45,7 +45,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Spline Interpolation
/// </summary>
private readonly SplineInterpolation _spline;
readonly SplineInterpolation _spline;
/// <summary>
/// Initializes a new instance of the CubicHermiteSplineInterpolation class.
@ -151,17 +151,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms
if (samplePoints[i] <= samplePoints[i - 1])
throw new ArgumentException(Resources.Interpolation_Initialize_SamplePointsNotStrictlyAscendingOrder, "samplePoints");
double[] coefficients = new double[4 * (samplePoints.Count - 1)];
double[] coefficients = new double[4*(samplePoints.Count - 1)];
for (int i = 0, j = 0; i < samplePoints.Count - 1; i++, j += 4)
{
double delta = samplePoints[i + 1] - samplePoints[i];
double delta2 = delta * delta;
double delta3 = delta * delta2;
double delta2 = delta*delta;
double delta3 = delta*delta2;
coefficients[j] = sampleValues[i];
coefficients[j + 1] = sampleDerivatives[i];
coefficients[j + 2] = ((3 * (sampleValues[i + 1] - sampleValues[i])) - (2 * sampleDerivatives[i] * delta) - (sampleDerivatives[i + 1] * delta)) / delta2;
coefficients[j + 3] = ((2 * (sampleValues[i] - sampleValues[i + 1])) + (sampleDerivatives[i] * delta) + (sampleDerivatives[i + 1] * delta)) / delta3;
coefficients[j + 2] = ((3*(sampleValues[i + 1] - sampleValues[i])) - (2*sampleDerivatives[i]*delta) - (sampleDerivatives[i + 1]*delta))/delta2;
coefficients[j + 3] = ((2*(sampleValues[i] - sampleValues[i + 1])) + (sampleDerivatives[i]*delta) + (sampleDerivatives[i + 1]*delta))/delta3;
}
return coefficients;
@ -217,4 +217,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return _spline.Integrate(t);
}
}
}
}

38
src/Numerics/Interpolation/Algorithms/CubicSplineInterpolation.cs → src/Numerics/Interpolation/CubicSplineInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Cubic Spline Interpolation Algorithm with continuous first and second derivatives.
/// </summary>
@ -45,7 +45,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Spline Interpolation
/// </summary>
private readonly CubicHermiteSplineInterpolation _spline;
readonly CubicHermiteSplineInterpolation _spline;
/// <summary>
/// Initializes a new instance of the CubicSplineInterpolation class.
@ -246,7 +246,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
a1[0] = 0;
a2[0] = 1;
a3[0] = 1;
b[0] = 2 * (sampleValues[1] - sampleValues[0]) / (samplePoints[1] - samplePoints[0]);
b[0] = 2*(sampleValues[1] - sampleValues[0])/(samplePoints[1] - samplePoints[0]);
break;
case SplineBoundaryCondition.FirstDerivative:
a1[0] = 0;
@ -258,7 +258,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
a1[0] = 0;
a2[0] = 2;
a3[0] = 1;
b[0] = (3 * ((sampleValues[1] - sampleValues[0]) / (samplePoints[1] - samplePoints[0]))) - (0.5 * leftBoundary * (samplePoints[1] - samplePoints[0]));
b[0] = (3*((sampleValues[1] - sampleValues[0])/(samplePoints[1] - samplePoints[0]))) - (0.5*leftBoundary*(samplePoints[1] - samplePoints[0]));
break;
default:
throw new NotSupportedException(Resources.InvalidLeftBoundaryCondition);
@ -268,9 +268,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
for (int i = 1; i < samplePoints.Count - 1; i++)
{
a1[i] = samplePoints[i + 1] - samplePoints[i];
a2[i] = 2 * (samplePoints[i + 1] - samplePoints[i - 1]);
a2[i] = 2*(samplePoints[i + 1] - samplePoints[i - 1]);
a3[i] = samplePoints[i] - samplePoints[i - 1];
b[i] = (3 * (sampleValues[i] - sampleValues[i - 1]) / (samplePoints[i] - samplePoints[i - 1]) * (samplePoints[i + 1] - samplePoints[i])) + (3 * (sampleValues[i + 1] - sampleValues[i]) / (samplePoints[i + 1] - samplePoints[i]) * (samplePoints[i] - samplePoints[i - 1]));
b[i] = (3*(sampleValues[i] - sampleValues[i - 1])/(samplePoints[i] - samplePoints[i - 1])*(samplePoints[i + 1] - samplePoints[i])) + (3*(sampleValues[i + 1] - sampleValues[i])/(samplePoints[i + 1] - samplePoints[i])*(samplePoints[i] - samplePoints[i - 1]));
}
// Right Boundary
@ -280,7 +280,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
a1[n - 1] = 1;
a2[n - 1] = 1;
a3[n - 1] = 0;
b[n - 1] = 2 * (sampleValues[n - 1] - sampleValues[n - 2]) / (samplePoints[n - 1] - samplePoints[n - 2]);
b[n - 1] = 2*(sampleValues[n - 1] - sampleValues[n - 2])/(samplePoints[n - 1] - samplePoints[n - 2]);
break;
case SplineBoundaryCondition.FirstDerivative:
a1[n - 1] = 0;
@ -292,7 +292,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
a1[n - 1] = 1;
a2[n - 1] = 2;
a3[n - 1] = 0;
b[n - 1] = (3 * (sampleValues[n - 1] - sampleValues[n - 2]) / (samplePoints[n - 1] - samplePoints[n - 2])) + (0.5 * rightBoundary * (samplePoints[n - 1] - samplePoints[n - 2]));
b[n - 1] = (3*(sampleValues[n - 1] - sampleValues[n - 2])/(samplePoints[n - 1] - samplePoints[n - 2])) + (0.5*rightBoundary*(samplePoints[n - 1] - samplePoints[n - 2]));
break;
default:
throw new NotSupportedException(Resources.InvalidRightBoundaryCondition);
@ -343,7 +343,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <param name="c">The c-vector[n].</param>
/// <param name="d">The d-vector[n], will be modified by this function.</param>
/// <returns>The x-vector[n]</returns>
private static double[] SolveTridiagonal(
static double[] SolveTridiagonal(
double[] a,
double[] b,
double[] c,
@ -353,15 +353,15 @@ namespace MathNet.Numerics.Interpolation.Algorithms
for (int k = 1; k < a.Length; k++)
{
double t = a[k] / b[k - 1];
b[k] = b[k] - (t * c[k - 1]);
d[k] = d[k] - (t * d[k - 1]);
double t = a[k]/b[k - 1];
b[k] = b[k] - (t*c[k - 1]);
d[k] = d[k] - (t*d[k - 1]);
}
x[x.Length - 1] = d[d.Length - 1] / b[b.Length - 1];
x[x.Length - 1] = d[d.Length - 1]/b[b.Length - 1];
for (int k = x.Length - 2; k >= 0; k--)
{
x[k] = (d[k] - (c[k] * x[k + 1])) / b[k];
x[k] = (d[k] - (c[k]*x[k + 1]))/b[k];
}
return x;
@ -417,4 +417,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return _spline.Integrate(t);
}
}
}
}

14
src/Numerics/Interpolation/Algorithms/EquidistantPolynomialInterpolation.cs → src/Numerics/Interpolation/EquidistantPolynomialInterpolation.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Barycentric Polynomial Interpolation where the given sample points are equidistant.
/// </summary>
@ -44,7 +44,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Barycentric Interpolation
/// </summary>
private readonly BarycentricInterpolation _barycentric;
readonly BarycentricInterpolation _barycentric;
/// <summary>
/// Initializes a new instance of the EquidistantPolynomialInterpolation class.
@ -124,7 +124,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
var samplePoints = new double[sampleValues.Count];
samplePoints[0] = leftBound;
double step = (rightBound - leftBound) / (samplePoints.Length - 1);
double step = (rightBound - leftBound)/(samplePoints.Length - 1);
for (int i = 1; i < samplePoints.Length; i++)
{
samplePoints[i] = samplePoints[i - 1] + step;
@ -172,7 +172,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
weights[0] = 1.0;
for (int i = 1; i < weights.Length; i++)
{
weights[i] = -(weights[i - 1] * (weights.Length - i)) / i;
weights[i] = -(weights[i - 1]*(weights.Length - i))/i;
}
return weights;

16
src/Numerics/Interpolation/Algorithms/FloaterHormannRationalInterpolation.cs → src/Numerics/Interpolation/FloaterHormannRationalInterpolation.cs

@ -28,11 +28,11 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Barycentric Rational Interpolation without poles, using Mike Floater and Kai Hormann's Algorithm.
/// </summary>
@ -44,7 +44,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Barycentric Interpolation
/// </summary>
private readonly BarycentricInterpolation _barycentric;
readonly BarycentricInterpolation _barycentric;
/// <summary>
/// Initializes a new instance of the FloaterHormannRationalInterpolation class.
@ -234,14 +234,14 @@ namespace MathNet.Numerics.Interpolation.Algorithms
{
if (j != k)
{
v = v / Math.Abs(sortedPoints[k] - sortedPoints[j]);
v = v/Math.Abs(sortedPoints[k] - sortedPoints[j]);
}
}
s = s + v;
}
sortedWeights[k] = sign * s;
sortedWeights[k] = sign*s;
sign = -sign;
}
@ -305,4 +305,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
throw new NotSupportedException();
}
}
}
}

2
src/Numerics/Interpolation/IInterpolation.cs

@ -86,4 +86,4 @@ namespace MathNet.Numerics.Interpolation
/// <seealso cref="SupportsIntegration"/>
double Integrate(double t);
}
}
}

18
src/Numerics/Interpolation/Algorithms/LinearSplineInterpolation.cs → src/Numerics/Interpolation/LinearSplineInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Linear Spline Interpolation Algorithm.
/// </summary>
@ -45,7 +45,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Internal Spline Interpolation
/// </summary>
private readonly SplineInterpolation _spline;
readonly SplineInterpolation _spline;
/// <summary>
/// Initializes a new instance of the LinearSplineInterpolation class.
@ -138,12 +138,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms
if (samplePoints[i] <= samplePoints[i - 1])
throw new ArgumentException(Resources.Interpolation_Initialize_SamplePointsNotStrictlyAscendingOrder, "samplePoints");
double[] coefficients = new double[4 * (samplePoints.Count - 1)];
double[] coefficients = new double[4*(samplePoints.Count - 1)];
for (int i = 0, j = 0; i < samplePoints.Count - 1; i++, j += 4)
{
coefficients[j] = sampleValues[i];
coefficients[j + 1] = (sampleValues[i + 1] - sampleValues[i]) / (samplePoints[i + 1] - samplePoints[i]);
coefficients[j + 1] = (sampleValues[i + 1] - sampleValues[i])/(samplePoints[i + 1] - samplePoints[i]);
coefficients[j + 2] = 0;
coefficients[j + 3] = 0;
}
@ -201,4 +201,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return _spline.Integrate(t);
}
}
}
}

28
src/Numerics/Interpolation/Algorithms/NevillePolynomialInterpolation.cs → src/Numerics/Interpolation/NevillePolynomialInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Lagrange Polynomial Interpolation using Neville's Algorithm.
/// </summary>
@ -52,12 +52,12 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Sample Points t.
/// </summary>
private IList<double> _points;
IList<double> _points;
/// <summary>
/// Spline Values x(t).
/// </summary>
private IList<double> _values;
IList<double> _values;
/// <summary>
/// Initializes a new instance of the NevillePolynomialInterpolation class.
@ -151,7 +151,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
double hp = t - _points[i + level];
double ho = _points[i] - t;
double den = _points[i] - _points[i + level];
x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den;
x[i] = ((hp*x[i]) + (ho*x[i + 1]))/den;
}
}
@ -178,8 +178,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms
double hp = t - _points[i + level];
double ho = _points[i] - t;
double den = _points[i] - _points[i + level];
dx[i] = ((hp * dx[i]) + x[i] + (ho * dx[i + 1]) - x[i + 1]) / den;
x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den;
dx[i] = ((hp*dx[i]) + x[i] + (ho*dx[i + 1]) - x[i + 1])/den;
x[i] = ((hp*x[i]) + (ho*x[i + 1]))/den;
}
}
@ -212,9 +212,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
double hp = t - _points[i + level];
double ho = _points[i] - t;
double den = _points[i] - _points[i + level];
ddx[i] = ((hp * ddx[i]) + (ho * ddx[i + 1]) + (2 * dx[i]) - (2 * dx[i + 1])) / den;
dx[i] = ((hp * dx[i]) + x[i] + (ho * dx[i + 1]) - x[i + 1]) / den;
x[i] = ((hp * x[i]) + (ho * x[i + 1])) / den;
ddx[i] = ((hp*ddx[i]) + (ho*ddx[i + 1]) + (2*dx[i]) - (2*dx[i + 1]))/den;
dx[i] = ((hp*dx[i]) + x[i] + (ho*dx[i + 1]) - x[i + 1])/den;
x[i] = ((hp*x[i]) + (ho*x[i + 1]))/den;
}
}
@ -234,4 +234,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
throw new NotSupportedException();
}
}
}
}

2
src/Numerics/Interpolation/SplineBoundaryCondition.cs

@ -55,4 +55,4 @@ namespace MathNet.Numerics.Interpolation
/// </summary>
SecondDerivative
}
}
}

64
src/Numerics/Interpolation/Algorithms/SplineInterpolation.cs → src/Numerics/Interpolation/SplineInterpolation.cs

@ -28,12 +28,12 @@
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.Interpolation.Algorithms
{
using System;
using System.Collections.Generic;
using Properties;
using System;
using System.Collections.Generic;
using MathNet.Numerics.Properties;
namespace MathNet.Numerics.Interpolation
{
/// <summary>
/// Third-Degree Spline Interpolation Algorithm.
/// </summary>
@ -45,17 +45,17 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// <summary>
/// Sample Points t.
/// </summary>
private IList<double> _points;
IList<double> _points;
/// <summary>
/// Spline Coefficients c(t).
/// </summary>
private IList<double> _coefficients;
IList<double> _coefficients;
/// <summary>
/// Number of samples.
/// </summary>
private int _sampleCount;
int _sampleCount;
/// <summary>
/// Initializes a new instance of the SplineInterpolation class.
@ -119,7 +119,7 @@ namespace MathNet.Numerics.Interpolation.Algorithms
throw new ArgumentOutOfRangeException("samplePoints");
}
if (splineCoefficients.Count != 4 * (samplePoints.Count - 1))
if (splineCoefficients.Count != 4*(samplePoints.Count - 1))
{
throw new ArgumentOutOfRangeException("splineCoefficients");
}
@ -147,9 +147,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
int k = closestLeftIndex << 2;
return _coefficients[k]
+ (offset * (_coefficients[k + 1]
+ (offset * (_coefficients[k + 2]
+ (offset * _coefficients[k + 3])))));
+ (offset*(_coefficients[k + 1]
+ (offset*(_coefficients[k + 2]
+ (offset*_coefficients[k + 3])))));
}
/// <summary>
@ -168,8 +168,8 @@ namespace MathNet.Numerics.Interpolation.Algorithms
int k = closestLeftIndex << 2;
return _coefficients[k + 1]
+ (2 * offset * _coefficients[k + 2])
+ (3 * offset * offset * _coefficients[k + 3]);
+ (2*offset*_coefficients[k + 2])
+ (3*offset*offset*_coefficients[k + 3]);
}
/// <summary>
@ -193,16 +193,16 @@ namespace MathNet.Numerics.Interpolation.Algorithms
int k = closestLeftIndex << 2;
interpolatedValue = _coefficients[k]
+ (offset * (_coefficients[k + 1]
+ (offset * (_coefficients[k + 2]
+ (offset * _coefficients[k + 3])))));
+ (offset*(_coefficients[k + 1]
+ (offset*(_coefficients[k + 2]
+ (offset*_coefficients[k + 3])))));
secondDerivative = (2 * _coefficients[k + 2])
+ (6 * offset * _coefficients[k + 3]);
secondDerivative = (2*_coefficients[k + 2])
+ (6*offset*_coefficients[k + 3]);
return _coefficients[k + 1]
+ (2 * offset * _coefficients[k + 2])
+ (3 * offset * offset * _coefficients[k + 3]);
+ (2*offset*_coefficients[k + 2])
+ (3*offset*offset*_coefficients[k + 3]);
}
/// <summary>
@ -220,19 +220,19 @@ namespace MathNet.Numerics.Interpolation.Algorithms
for (int i = 0, j = 0; i < closestLeftIndex; i++, j += 4)
{
double w = _points[i + 1] - _points[i];
result += w * (_coefficients[j]
+ ((w * _coefficients[j + 1] * 0.5)
+ (w * ((_coefficients[j + 2] / 3)
+ (w * _coefficients[j + 3] * 0.25)))));
result += w*(_coefficients[j]
+ ((w*_coefficients[j + 1]*0.5)
+ (w*((_coefficients[j + 2]/3)
+ (w*_coefficients[j + 3]*0.25)))));
}
double offset = t - _points[closestLeftIndex];
int k = closestLeftIndex << 2;
return result + (offset * (_coefficients[k]
+ (offset * _coefficients[k + 1] * 0.5)
+ (offset * _coefficients[k + 2] / 3)
+ (offset * _coefficients[k + 3] * 0.25)));
return result + (offset*(_coefficients[k]
+ (offset*_coefficients[k + 1]*0.5)
+ (offset*_coefficients[k + 2]/3)
+ (offset*_coefficients[k + 3]*0.25)));
}
/// <summary>
@ -240,14 +240,14 @@ namespace MathNet.Numerics.Interpolation.Algorithms
/// </summary>
/// <param name="t">The value to look for.</param>
/// <returns>The sample point index.</returns>
private int IndexOfClosestPointLeftOf(double t)
int IndexOfClosestPointLeftOf(double t)
{
// Binary search in the [ t[0], ..., t[n-2] ] (t[n-1] is not included)
int low = 0;
int high = _sampleCount - 1;
while (low != high - 1)
{
int middle = (low + high) / 2;
int middle = (low + high)/2;
if (_points[middle] > t)
{
high = middle;
@ -261,4 +261,4 @@ namespace MathNet.Numerics.Interpolation.Algorithms
return low;
}
}
}
}

22
src/Numerics/Numerics.csproj

@ -384,7 +384,7 @@
<Compile Include="IntegralTransforms\Algorithms\DiscreteHartleyTransform.Options.cs" />
<Compile Include="IntegralTransforms\HartleyOptions.cs" />
<Compile Include="GlobalizationHelper.cs" />
<Compile Include="Interpolation\Algorithms\EquidistantPolynomialInterpolation.cs" />
<Compile Include="Interpolation\EquidistantPolynomialInterpolation.cs" />
<Compile Include="IPrecisionSupport.cs" />
<Compile Include="IntegralTransforms\Algorithms\DiscreteFourierTransform.Options.cs" />
<Compile Include="IntegralTransforms\Algorithms\DiscreteFourierTransform.Bluestein.cs" />
@ -396,17 +396,17 @@
<Compile Include="Integration\Algorithms\SimpsonRule.cs" />
<Compile Include="Integration\Algorithms\NewtonCotesTrapeziumRule.cs" />
<Compile Include="Integration\Integrate.cs" />
<Compile Include="Interpolation\Algorithms\AkimaSplineInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\BarycentricInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\BulirschStoerRationalInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\CubicSplineInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\CubicHermiteSplineInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\FloaterHormannRationalInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\LinearSplineInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\NevillePolynomialInterpolation.cs" />
<Compile Include="Interpolation\Algorithms\SplineInterpolation.cs" />
<Compile Include="Interpolation\AkimaSplineInterpolation.cs" />
<Compile Include="Interpolation\BarycentricInterpolation.cs" />
<Compile Include="Interpolation\BulirschStoerRationalInterpolation.cs" />
<Compile Include="Interpolation\CubicSplineInterpolation.cs" />
<Compile Include="Interpolation\CubicHermiteSplineInterpolation.cs" />
<Compile Include="Interpolation\FloaterHormannRationalInterpolation.cs" />
<Compile Include="Interpolation\LinearSplineInterpolation.cs" />
<Compile Include="Interpolation\NevillePolynomialInterpolation.cs" />
<Compile Include="Interpolation\SplineInterpolation.cs" />
<Compile Include="Interpolation\IInterpolation.cs" />
<Compile Include="Interpolation\Interpolate.cs" />
<Compile Include="Interpolate.cs" />
<Compile Include="Interpolation\SplineBoundaryCondition.cs" />
<Compile Include="NumberTheory\IntegerTheory.Euclid.Big.cs" />
<Compile Include="NumberTheory\IntegerTheory.cs" />

1
src/UnitTests/InterpolationTests/AkimaSplineTest.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/BulirschStoerRationalTest.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/CubicSplineTest.cs

@ -35,7 +35,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using System.IO;
using System.Linq;
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/EquidistantPolynomialTest.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/FloaterHormannRationalTest.cs

@ -31,7 +31,6 @@
namespace MathNet.Numerics.UnitTests.InterpolationTests
{
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/LinearSplineTest.cs

@ -35,7 +35,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using System.IO;
using System.Linq;
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

1
src/UnitTests/InterpolationTests/NevillePolynomialTest.cs

@ -35,7 +35,6 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
using System.IO;
using System.Linq;
using Interpolation;
using Interpolation.Algorithms;
using NUnit.Framework;
/// <summary>

Loading…
Cancel
Save