forked from tsai/mathnet-numerics
4 changed files with 0 additions and 737 deletions
@ -1,235 +0,0 @@ |
|||||
// <copyright file="BarycentricInterpolation.cs" company="Math.NET">
|
|
||||
// Math.NET Numerics, part of the Math.NET Project
|
|
||||
// http://numerics.mathdotnet.com
|
|
||||
// http://github.com/mathnet/mathnet-numerics
|
|
||||
// http://mathnetnumerics.codeplex.com
|
|
||||
//
|
|
||||
// Copyright (c) 2009-2013 Math.NET
|
|
||||
//
|
|
||||
// Permission is hereby granted, free of charge, to any person
|
|
||||
// obtaining a copy of this software and associated documentation
|
|
||||
// files (the "Software"), to deal in the Software without
|
|
||||
// restriction, including without limitation the rights to use,
|
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||
// copies of the Software, and to permit persons to whom the
|
|
||||
// Software is furnished to do so, subject to the following
|
|
||||
// conditions:
|
|
||||
//
|
|
||||
// The above copyright notice and this permission notice shall be
|
|
||||
// included in all copies or substantial portions of the Software.
|
|
||||
//
|
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace MathNet.Numerics.Interpolation |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Barycentric Interpolation Algorithm.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// This algorithm neither supports differentiation nor integration.
|
|
||||
/// </remarks>
|
|
||||
public class BarycentricInterpolation : IInterpolation |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Sample Points t.
|
|
||||
/// </summary>
|
|
||||
IList<double> _points; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Sample Values x(t).
|
|
||||
/// </summary>
|
|
||||
IList<double> _values; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Barycentric Weights w(t).
|
|
||||
/// </summary>
|
|
||||
IList<double> _weights; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the BarycentricInterpolation class.
|
|
||||
/// </summary>
|
|
||||
public BarycentricInterpolation() |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the BarycentricInterpolation class.
|
|
||||
/// </summary>
|
|
||||
/// <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(IList<double> samplePoints, IList<double> sampleValues, IList<double> barycentricWeights) |
|
||||
{ |
|
||||
Initialize(samplePoints, sampleValues, barycentricWeights); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsDifferentiation |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsIntegration |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 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>
|
|
||||
/// <param name="barycentricWeights">Barycentric weights w(t)</param>
|
|
||||
public void Initialize(IList<double> samplePoints, IList<double> sampleValues, IList<double> barycentricWeights) |
|
||||
{ |
|
||||
if (null == samplePoints) |
|
||||
{ |
|
||||
throw new ArgumentNullException("samplePoints"); |
|
||||
} |
|
||||
|
|
||||
if (null == sampleValues) |
|
||||
{ |
|
||||
throw new ArgumentNullException("sampleValues"); |
|
||||
} |
|
||||
|
|
||||
if (null == barycentricWeights) |
|
||||
{ |
|
||||
throw new ArgumentNullException("barycentricWeights"); |
|
||||
} |
|
||||
|
|
||||
if (samplePoints.Count < 1) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException("samplePoints"); |
|
||||
} |
|
||||
|
|
||||
if (samplePoints.Count != sampleValues.Count) |
|
||||
{ |
|
||||
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength); |
|
||||
} |
|
||||
|
|
||||
if (samplePoints.Count != barycentricWeights.Count) |
|
||||
{ |
|
||||
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength); |
|
||||
} |
|
||||
|
|
||||
_points = samplePoints; |
|
||||
_values = sampleValues; |
|
||||
_weights = barycentricWeights; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Interpolate at point t.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated value x(t).</returns>
|
|
||||
public double Interpolate(double t) |
|
||||
{ |
|
||||
// trivial case: only one sample?
|
|
||||
if (_points.Count == 1) |
|
||||
{ |
|
||||
return _values[0]; |
|
||||
} |
|
||||
|
|
||||
// evaluate closest point and offset from that point (no sorting assumed)
|
|
||||
int closestPoint = 0; |
|
||||
double offset = t - _points[0]; |
|
||||
for (int i = 1; i < _points.Count; i++) |
|
||||
{ |
|
||||
if (Math.Abs(t - _points[i]) < Math.Abs(offset)) |
|
||||
{ |
|
||||
offset = t - _points[i]; |
|
||||
closestPoint = i; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// trivial case: on a known sample point?
|
|
||||
if (offset == 0.0) |
|
||||
{ |
|
||||
// NOTE (cdrnet, 200908) not offset.AlmostZero() by design
|
|
||||
return _values[closestPoint]; |
|
||||
} |
|
||||
|
|
||||
if (Math.Abs(offset) > 1e-150) |
|
||||
{ |
|
||||
// no need to guard against overflow, so use fast formula
|
|
||||
closestPoint = -1; |
|
||||
offset = 1.0; |
|
||||
} |
|
||||
|
|
||||
double s1 = 0.0; |
|
||||
double s2 = 0.0; |
|
||||
for (int i = 0; i < _points.Count; i++) |
|
||||
{ |
|
||||
if (i != closestPoint) |
|
||||
{ |
|
||||
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]); |
|
||||
s2 = s2 + v; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return s1/s2; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated first derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate twice at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated second derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate2(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Indefinite integral at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to integrate at.</param>
|
|
||||
double IInterpolation.Integrate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Definite integral between points a and b. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="a">Left bound of the integration interval [a,b].</param>
|
|
||||
/// <param name="b">Right bound of the integration interval [a,b].</param>
|
|
||||
double IInterpolation.Integrate(double a, double b) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,215 +0,0 @@ |
|||||
// <copyright file="EquidistantPolynomialInterpolation.cs" company="Math.NET">
|
|
||||
// Math.NET Numerics, part of the Math.NET Project
|
|
||||
// http://numerics.mathdotnet.com
|
|
||||
// http://github.com/mathnet/mathnet-numerics
|
|
||||
// http://mathnetnumerics.codeplex.com
|
|
||||
//
|
|
||||
// Copyright (c) 2009-2013 Math.NET
|
|
||||
//
|
|
||||
// Permission is hereby granted, free of charge, to any person
|
|
||||
// obtaining a copy of this software and associated documentation
|
|
||||
// files (the "Software"), to deal in the Software without
|
|
||||
// restriction, including without limitation the rights to use,
|
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||
// copies of the Software, and to permit persons to whom the
|
|
||||
// Software is furnished to do so, subject to the following
|
|
||||
// conditions:
|
|
||||
//
|
|
||||
// The above copyright notice and this permission notice shall be
|
|
||||
// included in all copies or substantial portions of the Software.
|
|
||||
//
|
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace MathNet.Numerics.Interpolation |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Barycentric Polynomial Interpolation where the given sample points are equidistant.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// This algorithm neither supports differentiation nor integration.
|
|
||||
/// </remarks>
|
|
||||
public class EquidistantPolynomialInterpolation : IInterpolation |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Internal Barycentric Interpolation
|
|
||||
/// </summary>
|
|
||||
readonly BarycentricInterpolation _barycentric; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the EquidistantPolynomialInterpolation class.
|
|
||||
/// </summary>
|
|
||||
public EquidistantPolynomialInterpolation() |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the EquidistantPolynomialInterpolation class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="leftBound">Left bound of the sample point interval.</param>
|
|
||||
/// <param name="rightBound">Right bound of the sample point interval.</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t) where t is equidistant over [a,b], i.e. x[i] = x(a+(b-a)*i/(n-1))</param>
|
|
||||
public EquidistantPolynomialInterpolation(double leftBound, double rightBound, IList<double> sampleValues) |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
Initialize(leftBound, rightBound, sampleValues); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the EquidistantPolynomialInterpolation class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="samplePoints">Equidistant Sample Points t = a+(b-a)*i/(n-1)</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t) where t are equidistant over [a,b], i.e. x[i] = x(a+(b-a)*i/(n-1))</param>
|
|
||||
public EquidistantPolynomialInterpolation(IList<double> samplePoints, IList<double> sampleValues) |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
Initialize(samplePoints, sampleValues); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsDifferentiation |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsIntegration |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initialize the interpolation method with the given sampls in the interval [leftBound,rightBound].
|
|
||||
/// </summary>
|
|
||||
/// <param name="leftBound">Left bound of the sample point interval.</param>
|
|
||||
/// <param name="rightBound">Right bound of the sample point interval.</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t) where t are equidistant over [a,b], i.e. x[i] = x(a+(b-a)*i/(n-1))</param>
|
|
||||
public void Initialize(double leftBound, double rightBound, IList<double> sampleValues) |
|
||||
{ |
|
||||
if (null == sampleValues) |
|
||||
{ |
|
||||
throw new ArgumentNullException("sampleValues"); |
|
||||
} |
|
||||
|
|
||||
if (sampleValues.Count < 1) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException("sampleValues"); |
|
||||
} |
|
||||
|
|
||||
var samplePoints = new double[sampleValues.Count]; |
|
||||
samplePoints[0] = leftBound; |
|
||||
double step = (rightBound - leftBound)/(samplePoints.Length - 1); |
|
||||
for (int i = 1; i < samplePoints.Length; i++) |
|
||||
{ |
|
||||
samplePoints[i] = samplePoints[i - 1] + step; |
|
||||
} |
|
||||
|
|
||||
var weights = EvaluateBarycentricWeights(sampleValues.Count); |
|
||||
|
|
||||
_barycentric.Initialize(samplePoints, sampleValues, weights); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initialize the interpolation method with the given sample set (no sorting assumed).
|
|
||||
/// </summary>
|
|
||||
/// <param name="samplePoints">Equidistant Sample Points t = a+(b-a)*i/(n-1)</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t) where t are equidistant over [a,b], i.e. x[i] = x(a+(b-a)*i/(n-1))</param>
|
|
||||
public void Initialize(IList<double> samplePoints, IList<double> sampleValues) |
|
||||
{ |
|
||||
if (null == sampleValues) |
|
||||
{ |
|
||||
throw new ArgumentNullException("sampleValues"); |
|
||||
} |
|
||||
|
|
||||
var weights = EvaluateBarycentricWeights(sampleValues.Count); |
|
||||
_barycentric.Initialize(samplePoints, sampleValues, weights); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Evaluate the barycentric weights as used
|
|
||||
/// internally by this interpolation algorithm.
|
|
||||
/// </summary>
|
|
||||
/// <param name="sampleCount">Count of Sample Values x(t).</param>
|
|
||||
/// <returns>Barycentric Weight Vector</returns>
|
|
||||
public static double[] EvaluateBarycentricWeights(int sampleCount) |
|
||||
{ |
|
||||
if (sampleCount < 1) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException("sampleCount"); |
|
||||
} |
|
||||
|
|
||||
var weights = new double[sampleCount]; |
|
||||
weights[0] = 1.0; |
|
||||
for (int i = 1; i < weights.Length; i++) |
|
||||
{ |
|
||||
weights[i] = -(weights[i - 1]*(weights.Length - i))/i; |
|
||||
} |
|
||||
|
|
||||
return weights; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Interpolate at point t.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated value x(t).</returns>
|
|
||||
public double Interpolate(double t) |
|
||||
{ |
|
||||
return _barycentric.Interpolate(t); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated first derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate twice at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated second derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate2(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Indefinite integral at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to integrate at.</param>
|
|
||||
double IInterpolation.Integrate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Definite integral between points a and b. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="a">Left bound of the integration interval [a,b].</param>
|
|
||||
/// <param name="b">Right bound of the integration interval [a,b].</param>
|
|
||||
double IInterpolation.Integrate(double a, double b) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,284 +0,0 @@ |
|||||
// <copyright file="FloaterHormannRationalInterpolation.cs" company="Math.NET">
|
|
||||
// Math.NET Numerics, part of the Math.NET Project
|
|
||||
// http://numerics.mathdotnet.com
|
|
||||
// http://github.com/mathnet/mathnet-numerics
|
|
||||
// http://mathnetnumerics.codeplex.com
|
|
||||
//
|
|
||||
// Copyright (c) 2009-2013 Math.NET
|
|
||||
//
|
|
||||
// Permission is hereby granted, free of charge, to any person
|
|
||||
// obtaining a copy of this software and associated documentation
|
|
||||
// files (the "Software"), to deal in the Software without
|
|
||||
// restriction, including without limitation the rights to use,
|
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||
// copies of the Software, and to permit persons to whom the
|
|
||||
// Software is furnished to do so, subject to the following
|
|
||||
// conditions:
|
|
||||
//
|
|
||||
// The above copyright notice and this permission notice shall be
|
|
||||
// included in all copies or substantial portions of the Software.
|
|
||||
//
|
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
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>
|
|
||||
/// <remarks>
|
|
||||
/// This algorithm neither supports differentiation nor integration.
|
|
||||
/// </remarks>
|
|
||||
public class FloaterHormannRationalInterpolation : IInterpolation |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Internal Barycentric Interpolation
|
|
||||
/// </summary>
|
|
||||
readonly BarycentricInterpolation _barycentric; |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the FloaterHormannRationalInterpolation class.
|
|
||||
/// </summary>
|
|
||||
public FloaterHormannRationalInterpolation() |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the FloaterHormannRationalInterpolation class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="samplePoints">Sample Points t</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t)</param>
|
|
||||
public FloaterHormannRationalInterpolation(IList<double> samplePoints, IList<double> sampleValues) |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
Initialize(samplePoints, sampleValues); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the FloaterHormannRationalInterpolation class.
|
|
||||
/// </summary>
|
|
||||
/// <param name="samplePoints">Sample Points t</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t)</param>
|
|
||||
/// <param name="order">
|
|
||||
/// Order of the interpolation scheme, 0 <= order <= N.
|
|
||||
/// In most cases a value between 3 and 8 gives good results.
|
|
||||
/// </param>
|
|
||||
public FloaterHormannRationalInterpolation(IList<double> samplePoints, IList<double> sampleValues, int order) |
|
||||
{ |
|
||||
_barycentric = new BarycentricInterpolation(); |
|
||||
Initialize(samplePoints, sampleValues, order); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports differentiation (interpolated derivative).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsDifferentiation |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Gets a value indicating whether the algorithm supports integration (interpolated quadrature).
|
|
||||
/// </summary>
|
|
||||
bool IInterpolation.SupportsIntegration |
|
||||
{ |
|
||||
get { return false; } |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Initialize the interpolation method with the given sample set.
|
|
||||
/// </summary>
|
|
||||
/// <remarks>
|
|
||||
/// The interpolation scheme order will be set to 3.
|
|
||||
/// </remarks>
|
|
||||
/// <param name="samplePoints">Sample Points t (no sorting assumed)</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t)</param>
|
|
||||
public void Initialize(IList<double> samplePoints, IList<double> sampleValues) |
|
||||
{ |
|
||||
if (null == samplePoints) |
|
||||
{ |
|
||||
throw new ArgumentNullException("samplePoints"); |
|
||||
} |
|
||||
|
|
||||
double[] weights = EvaluateBarycentricWeights(samplePoints, sampleValues, |
|
||||
Math.Min(3, samplePoints.Count - 1)); |
|
||||
|
|
||||
_barycentric.Initialize(samplePoints, sampleValues, weights); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// 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>
|
|
||||
/// <param name="order">
|
|
||||
/// Order of the interpolation scheme, 0 <= order <= N.
|
|
||||
/// In most cases a value between 3 and 8 gives good results.
|
|
||||
/// </param>
|
|
||||
public void Initialize(IList<double> samplePoints, IList<double> sampleValues, int order) |
|
||||
{ |
|
||||
double[] weights = EvaluateBarycentricWeights(samplePoints, sampleValues, order); |
|
||||
_barycentric.Initialize(samplePoints, sampleValues, weights); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Evaluate the barycentric weights as used
|
|
||||
/// internally by this interpolation algorithm.
|
|
||||
/// </summary>
|
|
||||
/// <param name="samplePoints">Sample Points t</param>
|
|
||||
/// <param name="sampleValues">Sample Values x(t)</param>
|
|
||||
/// <param name="order">
|
|
||||
/// Order of the interpolation scheme, 0 <= order <= N.
|
|
||||
/// In most cases a value between 3 and 8 gives good results.
|
|
||||
/// </param>
|
|
||||
/// <returns>Barycentric Weight Vector</returns>
|
|
||||
public static double[] EvaluateBarycentricWeights(IList<double> samplePoints, IList<double> sampleValues, int order) |
|
||||
{ |
|
||||
if (null == samplePoints) |
|
||||
{ |
|
||||
throw new ArgumentNullException("samplePoints"); |
|
||||
} |
|
||||
|
|
||||
if (null == sampleValues) |
|
||||
{ |
|
||||
throw new ArgumentNullException("sampleValues"); |
|
||||
} |
|
||||
|
|
||||
if (samplePoints.Count < 1) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException("samplePoints"); |
|
||||
} |
|
||||
|
|
||||
if (samplePoints.Count != sampleValues.Count) |
|
||||
{ |
|
||||
throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLength); |
|
||||
} |
|
||||
|
|
||||
if (0 > order || samplePoints.Count <= order) |
|
||||
{ |
|
||||
throw new ArgumentOutOfRangeException("order"); |
|
||||
} |
|
||||
|
|
||||
var sortedWeights = new double[sampleValues.Count]; |
|
||||
var sortedPoints = new double[samplePoints.Count]; |
|
||||
samplePoints.CopyTo(sortedPoints, 0); |
|
||||
|
|
||||
// order: odd -> negative, even -> positive
|
|
||||
double sign = ((order & 0x1) == 0x1) ? -1.0 : 1.0; |
|
||||
|
|
||||
// init permutation vector
|
|
||||
var perm = new int[sortedWeights.Length]; |
|
||||
for (int i = 0; i < perm.Length; i++) |
|
||||
{ |
|
||||
perm[i] = i; |
|
||||
} |
|
||||
|
|
||||
// sort and update permutation vector
|
|
||||
for (int i = 0; i < perm.Length - 1; i++) |
|
||||
{ |
|
||||
for (int j = i + 1; j < perm.Length; j++) |
|
||||
{ |
|
||||
if (sortedPoints[j] < sortedPoints[i]) |
|
||||
{ |
|
||||
double s = sortedPoints[i]; |
|
||||
sortedPoints[i] = sortedPoints[j]; |
|
||||
sortedPoints[j] = s; |
|
||||
int k = perm[i]; |
|
||||
perm[i] = perm[j]; |
|
||||
perm[j] = k; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
// compute barycentric weights
|
|
||||
for (int k = 0; k < sortedWeights.Length; k++) |
|
||||
{ |
|
||||
double s = 0; |
|
||||
for (int i = Math.Max(k - order, 0); i <= Math.Min(k, sortedWeights.Length - 1 - order); i++) |
|
||||
{ |
|
||||
double v = 1; |
|
||||
for (int j = i; j <= i + order; j++) |
|
||||
{ |
|
||||
if (j != k) |
|
||||
{ |
|
||||
v = v/Math.Abs(sortedPoints[k] - sortedPoints[j]); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
s = s + v; |
|
||||
} |
|
||||
|
|
||||
sortedWeights[k] = sign*s; |
|
||||
sign = -sign; |
|
||||
} |
|
||||
|
|
||||
// reorder back to original order, based on the permutation vector.
|
|
||||
var weights = new double[sortedWeights.Length]; |
|
||||
for (int i = 0; i < weights.Length; i++) |
|
||||
{ |
|
||||
weights[perm[i]] = sortedWeights[i]; |
|
||||
} |
|
||||
return weights; |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Interpolate at point t.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated value x(t).</returns>
|
|
||||
public double Interpolate(double t) |
|
||||
{ |
|
||||
return _barycentric.Interpolate(t); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated first derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Differentiate twice at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to interpolate at.</param>
|
|
||||
/// <returns>Interpolated second derivative at point t.</returns>
|
|
||||
double IInterpolation.Differentiate2(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Indefinite integral at point t. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="t">Point t to integrate at.</param>
|
|
||||
double IInterpolation.Integrate(double t) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
|
|
||||
/// <summary>
|
|
||||
/// Definite integral between points a and b. NOT SUPPORTED.
|
|
||||
/// </summary>
|
|
||||
/// <param name="a">Left bound of the integration interval [a,b].</param>
|
|
||||
/// <param name="b">Right bound of the integration interval [a,b].</param>
|
|
||||
double IInterpolation.Integrate(double a, double b) |
|
||||
{ |
|
||||
throw new NotSupportedException(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue