/usr/include/polint.h is in libalglib-dev 2.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | /*************************************************************************
Copyright (c) 2006-2009, Sergey Bochkanov (ALGLIB project).
>>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
#ifndef _polint_h
#define _polint_h
#include "ap.h"
#include "ialglib.h"
#include "tsort.h"
#include "ratinterpolation.h"
#include "blas.h"
#include "reflections.h"
#include "creflections.h"
#include "hqrnd.h"
#include "matgen.h"
#include "ablasf.h"
#include "ablas.h"
#include "trfac.h"
#include "trlinsolve.h"
#include "safesolve.h"
#include "rcond.h"
#include "matinv.h"
#include "hblas.h"
#include "sblas.h"
#include "ortfac.h"
#include "rotations.h"
#include "bdsvd.h"
#include "svd.h"
#include "xblas.h"
#include "densesolver.h"
#include "linmin.h"
#include "minlbfgs.h"
#include "minlm.h"
#include "lsfit.h"
#include "ratint.h"
#include "apserv.h"
/*************************************************************************
Polynomial fitting report:
TaskRCond reciprocal of task's condition number
RMSError RMS error
AvgError average error
AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error
*************************************************************************/
struct polynomialfitreport
{
double taskrcond;
double rmserror;
double avgerror;
double avgrelerror;
double maxerror;
};
/*************************************************************************
Lagrange intepolant: generation of the model on the general grid.
This function has O(N^2) complexity.
INPUT PARAMETERS:
X - abscissas, array[0..N-1]
Y - function values, array[0..N-1]
N - number of points, N>=1
OIYTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialbuild(const ap::real_1d_array& x,
const ap::real_1d_array& y,
int n,
barycentricinterpolant& p);
/*************************************************************************
Lagrange intepolant: generation of the model on equidistant grid.
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1]
N - number of points, N>=1
for N=1 a constant model is constructed.
OIYTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialbuildeqdist(double a,
double b,
const ap::real_1d_array& y,
int n,
barycentricinterpolant& p);
/*************************************************************************
Lagrange intepolant on Chebyshev grid (first kind).
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1],
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n)))
N - number of points, N>=1
for N=1 a constant model is constructed.
OIYTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialbuildcheb1(double a,
double b,
const ap::real_1d_array& y,
int n,
barycentricinterpolant& p);
/*************************************************************************
Lagrange intepolant on Chebyshev grid (second kind).
This function has O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
Y - function values at the nodes, array[0..N-1],
Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)))
N - number of points, N>=1
for N=1 a constant model is constructed.
OIYTPUT PARAMETERS
P - barycentric model which represents Lagrange interpolant
(see ratint unit info and BarycentricCalc() description for
more information).
-- ALGLIB --
Copyright 03.12.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialbuildcheb2(double a,
double b,
const ap::real_1d_array& y,
int n,
barycentricinterpolant& p);
/*************************************************************************
Fast equidistant polynomial interpolation function with O(N) complexity
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on equidistant grid, N>=1
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolynomialBuildEqDist()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
double polynomialcalceqdist(double a,
double b,
const ap::real_1d_array& f,
int n,
double t);
/*************************************************************************
Fast polynomial interpolation function on Chebyshev points (first kind)
with O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (first kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb1()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
double polynomialcalccheb1(double a,
double b,
const ap::real_1d_array& f,
int n,
double t);
/*************************************************************************
Fast polynomial interpolation function on Chebyshev points (second kind)
with O(N) complexity.
INPUT PARAMETERS:
A - left boundary of [A,B]
B - right boundary of [A,B]
F - function values, array[0..N-1]
N - number of points on Chebyshev grid (second kind),
X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))
for N=1 a constant model is constructed.
T - position where P(x) is calculated
RESULT
value of the Lagrange interpolant at T
IMPORTANT
this function provides fast interface which is not overflow-safe
nor it is very precise.
the best option is to use PolIntBuildCheb2()/BarycentricCalc()
subroutines unless you are pretty sure that your data will not result
in overflow.
-- ALGLIB --
Copyright 02.12.2009 by Bochkanov Sergey
*************************************************************************/
double polynomialcalccheb2(double a,
double b,
const ap::real_1d_array& f,
int n,
double t);
/*************************************************************************
Least squares fitting by polynomial.
This subroutine is "lightweight" alternative for more complex and feature-
rich PolynomialFitWC(). See PolynomialFitWC() for more information about
subroutine parameters (we don't duplicate it here because of length)
-- ALGLIB PROJECT --
Copyright 12.10.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialfit(const ap::real_1d_array& x,
const ap::real_1d_array& y,
int n,
int m,
int& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
/*************************************************************************
Weighted fitting by Chebyshev polynomial in barycentric form, with
constraints on function values or first derivatives.
Small regularizing term is used when solving constrained tasks (to improve
stability).
Task is linear, so linear least squares solver is used. Complexity of this
computational scheme is O(N*M^2), mostly dominated by least squares solver
SEE ALSO:
PolynomialFit()
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 polynomial 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 P(XC[i])=YC[i]
* DC[i]=1 means that P'(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 (= polynomial_degree + 1), M>=1
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
-1 means another errors in parameters passed
(N<=0, for example)
P - interpolant in barycentric form.
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.
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:
* even simple constraints can be inconsistent, see Wikipedia article on
this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation
* 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 one special cases, however, we can guarantee consistency. This
case is: M>1 and constraints on the function values (NOT DERIVATIVES)
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 10.12.2009 by Bochkanov Sergey
*************************************************************************/
void polynomialfitwc(ap::real_1d_array x,
ap::real_1d_array y,
const ap::real_1d_array& w,
int n,
ap::real_1d_array xc,
ap::real_1d_array yc,
const ap::integer_1d_array& dc,
int k,
int m,
int& info,
barycentricinterpolant& p,
polynomialfitreport& rep);
#endif
|