本文整理汇总了C#中spline1dinterpolant类的典型用法代码示例。如果您正苦于以下问题:C# spline1dinterpolant类的具体用法?C# spline1dinterpolant怎么用?C# spline1dinterpolant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
spline1dinterpolant类属于命名空间,在下文中一共展示了spline1dinterpolant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: spline1dbuildlinear
/*************************************************************************
This subroutine builds linear spline interpolant
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
N - points count, N>=2
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dbuildlinear(double[] x,
double[] y,
int n,
ref spline1dinterpolant c)
{
int i = 0;
x = (double[])x.Clone();
y = (double[])y.Clone();
System.Diagnostics.Debug.Assert(n>1, "Spline1DBuildLinear: N<2!");
//
// Sort points
//
heapsortpoints(ref x, ref y, n);
//
// Build
//
c.periodic = false;
c.n = n;
c.k = 3;
c.x = new double[n];
c.c = new double[4*(n-1)];
for(i=0; i<=n-1; i++)
{
c.x[i] = x[i];
}
for(i=0; i<=n-2; i++)
{
c.c[4*i+0] = y[i];
c.c[4*i+1] = (y[i+1]-y[i])/(x[i+1]-x[i]);
c.c[4*i+2] = 0;
c.c[4*i+3] = 0;
}
}
示例2: spline1dbuildhermite
/*************************************************************************
This subroutine builds Hermite spline interpolant.
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
D - derivatives, array[0..N-1]
N - points count, N>=2
OUTPUT PARAMETERS:
C - spline interpolant.
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dbuildhermite(double[] x,
double[] y,
double[] d,
int n,
ref spline1dinterpolant c)
{
int i = 0;
double delta = 0;
double delta2 = 0;
double delta3 = 0;
x = (double[])x.Clone();
y = (double[])y.Clone();
d = (double[])d.Clone();
System.Diagnostics.Debug.Assert(n>=2, "BuildHermiteSpline: N<2!");
//
// Sort points
//
heapsortdpoints(ref x, ref y, ref d, n);
//
// Build
//
c.x = new double[n];
c.c = new double[4*(n-1)];
c.periodic = false;
c.k = 3;
c.n = n;
for(i=0; i<=n-1; i++)
{
c.x[i] = x[i];
}
for(i=0; i<=n-2; i++)
{
delta = x[i+1]-x[i];
delta2 = AP.Math.Sqr(delta);
delta3 = delta*delta2;
c.c[4*i+0] = y[i];
c.c[4*i+1] = d[i];
c.c[4*i+2] = (3*(y[i+1]-y[i])-2*d[i]*delta-d[i+1]*delta)/delta2;
c.c[4*i+3] = (2*(y[i]-y[i+1])+d[i]*delta+d[i+1]*delta)/delta3;
}
}
示例3: count
/*************************************************************************
This subroutine builds linear spline interpolant
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
N - points count (optional):
* N>=2
* if given, only first N points are used to build spline
* if not given, automatically detected from X/Y sizes
(len(X) must be equal to len(Y))
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dbuildlinear(double[] x,
double[] y,
int n,
spline1dinterpolant c)
{
int i = 0;
x = (double[])x.Clone();
y = (double[])y.Clone();
alglib.ap.assert(n>1, "Spline1DBuildLinear: N<2!");
alglib.ap.assert(alglib.ap.len(x)>=n, "Spline1DBuildLinear: Length(X)<N!");
alglib.ap.assert(alglib.ap.len(y)>=n, "Spline1DBuildLinear: Length(Y)<N!");
//
// check and sort points
//
alglib.ap.assert(apserv.isfinitevector(x, n), "Spline1DBuildLinear: X contains infinite or NAN values!");
alglib.ap.assert(apserv.isfinitevector(y, n), "Spline1DBuildLinear: Y contains infinite or NAN values!");
heapsortpoints(ref x, ref y, n);
alglib.ap.assert(apserv.aredistinct(x, n), "Spline1DBuildLinear: at least two consequent points are too close!");
//
// Build
//
c.periodic = false;
c.n = n;
c.k = 3;
c.continuity = 0;
c.x = new double[n];
c.c = new double[4*(n-1)+2];
for(i=0; i<=n-1; i++)
{
c.x[i] = x[i];
}
for(i=0; i<=n-2; i++)
{
c.c[4*i+0] = y[i];
c.c[4*i+1] = (y[i+1]-y[i])/(x[i+1]-x[i]);
c.c[4*i+2] = 0;
c.c[4*i+3] = 0;
}
c.c[4*(n-1)+0] = y[n-1];
c.c[4*(n-1)+1] = c.c[4*(n-2)+1];
}
示例4: points
/*************************************************************************
This function builds monotone cubic Hermite interpolant. This interpolant
is monotonic in [x(0),x(n-1)] and is constant outside of this interval.
In case y[] form non-monotonic sequence, interpolant is piecewise
monotonic. Say, for x=(0,1,2,3,4) and y=(0,1,2,1,0) interpolant will
monotonically grow at [0..2] and monotonically decrease at [2..4].
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]. Subroutine automatically
sorts points, so caller may pass unsorted array.
Y - function values, array[0..N-1]
N - the number of points(N>=2).
OUTPUT PARAMETERS:
C - spline interpolant.
-- ALGLIB PROJECT --
Copyright 21.06.2012 by Bochkanov Sergey
*************************************************************************/
public static void spline1dbuildmonotone(double[] x,
double[] y,
int n,
spline1dinterpolant c)
{
double[] d = new double[0];
double[] ex = new double[0];
double[] ey = new double[0];
int[] p = new int[0];
double delta = 0;
double alpha = 0;
double beta = 0;
int tmpn = 0;
int sn = 0;
double ca = 0;
double cb = 0;
double epsilon = 0;
int i = 0;
int j = 0;
x = (double[])x.Clone();
y = (double[])y.Clone();
//
// Check lengths of arguments
//
alglib.ap.assert(n>=2, "Spline1DBuildMonotone: N<2");
alglib.ap.assert(alglib.ap.len(x)>=n, "Spline1DBuildMonotone: Length(X)<N");
alglib.ap.assert(alglib.ap.len(y)>=n, "Spline1DBuildMonotone: Length(Y)<N");
//
// Check and sort points
//
alglib.ap.assert(apserv.isfinitevector(x, n), "Spline1DBuildMonotone: X contains infinite or NAN values");
alglib.ap.assert(apserv.isfinitevector(y, n), "Spline1DBuildMonotone: Y contains infinite or NAN values");
heapsortppoints(ref x, ref y, ref p, n);
alglib.ap.assert(apserv.aredistinct(x, n), "Spline1DBuildMonotone: at least two consequent points are too close");
epsilon = math.machineepsilon;
n = n+2;
d = new double[n];
ex = new double[n];
ey = new double[n];
ex[0] = x[0]-Math.Abs(x[1]-x[0]);
ex[n-1] = x[n-3]+Math.Abs(x[n-3]-x[n-4]);
ey[0] = y[0];
ey[n-1] = y[n-3];
for(i=1; i<=n-2; i++)
{
ex[i] = x[i-1];
ey[i] = y[i-1];
}
//
// Init sign of the function for first segment
//
i = 0;
ca = 0;
do
{
ca = ey[i+1]-ey[i];
i = i+1;
}
while( !((double)(ca)!=(double)(0) || i>n-2) );
if( (double)(ca)!=(double)(0) )
{
ca = ca/Math.Abs(ca);
}
i = 0;
while( i<n-1 )
{
//
// Partition of the segment [X0;Xn]
//
tmpn = 1;
for(j=i; j<=n-2; j++)
{
cb = ey[j+1]-ey[j];
if( (double)(ca*cb)>=(double)(0) )
//.........这里部分代码省略.........
示例5: min
/*************************************************************************
This subroutine integrates the spline.
INPUT PARAMETERS:
C - spline interpolant.
X - right bound of the integration interval [a, x],
here 'a' denotes min(x[])
Result:
integral(S(t)dt,a,x)
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
public static double spline1dintegrate(spline1dinterpolant c,
double x)
{
double result = 0;
int n = 0;
int i = 0;
int j = 0;
int l = 0;
int r = 0;
int m = 0;
double w = 0;
double v = 0;
double t = 0;
double intab = 0;
double additionalterm = 0;
n = c.n;
//
// Periodic splines require special treatment. We make
// following transformation:
//
// integral(S(t)dt,A,X) = integral(S(t)dt,A,Z)+AdditionalTerm
//
// here X may lie outside of [A,B], Z lies strictly in [A,B],
// AdditionalTerm is equals to integral(S(t)dt,A,B) times some
// integer number (may be zero).
//
if( c.periodic && ((double)(x)<(double)(c.x[0]) || (double)(x)>(double)(c.x[c.n-1])) )
{
//
// compute integral(S(x)dx,A,B)
//
intab = 0;
for(i=0; i<=c.n-2; i++)
{
w = c.x[i+1]-c.x[i];
m = (c.k+1)*i;
intab = intab+c.c[m]*w;
v = w;
for(j=1; j<=c.k; j++)
{
v = v*w;
intab = intab+c.c[m+j]*v/(j+1);
}
}
//
// map X into [A,B]
//
apserv.apperiodicmap(ref x, c.x[0], c.x[c.n-1], ref t);
additionalterm = t*intab;
}
else
{
additionalterm = 0;
}
//
// Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included)
//
l = 0;
r = n-2+1;
while( l!=r-1 )
{
m = (l+r)/2;
if( (double)(c.x[m])>=(double)(x) )
{
r = m;
}
else
{
l = m;
}
}
//
// Integration
//
result = 0;
for(i=0; i<=l-1; i++)
{
w = c.x[i+1]-c.x[i];
m = (c.k+1)*i;
result = result+c.c[m]*w;
v = w;
//.........这里部分代码省略.........
示例6: spline1dlintransx
/*************************************************************************
This subroutine performs linear transformation of the spline argument.
INPUT PARAMETERS:
C - spline interpolant.
A, B- transformation coefficients: x = A*t + B
Result:
C - transformed spline
-- ALGLIB PROJECT --
Copyright 30.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dlintransx(spline1dinterpolant c,
double a,
double b)
{
int i = 0;
int n = 0;
double v = 0;
double dv = 0;
double d2v = 0;
double[] x = new double[0];
double[] y = new double[0];
double[] d = new double[0];
bool isperiodic = new bool();
int contval = 0;
alglib.ap.assert(c.k==3, "Spline1DLinTransX: internal error");
n = c.n;
x = new double[n];
y = new double[n];
d = new double[n];
//
// Unpack, X, Y, dY/dX.
// Scale and pack with Spline1DBuildHermite again.
//
if( (double)(a)==(double)(0) )
{
//
// Special case: A=0
//
v = spline1dcalc(c, b);
for(i=0; i<=n-1; i++)
{
x[i] = c.x[i];
y[i] = v;
d[i] = 0.0;
}
}
else
{
//
// General case, A<>0
//
for(i=0; i<=n-1; i++)
{
x[i] = c.x[i];
spline1ddiff(c, x[i], ref v, ref dv, ref d2v);
x[i] = (x[i]-b)/a;
y[i] = v;
d[i] = a*dv;
}
}
isperiodic = c.periodic;
contval = c.continuity;
if( contval>0 )
{
spline1dbuildhermite(x, y, d, n, c);
}
else
{
spline1dbuildlinear(x, y, n, c);
}
c.periodic = isperiodic;
c.continuity = contval;
}
示例7: spline1dcopy
/*************************************************************************
This subroutine makes the copy of the spline.
INPUT PARAMETERS:
C - spline interpolant.
Result:
CC - spline copy
-- ALGLIB PROJECT --
Copyright 29.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dcopy(spline1dinterpolant c,
spline1dinterpolant cc)
{
int s = 0;
int i_ = 0;
cc.periodic = c.periodic;
cc.n = c.n;
cc.k = c.k;
cc.continuity = c.continuity;
cc.x = new double[cc.n];
for(i_=0; i_<=cc.n-1;i_++)
{
cc.x[i_] = c.x[i_];
}
s = alglib.ap.len(c.c);
cc.c = new double[s];
for(i_=0; i_<=s-1;i_++)
{
cc.c[i_] = c.c[i_];
}
}
示例8: S
/*************************************************************************
This subroutine calculates the value of the spline at the given point X.
INPUT PARAMETERS:
C - spline interpolant
X - point
Result:
S(x)
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
public static double spline1dcalc(spline1dinterpolant c,
double x)
{
double result = 0;
int l = 0;
int r = 0;
int m = 0;
double t = 0;
alglib.ap.assert(c.k==3, "Spline1DCalc: internal error");
alglib.ap.assert(!Double.IsInfinity(x), "Spline1DCalc: infinite X!");
//
// special case: NaN
//
if( Double.IsNaN(x) )
{
result = Double.NaN;
return result;
}
//
// correct if periodic
//
if( c.periodic )
{
apserv.apperiodicmap(ref x, c.x[0], c.x[c.n-1], ref t);
}
//
// Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included)
//
l = 0;
r = c.n-2+1;
while( l!=r-1 )
{
m = (l+r)/2;
if( c.x[m]>=x )
{
r = m;
}
else
{
l = m;
}
}
//
// Interpolation
//
x = x-c.x[l];
m = 4*l;
result = c.c[m]+x*(c.c[m+1]+x*(c.c[m+2]+x*c.c[m+3]));
return result;
}
示例9: tasks
//.........这里部分代码省略.........
Spline1DFitCubicWC() - fitting by Cubic splines (less flexible,
more smooth)
Spline1DFitHermite() - "lightweight" Hermite fitting, without
invididual weights and constraints
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints (optional):
* 0<=K<M.
* K=0 means no constraints (XC/YC/DC are not used)
* if given, only first K elements of XC/YC/DC are used
* if not given, automatically determined from XC/YC/DC
M - number of basis functions (= 2 * number of nodes),
M>=4,
M IS EVEN!
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-2 means odd M was passed (which is not supported)
-1 means another errors in parameters passed
(N<=0, for example)
S - spline interpolant.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
IMPORTANT:
this subroitine supports only even M's
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the several special cases, however, we can guarantee consistency.
* one of this cases is M>=4 and constraints on the function value
(AND/OR its derivative) at the interval boundaries.
* another special case is M>=4 and ONE constraint on the function value
(OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
Our final recommendation is to use constraints WHEN AND ONLY when you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
public static void spline1dfithermitewc(double[] x, double[] y, double[] w, int n, double[] xc, double[] yc, int[] dc, int k, int m, out int info, out spline1dinterpolant s, out spline1dfitreport rep)
{
info = 0;
s = new spline1dinterpolant();
rep = new spline1dfitreport();
lsfit.spline1dfithermitewc(x, y, w, n, xc, yc, dc, k, m, ref info, s.innerobj, rep.innerobj);
return;
}
示例10: S
/*************************************************************************
Weighted fitting by penalized cubic spline.
Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
basis functions. Basis functions are cubic splines with natural boundary
conditions. Problem is regularized by adding non-linearity penalty to the
usual least squares penalty function:
S(x) = arg min { LS + P }, where
LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
rho - tunable constant given by user
C - automatically determined scale parameter,
makes penalty invariant with respect to scaling of X, Y, W.
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
problem.
N - number of points (optional):
* N>0
* if given, only first N elements of X/Y/W are processed
* if not given, automatically determined from X/Y/W sizes
M - number of basis functions ( = number_of_nodes), M>=4.
Rho - regularization constant passed by user. It penalizes
nonlinearity in the regression spline. It is logarithmically
scaled, i.e. actual value of regularization constant is
calculated as 10^Rho. It is automatically scaled so that:
* Rho=2.0 corresponds to moderate amount of nonlinearity
* generally, it should be somewhere in the [-8.0,+8.0]
If you do not want to penalize nonlineary,
pass small Rho. Values as low as -15 should work.
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearWC() subroutine.
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD or
Cholesky decomposition; problem may be
too ill-conditioned (very rare)
S - spline interpolant.
Rep - Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
NOTE 1: additional nodes are added to the spline outside of the fitting
interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
it is natural to force linearity outside of this interval.
NOTE 2: function automatically sorts points, so caller may pass unsorted
array.
-- ALGLIB PROJECT --
Copyright 19.10.2010 by Bochkanov Sergey
*************************************************************************/
public static void spline1dfitpenalizedw(double[] x, double[] y, double[] w, int n, int m, double rho, out int info, out spline1dinterpolant s, out spline1dfitreport rep)
{
info = 0;
s = new spline1dinterpolant();
rep = new spline1dfitreport();
lsfit.spline1dfitpenalizedw(x, y, w, n, m, rho, ref info, s.innerobj, rep.innerobj);
return;
}
示例11: S
/*************************************************************************
This subroutine calculates the value of the spline at the given point X.
INPUT PARAMETERS:
C - spline interpolant
X - point
Result:
S(x)
-- ALGLIB PROJECT --
Copyright 23.06.2007 by Bochkanov Sergey
*************************************************************************/
public static double spline1dcalc(ref spline1dinterpolant c,
double x)
{
double result = 0;
int l = 0;
int r = 0;
int m = 0;
double t = 0;
System.Diagnostics.Debug.Assert(c.k==3, "Spline1DCalc: internal error");
//
// correct if periodic
//
if( c.periodic )
{
apserv.apperiodicmap(ref x, c.x[0], c.x[c.n-1], ref t);
}
//
// Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included)
//
l = 0;
r = c.n-2+1;
while( l!=r-1 )
{
m = (l+r)/2;
if( (double)(c.x[m])>=(double)(x) )
{
r = m;
}
else
{
l = m;
}
}
//
// Interpolation
//
x = x-c.x[l];
m = 4*l;
result = c.c[m]+x*(c.c[m+1]+x*(c.c[m+2]+x*c.c[m+3]));
return result;
}
示例12: Spline1DFitHermiteWC
/*************************************************************************
Least squares fitting by Hermite spline.
This subroutine is "lightweight" alternative for more complex and feature-
rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for
more information about subroutine parameters (we don't duplicate it here
because of length).
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
public static void spline1dfithermite(ref double[] x,
ref double[] y,
int n,
int m,
ref int info,
ref spline1dinterpolant s,
ref spline1dfitreport rep)
{
int i = 0;
double[] w = new double[0];
double[] xc = new double[0];
double[] yc = new double[0];
int[] dc = new int[0];
if( n>0 )
{
w = new double[n];
for(i=0; i<=n-1; i++)
{
w[i] = 1;
}
}
spline1dfithermitewc(ref x, ref y, ref w, n, ref xc, ref yc, ref dc, 0, m, ref info, ref s, ref rep);
}
示例13: tasks
//.........这里部分代码省略.........
more smooth)
Spline1DFitHermite() - "lightweight" Hermite fitting, without
invididual weights and constraints
INPUT PARAMETERS:
X - points, array[0..N-1].
Y - function values, array[0..N-1].
W - weights, array[0..N-1]
Each summand in square sum of approximation deviations from
given values is multiplied by the square of corresponding
weight. Fill it by 1's if you don't want to solve weighted
task.
N - number of points, N>0.
XC - points where spline values/derivatives are constrained,
array[0..K-1].
YC - values of constraints, array[0..K-1]
DC - array[0..K-1], types of constraints:
* DC[i]=0 means that S(XC[i])=YC[i]
* DC[i]=1 means that S'(XC[i])=YC[i]
SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
K - number of constraints, 0<=K<M.
K=0 means no constraints (XC/YC/DC are not used in such cases)
M - number of basis functions (= 2 * number of nodes),
M>=4,
M IS EVEN!
OUTPUT PARAMETERS:
Info- same format as in LSFitLinearW() subroutine:
* Info>0 task is solved
* Info<=0 an error occured:
-4 means inconvergence of internal SVD
-3 means inconsistent constraints
-2 means odd M was passed (which is not supported)
-1 means another errors in parameters passed
(N<=0, for example)
S - spline interpolant.
Rep - report, same format as in LSFitLinearW() subroutine.
Following fields are set:
* RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y
* MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED
IMPORTANT:
this subroitine doesn't calculate task's condition number for K<>0.
IMPORTANT:
this subroitine supports only even M's
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
Setting constraints can lead to undesired results, like ill-conditioned
behavior, or inconsistency being detected. From the other side, it allows
us to improve quality of the fit. Here we summarize our experience with
constrained regression splines:
* excessive constraints can be inconsistent. Splines are piecewise cubic
functions, and it is easy to create an example, where large number of
constraints concentrated in small area will result in inconsistency.
Just because spline is not flexible enough to satisfy all of them. And
same constraints spread across the [min(x),max(x)] will be perfectly
consistent.
* the more evenly constraints are spread across [min(x),max(x)], the more
chances that they will be consistent
* the greater is M (given fixed constraints), the more chances that
constraints will be consistent
* in the general case, consistency of constraints is NOT GUARANTEED.
* in the several special cases, however, we can guarantee consistency.
* one of this cases is M>=4 and constraints on the function value
(AND/OR its derivative) at the interval boundaries.
* another special case is M>=4 and ONE constraint on the function value
(OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
Our final recommendation is to use constraints WHEN AND ONLY when you
can't solve your task without them. Anything beyond special cases given
above is not guaranteed and may result in inconsistency.
-- ALGLIB PROJECT --
Copyright 18.08.2009 by Bochkanov Sergey
*************************************************************************/
public static void spline1dfithermitewc(ref double[] x,
ref double[] y,
ref double[] w,
int n,
ref double[] xc,
ref double[] yc,
ref int[] dc,
int k,
int m,
ref int info,
ref spline1dinterpolant s,
ref spline1dfitreport rep)
{
spline1dfitinternal(1, x, y, ref w, n, xc, yc, ref dc, k, m, ref info, ref s, ref rep);
}
示例14: spline1dbuildakima
/*************************************************************************
This subroutine builds Akima spline interpolant
INPUT PARAMETERS:
X - spline nodes, array[0..N-1]
Y - function values, array[0..N-1]
N - points count, N>=5
OUTPUT PARAMETERS:
C - spline interpolant
ORDER OF POINTS
Subroutine automatically sorts points, so caller may pass unsorted array.
-- ALGLIB PROJECT --
Copyright 24.06.2007 by Bochkanov Sergey
*************************************************************************/
public static void spline1dbuildakima(double[] x,
double[] y,
int n,
ref spline1dinterpolant c)
{
int i = 0;
double[] d = new double[0];
double[] w = new double[0];
double[] diff = new double[0];
x = (double[])x.Clone();
y = (double[])y.Clone();
System.Diagnostics.Debug.Assert(n>=5, "BuildAkimaSpline: N<5!");
//
// Sort points
//
heapsortpoints(ref x, ref y, n);
//
// Prepare W (weights), Diff (divided differences)
//
w = new double[n-1];
diff = new double[n-1];
for(i=0; i<=n-2; i++)
{
diff[i] = (y[i+1]-y[i])/(x[i+1]-x[i]);
}
for(i=1; i<=n-2; i++)
{
w[i] = Math.Abs(diff[i]-diff[i-1]);
}
//
// Prepare Hermite interpolation scheme
//
d = new double[n];
for(i=2; i<=n-3; i++)
{
if( (double)(Math.Abs(w[i-1])+Math.Abs(w[i+1]))!=(double)(0) )
{
d[i] = (w[i+1]*diff[i-1]+w[i-1]*diff[i])/(w[i+1]+w[i-1]);
}
else
{
d[i] = ((x[i+1]-x[i])*diff[i-1]+(x[i]-x[i-1])*diff[i])/(x[i+1]-x[i-1]);
}
}
d[0] = diffthreepoint(x[0], x[0], y[0], x[1], y[1], x[2], y[2]);
d[1] = diffthreepoint(x[1], x[0], y[0], x[1], y[1], x[2], y[2]);
d[n-2] = diffthreepoint(x[n-2], x[n-3], y[n-3], x[n-2], y[n-2], x[n-1], y[n-1]);
d[n-1] = diffthreepoint(x[n-1], x[n-3], y[n-3], x[n-2], y[n-2], x[n-1], y[n-1]);
//
// Build Akima spline using Hermite interpolation scheme
//
spline1dbuildhermite(x, y, d, n, ref c);
}
示例15: spline1dfithermitewc
public static void spline1dfithermitewc(double[] x, double[] y, double[] w, double[] xc, double[] yc, int[] dc, int m, out int info, out spline1dinterpolant s, out spline1dfitreport rep)
{
int n;
int k;
if( (ap.len(x)!=ap.len(y)) || (ap.len(x)!=ap.len(w)))
throw new alglibexception("Error while calling 'spline1dfithermitewc': looks like one of arguments has wrong size");
if( (ap.len(xc)!=ap.len(yc)) || (ap.len(xc)!=ap.len(dc)))
throw new alglibexception("Error while calling 'spline1dfithermitewc': looks like one of arguments has wrong size");
info = 0;
s = new spline1dinterpolant();
rep = new spline1dfitreport();
n = ap.len(x);
k = ap.len(xc);
lsfit.spline1dfithermitewc(x, y, w, n, xc, yc, dc, k, m, ref info, s.innerobj, rep.innerobj);
return;
}