Class documentation of Concepts

Loading...
Searching...
No Matches
interpolation.h
1/*************************************************************************
2ALGLIB 3.11.0 (source code generated 2017-05-11)
3Copyright (c) Sergey Bochkanov (ALGLIB project).
4
5>>> SOURCE LICENSE >>>
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation (www.fsf.org); either version 2 of the
9License, or (at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16A copy of the GNU General Public License is available at
17http://www.fsf.org/licensing/licenses
18>>> END OF LICENSE >>>
19*************************************************************************/
20#ifndef _interpolation_pkg_h
21#define _interpolation_pkg_h
22#include "ap.h"
23#include "alglibinternal.h"
24#include "alglibmisc.h"
25#include "linalg.h"
26#include "solvers.h"
27#include "specialfunctions.h"
28#include "integration.h"
29#include "optimization.h"
30
32//
33// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
34//
36namespace alglib_impl
37{
38typedef struct
39{
40 ae_int_t n;
41 ae_int_t nx;
42 ae_int_t d;
43 double r;
44 ae_int_t nw;
45 kdtree tree;
46 ae_int_t modeltype;
47 ae_matrix q;
48 ae_vector xbuf;
49 ae_vector tbuf;
50 ae_vector rbuf;
51 ae_matrix xybuf;
52 ae_int_t debugsolverfailures;
53 double debugworstrcond;
54 double debugbestrcond;
56typedef struct
57{
58 ae_int_t n;
59 double sy;
60 ae_vector x;
61 ae_vector y;
62 ae_vector w;
64typedef struct
65{
66 ae_bool periodic;
67 ae_int_t n;
68 ae_int_t k;
69 ae_int_t continuity;
70 ae_vector x;
71 ae_vector c;
73typedef struct
74{
75 ae_int_t n;
76 ae_bool periodic;
77 ae_vector p;
81typedef struct
82{
83 ae_int_t n;
84 ae_bool periodic;
85 ae_vector p;
90typedef struct
91{
92 ae_int_t k;
93 ae_int_t stype;
94 ae_int_t n;
95 ae_int_t m;
96 ae_int_t l;
97 ae_int_t d;
98 ae_vector x;
99 ae_vector y;
100 ae_vector z;
101 ae_vector f;
103typedef struct
104{
105 double taskrcond;
106 double rmserror;
107 double avgerror;
108 double avgrelerror;
109 double maxerror;
111typedef struct
112{
113 double taskrcond;
114 ae_int_t dbest;
115 double rmserror;
116 double avgerror;
117 double avgrelerror;
118 double maxerror;
120typedef struct
121{
122 double taskrcond;
123 double rmserror;
124 double avgerror;
125 double avgrelerror;
126 double maxerror;
128typedef struct
129{
130 double taskrcond;
131 ae_int_t iterationscount;
132 ae_int_t varidx;
133 double rmserror;
134 double avgerror;
135 double avgrelerror;
136 double maxerror;
137 double wrmserror;
138 ae_matrix covpar;
139 ae_vector errpar;
140 ae_vector errcurve;
141 ae_vector noise;
142 double r2;
144typedef struct
145{
146 ae_int_t optalgo;
147 ae_int_t m;
148 ae_int_t k;
149 double epsx;
150 ae_int_t maxits;
151 double stpmax;
152 ae_bool xrep;
153 ae_vector s;
154 ae_vector bndl;
155 ae_vector bndu;
156 ae_matrix taskx;
157 ae_vector tasky;
158 ae_int_t npoints;
159 ae_vector taskw;
160 ae_int_t nweights;
161 ae_int_t wkind;
162 ae_int_t wits;
163 double diffstep;
164 double teststep;
165 ae_matrix cleic;
166 ae_int_t nec;
167 ae_int_t nic;
168 ae_bool xupdated;
169 ae_bool needf;
170 ae_bool needfg;
171 ae_bool needfgh;
172 ae_int_t pointindex;
173 ae_vector x;
174 ae_vector c;
175 double f;
176 ae_vector g;
177 ae_matrix h;
178 ae_vector wcur;
179 ae_vector tmpct;
180 ae_vector tmp;
181 ae_vector tmpf;
182 ae_matrix tmpjac;
183 ae_matrix tmpjacw;
184 double tmpnoise;
185 matinvreport invrep;
186 ae_int_t repiterationscount;
187 ae_int_t repterminationtype;
188 ae_int_t repvaridx;
189 double reprmserror;
190 double repavgerror;
191 double repavgrelerror;
192 double repmaxerror;
193 double repwrmserror;
194 lsfitreport rep;
195 minlmstate optstate;
196 minlmreport optrep;
197 ae_int_t prevnpt;
198 ae_int_t prevalgo;
199 rcommstate rstate;
200} lsfitstate;
201typedef struct
202{
203 ae_vector x;
204 ae_vector curboxmin;
205 ae_vector curboxmax;
206 double curdist2;
207 ae_vector x123;
208 ae_vector y123;
210typedef struct
211{
212 ae_int_t ny;
213 ae_int_t nx;
214 ae_int_t bf;
215 ae_int_t nh;
216 ae_vector ri;
217 ae_vector s;
218 ae_vector kdroots;
219 ae_vector kdnodes;
220 ae_vector kdsplits;
221 ae_vector kdboxmin;
222 ae_vector kdboxmax;
223 ae_vector cw;
224 ae_matrix v;
225 double lambdareg;
226 ae_int_t maxits;
227 double supportr;
228 ae_int_t basisfunction;
229 rbfv2calcbuffer calcbuf;
230} rbfv2model;
231typedef struct
232{
233 rbfv2calcbuffer calcbuf;
234 ae_vector cx;
235 ae_vector rx;
236 ae_vector ry;
237 ae_vector tx;
238 ae_vector ty;
239 ae_vector rf;
241typedef struct
242{
243 ae_int_t terminationtype;
244 double maxerror;
245 double rmserror;
247typedef struct
248{
249 ae_int_t nfev;
250 ae_int_t iterationscount;
252typedef struct
253{
254 ae_int_t k;
255 ae_int_t stype;
256 ae_int_t n;
257 ae_int_t m;
258 ae_int_t d;
259 ae_vector x;
260 ae_vector y;
261 ae_vector f;
263typedef struct
264{
265 ae_vector calcbufxcx;
266 ae_matrix calcbufx;
267 ae_vector calcbuftags;
268 kdtreerequestbuffer requestbuffer;
270typedef struct
271{
272 ae_int_t ny;
273 ae_int_t nx;
274 ae_int_t nc;
275 ae_int_t nl;
276 kdtree tree;
277 ae_matrix xc;
278 ae_matrix wr;
279 double rmax;
280 ae_matrix v;
281 ae_vector calcbufxcx;
282 ae_matrix calcbufx;
283 ae_vector calcbuftags;
284} rbfv1model;
285typedef struct
286{
287 ae_vector tx;
288 ae_vector cx;
289 ae_vector ty;
290 ae_vector flag0;
291 ae_vector flag1;
292 ae_vector flag2;
293 ae_vector flag12;
294 ae_vector expbuf0;
295 ae_vector expbuf1;
296 ae_vector expbuf2;
297 kdtreerequestbuffer requestbuf;
298 ae_matrix calcbufx;
299 ae_vector calcbuftags;
301typedef struct
302{
303 ae_int_t arows;
304 ae_int_t acols;
305 ae_int_t annz;
306 ae_int_t iterationscount;
307 ae_int_t nmv;
308 ae_int_t terminationtype;
310typedef struct
311{
312 ae_int_t modelversion;
313 rbfv1calcbuffer bufv1;
314 rbfv2calcbuffer bufv2;
316typedef struct
317{
318 ae_int_t nx;
319 ae_int_t ny;
320 ae_int_t modelversion;
321 rbfv1model model1;
322 rbfv2model model2;
323 double lambdav;
324 double radvalue;
325 double radzvalue;
326 ae_int_t nlayers;
327 ae_int_t aterm;
328 ae_int_t algorithmtype;
329 double epsort;
330 double epserr;
331 ae_int_t maxits;
332 ae_int_t nnmaxits;
333 ae_int_t n;
334 ae_matrix x;
335 ae_matrix y;
336 ae_bool hasscale;
337 ae_vector s;
338} rbfmodel;
339typedef struct
340{
341 double rmserror;
342 double maxerror;
343 ae_int_t arows;
344 ae_int_t acols;
345 ae_int_t annz;
346 ae_int_t iterationscount;
347 ae_int_t nmv;
348 ae_int_t terminationtype;
349} rbfreport;
350
351}
352
354//
355// THIS SECTION CONTAINS C++ INTERFACE
356//
358namespace alglib
359{
360
361/*************************************************************************
362IDW interpolant.
363*************************************************************************/
365{
366public:
369 _idwinterpolant_owner& operator=(const _idwinterpolant_owner &rhs);
370 virtual ~_idwinterpolant_owner();
372 alglib_impl::idwinterpolant* c_ptr() const;
373protected:
375};
377{
378public:
380 idwinterpolant(const idwinterpolant &rhs);
381 idwinterpolant& operator=(const idwinterpolant &rhs);
382 virtual ~idwinterpolant();
383
384};
385
386/*************************************************************************
387Barycentric interpolant.
388*************************************************************************/
410
411/*************************************************************************
4121-dimensional spline interpolant
413*************************************************************************/
427{
428public:
431 spline1dinterpolant& operator=(const spline1dinterpolant &rhs);
432 virtual ~spline1dinterpolant();
433
434};
435
436/*************************************************************************
437Parametric spline inteprolant: 2-dimensional curve.
438
439You should not try to access its members directly - use PSpline2XXXXXXXX()
440functions instead.
441*************************************************************************/
455{
456public:
459 pspline2interpolant& operator=(const pspline2interpolant &rhs);
460 virtual ~pspline2interpolant();
461
462};
463
464
465/*************************************************************************
466Parametric spline inteprolant: 3-dimensional curve.
467
468You should not try to access its members directly - use PSpline3XXXXXXXX()
469functions instead.
470*************************************************************************/
484{
485public:
488 pspline3interpolant& operator=(const pspline3interpolant &rhs);
489 virtual ~pspline3interpolant();
490
491};
492
493/*************************************************************************
4943-dimensional spline inteprolant
495*************************************************************************/
509{
510public:
513 spline3dinterpolant& operator=(const spline3dinterpolant &rhs);
514 virtual ~spline3dinterpolant();
515
516};
517
518
519
520/*************************************************************************
521Polynomial fitting report:
522 TaskRCond reciprocal of task's condition number
523 RMSError RMS error
524 AvgError average error
525 AvgRelError average relative error (for non-zero Y[I])
526 MaxError maximum error
527*************************************************************************/
541{
542public:
545 polynomialfitreport& operator=(const polynomialfitreport &rhs);
546 virtual ~polynomialfitreport();
547 double &taskrcond;
548 double &rmserror;
549 double &avgerror;
550 double &avgrelerror;
551 double &maxerror;
552
553};
554
555
556/*************************************************************************
557Barycentric fitting report:
558 RMSError RMS error
559 AvgError average error
560 AvgRelError average relative error (for non-zero Y[I])
561 MaxError maximum error
562 TaskRCond reciprocal of task's condition number
563*************************************************************************/
577{
578public:
581 barycentricfitreport& operator=(const barycentricfitreport &rhs);
582 virtual ~barycentricfitreport();
583 double &taskrcond;
584 ae_int_t &dbest;
585 double &rmserror;
586 double &avgerror;
587 double &avgrelerror;
588 double &maxerror;
589
590};
591
592
593/*************************************************************************
594Spline fitting report:
595 RMSError RMS error
596 AvgError average error
597 AvgRelError average relative error (for non-zero Y[I])
598 MaxError maximum error
599
600Fields below are filled by obsolete functions (Spline1DFitCubic,
601Spline1DFitHermite). Modern fitting functions do NOT fill these fields:
602 TaskRCond reciprocal of task's condition number
603*************************************************************************/
617{
618public:
621 spline1dfitreport& operator=(const spline1dfitreport &rhs);
622 virtual ~spline1dfitreport();
623 double &taskrcond;
624 double &rmserror;
625 double &avgerror;
626 double &avgrelerror;
627 double &maxerror;
628
629};
630
631
632/*************************************************************************
633Least squares fitting report. This structure contains informational fields
634which are set by fitting functions provided by this unit.
635
636Different functions initialize different sets of fields, so you should
637read documentation on specific function you used in order to know which
638fields are initialized.
639
640 TaskRCond reciprocal of task's condition number
641 IterationsCount number of internal iterations
642
643 VarIdx if user-supplied gradient contains errors which were
644 detected by nonlinear fitter, this field is set to
645 index of the first component of gradient which is
646 suspected to be spoiled by bugs.
647
648 RMSError RMS error
649 AvgError average error
650 AvgRelError average relative error (for non-zero Y[I])
651 MaxError maximum error
652
653 WRMSError weighted RMS error
654
655 CovPar covariance matrix for parameters, filled by some solvers
656 ErrPar vector of errors in parameters, filled by some solvers
657 ErrCurve vector of fit errors - variability of the best-fit
658 curve, filled by some solvers.
659 Noise vector of per-point noise estimates, filled by
660 some solvers.
661 R2 coefficient of determination (non-weighted, non-adjusted),
662 filled by some solvers.
663*************************************************************************/
665{
666public:
669 _lsfitreport_owner& operator=(const _lsfitreport_owner &rhs);
670 virtual ~_lsfitreport_owner();
672 alglib_impl::lsfitreport* c_ptr() const;
673protected:
674 alglib_impl::lsfitreport *p_struct;
675};
677{
678public:
679 lsfitreport();
680 lsfitreport(const lsfitreport &rhs);
681 lsfitreport& operator=(const lsfitreport &rhs);
682 virtual ~lsfitreport();
683 double &taskrcond;
684 ae_int_t &iterationscount;
685 ae_int_t &varidx;
686 double &rmserror;
687 double &avgerror;
688 double &avgrelerror;
689 double &maxerror;
690 double &wrmserror;
691 real_2d_array covpar;
692 real_1d_array errpar;
693 real_1d_array errcurve;
694 real_1d_array noise;
695 double &r2;
696
697};
698
699
700/*************************************************************************
701Nonlinear fitter.
702
703You should use ALGLIB functions to work with fitter.
704Never try to access its fields directly!
705*************************************************************************/
707{
708public:
711 _lsfitstate_owner& operator=(const _lsfitstate_owner &rhs);
712 virtual ~_lsfitstate_owner();
714 alglib_impl::lsfitstate* c_ptr() const;
715protected:
716 alglib_impl::lsfitstate *p_struct;
717};
719{
720public:
721 lsfitstate();
722 lsfitstate(const lsfitstate &rhs);
723 lsfitstate& operator=(const lsfitstate &rhs);
724 virtual ~lsfitstate();
725 ae_bool &needf;
726 ae_bool &needfg;
727 ae_bool &needfgh;
728 ae_bool &xupdated;
730 double &f;
734
735};
736
737
738
739
740
741/*************************************************************************
7422-dimensional spline inteprolant
743*************************************************************************/
757{
758public:
761 spline2dinterpolant& operator=(const spline2dinterpolant &rhs);
762 virtual ~spline2dinterpolant();
763
764};
765
766
767
768/*************************************************************************
769Buffer object which is used to perform nearest neighbor requests in the
770multithreaded mode (multiple threads working with same KD-tree object).
771
772This object should be created with KDTreeCreateBuffer().
773*************************************************************************/
775{
776public:
779 _rbfcalcbuffer_owner& operator=(const _rbfcalcbuffer_owner &rhs);
780 virtual ~_rbfcalcbuffer_owner();
782 alglib_impl::rbfcalcbuffer* c_ptr() const;
783protected:
785};
787{
788public:
790 rbfcalcbuffer(const rbfcalcbuffer &rhs);
791 rbfcalcbuffer& operator=(const rbfcalcbuffer &rhs);
792 virtual ~rbfcalcbuffer();
793
794};
795
796
797/*************************************************************************
798RBF model.
799
800Never try to directly work with fields of this object - always use ALGLIB
801functions to use this object.
802*************************************************************************/
804{
805public:
808 _rbfmodel_owner& operator=(const _rbfmodel_owner &rhs);
809 virtual ~_rbfmodel_owner();
810 alglib_impl::rbfmodel* c_ptr();
811 alglib_impl::rbfmodel* c_ptr() const;
812protected:
813 alglib_impl::rbfmodel *p_struct;
814};
816{
817public:
818 rbfmodel();
819 rbfmodel(const rbfmodel &rhs);
820 rbfmodel& operator=(const rbfmodel &rhs);
821 virtual ~rbfmodel();
822
823};
824
825
826/*************************************************************************
827RBF solution report:
828* TerminationType - termination type, positive values - success,
829 non-positive - failure.
830
831Fields which are set by modern RBF solvers (hierarchical):
832* RMSError - root-mean-square error; NAN for old solvers (ML, QNN)
833* MaxError - maximum error; NAN for old solvers (ML, QNN)
834*************************************************************************/
836{
837public:
840 _rbfreport_owner& operator=(const _rbfreport_owner &rhs);
841 virtual ~_rbfreport_owner();
842 alglib_impl::rbfreport* c_ptr();
843 alglib_impl::rbfreport* c_ptr() const;
844protected:
845 alglib_impl::rbfreport *p_struct;
846};
848{
849public:
850 rbfreport();
851 rbfreport(const rbfreport &rhs);
852 rbfreport& operator=(const rbfreport &rhs);
853 virtual ~rbfreport();
854 double &rmserror;
855 double &maxerror;
856 ae_int_t &arows;
857 ae_int_t &acols;
858 ae_int_t &annz;
859 ae_int_t &iterationscount;
860 ae_int_t &nmv;
861 ae_int_t &terminationtype;
862
863};
864
865/*************************************************************************
866IDW interpolation
867
868INPUT PARAMETERS:
869 Z - IDW interpolant built with one of model building
870 subroutines.
871 X - array[0..NX-1], interpolation point
872
873Result:
874 IDW interpolant Z(X)
875
876 -- ALGLIB --
877 Copyright 02.03.2010 by Bochkanov Sergey
878*************************************************************************/
879double idwcalc(const idwinterpolant &z, const real_1d_array &x);
880
881
882/*************************************************************************
883IDW interpolant using modified Shepard method for uniform point
884distributions.
885
886INPUT PARAMETERS:
887 XY - X and Y values, array[0..N-1,0..NX].
888 First NX columns contain X-values, last column contain
889 Y-values.
890 N - number of nodes, N>0.
891 NX - space dimension, NX>=1.
892 D - nodal function type, either:
893 * 0 constant model. Just for demonstration only, worst
894 model ever.
895 * 1 linear model, least squares fitting. Simpe model for
896 datasets too small for quadratic models
897 * 2 quadratic model, least squares fitting. Best model
898 available (if your dataset is large enough).
899 * -1 "fast" linear model, use with caution!!! It is
900 significantly faster than linear/quadratic and better
901 than constant model. But it is less robust (especially
902 in the presence of noise).
903 NQ - number of points used to calculate nodal functions (ignored
904 for constant models). NQ should be LARGER than:
905 * max(1.5*(1+NX),2^NX+1) for linear model,
906 * max(3/4*(NX+2)*(NX+1),2^NX+1) for quadratic model.
907 Values less than this threshold will be silently increased.
908 NW - number of points used to calculate weights and to interpolate.
909 Required: >=2^NX+1, values less than this threshold will be
910 silently increased.
911 Recommended value: about 2*NQ
912
913OUTPUT PARAMETERS:
914 Z - IDW interpolant.
915
916NOTES:
917 * best results are obtained with quadratic models, worst - with constant
918 models
919 * when N is large, NQ and NW must be significantly smaller than N both
920 to obtain optimal performance and to obtain optimal accuracy. In 2 or
921 3-dimensional tasks NQ=15 and NW=25 are good values to start with.
922 * NQ and NW may be greater than N. In such cases they will be
923 automatically decreased.
924 * this subroutine is always succeeds (as long as correct parameters are
925 passed).
926 * see 'Multivariate Interpolation of Large Sets of Scattered Data' by
927 Robert J. Renka for more information on this algorithm.
928 * this subroutine assumes that point distribution is uniform at the small
929 scales. If it isn't - for example, points are concentrated along
930 "lines", but "lines" distribution is uniform at the larger scale - then
931 you should use IDWBuildModifiedShepardR()
932
933
934 -- ALGLIB PROJECT --
935 Copyright 02.03.2010 by Bochkanov Sergey
936*************************************************************************/
937void idwbuildmodifiedshepard(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolant &z);
938
939
940/*************************************************************************
941IDW interpolant using modified Shepard method for non-uniform datasets.
942
943This type of model uses constant nodal functions and interpolates using
944all nodes which are closer than user-specified radius R. It may be used
945when points distribution is non-uniform at the small scale, but it is at
946the distances as large as R.
947
948INPUT PARAMETERS:
949 XY - X and Y values, array[0..N-1,0..NX].
950 First NX columns contain X-values, last column contain
951 Y-values.
952 N - number of nodes, N>0.
953 NX - space dimension, NX>=1.
954 R - radius, R>0
955
956OUTPUT PARAMETERS:
957 Z - IDW interpolant.
958
959NOTES:
960* if there is less than IDWKMin points within R-ball, algorithm selects
961 IDWKMin closest ones, so that continuity properties of interpolant are
962 preserved even far from points.
963
964 -- ALGLIB PROJECT --
965 Copyright 11.04.2010 by Bochkanov Sergey
966*************************************************************************/
967void idwbuildmodifiedshepardr(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const double r, idwinterpolant &z);
968
969
970/*************************************************************************
971IDW model for noisy data.
972
973This subroutine may be used to handle noisy data, i.e. data with noise in
974OUTPUT values. It differs from IDWBuildModifiedShepard() in the following
975aspects:
976* nodal functions are not constrained to pass through nodes: Qi(xi)<>yi,
977 i.e. we have fitting instead of interpolation.
978* weights which are used during least squares fitting stage are all equal
979 to 1.0 (independently of distance)
980* "fast"-linear or constant nodal functions are not supported (either not
981 robust enough or too rigid)
982
983This problem require far more complex tuning than interpolation problems.
984Below you can find some recommendations regarding this problem:
985* focus on tuning NQ; it controls noise reduction. As for NW, you can just
986 make it equal to 2*NQ.
987* you can use cross-validation to determine optimal NQ.
988* optimal NQ is a result of complex tradeoff between noise level (more
989 noise = larger NQ required) and underlying function complexity (given
990 fixed N, larger NQ means smoothing of compex features in the data). For
991 example, NQ=N will reduce noise to the minimum level possible, but you
992 will end up with just constant/linear/quadratic (depending on D) least
993 squares model for the whole dataset.
994
995INPUT PARAMETERS:
996 XY - X and Y values, array[0..N-1,0..NX].
997 First NX columns contain X-values, last column contain
998 Y-values.
999 N - number of nodes, N>0.
1000 NX - space dimension, NX>=1.
1001 D - nodal function degree, either:
1002 * 1 linear model, least squares fitting. Simpe model for
1003 datasets too small for quadratic models (or for very
1004 noisy problems).
1005 * 2 quadratic model, least squares fitting. Best model
1006 available (if your dataset is large enough).
1007 NQ - number of points used to calculate nodal functions. NQ should
1008 be significantly larger than 1.5 times the number of
1009 coefficients in a nodal function to overcome effects of noise:
1010 * larger than 1.5*(1+NX) for linear model,
1011 * larger than 3/4*(NX+2)*(NX+1) for quadratic model.
1012 Values less than this threshold will be silently increased.
1013 NW - number of points used to calculate weights and to interpolate.
1014 Required: >=2^NX+1, values less than this threshold will be
1015 silently increased.
1016 Recommended value: about 2*NQ or larger
1017
1018OUTPUT PARAMETERS:
1019 Z - IDW interpolant.
1020
1021NOTES:
1022 * best results are obtained with quadratic models, linear models are not
1023 recommended to use unless you are pretty sure that it is what you want
1024 * this subroutine is always succeeds (as long as correct parameters are
1025 passed).
1026 * see 'Multivariate Interpolation of Large Sets of Scattered Data' by
1027 Robert J. Renka for more information on this algorithm.
1028
1029
1030 -- ALGLIB PROJECT --
1031 Copyright 02.03.2010 by Bochkanov Sergey
1032*************************************************************************/
1033void idwbuildnoisy(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolant &z);
1034
1035/*************************************************************************
1036Rational interpolation using barycentric formula
1037
1038F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
1039
1040Input parameters:
1041 B - barycentric interpolant built with one of model building
1042 subroutines.
1043 T - interpolation point
1044
1045Result:
1046 barycentric interpolant F(t)
1047
1048 -- ALGLIB --
1049 Copyright 17.08.2009 by Bochkanov Sergey
1050*************************************************************************/
1051double barycentriccalc(const barycentricinterpolant &b, const double t);
1052
1053
1054/*************************************************************************
1055Differentiation of barycentric interpolant: first derivative.
1056
1057Algorithm used in this subroutine is very robust and should not fail until
1058provided with values too close to MaxRealNumber (usually MaxRealNumber/N
1059or greater will overflow).
1060
1061INPUT PARAMETERS:
1062 B - barycentric interpolant built with one of model building
1063 subroutines.
1064 T - interpolation point
1065
1066OUTPUT PARAMETERS:
1067 F - barycentric interpolant at T
1068 DF - first derivative
1069
1070NOTE
1071
1072
1073 -- ALGLIB --
1074 Copyright 17.08.2009 by Bochkanov Sergey
1075*************************************************************************/
1076void barycentricdiff1(const barycentricinterpolant &b, const double t, double &f, double &df);
1077
1078
1079/*************************************************************************
1080Differentiation of barycentric interpolant: first/second derivatives.
1081
1082INPUT PARAMETERS:
1083 B - barycentric interpolant built with one of model building
1084 subroutines.
1085 T - interpolation point
1086
1087OUTPUT PARAMETERS:
1088 F - barycentric interpolant at T
1089 DF - first derivative
1090 D2F - second derivative
1091
1092NOTE: this algorithm may fail due to overflow/underflor if used on data
1093whose values are close to MaxRealNumber or MinRealNumber. Use more robust
1094BarycentricDiff1() subroutine in such cases.
1095
1096
1097 -- ALGLIB --
1098 Copyright 17.08.2009 by Bochkanov Sergey
1099*************************************************************************/
1100void barycentricdiff2(const barycentricinterpolant &b, const double t, double &f, double &df, double &d2f);
1101
1102
1103/*************************************************************************
1104This subroutine performs linear transformation of the argument.
1105
1106INPUT PARAMETERS:
1107 B - rational interpolant in barycentric form
1108 CA, CB - transformation coefficients: x = CA*t + CB
1109
1110OUTPUT PARAMETERS:
1111 B - transformed interpolant with X replaced by T
1112
1113 -- ALGLIB PROJECT --
1114 Copyright 19.08.2009 by Bochkanov Sergey
1115*************************************************************************/
1116void barycentriclintransx(const barycentricinterpolant &b, const double ca, const double cb);
1117
1118
1119/*************************************************************************
1120This subroutine performs linear transformation of the barycentric
1121interpolant.
1122
1123INPUT PARAMETERS:
1124 B - rational interpolant in barycentric form
1125 CA, CB - transformation coefficients: B2(x) = CA*B(x) + CB
1126
1127OUTPUT PARAMETERS:
1128 B - transformed interpolant
1129
1130 -- ALGLIB PROJECT --
1131 Copyright 19.08.2009 by Bochkanov Sergey
1132*************************************************************************/
1133void barycentriclintransy(const barycentricinterpolant &b, const double ca, const double cb);
1134
1135
1136/*************************************************************************
1137Extracts X/Y/W arrays from rational interpolant
1138
1139INPUT PARAMETERS:
1140 B - barycentric interpolant
1141
1142OUTPUT PARAMETERS:
1143 N - nodes count, N>0
1144 X - interpolation nodes, array[0..N-1]
1145 F - function values, array[0..N-1]
1146 W - barycentric weights, array[0..N-1]
1147
1148 -- ALGLIB --
1149 Copyright 17.08.2009 by Bochkanov Sergey
1150*************************************************************************/
1151void barycentricunpack(const barycentricinterpolant &b, ae_int_t &n, real_1d_array &x, real_1d_array &y, real_1d_array &w);
1152
1153
1154/*************************************************************************
1155Rational interpolant from X/Y/W arrays
1156
1157F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i]))
1158
1159INPUT PARAMETERS:
1160 X - interpolation nodes, array[0..N-1]
1161 F - function values, array[0..N-1]
1162 W - barycentric weights, array[0..N-1]
1163 N - nodes count, N>0
1164
1165OUTPUT PARAMETERS:
1166 B - barycentric interpolant built from (X, Y, W)
1167
1168 -- ALGLIB --
1169 Copyright 17.08.2009 by Bochkanov Sergey
1170*************************************************************************/
1171void barycentricbuildxyw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, barycentricinterpolant &b);
1172
1173
1174/*************************************************************************
1175Rational interpolant without poles
1176
1177The subroutine constructs the rational interpolating function without real
1178poles (see 'Barycentric rational interpolation with no poles and high
1179rates of approximation', Michael S. Floater. and Kai Hormann, for more
1180information on this subject).
1181
1182Input parameters:
1183 X - interpolation nodes, array[0..N-1].
1184 Y - function values, array[0..N-1].
1185 N - number of nodes, N>0.
1186 D - order of the interpolation scheme, 0 <= D <= N-1.
1187 D<0 will cause an error.
1188 D>=N it will be replaced with D=N-1.
1189 if you don't know what D to choose, use small value about 3-5.
1190
1191Output parameters:
1192 B - barycentric interpolant.
1193
1194Note:
1195 this algorithm always succeeds and calculates the weights with close
1196 to machine precision.
1197
1198 -- ALGLIB PROJECT --
1199 Copyright 17.06.2007 by Bochkanov Sergey
1200*************************************************************************/
1201void barycentricbuildfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t d, barycentricinterpolant &b);
1202
1203/*************************************************************************
1204This subroutine builds linear spline interpolant
1205
1206INPUT PARAMETERS:
1207 X - spline nodes, array[0..N-1]
1208 Y - function values, array[0..N-1]
1209 N - points count (optional):
1210 * N>=2
1211 * if given, only first N points are used to build spline
1212 * if not given, automatically detected from X/Y sizes
1213 (len(X) must be equal to len(Y))
1214
1215OUTPUT PARAMETERS:
1216 C - spline interpolant
1217
1218
1219ORDER OF POINTS
1220
1221Subroutine automatically sorts points, so caller may pass unsorted array.
1222
1223 -- ALGLIB PROJECT --
1224 Copyright 24.06.2007 by Bochkanov Sergey
1225*************************************************************************/
1226void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c);
1227void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c);
1228
1229
1230/*************************************************************************
1231This subroutine builds cubic spline interpolant.
1232
1233INPUT PARAMETERS:
1234 X - spline nodes, array[0..N-1].
1235 Y - function values, array[0..N-1].
1236
1237OPTIONAL PARAMETERS:
1238 N - points count:
1239 * N>=2
1240 * if given, only first N points are used to build spline
1241 * if not given, automatically detected from X/Y sizes
1242 (len(X) must be equal to len(Y))
1243 BoundLType - boundary condition type for the left boundary
1244 BoundL - left boundary condition (first or second derivative,
1245 depending on the BoundLType)
1246 BoundRType - boundary condition type for the right boundary
1247 BoundR - right boundary condition (first or second derivative,
1248 depending on the BoundRType)
1249
1250OUTPUT PARAMETERS:
1251 C - spline interpolant
1252
1253ORDER OF POINTS
1254
1255Subroutine automatically sorts points, so caller may pass unsorted array.
1256
1257SETTING BOUNDARY VALUES:
1258
1259The BoundLType/BoundRType parameters can have the following values:
1260 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1261 In this case:
1262 * both BoundLType and BoundRType must be equal to -1.
1263 * BoundL/BoundR are ignored
1264 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1265 * 0, which corresponds to the parabolically terminated spline
1266 (BoundL and/or BoundR are ignored).
1267 * 1, which corresponds to the first derivative boundary condition
1268 * 2, which corresponds to the second derivative boundary condition
1269 * by default, BoundType=0 is used
1270
1271PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1272
1273Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1274However, this subroutine doesn't require you to specify equal values for
1275the first and last points - it automatically forces them to be equal by
1276copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1277Y[last_point]. However it is recommended to pass consistent values of Y[],
1278i.e. to make Y[first_point]=Y[last_point].
1279
1280 -- ALGLIB PROJECT --
1281 Copyright 23.06.2007 by Bochkanov Sergey
1282*************************************************************************/
1283void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, spline1dinterpolant &c);
1284void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c);
1285
1286
1287/*************************************************************************
1288This function solves following problem: given table y[] of function values
1289at nodes x[], it calculates and returns table of function derivatives d[]
1290(calculated at the same nodes x[]).
1291
1292This function yields same result as Spline1DBuildCubic() call followed by
1293sequence of Spline1DDiff() calls, but it can be several times faster when
1294called for ordered X[] and X2[].
1295
1296INPUT PARAMETERS:
1297 X - spline nodes
1298 Y - function values
1299
1300OPTIONAL PARAMETERS:
1301 N - points count:
1302 * N>=2
1303 * if given, only first N points are used
1304 * if not given, automatically detected from X/Y sizes
1305 (len(X) must be equal to len(Y))
1306 BoundLType - boundary condition type for the left boundary
1307 BoundL - left boundary condition (first or second derivative,
1308 depending on the BoundLType)
1309 BoundRType - boundary condition type for the right boundary
1310 BoundR - right boundary condition (first or second derivative,
1311 depending on the BoundRType)
1312
1313OUTPUT PARAMETERS:
1314 D - derivative values at X[]
1315
1316ORDER OF POINTS
1317
1318Subroutine automatically sorts points, so caller may pass unsorted array.
1319Derivative values are correctly reordered on return, so D[I] is always
1320equal to S'(X[I]) independently of points order.
1321
1322SETTING BOUNDARY VALUES:
1323
1324The BoundLType/BoundRType parameters can have the following values:
1325 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1326 In this case:
1327 * both BoundLType and BoundRType must be equal to -1.
1328 * BoundL/BoundR are ignored
1329 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1330 * 0, which corresponds to the parabolically terminated spline
1331 (BoundL and/or BoundR are ignored).
1332 * 1, which corresponds to the first derivative boundary condition
1333 * 2, which corresponds to the second derivative boundary condition
1334 * by default, BoundType=0 is used
1335
1336PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1337
1338Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1339However, this subroutine doesn't require you to specify equal values for
1340the first and last points - it automatically forces them to be equal by
1341copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1342Y[last_point]. However it is recommended to pass consistent values of Y[],
1343i.e. to make Y[first_point]=Y[last_point].
1344
1345 -- ALGLIB PROJECT --
1346 Copyright 03.09.2010 by Bochkanov Sergey
1347*************************************************************************/
1348void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, real_1d_array &d);
1349void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, real_1d_array &d);
1350
1351
1352/*************************************************************************
1353This function solves following problem: given table y[] of function values
1354at nodes x[], it calculates and returns tables of first and second
1355function derivatives d1[] and d2[] (calculated at the same nodes x[]).
1356
1357This function yields same result as Spline1DBuildCubic() call followed by
1358sequence of Spline1DDiff() calls, but it can be several times faster when
1359called for ordered X[] and X2[].
1360
1361INPUT PARAMETERS:
1362 X - spline nodes
1363 Y - function values
1364
1365OPTIONAL PARAMETERS:
1366 N - points count:
1367 * N>=2
1368 * if given, only first N points are used
1369 * if not given, automatically detected from X/Y sizes
1370 (len(X) must be equal to len(Y))
1371 BoundLType - boundary condition type for the left boundary
1372 BoundL - left boundary condition (first or second derivative,
1373 depending on the BoundLType)
1374 BoundRType - boundary condition type for the right boundary
1375 BoundR - right boundary condition (first or second derivative,
1376 depending on the BoundRType)
1377
1378OUTPUT PARAMETERS:
1379 D1 - S' values at X[]
1380 D2 - S'' values at X[]
1381
1382ORDER OF POINTS
1383
1384Subroutine automatically sorts points, so caller may pass unsorted array.
1385Derivative values are correctly reordered on return, so D[I] is always
1386equal to S'(X[I]) independently of points order.
1387
1388SETTING BOUNDARY VALUES:
1389
1390The BoundLType/BoundRType parameters can have the following values:
1391 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1392 In this case:
1393 * both BoundLType and BoundRType must be equal to -1.
1394 * BoundL/BoundR are ignored
1395 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1396 * 0, which corresponds to the parabolically terminated spline
1397 (BoundL and/or BoundR are ignored).
1398 * 1, which corresponds to the first derivative boundary condition
1399 * 2, which corresponds to the second derivative boundary condition
1400 * by default, BoundType=0 is used
1401
1402PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1403
1404Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1405However, this subroutine doesn't require you to specify equal values for
1406the first and last points - it automatically forces them to be equal by
1407copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1408Y[last_point]. However it is recommended to pass consistent values of Y[],
1409i.e. to make Y[first_point]=Y[last_point].
1410
1411 -- ALGLIB PROJECT --
1412 Copyright 03.09.2010 by Bochkanov Sergey
1413*************************************************************************/
1414void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, real_1d_array &d1, real_1d_array &d2);
1415void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, real_1d_array &d1, real_1d_array &d2);
1416
1417
1418/*************************************************************************
1419This function solves following problem: given table y[] of function values
1420at old nodes x[] and new nodes x2[], it calculates and returns table of
1421function values y2[] (calculated at x2[]).
1422
1423This function yields same result as Spline1DBuildCubic() call followed by
1424sequence of Spline1DDiff() calls, but it can be several times faster when
1425called for ordered X[] and X2[].
1426
1427INPUT PARAMETERS:
1428 X - old spline nodes
1429 Y - function values
1430 X2 - new spline nodes
1431
1432OPTIONAL PARAMETERS:
1433 N - points count:
1434 * N>=2
1435 * if given, only first N points from X/Y are used
1436 * if not given, automatically detected from X/Y sizes
1437 (len(X) must be equal to len(Y))
1438 BoundLType - boundary condition type for the left boundary
1439 BoundL - left boundary condition (first or second derivative,
1440 depending on the BoundLType)
1441 BoundRType - boundary condition type for the right boundary
1442 BoundR - right boundary condition (first or second derivative,
1443 depending on the BoundRType)
1444 N2 - new points count:
1445 * N2>=2
1446 * if given, only first N2 points from X2 are used
1447 * if not given, automatically detected from X2 size
1448
1449OUTPUT PARAMETERS:
1450 F2 - function values at X2[]
1451
1452ORDER OF POINTS
1453
1454Subroutine automatically sorts points, so caller may pass unsorted array.
1455Function values are correctly reordered on return, so F2[I] is always
1456equal to S(X2[I]) independently of points order.
1457
1458SETTING BOUNDARY VALUES:
1459
1460The BoundLType/BoundRType parameters can have the following values:
1461 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1462 In this case:
1463 * both BoundLType and BoundRType must be equal to -1.
1464 * BoundL/BoundR are ignored
1465 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1466 * 0, which corresponds to the parabolically terminated spline
1467 (BoundL and/or BoundR are ignored).
1468 * 1, which corresponds to the first derivative boundary condition
1469 * 2, which corresponds to the second derivative boundary condition
1470 * by default, BoundType=0 is used
1471
1472PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1473
1474Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1475However, this subroutine doesn't require you to specify equal values for
1476the first and last points - it automatically forces them to be equal by
1477copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1478Y[last_point]. However it is recommended to pass consistent values of Y[],
1479i.e. to make Y[first_point]=Y[last_point].
1480
1481 -- ALGLIB PROJECT --
1482 Copyright 03.09.2010 by Bochkanov Sergey
1483*************************************************************************/
1484void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2);
1485void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, const real_1d_array &x2, real_1d_array &y2);
1486
1487
1488/*************************************************************************
1489This function solves following problem: given table y[] of function values
1490at old nodes x[] and new nodes x2[], it calculates and returns table of
1491function values y2[] and derivatives d2[] (calculated at x2[]).
1492
1493This function yields same result as Spline1DBuildCubic() call followed by
1494sequence of Spline1DDiff() calls, but it can be several times faster when
1495called for ordered X[] and X2[].
1496
1497INPUT PARAMETERS:
1498 X - old spline nodes
1499 Y - function values
1500 X2 - new spline nodes
1501
1502OPTIONAL PARAMETERS:
1503 N - points count:
1504 * N>=2
1505 * if given, only first N points from X/Y are used
1506 * if not given, automatically detected from X/Y sizes
1507 (len(X) must be equal to len(Y))
1508 BoundLType - boundary condition type for the left boundary
1509 BoundL - left boundary condition (first or second derivative,
1510 depending on the BoundLType)
1511 BoundRType - boundary condition type for the right boundary
1512 BoundR - right boundary condition (first or second derivative,
1513 depending on the BoundRType)
1514 N2 - new points count:
1515 * N2>=2
1516 * if given, only first N2 points from X2 are used
1517 * if not given, automatically detected from X2 size
1518
1519OUTPUT PARAMETERS:
1520 F2 - function values at X2[]
1521 D2 - first derivatives at X2[]
1522
1523ORDER OF POINTS
1524
1525Subroutine automatically sorts points, so caller may pass unsorted array.
1526Function values are correctly reordered on return, so F2[I] is always
1527equal to S(X2[I]) independently of points order.
1528
1529SETTING BOUNDARY VALUES:
1530
1531The BoundLType/BoundRType parameters can have the following values:
1532 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1533 In this case:
1534 * both BoundLType and BoundRType must be equal to -1.
1535 * BoundL/BoundR are ignored
1536 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1537 * 0, which corresponds to the parabolically terminated spline
1538 (BoundL and/or BoundR are ignored).
1539 * 1, which corresponds to the first derivative boundary condition
1540 * 2, which corresponds to the second derivative boundary condition
1541 * by default, BoundType=0 is used
1542
1543PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1544
1545Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1546However, this subroutine doesn't require you to specify equal values for
1547the first and last points - it automatically forces them to be equal by
1548copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1549Y[last_point]. However it is recommended to pass consistent values of Y[],
1550i.e. to make Y[first_point]=Y[last_point].
1551
1552 -- ALGLIB PROJECT --
1553 Copyright 03.09.2010 by Bochkanov Sergey
1554*************************************************************************/
1555void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2, real_1d_array &d2);
1556void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2);
1557
1558
1559/*************************************************************************
1560This function solves following problem: given table y[] of function values
1561at old nodes x[] and new nodes x2[], it calculates and returns table of
1562function values y2[], first and second derivatives d2[] and dd2[]
1563(calculated at x2[]).
1564
1565This function yields same result as Spline1DBuildCubic() call followed by
1566sequence of Spline1DDiff() calls, but it can be several times faster when
1567called for ordered X[] and X2[].
1568
1569INPUT PARAMETERS:
1570 X - old spline nodes
1571 Y - function values
1572 X2 - new spline nodes
1573
1574OPTIONAL PARAMETERS:
1575 N - points count:
1576 * N>=2
1577 * if given, only first N points from X/Y are used
1578 * if not given, automatically detected from X/Y sizes
1579 (len(X) must be equal to len(Y))
1580 BoundLType - boundary condition type for the left boundary
1581 BoundL - left boundary condition (first or second derivative,
1582 depending on the BoundLType)
1583 BoundRType - boundary condition type for the right boundary
1584 BoundR - right boundary condition (first or second derivative,
1585 depending on the BoundRType)
1586 N2 - new points count:
1587 * N2>=2
1588 * if given, only first N2 points from X2 are used
1589 * if not given, automatically detected from X2 size
1590
1591OUTPUT PARAMETERS:
1592 F2 - function values at X2[]
1593 D2 - first derivatives at X2[]
1594 DD2 - second derivatives at X2[]
1595
1596ORDER OF POINTS
1597
1598Subroutine automatically sorts points, so caller may pass unsorted array.
1599Function values are correctly reordered on return, so F2[I] is always
1600equal to S(X2[I]) independently of points order.
1601
1602SETTING BOUNDARY VALUES:
1603
1604The BoundLType/BoundRType parameters can have the following values:
1605 * -1, which corresonds to the periodic (cyclic) boundary conditions.
1606 In this case:
1607 * both BoundLType and BoundRType must be equal to -1.
1608 * BoundL/BoundR are ignored
1609 * Y[last] is ignored (it is assumed to be equal to Y[first]).
1610 * 0, which corresponds to the parabolically terminated spline
1611 (BoundL and/or BoundR are ignored).
1612 * 1, which corresponds to the first derivative boundary condition
1613 * 2, which corresponds to the second derivative boundary condition
1614 * by default, BoundType=0 is used
1615
1616PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1617
1618Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1619However, this subroutine doesn't require you to specify equal values for
1620the first and last points - it automatically forces them to be equal by
1621copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1622Y[last_point]. However it is recommended to pass consistent values of Y[],
1623i.e. to make Y[first_point]=Y[last_point].
1624
1625 -- ALGLIB PROJECT --
1626 Copyright 03.09.2010 by Bochkanov Sergey
1627*************************************************************************/
1628void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2, real_1d_array &d2, real_1d_array &dd2);
1629void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y, const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2, real_1d_array &dd2);
1630
1631
1632/*************************************************************************
1633This subroutine builds Catmull-Rom spline interpolant.
1634
1635INPUT PARAMETERS:
1636 X - spline nodes, array[0..N-1].
1637 Y - function values, array[0..N-1].
1638
1639OPTIONAL PARAMETERS:
1640 N - points count:
1641 * N>=2
1642 * if given, only first N points are used to build spline
1643 * if not given, automatically detected from X/Y sizes
1644 (len(X) must be equal to len(Y))
1645 BoundType - boundary condition type:
1646 * -1 for periodic boundary condition
1647 * 0 for parabolically terminated spline (default)
1648 Tension - tension parameter:
1649 * tension=0 corresponds to classic Catmull-Rom spline (default)
1650 * 0<tension<1 corresponds to more general form - cardinal spline
1651
1652OUTPUT PARAMETERS:
1653 C - spline interpolant
1654
1655
1656ORDER OF POINTS
1657
1658Subroutine automatically sorts points, so caller may pass unsorted array.
1659
1660PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS:
1661
1662Problems with periodic boundary conditions have Y[first_point]=Y[last_point].
1663However, this subroutine doesn't require you to specify equal values for
1664the first and last points - it automatically forces them to be equal by
1665copying Y[first_point] (corresponds to the leftmost, minimal X[]) to
1666Y[last_point]. However it is recommended to pass consistent values of Y[],
1667i.e. to make Y[first_point]=Y[last_point].
1668
1669 -- ALGLIB PROJECT --
1670 Copyright 23.06.2007 by Bochkanov Sergey
1671*************************************************************************/
1672void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundtype, const double tension, spline1dinterpolant &c);
1673void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c);
1674
1675
1676/*************************************************************************
1677This subroutine builds Hermite spline interpolant.
1678
1679INPUT PARAMETERS:
1680 X - spline nodes, array[0..N-1]
1681 Y - function values, array[0..N-1]
1682 D - derivatives, array[0..N-1]
1683 N - points count (optional):
1684 * N>=2
1685 * if given, only first N points are used to build spline
1686 * if not given, automatically detected from X/Y sizes
1687 (len(X) must be equal to len(Y))
1688
1689OUTPUT PARAMETERS:
1690 C - spline interpolant.
1691
1692
1693ORDER OF POINTS
1694
1695Subroutine automatically sorts points, so caller may pass unsorted array.
1696
1697 -- ALGLIB PROJECT --
1698 Copyright 23.06.2007 by Bochkanov Sergey
1699*************************************************************************/
1700void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, const real_1d_array &d, const ae_int_t n, spline1dinterpolant &c);
1701void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, const real_1d_array &d, spline1dinterpolant &c);
1702
1703
1704/*************************************************************************
1705This subroutine builds Akima spline interpolant
1706
1707INPUT PARAMETERS:
1708 X - spline nodes, array[0..N-1]
1709 Y - function values, array[0..N-1]
1710 N - points count (optional):
1711 * N>=2
1712 * if given, only first N points are used to build spline
1713 * if not given, automatically detected from X/Y sizes
1714 (len(X) must be equal to len(Y))
1715
1716OUTPUT PARAMETERS:
1717 C - spline interpolant
1718
1719
1720ORDER OF POINTS
1721
1722Subroutine automatically sorts points, so caller may pass unsorted array.
1723
1724 -- ALGLIB PROJECT --
1725 Copyright 24.06.2007 by Bochkanov Sergey
1726*************************************************************************/
1727void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c);
1728void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c);
1729
1730
1731/*************************************************************************
1732This subroutine calculates the value of the spline at the given point X.
1733
1734INPUT PARAMETERS:
1735 C - spline interpolant
1736 X - point
1737
1738Result:
1739 S(x)
1740
1741 -- ALGLIB PROJECT --
1742 Copyright 23.06.2007 by Bochkanov Sergey
1743*************************************************************************/
1744double spline1dcalc(const spline1dinterpolant &c, const double x);
1745
1746
1747/*************************************************************************
1748This subroutine differentiates the spline.
1749
1750INPUT PARAMETERS:
1751 C - spline interpolant.
1752 X - point
1753
1754Result:
1755 S - S(x)
1756 DS - S'(x)
1757 D2S - S''(x)
1758
1759 -- ALGLIB PROJECT --
1760 Copyright 24.06.2007 by Bochkanov Sergey
1761*************************************************************************/
1762void spline1ddiff(const spline1dinterpolant &c, const double x, double &s, double &ds, double &d2s);
1763
1764
1765/*************************************************************************
1766This subroutine unpacks the spline into the coefficients table.
1767
1768INPUT PARAMETERS:
1769 C - spline interpolant.
1770 X - point
1771
1772OUTPUT PARAMETERS:
1773 Tbl - coefficients table, unpacked format, array[0..N-2, 0..5].
1774 For I = 0...N-2:
1775 Tbl[I,0] = X[i]
1776 Tbl[I,1] = X[i+1]
1777 Tbl[I,2] = C0
1778 Tbl[I,3] = C1
1779 Tbl[I,4] = C2
1780 Tbl[I,5] = C3
1781 On [x[i], x[i+1]] spline is equals to:
1782 S(x) = C0 + C1*t + C2*t^2 + C3*t^3
1783 t = x-x[i]
1784
1785NOTE:
1786 You can rebuild spline with Spline1DBuildHermite() function, which
1787 accepts as inputs function values and derivatives at nodes, which are
1788 easy to calculate when you have coefficients.
1789
1790 -- ALGLIB PROJECT --
1791 Copyright 29.06.2007 by Bochkanov Sergey
1792*************************************************************************/
1793void spline1dunpack(const spline1dinterpolant &c, ae_int_t &n, real_2d_array &tbl);
1794
1795
1796/*************************************************************************
1797This subroutine performs linear transformation of the spline argument.
1798
1799INPUT PARAMETERS:
1800 C - spline interpolant.
1801 A, B- transformation coefficients: x = A*t + B
1802Result:
1803 C - transformed spline
1804
1805 -- ALGLIB PROJECT --
1806 Copyright 30.06.2007 by Bochkanov Sergey
1807*************************************************************************/
1808void spline1dlintransx(const spline1dinterpolant &c, const double a, const double b);
1809
1810
1811/*************************************************************************
1812This subroutine performs linear transformation of the spline.
1813
1814INPUT PARAMETERS:
1815 C - spline interpolant.
1816 A, B- transformation coefficients: S2(x) = A*S(x) + B
1817Result:
1818 C - transformed spline
1819
1820 -- ALGLIB PROJECT --
1821 Copyright 30.06.2007 by Bochkanov Sergey
1822*************************************************************************/
1823void spline1dlintransy(const spline1dinterpolant &c, const double a, const double b);
1824
1825
1826/*************************************************************************
1827This subroutine integrates the spline.
1828
1829INPUT PARAMETERS:
1830 C - spline interpolant.
1831 X - right bound of the integration interval [a, x],
1832 here 'a' denotes min(x[])
1833Result:
1834 integral(S(t)dt,a,x)
1835
1836 -- ALGLIB PROJECT --
1837 Copyright 23.06.2007 by Bochkanov Sergey
1838*************************************************************************/
1839double spline1dintegrate(const spline1dinterpolant &c, const double x);
1840
1841
1842/*************************************************************************
1843This function builds monotone cubic Hermite interpolant. This interpolant
1844is monotonic in [x(0),x(n-1)] and is constant outside of this interval.
1845
1846In case y[] form non-monotonic sequence, interpolant is piecewise
1847monotonic. Say, for x=(0,1,2,3,4) and y=(0,1,2,1,0) interpolant will
1848monotonically grow at [0..2] and monotonically decrease at [2..4].
1849
1850INPUT PARAMETERS:
1851 X - spline nodes, array[0..N-1]. Subroutine automatically
1852 sorts points, so caller may pass unsorted array.
1853 Y - function values, array[0..N-1]
1854 N - the number of points(N>=2).
1855
1856OUTPUT PARAMETERS:
1857 C - spline interpolant.
1858
1859 -- ALGLIB PROJECT --
1860 Copyright 21.06.2012 by Bochkanov Sergey
1861*************************************************************************/
1862void spline1dbuildmonotone(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c);
1863void spline1dbuildmonotone(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c);
1864
1865/*************************************************************************
1866This function builds non-periodic 2-dimensional parametric spline which
1867starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).
1868
1869INPUT PARAMETERS:
1870 XY - points, array[0..N-1,0..1].
1871 XY[I,0:1] corresponds to the Ith point.
1872 Order of points is important!
1873 N - points count, N>=5 for Akima splines, N>=2 for other types of
1874 splines.
1875 ST - spline type:
1876 * 0 Akima spline
1877 * 1 parabolically terminated Catmull-Rom spline (Tension=0)
1878 * 2 parabolically terminated cubic spline
1879 PT - parameterization type:
1880 * 0 uniform
1881 * 1 chord length
1882 * 2 centripetal
1883
1884OUTPUT PARAMETERS:
1885 P - parametric spline interpolant
1886
1887
1888NOTES:
1889* this function assumes that there all consequent points are distinct.
1890 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on.
1891 However, non-consequent points may coincide, i.e. we can have (x0,y0)=
1892 =(x2,y2).
1893
1894 -- ALGLIB PROJECT --
1895 Copyright 28.05.2010 by Bochkanov Sergey
1896*************************************************************************/
1897void pspline2build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p);
1898
1899
1900/*************************************************************************
1901This function builds non-periodic 3-dimensional parametric spline which
1902starts at (X[0],Y[0],Z[0]) and ends at (X[N-1],Y[N-1],Z[N-1]).
1903
1904Same as PSpline2Build() function, but for 3D, so we won't duplicate its
1905description here.
1906
1907 -- ALGLIB PROJECT --
1908 Copyright 28.05.2010 by Bochkanov Sergey
1909*************************************************************************/
1910void pspline3build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p);
1911
1912
1913/*************************************************************************
1914This function builds periodic 2-dimensional parametric spline which
1915starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then
1916back to (X[0],Y[0]).
1917
1918INPUT PARAMETERS:
1919 XY - points, array[0..N-1,0..1].
1920 XY[I,0:1] corresponds to the Ith point.
1921 XY[N-1,0:1] must be different from XY[0,0:1].
1922 Order of points is important!
1923 N - points count, N>=3 for other types of splines.
1924 ST - spline type:
1925 * 1 Catmull-Rom spline (Tension=0) with cyclic boundary conditions
1926 * 2 cubic spline with cyclic boundary conditions
1927 PT - parameterization type:
1928 * 0 uniform
1929 * 1 chord length
1930 * 2 centripetal
1931
1932OUTPUT PARAMETERS:
1933 P - parametric spline interpolant
1934
1935
1936NOTES:
1937* this function assumes that there all consequent points are distinct.
1938 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on.
1939 However, non-consequent points may coincide, i.e. we can have (x0,y0)=
1940 =(x2,y2).
1941* last point of sequence is NOT equal to the first point. You shouldn't
1942 make curve "explicitly periodic" by making them equal.
1943
1944 -- ALGLIB PROJECT --
1945 Copyright 28.05.2010 by Bochkanov Sergey
1946*************************************************************************/
1947void pspline2buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p);
1948
1949
1950/*************************************************************************
1951This function builds periodic 3-dimensional parametric spline which
1952starts at (X[0],Y[0],Z[0]), goes through all points to (X[N-1],Y[N-1],Z[N-1])
1953and then back to (X[0],Y[0],Z[0]).
1954
1955Same as PSpline2Build() function, but for 3D, so we won't duplicate its
1956description here.
1957
1958 -- ALGLIB PROJECT --
1959 Copyright 28.05.2010 by Bochkanov Sergey
1960*************************************************************************/
1961void pspline3buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p);
1962
1963
1964/*************************************************************************
1965This function returns vector of parameter values correspoding to points.
1966
1967I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P) we
1968have
1969 (X[0],Y[0]) = PSpline2Calc(P,U[0]),
1970 (X[1],Y[1]) = PSpline2Calc(P,U[1]),
1971 (X[2],Y[2]) = PSpline2Calc(P,U[2]),
1972 ...
1973
1974INPUT PARAMETERS:
1975 P - parametric spline interpolant
1976
1977OUTPUT PARAMETERS:
1978 N - array size
1979 T - array[0..N-1]
1980
1981
1982NOTES:
1983* for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1
1984* for periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1
1985
1986 -- ALGLIB PROJECT --
1987 Copyright 28.05.2010 by Bochkanov Sergey
1988*************************************************************************/
1989void pspline2parametervalues(const pspline2interpolant &p, ae_int_t &n, real_1d_array &t);
1990
1991
1992/*************************************************************************
1993This function returns vector of parameter values correspoding to points.
1994
1995Same as PSpline2ParameterValues(), but for 3D.
1996
1997 -- ALGLIB PROJECT --
1998 Copyright 28.05.2010 by Bochkanov Sergey
1999*************************************************************************/
2000void pspline3parametervalues(const pspline3interpolant &p, ae_int_t &n, real_1d_array &t);
2001
2002
2003/*************************************************************************
2004This function calculates the value of the parametric spline for a given
2005value of parameter T
2006
2007INPUT PARAMETERS:
2008 P - parametric spline interpolant
2009 T - point:
2010 * T in [0,1] corresponds to interval spanned by points
2011 * for non-periodic splines T<0 (or T>1) correspond to parts of
2012 the curve before the first (after the last) point
2013 * for periodic splines T<0 (or T>1) are projected into [0,1]
2014 by making T=T-floor(T).
2015
2016OUTPUT PARAMETERS:
2017 X - X-position
2018 Y - Y-position
2019
2020
2021 -- ALGLIB PROJECT --
2022 Copyright 28.05.2010 by Bochkanov Sergey
2023*************************************************************************/
2024void pspline2calc(const pspline2interpolant &p, const double t, double &x, double &y);
2025
2026
2027/*************************************************************************
2028This function calculates the value of the parametric spline for a given
2029value of parameter T.
2030
2031INPUT PARAMETERS:
2032 P - parametric spline interpolant
2033 T - point:
2034 * T in [0,1] corresponds to interval spanned by points
2035 * for non-periodic splines T<0 (or T>1) correspond to parts of
2036 the curve before the first (after the last) point
2037 * for periodic splines T<0 (or T>1) are projected into [0,1]
2038 by making T=T-floor(T).
2039
2040OUTPUT PARAMETERS:
2041 X - X-position
2042 Y - Y-position
2043 Z - Z-position
2044
2045
2046 -- ALGLIB PROJECT --
2047 Copyright 28.05.2010 by Bochkanov Sergey
2048*************************************************************************/
2049void pspline3calc(const pspline3interpolant &p, const double t, double &x, double &y, double &z);
2050
2051
2052/*************************************************************************
2053This function calculates tangent vector for a given value of parameter T
2054
2055INPUT PARAMETERS:
2056 P - parametric spline interpolant
2057 T - point:
2058 * T in [0,1] corresponds to interval spanned by points
2059 * for non-periodic splines T<0 (or T>1) correspond to parts of
2060 the curve before the first (after the last) point
2061 * for periodic splines T<0 (or T>1) are projected into [0,1]
2062 by making T=T-floor(T).
2063
2064OUTPUT PARAMETERS:
2065 X - X-component of tangent vector (normalized)
2066 Y - Y-component of tangent vector (normalized)
2067
2068NOTE:
2069 X^2+Y^2 is either 1 (for non-zero tangent vector) or 0.
2070
2071
2072 -- ALGLIB PROJECT --
2073 Copyright 28.05.2010 by Bochkanov Sergey
2074*************************************************************************/
2075void pspline2tangent(const pspline2interpolant &p, const double t, double &x, double &y);
2076
2077
2078/*************************************************************************
2079This function calculates tangent vector for a given value of parameter T
2080
2081INPUT PARAMETERS:
2082 P - parametric spline interpolant
2083 T - point:
2084 * T in [0,1] corresponds to interval spanned by points
2085 * for non-periodic splines T<0 (or T>1) correspond to parts of
2086 the curve before the first (after the last) point
2087 * for periodic splines T<0 (or T>1) are projected into [0,1]
2088 by making T=T-floor(T).
2089
2090OUTPUT PARAMETERS:
2091 X - X-component of tangent vector (normalized)
2092 Y - Y-component of tangent vector (normalized)
2093 Z - Z-component of tangent vector (normalized)
2094
2095NOTE:
2096 X^2+Y^2+Z^2 is either 1 (for non-zero tangent vector) or 0.
2097
2098
2099 -- ALGLIB PROJECT --
2100 Copyright 28.05.2010 by Bochkanov Sergey
2101*************************************************************************/
2102void pspline3tangent(const pspline3interpolant &p, const double t, double &x, double &y, double &z);
2103
2104
2105/*************************************************************************
2106This function calculates derivative, i.e. it returns (dX/dT,dY/dT).
2107
2108INPUT PARAMETERS:
2109 P - parametric spline interpolant
2110 T - point:
2111 * T in [0,1] corresponds to interval spanned by points
2112 * for non-periodic splines T<0 (or T>1) correspond to parts of
2113 the curve before the first (after the last) point
2114 * for periodic splines T<0 (or T>1) are projected into [0,1]
2115 by making T=T-floor(T).
2116
2117OUTPUT PARAMETERS:
2118 X - X-value
2119 DX - X-derivative
2120 Y - Y-value
2121 DY - Y-derivative
2122
2123
2124 -- ALGLIB PROJECT --
2125 Copyright 28.05.2010 by Bochkanov Sergey
2126*************************************************************************/
2127void pspline2diff(const pspline2interpolant &p, const double t, double &x, double &dx, double &y, double &dy);
2128
2129
2130/*************************************************************************
2131This function calculates derivative, i.e. it returns (dX/dT,dY/dT,dZ/dT).
2132
2133INPUT PARAMETERS:
2134 P - parametric spline interpolant
2135 T - point:
2136 * T in [0,1] corresponds to interval spanned by points
2137 * for non-periodic splines T<0 (or T>1) correspond to parts of
2138 the curve before the first (after the last) point
2139 * for periodic splines T<0 (or T>1) are projected into [0,1]
2140 by making T=T-floor(T).
2141
2142OUTPUT PARAMETERS:
2143 X - X-value
2144 DX - X-derivative
2145 Y - Y-value
2146 DY - Y-derivative
2147 Z - Z-value
2148 DZ - Z-derivative
2149
2150
2151 -- ALGLIB PROJECT --
2152 Copyright 28.05.2010 by Bochkanov Sergey
2153*************************************************************************/
2154void pspline3diff(const pspline3interpolant &p, const double t, double &x, double &dx, double &y, double &dy, double &z, double &dz);
2155
2156
2157/*************************************************************************
2158This function calculates first and second derivative with respect to T.
2159
2160INPUT PARAMETERS:
2161 P - parametric spline interpolant
2162 T - point:
2163 * T in [0,1] corresponds to interval spanned by points
2164 * for non-periodic splines T<0 (or T>1) correspond to parts of
2165 the curve before the first (after the last) point
2166 * for periodic splines T<0 (or T>1) are projected into [0,1]
2167 by making T=T-floor(T).
2168
2169OUTPUT PARAMETERS:
2170 X - X-value
2171 DX - derivative
2172 D2X - second derivative
2173 Y - Y-value
2174 DY - derivative
2175 D2Y - second derivative
2176
2177
2178 -- ALGLIB PROJECT --
2179 Copyright 28.05.2010 by Bochkanov Sergey
2180*************************************************************************/
2181void pspline2diff2(const pspline2interpolant &p, const double t, double &x, double &dx, double &d2x, double &y, double &dy, double &d2y);
2182
2183
2184/*************************************************************************
2185This function calculates first and second derivative with respect to T.
2186
2187INPUT PARAMETERS:
2188 P - parametric spline interpolant
2189 T - point:
2190 * T in [0,1] corresponds to interval spanned by points
2191 * for non-periodic splines T<0 (or T>1) correspond to parts of
2192 the curve before the first (after the last) point
2193 * for periodic splines T<0 (or T>1) are projected into [0,1]
2194 by making T=T-floor(T).
2195
2196OUTPUT PARAMETERS:
2197 X - X-value
2198 DX - derivative
2199 D2X - second derivative
2200 Y - Y-value
2201 DY - derivative
2202 D2Y - second derivative
2203 Z - Z-value
2204 DZ - derivative
2205 D2Z - second derivative
2206
2207
2208 -- ALGLIB PROJECT --
2209 Copyright 28.05.2010 by Bochkanov Sergey
2210*************************************************************************/
2211void pspline3diff2(const pspline3interpolant &p, const double t, double &x, double &dx, double &d2x, double &y, double &dy, double &d2y, double &z, double &dz, double &d2z);
2212
2213
2214/*************************************************************************
2215This function calculates arc length, i.e. length of curve between t=a
2216and t=b.
2217
2218INPUT PARAMETERS:
2219 P - parametric spline interpolant
2220 A,B - parameter values corresponding to arc ends:
2221 * B>A will result in positive length returned
2222 * B<A will result in negative length returned
2223
2224RESULT:
2225 length of arc starting at T=A and ending at T=B.
2226
2227
2228 -- ALGLIB PROJECT --
2229 Copyright 30.05.2010 by Bochkanov Sergey
2230*************************************************************************/
2231double pspline2arclength(const pspline2interpolant &p, const double a, const double b);
2232
2233
2234/*************************************************************************
2235This function calculates arc length, i.e. length of curve between t=a
2236and t=b.
2237
2238INPUT PARAMETERS:
2239 P - parametric spline interpolant
2240 A,B - parameter values corresponding to arc ends:
2241 * B>A will result in positive length returned
2242 * B<A will result in negative length returned
2243
2244RESULT:
2245 length of arc starting at T=A and ending at T=B.
2246
2247
2248 -- ALGLIB PROJECT --
2249 Copyright 30.05.2010 by Bochkanov Sergey
2250*************************************************************************/
2251double pspline3arclength(const pspline3interpolant &p, const double a, const double b);
2252
2253
2254/*************************************************************************
2255This subroutine fits piecewise linear curve to points with Ramer-Douglas-
2256Peucker algorithm. This function performs PARAMETRIC fit, i.e. it can be
2257used to fit curves like circles.
2258
2259On input it accepts dataset which describes parametric multidimensional
2260curve X(t), with X being vector, and t taking values in [0,N), where N is
2261a number of points in dataset. As result, it returns reduced dataset X2,
2262which can be used to build parametric curve X2(t), which approximates
2263X(t) with desired precision (or has specified number of sections).
2264
2265
2266INPUT PARAMETERS:
2267 X - array of multidimensional points:
2268 * at least N elements, leading N elements are used if more
2269 than N elements were specified
2270 * order of points is IMPORTANT because it is parametric
2271 fit
2272 * each row of array is one point which has D coordinates
2273 N - number of elements in X
2274 D - number of dimensions (elements per row of X)
2275 StopM - stopping condition - desired number of sections:
2276 * at most M sections are generated by this function
2277 * less than M sections can be generated if we have N<M
2278 (or some X are non-distinct).
2279 * zero StopM means that algorithm does not stop after
2280 achieving some pre-specified section count
2281 StopEps - stopping condition - desired precision:
2282 * algorithm stops after error in each section is at most Eps
2283 * zero Eps means that algorithm does not stop after
2284 achieving some pre-specified precision
2285
2286OUTPUT PARAMETERS:
2287 X2 - array of corner points for piecewise approximation,
2288 has length NSections+1 or zero (for NSections=0).
2289 Idx2 - array of indexes (parameter values):
2290 * has length NSections+1 or zero (for NSections=0).
2291 * each element of Idx2 corresponds to same-numbered
2292 element of X2
2293 * each element of Idx2 is index of corresponding element
2294 of X2 at original array X, i.e. I-th row of X2 is
2295 Idx2[I]-th row of X.
2296 * elements of Idx2 can be treated as parameter values
2297 which should be used when building new parametric curve
2298 * Idx2[0]=0, Idx2[NSections]=N-1
2299 NSections- number of sections found by algorithm, NSections<=M,
2300 NSections can be zero for degenerate datasets
2301 (N<=1 or all X[] are non-distinct).
2302
2303NOTE: algorithm stops after:
2304 a) dividing curve into StopM sections
2305 b) achieving required precision StopEps
2306 c) dividing curve into N-1 sections
2307 If both StopM and StopEps are non-zero, algorithm is stopped by the
2308 FIRST criterion which is satisfied. In case both StopM and StopEps
2309 are zero, algorithm stops because of (c).
2310
2311 -- ALGLIB --
2312 Copyright 02.10.2014 by Bochkanov Sergey
2313*************************************************************************/
2314void parametricrdpfixed(const real_2d_array &x, const ae_int_t n, const ae_int_t d, const ae_int_t stopm, const double stopeps, real_2d_array &x2, integer_1d_array &idx2, ae_int_t &nsections);
2315
2316/*************************************************************************
2317This subroutine calculates the value of the trilinear or tricubic spline at
2318the given point (X,Y,Z).
2319
2320INPUT PARAMETERS:
2321 C - coefficients table.
2322 Built by BuildBilinearSpline or BuildBicubicSpline.
2323 X, Y,
2324 Z - point
2325
2326Result:
2327 S(x,y,z)
2328
2329 -- ALGLIB PROJECT --
2330 Copyright 26.04.2012 by Bochkanov Sergey
2331*************************************************************************/
2332double spline3dcalc(const spline3dinterpolant &c, const double x, const double y, const double z);
2333
2334
2335/*************************************************************************
2336This subroutine performs linear transformation of the spline argument.
2337
2338INPUT PARAMETERS:
2339 C - spline interpolant
2340 AX, BX - transformation coefficients: x = A*u + B
2341 AY, BY - transformation coefficients: y = A*v + B
2342 AZ, BZ - transformation coefficients: z = A*w + B
2343
2344OUTPUT PARAMETERS:
2345 C - transformed spline
2346
2347 -- ALGLIB PROJECT --
2348 Copyright 26.04.2012 by Bochkanov Sergey
2349*************************************************************************/
2350void spline3dlintransxyz(const spline3dinterpolant &c, const double ax, const double bx, const double ay, const double by, const double az, const double bz);
2351
2352
2353/*************************************************************************
2354This subroutine performs linear transformation of the spline.
2355
2356INPUT PARAMETERS:
2357 C - spline interpolant.
2358 A, B- transformation coefficients: S2(x,y) = A*S(x,y,z) + B
2359
2360OUTPUT PARAMETERS:
2361 C - transformed spline
2362
2363 -- ALGLIB PROJECT --
2364 Copyright 26.04.2012 by Bochkanov Sergey
2365*************************************************************************/
2366void spline3dlintransf(const spline3dinterpolant &c, const double a, const double b);
2367
2368
2369/*************************************************************************
2370Trilinear spline resampling
2371
2372INPUT PARAMETERS:
2373 A - array[0..OldXCount*OldYCount*OldZCount-1], function
2374 values at the old grid, :
2375 A[0] x=0,y=0,z=0
2376 A[1] x=1,y=0,z=0
2377 A[..] ...
2378 A[..] x=oldxcount-1,y=0,z=0
2379 A[..] x=0,y=1,z=0
2380 A[..] ...
2381 ...
2382 OldZCount - old Z-count, OldZCount>1
2383 OldYCount - old Y-count, OldYCount>1
2384 OldXCount - old X-count, OldXCount>1
2385 NewZCount - new Z-count, NewZCount>1
2386 NewYCount - new Y-count, NewYCount>1
2387 NewXCount - new X-count, NewXCount>1
2388
2389OUTPUT PARAMETERS:
2390 B - array[0..NewXCount*NewYCount*NewZCount-1], function
2391 values at the new grid:
2392 B[0] x=0,y=0,z=0
2393 B[1] x=1,y=0,z=0
2394 B[..] ...
2395 B[..] x=newxcount-1,y=0,z=0
2396 B[..] x=0,y=1,z=0
2397 B[..] ...
2398 ...
2399
2400 -- ALGLIB routine --
2401 26.04.2012
2402 Copyright by Bochkanov Sergey
2403*************************************************************************/
2404void spline3dresampletrilinear(const real_1d_array &a, const ae_int_t oldzcount, const ae_int_t oldycount, const ae_int_t oldxcount, const ae_int_t newzcount, const ae_int_t newycount, const ae_int_t newxcount, real_1d_array &b);
2405
2406
2407/*************************************************************************
2408This subroutine builds trilinear vector-valued spline.
2409
2410INPUT PARAMETERS:
2411 X - spline abscissas, array[0..N-1]
2412 Y - spline ordinates, array[0..M-1]
2413 Z - spline applicates, array[0..L-1]
2414 F - function values, array[0..M*N*L*D-1]:
2415 * first D elements store D values at (X[0],Y[0],Z[0])
2416 * next D elements store D values at (X[1],Y[0],Z[0])
2417 * next D elements store D values at (X[2],Y[0],Z[0])
2418 * ...
2419 * next D elements store D values at (X[0],Y[1],Z[0])
2420 * next D elements store D values at (X[1],Y[1],Z[0])
2421 * next D elements store D values at (X[2],Y[1],Z[0])
2422 * ...
2423 * next D elements store D values at (X[0],Y[0],Z[1])
2424 * next D elements store D values at (X[1],Y[0],Z[1])
2425 * next D elements store D values at (X[2],Y[0],Z[1])
2426 * ...
2427 * general form - D function values at (X[i],Y[j]) are stored
2428 at F[D*(N*(M*K+J)+I)...D*(N*(M*K+J)+I)+D-1].
2429 M,N,
2430 L - grid size, M>=2, N>=2, L>=2
2431 D - vector dimension, D>=1
2432
2433OUTPUT PARAMETERS:
2434 C - spline interpolant
2435
2436 -- ALGLIB PROJECT --
2437 Copyright 26.04.2012 by Bochkanov Sergey
2438*************************************************************************/
2439void spline3dbuildtrilinearv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &z, const ae_int_t l, const real_1d_array &f, const ae_int_t d, spline3dinterpolant &c);
2440
2441
2442/*************************************************************************
2443This subroutine calculates bilinear or bicubic vector-valued spline at the
2444given point (X,Y,Z).
2445
2446INPUT PARAMETERS:
2447 C - spline interpolant.
2448 X, Y,
2449 Z - point
2450 F - output buffer, possibly preallocated array. In case array size
2451 is large enough to store result, it is not reallocated. Array
2452 which is too short will be reallocated
2453
2454OUTPUT PARAMETERS:
2455 F - array[D] (or larger) which stores function values
2456
2457 -- ALGLIB PROJECT --
2458 Copyright 26.04.2012 by Bochkanov Sergey
2459*************************************************************************/
2460void spline3dcalcvbuf(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f);
2461
2462
2463/*************************************************************************
2464This subroutine calculates trilinear or tricubic vector-valued spline at the
2465given point (X,Y,Z).
2466
2467INPUT PARAMETERS:
2468 C - spline interpolant.
2469 X, Y,
2470 Z - point
2471
2472OUTPUT PARAMETERS:
2473 F - array[D] which stores function values. F is out-parameter and
2474 it is reallocated after call to this function. In case you
2475 want to reuse previously allocated F, you may use
2476 Spline2DCalcVBuf(), which reallocates F only when it is too
2477 small.
2478
2479 -- ALGLIB PROJECT --
2480 Copyright 26.04.2012 by Bochkanov Sergey
2481*************************************************************************/
2482void spline3dcalcv(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f);
2483
2484
2485/*************************************************************************
2486This subroutine unpacks tri-dimensional spline into the coefficients table
2487
2488INPUT PARAMETERS:
2489 C - spline interpolant.
2490
2491Result:
2492 N - grid size (X)
2493 M - grid size (Y)
2494 L - grid size (Z)
2495 D - number of components
2496 SType- spline type. Currently, only one spline type is supported:
2497 trilinear spline, as indicated by SType=1.
2498 Tbl - spline coefficients: [0..(N-1)*(M-1)*(L-1)*D-1, 0..13].
2499 For T=0..D-1 (component index), I = 0...N-2 (x index),
2500 J=0..M-2 (y index), K=0..L-2 (z index):
2501 Q := T + I*D + J*D*(N-1) + K*D*(N-1)*(M-1),
2502
2503 Q-th row stores decomposition for T-th component of the
2504 vector-valued function
2505
2506 Tbl[Q,0] = X[i]
2507 Tbl[Q,1] = X[i+1]
2508 Tbl[Q,2] = Y[j]
2509 Tbl[Q,3] = Y[j+1]
2510 Tbl[Q,4] = Z[k]
2511 Tbl[Q,5] = Z[k+1]
2512
2513 Tbl[Q,6] = C000
2514 Tbl[Q,7] = C100
2515 Tbl[Q,8] = C010
2516 Tbl[Q,9] = C110
2517 Tbl[Q,10]= C001
2518 Tbl[Q,11]= C101
2519 Tbl[Q,12]= C011
2520 Tbl[Q,13]= C111
2521 On each grid square spline is equals to:
2522 S(x) = SUM(c[i,j,k]*(x^i)*(y^j)*(z^k), i=0..1, j=0..1, k=0..1)
2523 t = x-x[j]
2524 u = y-y[i]
2525 v = z-z[k]
2526
2527 NOTE: format of Tbl is given for SType=1. Future versions of
2528 ALGLIB can use different formats for different values of
2529 SType.
2530
2531 -- ALGLIB PROJECT --
2532 Copyright 26.04.2012 by Bochkanov Sergey
2533*************************************************************************/
2534void spline3dunpackv(const spline3dinterpolant &c, ae_int_t &n, ae_int_t &m, ae_int_t &l, ae_int_t &d, ae_int_t &stype, real_2d_array &tbl);
2535
2536/*************************************************************************
2537Conversion from barycentric representation to Chebyshev basis.
2538This function has O(N^2) complexity.
2539
2540INPUT PARAMETERS:
2541 P - polynomial in barycentric form
2542 A,B - base interval for Chebyshev polynomials (see below)
2543 A<>B
2544
2545OUTPUT PARAMETERS
2546 T - coefficients of Chebyshev representation;
2547 P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N-1 },
2548 where Ti - I-th Chebyshev polynomial.
2549
2550NOTES:
2551 barycentric interpolant passed as P may be either polynomial obtained
2552 from polynomial interpolation/ fitting or rational function which is
2553 NOT polynomial. We can't distinguish between these two cases, and this
2554 algorithm just tries to work assuming that P IS a polynomial. If not,
2555 algorithm will return results, but they won't have any meaning.
2556
2557 -- ALGLIB --
2558 Copyright 30.09.2010 by Bochkanov Sergey
2559*************************************************************************/
2560void polynomialbar2cheb(const barycentricinterpolant &p, const double a, const double b, real_1d_array &t);
2561
2562
2563/*************************************************************************
2564Conversion from Chebyshev basis to barycentric representation.
2565This function has O(N^2) complexity.
2566
2567INPUT PARAMETERS:
2568 T - coefficients of Chebyshev representation;
2569 P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N },
2570 where Ti - I-th Chebyshev polynomial.
2571 N - number of coefficients:
2572 * if given, only leading N elements of T are used
2573 * if not given, automatically determined from size of T
2574 A,B - base interval for Chebyshev polynomials (see above)
2575 A<B
2576
2577OUTPUT PARAMETERS
2578 P - polynomial in barycentric form
2579
2580 -- ALGLIB --
2581 Copyright 30.09.2010 by Bochkanov Sergey
2582*************************************************************************/
2583void polynomialcheb2bar(const real_1d_array &t, const ae_int_t n, const double a, const double b, barycentricinterpolant &p);
2584void polynomialcheb2bar(const real_1d_array &t, const double a, const double b, barycentricinterpolant &p);
2585
2586
2587/*************************************************************************
2588Conversion from barycentric representation to power basis.
2589This function has O(N^2) complexity.
2590
2591INPUT PARAMETERS:
2592 P - polynomial in barycentric form
2593 C - offset (see below); 0.0 is used as default value.
2594 S - scale (see below); 1.0 is used as default value. S<>0.
2595
2596OUTPUT PARAMETERS
2597 A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
2598 N - number of coefficients (polynomial degree plus 1)
2599
2600NOTES:
26011. this function accepts offset and scale, which can be set to improve
2602 numerical properties of polynomial. For example, if P was obtained as
2603 result of interpolation on [-1,+1], you can set C=0 and S=1 and
2604 represent P as sum of 1, x, x^2, x^3 and so on. In most cases you it
2605 is exactly what you need.
2606
2607 However, if your interpolation model was built on [999,1001], you will
2608 see significant growth of numerical errors when using {1, x, x^2, x^3}
2609 as basis. Representing P as sum of 1, (x-1000), (x-1000)^2, (x-1000)^3
2610 will be better option. Such representation can be obtained by using
2611 1000.0 as offset C and 1.0 as scale S.
2612
26132. power basis is ill-conditioned and tricks described above can't solve
2614 this problem completely. This function will return coefficients in
2615 any case, but for N>8 they will become unreliable. However, N's
2616 less than 5 are pretty safe.
2617
26183. barycentric interpolant passed as P may be either polynomial obtained
2619 from polynomial interpolation/ fitting or rational function which is
2620 NOT polynomial. We can't distinguish between these two cases, and this
2621 algorithm just tries to work assuming that P IS a polynomial. If not,
2622 algorithm will return results, but they won't have any meaning.
2623
2624 -- ALGLIB --
2625 Copyright 30.09.2010 by Bochkanov Sergey
2626*************************************************************************/
2627void polynomialbar2pow(const barycentricinterpolant &p, const double c, const double s, real_1d_array &a);
2628void polynomialbar2pow(const barycentricinterpolant &p, real_1d_array &a);
2629
2630
2631/*************************************************************************
2632Conversion from power basis to barycentric representation.
2633This function has O(N^2) complexity.
2634
2635INPUT PARAMETERS:
2636 A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 }
2637 N - number of coefficients (polynomial degree plus 1)
2638 * if given, only leading N elements of A are used
2639 * if not given, automatically determined from size of A
2640 C - offset (see below); 0.0 is used as default value.
2641 S - scale (see below); 1.0 is used as default value. S<>0.
2642
2643OUTPUT PARAMETERS
2644 P - polynomial in barycentric form
2645
2646
2647NOTES:
26481. this function accepts offset and scale, which can be set to improve
2649 numerical properties of polynomial. For example, if you interpolate on
2650 [-1,+1], you can set C=0 and S=1 and convert from sum of 1, x, x^2,
2651 x^3 and so on. In most cases you it is exactly what you need.
2652
2653 However, if your interpolation model was built on [999,1001], you will
2654 see significant growth of numerical errors when using {1, x, x^2, x^3}
2655 as input basis. Converting from sum of 1, (x-1000), (x-1000)^2,
2656 (x-1000)^3 will be better option (you have to specify 1000.0 as offset
2657 C and 1.0 as scale S).
2658
26592. power basis is ill-conditioned and tricks described above can't solve
2660 this problem completely. This function will return barycentric model
2661 in any case, but for N>8 accuracy well degrade. However, N's less than
2662 5 are pretty safe.
2663
2664 -- ALGLIB --
2665 Copyright 30.09.2010 by Bochkanov Sergey
2666*************************************************************************/
2667void polynomialpow2bar(const real_1d_array &a, const ae_int_t n, const double c, const double s, barycentricinterpolant &p);
2668void polynomialpow2bar(const real_1d_array &a, barycentricinterpolant &p);
2669
2670
2671/*************************************************************************
2672Lagrange intepolant: generation of the model on the general grid.
2673This function has O(N^2) complexity.
2674
2675INPUT PARAMETERS:
2676 X - abscissas, array[0..N-1]
2677 Y - function values, array[0..N-1]
2678 N - number of points, N>=1
2679
2680OUTPUT PARAMETERS
2681 P - barycentric model which represents Lagrange interpolant
2682 (see ratint unit info and BarycentricCalc() description for
2683 more information).
2684
2685 -- ALGLIB --
2686 Copyright 02.12.2009 by Bochkanov Sergey
2687*************************************************************************/
2688void polynomialbuild(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p);
2689void polynomialbuild(const real_1d_array &x, const real_1d_array &y, barycentricinterpolant &p);
2690
2691
2692/*************************************************************************
2693Lagrange intepolant: generation of the model on equidistant grid.
2694This function has O(N) complexity.
2695
2696INPUT PARAMETERS:
2697 A - left boundary of [A,B]
2698 B - right boundary of [A,B]
2699 Y - function values at the nodes, array[0..N-1]
2700 N - number of points, N>=1
2701 for N=1 a constant model is constructed.
2702
2703OUTPUT PARAMETERS
2704 P - barycentric model which represents Lagrange interpolant
2705 (see ratint unit info and BarycentricCalc() description for
2706 more information).
2707
2708 -- ALGLIB --
2709 Copyright 03.12.2009 by Bochkanov Sergey
2710*************************************************************************/
2711void polynomialbuildeqdist(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p);
2712void polynomialbuildeqdist(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p);
2713
2714
2715/*************************************************************************
2716Lagrange intepolant on Chebyshev grid (first kind).
2717This function has O(N) complexity.
2718
2719INPUT PARAMETERS:
2720 A - left boundary of [A,B]
2721 B - right boundary of [A,B]
2722 Y - function values at the nodes, array[0..N-1],
2723 Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n)))
2724 N - number of points, N>=1
2725 for N=1 a constant model is constructed.
2726
2727OUTPUT PARAMETERS
2728 P - barycentric model which represents Lagrange interpolant
2729 (see ratint unit info and BarycentricCalc() description for
2730 more information).
2731
2732 -- ALGLIB --
2733 Copyright 03.12.2009 by Bochkanov Sergey
2734*************************************************************************/
2735void polynomialbuildcheb1(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p);
2736void polynomialbuildcheb1(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p);
2737
2738
2739/*************************************************************************
2740Lagrange intepolant on Chebyshev grid (second kind).
2741This function has O(N) complexity.
2742
2743INPUT PARAMETERS:
2744 A - left boundary of [A,B]
2745 B - right boundary of [A,B]
2746 Y - function values at the nodes, array[0..N-1],
2747 Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)))
2748 N - number of points, N>=1
2749 for N=1 a constant model is constructed.
2750
2751OUTPUT PARAMETERS
2752 P - barycentric model which represents Lagrange interpolant
2753 (see ratint unit info and BarycentricCalc() description for
2754 more information).
2755
2756 -- ALGLIB --
2757 Copyright 03.12.2009 by Bochkanov Sergey
2758*************************************************************************/
2759void polynomialbuildcheb2(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p);
2760void polynomialbuildcheb2(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p);
2761
2762
2763/*************************************************************************
2764Fast equidistant polynomial interpolation function with O(N) complexity
2765
2766INPUT PARAMETERS:
2767 A - left boundary of [A,B]
2768 B - right boundary of [A,B]
2769 F - function values, array[0..N-1]
2770 N - number of points on equidistant grid, N>=1
2771 for N=1 a constant model is constructed.
2772 T - position where P(x) is calculated
2773
2774RESULT
2775 value of the Lagrange interpolant at T
2776
2777IMPORTANT
2778 this function provides fast interface which is not overflow-safe
2779 nor it is very precise.
2780 the best option is to use PolynomialBuildEqDist()/BarycentricCalc()
2781 subroutines unless you are pretty sure that your data will not result
2782 in overflow.
2783
2784 -- ALGLIB --
2785 Copyright 02.12.2009 by Bochkanov Sergey
2786*************************************************************************/
2787double polynomialcalceqdist(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t);
2788double polynomialcalceqdist(const double a, const double b, const real_1d_array &f, const double t);
2789
2790
2791/*************************************************************************
2792Fast polynomial interpolation function on Chebyshev points (first kind)
2793with O(N) complexity.
2794
2795INPUT PARAMETERS:
2796 A - left boundary of [A,B]
2797 B - right boundary of [A,B]
2798 F - function values, array[0..N-1]
2799 N - number of points on Chebyshev grid (first kind),
2800 X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))
2801 for N=1 a constant model is constructed.
2802 T - position where P(x) is calculated
2803
2804RESULT
2805 value of the Lagrange interpolant at T
2806
2807IMPORTANT
2808 this function provides fast interface which is not overflow-safe
2809 nor it is very precise.
2810 the best option is to use PolIntBuildCheb1()/BarycentricCalc()
2811 subroutines unless you are pretty sure that your data will not result
2812 in overflow.
2813
2814 -- ALGLIB --
2815 Copyright 02.12.2009 by Bochkanov Sergey
2816*************************************************************************/
2817double polynomialcalccheb1(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t);
2818double polynomialcalccheb1(const double a, const double b, const real_1d_array &f, const double t);
2819
2820
2821/*************************************************************************
2822Fast polynomial interpolation function on Chebyshev points (second kind)
2823with O(N) complexity.
2824
2825INPUT PARAMETERS:
2826 A - left boundary of [A,B]
2827 B - right boundary of [A,B]
2828 F - function values, array[0..N-1]
2829 N - number of points on Chebyshev grid (second kind),
2830 X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))
2831 for N=1 a constant model is constructed.
2832 T - position where P(x) is calculated
2833
2834RESULT
2835 value of the Lagrange interpolant at T
2836
2837IMPORTANT
2838 this function provides fast interface which is not overflow-safe
2839 nor it is very precise.
2840 the best option is to use PolIntBuildCheb2()/BarycentricCalc()
2841 subroutines unless you are pretty sure that your data will not result
2842 in overflow.
2843
2844 -- ALGLIB --
2845 Copyright 02.12.2009 by Bochkanov Sergey
2846*************************************************************************/
2847double polynomialcalccheb2(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t);
2848double polynomialcalccheb2(const double a, const double b, const real_1d_array &f, const double t);
2849
2850/*************************************************************************
2851This subroutine fits piecewise linear curve to points with Ramer-Douglas-
2852Peucker algorithm, which stops after generating specified number of linear
2853sections.
2854
2855IMPORTANT:
2856* it does NOT perform least-squares fitting; it builds curve, but this
2857 curve does not minimize some least squares metric. See description of
2858 RDP algorithm (say, in Wikipedia) for more details on WHAT is performed.
2859* this function does NOT work with parametric curves (i.e. curves which
2860 can be represented as {X(t),Y(t)}. It works with curves which can be
2861 represented as Y(X). Thus, it is impossible to model figures like
2862 circles with this functions.
2863 If you want to work with parametric curves, you should use
2864 ParametricRDPFixed() function provided by "Parametric" subpackage of
2865 "Interpolation" package.
2866
2867INPUT PARAMETERS:
2868 X - array of X-coordinates:
2869 * at least N elements
2870 * can be unordered (points are automatically sorted)
2871 * this function may accept non-distinct X (see below for
2872 more information on handling of such inputs)
2873 Y - array of Y-coordinates:
2874 * at least N elements
2875 N - number of elements in X/Y
2876 M - desired number of sections:
2877 * at most M sections are generated by this function
2878 * less than M sections can be generated if we have N<M
2879 (or some X are non-distinct).
2880
2881OUTPUT PARAMETERS:
2882 X2 - X-values of corner points for piecewise approximation,
2883 has length NSections+1 or zero (for NSections=0).
2884 Y2 - Y-values of corner points,
2885 has length NSections+1 or zero (for NSections=0).
2886 NSections- number of sections found by algorithm, NSections<=M,
2887 NSections can be zero for degenerate datasets
2888 (N<=1 or all X[] are non-distinct).
2889
2890NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of
2891 curve, (X2[NSection-1],Y2[NSection-1]) is the last point.
2892
2893 -- ALGLIB --
2894 Copyright 02.10.2014 by Bochkanov Sergey
2895*************************************************************************/
2896void lstfitpiecewiselinearrdpfixed(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, real_1d_array &x2, real_1d_array &y2, ae_int_t &nsections);
2897
2898
2899/*************************************************************************
2900This subroutine fits piecewise linear curve to points with Ramer-Douglas-
2901Peucker algorithm, which stops after achieving desired precision.
2902
2903IMPORTANT:
2904* it performs non-least-squares fitting; it builds curve, but this curve
2905 does not minimize some least squares metric. See description of RDP
2906 algorithm (say, in Wikipedia) for more details on WHAT is performed.
2907* this function does NOT work with parametric curves (i.e. curves which
2908 can be represented as {X(t),Y(t)}. It works with curves which can be
2909 represented as Y(X). Thus, it is impossible to model figures like circles
2910 with this functions.
2911 If you want to work with parametric curves, you should use
2912 ParametricRDPFixed() function provided by "Parametric" subpackage of
2913 "Interpolation" package.
2914
2915INPUT PARAMETERS:
2916 X - array of X-coordinates:
2917 * at least N elements
2918 * can be unordered (points are automatically sorted)
2919 * this function may accept non-distinct X (see below for
2920 more information on handling of such inputs)
2921 Y - array of Y-coordinates:
2922 * at least N elements
2923 N - number of elements in X/Y
2924 Eps - positive number, desired precision.
2925
2926
2927OUTPUT PARAMETERS:
2928 X2 - X-values of corner points for piecewise approximation,
2929 has length NSections+1 or zero (for NSections=0).
2930 Y2 - Y-values of corner points,
2931 has length NSections+1 or zero (for NSections=0).
2932 NSections- number of sections found by algorithm,
2933 NSections can be zero for degenerate datasets
2934 (N<=1 or all X[] are non-distinct).
2935
2936NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of
2937 curve, (X2[NSection-1],Y2[NSection-1]) is the last point.
2938
2939 -- ALGLIB --
2940 Copyright 02.10.2014 by Bochkanov Sergey
2941*************************************************************************/
2942void lstfitpiecewiselinearrdp(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const double eps, real_1d_array &x2, real_1d_array &y2, ae_int_t &nsections);
2943
2944
2945/*************************************************************************
2946Fitting by polynomials in barycentric form. This function provides simple
2947unterface for unconstrained unweighted fitting. See PolynomialFitWC() if
2948you need constrained fitting.
2949
2950Task is linear, so linear least squares solver is used. Complexity of this
2951computational scheme is O(N*M^2), mostly dominated by least squares solver
2952
2953SEE ALSO:
2954 PolynomialFitWC()
2955
2956COMMERCIAL EDITION OF ALGLIB:
2957
2958 ! Commercial version of ALGLIB includes two important improvements of
2959 ! this function, which can be used from C++ and C#:
2960 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
2961 ! * multithreading support
2962 !
2963 ! Intel MKL gives approximately constant (with respect to number of
2964 ! worker threads) acceleration factor which depends on CPU being used,
2965 ! problem size and "baseline" ALGLIB edition which is used for
2966 ! comparison.
2967 !
2968 ! Speed-up provided by multithreading greatly depends on problem size
2969 ! - only large problems (number of coefficients is more than 500) can be
2970 ! efficiently multithreaded.
2971 !
2972 ! Generally, commercial ALGLIB is several times faster than open-source
2973 ! generic C edition, and many times faster than open-source C# edition.
2974 !
2975 ! We recommend you to read 'Working with commercial version' section of
2976 ! ALGLIB Reference Manual in order to find out how to use performance-
2977 ! related features provided by commercial edition of ALGLIB.
2978
2979INPUT PARAMETERS:
2980 X - points, array[0..N-1].
2981 Y - function values, array[0..N-1].
2982 N - number of points, N>0
2983 * if given, only leading N elements of X/Y are used
2984 * if not given, automatically determined from sizes of X/Y
2985 M - number of basis functions (= polynomial_degree + 1), M>=1
2986
2987OUTPUT PARAMETERS:
2988 Info- same format as in LSFitLinearW() subroutine:
2989 * Info>0 task is solved
2990 * Info<=0 an error occured:
2991 -4 means inconvergence of internal SVD
2992 P - interpolant in barycentric form.
2993 Rep - report, same format as in LSFitLinearW() subroutine.
2994 Following fields are set:
2995 * RMSError rms error on the (X,Y).
2996 * AvgError average error on the (X,Y).
2997 * AvgRelError average relative error on the non-zero Y
2998 * MaxError maximum error
2999 NON-WEIGHTED ERRORS ARE CALCULATED
3000
3001NOTES:
3002 you can convert P from barycentric form to the power or Chebyshev
3003 basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
3004 POLINT subpackage.
3005
3006 -- ALGLIB PROJECT --
3007 Copyright 10.12.2009 by Bochkanov Sergey
3008*************************************************************************/
3009void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3010void smp_polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3011void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3012void smp_polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3013
3014
3015/*************************************************************************
3016Weighted fitting by polynomials in barycentric form, with constraints on
3017function values or first derivatives.
3018
3019Small regularizing term is used when solving constrained tasks (to improve
3020stability).
3021
3022Task is linear, so linear least squares solver is used. Complexity of this
3023computational scheme is O(N*M^2), mostly dominated by least squares solver
3024
3025SEE ALSO:
3026 PolynomialFit()
3027
3028COMMERCIAL EDITION OF ALGLIB:
3029
3030 ! Commercial version of ALGLIB includes two important improvements of
3031 ! this function, which can be used from C++ and C#:
3032 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
3033 ! * multithreading support
3034 !
3035 ! Intel MKL gives approximately constant (with respect to number of
3036 ! worker threads) acceleration factor which depends on CPU being used,
3037 ! problem size and "baseline" ALGLIB edition which is used for
3038 ! comparison.
3039 !
3040 ! Speed-up provided by multithreading greatly depends on problem size
3041 ! - only large problems (number of coefficients is more than 500) can be
3042 ! efficiently multithreaded.
3043 !
3044 ! Generally, commercial ALGLIB is several times faster than open-source
3045 ! generic C edition, and many times faster than open-source C# edition.
3046 !
3047 ! We recommend you to read 'Working with commercial version' section of
3048 ! ALGLIB Reference Manual in order to find out how to use performance-
3049 ! related features provided by commercial edition of ALGLIB.
3050
3051INPUT PARAMETERS:
3052 X - points, array[0..N-1].
3053 Y - function values, array[0..N-1].
3054 W - weights, array[0..N-1]
3055 Each summand in square sum of approximation deviations from
3056 given values is multiplied by the square of corresponding
3057 weight. Fill it by 1's if you don't want to solve weighted
3058 task.
3059 N - number of points, N>0.
3060 * if given, only leading N elements of X/Y/W are used
3061 * if not given, automatically determined from sizes of X/Y/W
3062 XC - points where polynomial values/derivatives are constrained,
3063 array[0..K-1].
3064 YC - values of constraints, array[0..K-1]
3065 DC - array[0..K-1], types of constraints:
3066 * DC[i]=0 means that P(XC[i])=YC[i]
3067 * DC[i]=1 means that P'(XC[i])=YC[i]
3068 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
3069 K - number of constraints, 0<=K<M.
3070 K=0 means no constraints (XC/YC/DC are not used in such cases)
3071 M - number of basis functions (= polynomial_degree + 1), M>=1
3072
3073OUTPUT PARAMETERS:
3074 Info- same format as in LSFitLinearW() subroutine:
3075 * Info>0 task is solved
3076 * Info<=0 an error occured:
3077 -4 means inconvergence of internal SVD
3078 -3 means inconsistent constraints
3079 P - interpolant in barycentric form.
3080 Rep - report, same format as in LSFitLinearW() subroutine.
3081 Following fields are set:
3082 * RMSError rms error on the (X,Y).
3083 * AvgError average error on the (X,Y).
3084 * AvgRelError average relative error on the non-zero Y
3085 * MaxError maximum error
3086 NON-WEIGHTED ERRORS ARE CALCULATED
3087
3088IMPORTANT:
3089 this subroitine doesn't calculate task's condition number for K<>0.
3090
3091NOTES:
3092 you can convert P from barycentric form to the power or Chebyshev
3093 basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from
3094 POLINT subpackage.
3095
3096SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
3097
3098Setting constraints can lead to undesired results, like ill-conditioned
3099behavior, or inconsistency being detected. From the other side, it allows
3100us to improve quality of the fit. Here we summarize our experience with
3101constrained regression splines:
3102* even simple constraints can be inconsistent, see Wikipedia article on
3103 this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation
3104* the greater is M (given fixed constraints), the more chances that
3105 constraints will be consistent
3106* in the general case, consistency of constraints is NOT GUARANTEED.
3107* in the one special cases, however, we can guarantee consistency. This
3108 case is: M>1 and constraints on the function values (NOT DERIVATIVES)
3109
3110Our final recommendation is to use constraints WHEN AND ONLY when you
3111can't solve your task without them. Anything beyond special cases given
3112above is not guaranteed and may result in inconsistency.
3113
3114 -- ALGLIB PROJECT --
3115 Copyright 10.12.2009 by Bochkanov Sergey
3116*************************************************************************/
3117void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3118void smp_polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3119void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3120void smp_polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep);
3121
3122
3123/*************************************************************************
3124This function calculates value of four-parameter logistic (4PL) model at
3125specified point X. 4PL model has following form:
3126
3127 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
3128
3129INPUT PARAMETERS:
3130 X - current point, X>=0:
3131 * zero X is correctly handled even for B<=0
3132 * negative X results in exception.
3133 A, B, C, D- parameters of 4PL model:
3134 * A is unconstrained
3135 * B is unconstrained; zero or negative values are handled
3136 correctly.
3137 * C>0, non-positive value results in exception
3138 * D is unconstrained
3139
3140RESULT:
3141 model value at X
3142
3143NOTE: if B=0, denominator is assumed to be equal to 2.0 even for zero X
3144 (strictly speaking, 0^0 is undefined).
3145
3146NOTE: this function also throws exception if all input parameters are
3147 correct, but overflow was detected during calculations.
3148
3149NOTE: this function performs a lot of checks; if you need really high
3150 performance, consider evaluating model yourself, without checking
3151 for degenerate cases.
3152
3153
3154 -- ALGLIB PROJECT --
3155 Copyright 14.05.2014 by Bochkanov Sergey
3156*************************************************************************/
3157double logisticcalc4(const double x, const double a, const double b, const double c, const double d);
3158
3159
3160/*************************************************************************
3161This function calculates value of five-parameter logistic (5PL) model at
3162specified point X. 5PL model has following form:
3163
3164 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
3165
3166INPUT PARAMETERS:
3167 X - current point, X>=0:
3168 * zero X is correctly handled even for B<=0
3169 * negative X results in exception.
3170 A, B, C, D, G- parameters of 5PL model:
3171 * A is unconstrained
3172 * B is unconstrained; zero or negative values are handled
3173 correctly.
3174 * C>0, non-positive value results in exception
3175 * D is unconstrained
3176 * G>0, non-positive value results in exception
3177
3178RESULT:
3179 model value at X
3180
3181NOTE: if B=0, denominator is assumed to be equal to Power(2.0,G) even for
3182 zero X (strictly speaking, 0^0 is undefined).
3183
3184NOTE: this function also throws exception if all input parameters are
3185 correct, but overflow was detected during calculations.
3186
3187NOTE: this function performs a lot of checks; if you need really high
3188 performance, consider evaluating model yourself, without checking
3189 for degenerate cases.
3190
3191
3192 -- ALGLIB PROJECT --
3193 Copyright 14.05.2014 by Bochkanov Sergey
3194*************************************************************************/
3195double logisticcalc5(const double x, const double a, const double b, const double c, const double d, const double g);
3196
3197
3198/*************************************************************************
3199This function fits four-parameter logistic (4PL) model to data provided
3200by user. 4PL model has following form:
3201
3202 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
3203
3204Here:
3205 * A, D - unconstrained (see LogisticFit4EC() for constrained 4PL)
3206 * B>=0
3207 * C>0
3208
3209IMPORTANT: output of this function is constrained in such way that B>0.
3210 Because 4PL model is symmetric with respect to B, there is no
3211 need to explore B<0. Constraining B makes algorithm easier
3212 to stabilize and debug.
3213 Users who for some reason prefer to work with negative B's
3214 should transform output themselves (swap A and D, replace B by
3215 -B).
3216
32174PL fitting is implemented as follows:
3218* we perform small number of restarts from random locations which helps to
3219 solve problem of bad local extrema. Locations are only partially random
3220 - we use input data to determine good initial guess, but we include
3221 controlled amount of randomness.
3222* we perform Levenberg-Marquardt fitting with very tight constraints on
3223 parameters B and C - it allows us to find good initial guess for the
3224 second stage without risk of running into "flat spot".
3225* second Levenberg-Marquardt round is performed without excessive
3226 constraints. Results from the previous round are used as initial guess.
3227* after fitting is done, we compare results with best values found so far,
3228 rewrite "best solution" if needed, and move to next random location.
3229
3230Overall algorithm is very stable and is not prone to bad local extrema.
3231Furthermore, it automatically scales when input data have very large or
3232very small range.
3233
3234INPUT PARAMETERS:
3235 X - array[N], stores X-values.
3236 MUST include only non-negative numbers (but may include
3237 zero values). Can be unsorted.
3238 Y - array[N], values to fit.
3239 N - number of points. If N is less than length of X/Y, only
3240 leading N elements are used.
3241
3242OUTPUT PARAMETERS:
3243 A, B, C, D- parameters of 4PL model
3244 Rep - fitting report. This structure has many fields, but ONLY
3245 ONES LISTED BELOW ARE SET:
3246 * Rep.IterationsCount - number of iterations performed
3247 * Rep.RMSError - root-mean-square error
3248 * Rep.AvgError - average absolute error
3249 * Rep.AvgRelError - average relative error (calculated for
3250 non-zero Y-values)
3251 * Rep.MaxError - maximum absolute error
3252 * Rep.R2 - coefficient of determination, R-squared. This
3253 coefficient is calculated as R2=1-RSS/TSS (in case
3254 of nonlinear regression there are multiple ways to
3255 define R2, each of them giving different results).
3256
3257NOTE: after you obtained coefficients, you can evaluate model with
3258 LogisticCalc4() function.
3259
3260NOTE: if you need better control over fitting process than provided by this
3261 function, you may use LogisticFit45X().
3262
3263NOTE: step is automatically scaled according to scale of parameters being
3264 fitted before we compare its length with EpsX. Thus, this function
3265 can be used to fit data with very small or very large values without
3266 changing EpsX.
3267
3268
3269 -- ALGLIB PROJECT --
3270 Copyright 14.02.2014 by Bochkanov Sergey
3271*************************************************************************/
3272void logisticfit4(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, double &a, double &b, double &c, double &d, lsfitreport &rep);
3273
3274
3275/*************************************************************************
3276This function fits four-parameter logistic (4PL) model to data provided
3277by user, with optional constraints on parameters A and D. 4PL model has
3278following form:
3279
3280 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B))
3281
3282Here:
3283 * A, D - with optional equality constraints
3284 * B>=0
3285 * C>0
3286
3287IMPORTANT: output of this function is constrained in such way that B>0.
3288 Because 4PL model is symmetric with respect to B, there is no
3289 need to explore B<0. Constraining B makes algorithm easier
3290 to stabilize and debug.
3291 Users who for some reason prefer to work with negative B's
3292 should transform output themselves (swap A and D, replace B by
3293 -B).
3294
32954PL fitting is implemented as follows:
3296* we perform small number of restarts from random locations which helps to
3297 solve problem of bad local extrema. Locations are only partially random
3298 - we use input data to determine good initial guess, but we include
3299 controlled amount of randomness.
3300* we perform Levenberg-Marquardt fitting with very tight constraints on
3301 parameters B and C - it allows us to find good initial guess for the
3302 second stage without risk of running into "flat spot".
3303* second Levenberg-Marquardt round is performed without excessive
3304 constraints. Results from the previous round are used as initial guess.
3305* after fitting is done, we compare results with best values found so far,
3306 rewrite "best solution" if needed, and move to next random location.
3307
3308Overall algorithm is very stable and is not prone to bad local extrema.
3309Furthermore, it automatically scales when input data have very large or
3310very small range.
3311
3312INPUT PARAMETERS:
3313 X - array[N], stores X-values.
3314 MUST include only non-negative numbers (but may include
3315 zero values). Can be unsorted.
3316 Y - array[N], values to fit.
3317 N - number of points. If N is less than length of X/Y, only
3318 leading N elements are used.
3319 CnstrLeft- optional equality constraint for model value at the left
3320 boundary (at X=0). Specify NAN (Not-a-Number) if you do
3321 not need constraint on the model value at X=0 (in C++ you
3322 can pass alglib::fp_nan as parameter, in C# it will be
3323 Double.NaN).
3324 See below, section "EQUALITY CONSTRAINTS" for more
3325 information about constraints.
3326 CnstrRight- optional equality constraint for model value at X=infinity.
3327 Specify NAN (Not-a-Number) if you do not need constraint
3328 on the model value (in C++ you can pass alglib::fp_nan as
3329 parameter, in C# it will be Double.NaN).
3330 See below, section "EQUALITY CONSTRAINTS" for more
3331 information about constraints.
3332
3333OUTPUT PARAMETERS:
3334 A, B, C, D- parameters of 4PL model
3335 Rep - fitting report. This structure has many fields, but ONLY
3336 ONES LISTED BELOW ARE SET:
3337 * Rep.IterationsCount - number of iterations performed
3338 * Rep.RMSError - root-mean-square error
3339 * Rep.AvgError - average absolute error
3340 * Rep.AvgRelError - average relative error (calculated for
3341 non-zero Y-values)
3342 * Rep.MaxError - maximum absolute error
3343 * Rep.R2 - coefficient of determination, R-squared. This
3344 coefficient is calculated as R2=1-RSS/TSS (in case
3345 of nonlinear regression there are multiple ways to
3346 define R2, each of them giving different results).
3347
3348NOTE: after you obtained coefficients, you can evaluate model with
3349 LogisticCalc4() function.
3350
3351NOTE: if you need better control over fitting process than provided by this
3352 function, you may use LogisticFit45X().
3353
3354NOTE: step is automatically scaled according to scale of parameters being
3355 fitted before we compare its length with EpsX. Thus, this function
3356 can be used to fit data with very small or very large values without
3357 changing EpsX.
3358
3359EQUALITY CONSTRAINTS ON PARAMETERS
3360
33614PL/5PL solver supports equality constraints on model values at the left
3362boundary (X=0) and right boundary (X=infinity). These constraints are
3363completely optional and you can specify both of them, only one - or no
3364constraints at all.
3365
3366Parameter CnstrLeft contains left constraint (or NAN for unconstrained
3367fitting), and CnstrRight contains right one. For 4PL, left constraint
3368ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on
3369D. That's because 4PL model is normalized in such way that B>=0.
3370
3371
3372 -- ALGLIB PROJECT --
3373 Copyright 14.02.2014 by Bochkanov Sergey
3374*************************************************************************/
3375void logisticfit4ec(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const double cnstrleft, const double cnstrright, double &a, double &b, double &c, double &d, lsfitreport &rep);
3376
3377
3378/*************************************************************************
3379This function fits five-parameter logistic (5PL) model to data provided
3380by user. 5PL model has following form:
3381
3382 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
3383
3384Here:
3385 * A, D - unconstrained
3386 * B - unconstrained
3387 * C>0
3388 * G>0
3389
3390IMPORTANT: unlike in 4PL fitting, output of this function is NOT
3391 constrained in such way that B is guaranteed to be positive.
3392 Furthermore, unlike 4PL, 5PL model is NOT symmetric with
3393 respect to B, so you can NOT transform model to equivalent one,
3394 with B having desired sign (>0 or <0).
3395
33965PL fitting is implemented as follows:
3397* we perform small number of restarts from random locations which helps to
3398 solve problem of bad local extrema. Locations are only partially random
3399 - we use input data to determine good initial guess, but we include
3400 controlled amount of randomness.
3401* we perform Levenberg-Marquardt fitting with very tight constraints on
3402 parameters B and C - it allows us to find good initial guess for the
3403 second stage without risk of running into "flat spot". Parameter G is
3404 fixed at G=1.
3405* second Levenberg-Marquardt round is performed without excessive
3406 constraints on B and C, but with G still equal to 1. Results from the
3407 previous round are used as initial guess.
3408* third Levenberg-Marquardt round relaxes constraints on G and tries two
3409 different models - one with B>0 and one with B<0.
3410* after fitting is done, we compare results with best values found so far,
3411 rewrite "best solution" if needed, and move to next random location.
3412
3413Overall algorithm is very stable and is not prone to bad local extrema.
3414Furthermore, it automatically scales when input data have very large or
3415very small range.
3416
3417INPUT PARAMETERS:
3418 X - array[N], stores X-values.
3419 MUST include only non-negative numbers (but may include
3420 zero values). Can be unsorted.
3421 Y - array[N], values to fit.
3422 N - number of points. If N is less than length of X/Y, only
3423 leading N elements are used.
3424
3425OUTPUT PARAMETERS:
3426 A,B,C,D,G- parameters of 5PL model
3427 Rep - fitting report. This structure has many fields, but ONLY
3428 ONES LISTED BELOW ARE SET:
3429 * Rep.IterationsCount - number of iterations performed
3430 * Rep.RMSError - root-mean-square error
3431 * Rep.AvgError - average absolute error
3432 * Rep.AvgRelError - average relative error (calculated for
3433 non-zero Y-values)
3434 * Rep.MaxError - maximum absolute error
3435 * Rep.R2 - coefficient of determination, R-squared. This
3436 coefficient is calculated as R2=1-RSS/TSS (in case
3437 of nonlinear regression there are multiple ways to
3438 define R2, each of them giving different results).
3439
3440NOTE: after you obtained coefficients, you can evaluate model with
3441 LogisticCalc5() function.
3442
3443NOTE: if you need better control over fitting process than provided by this
3444 function, you may use LogisticFit45X().
3445
3446NOTE: step is automatically scaled according to scale of parameters being
3447 fitted before we compare its length with EpsX. Thus, this function
3448 can be used to fit data with very small or very large values without
3449 changing EpsX.
3450
3451
3452 -- ALGLIB PROJECT --
3453 Copyright 14.02.2014 by Bochkanov Sergey
3454*************************************************************************/
3455void logisticfit5(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, double &a, double &b, double &c, double &d, double &g, lsfitreport &rep);
3456
3457
3458/*************************************************************************
3459This function fits five-parameter logistic (5PL) model to data provided
3460by user, subject to optional equality constraints on parameters A and D.
34615PL model has following form:
3462
3463 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G)
3464
3465Here:
3466 * A, D - with optional equality constraints
3467 * B - unconstrained
3468 * C>0
3469 * G>0
3470
3471IMPORTANT: unlike in 4PL fitting, output of this function is NOT
3472 constrained in such way that B is guaranteed to be positive.
3473 Furthermore, unlike 4PL, 5PL model is NOT symmetric with
3474 respect to B, so you can NOT transform model to equivalent one,
3475 with B having desired sign (>0 or <0).
3476
34775PL fitting is implemented as follows:
3478* we perform small number of restarts from random locations which helps to
3479 solve problem of bad local extrema. Locations are only partially random
3480 - we use input data to determine good initial guess, but we include
3481 controlled amount of randomness.
3482* we perform Levenberg-Marquardt fitting with very tight constraints on
3483 parameters B and C - it allows us to find good initial guess for the
3484 second stage without risk of running into "flat spot". Parameter G is
3485 fixed at G=1.
3486* second Levenberg-Marquardt round is performed without excessive
3487 constraints on B and C, but with G still equal to 1. Results from the
3488 previous round are used as initial guess.
3489* third Levenberg-Marquardt round relaxes constraints on G and tries two
3490 different models - one with B>0 and one with B<0.
3491* after fitting is done, we compare results with best values found so far,
3492 rewrite "best solution" if needed, and move to next random location.
3493
3494Overall algorithm is very stable and is not prone to bad local extrema.
3495Furthermore, it automatically scales when input data have very large or
3496very small range.
3497
3498INPUT PARAMETERS:
3499 X - array[N], stores X-values.
3500 MUST include only non-negative numbers (but may include
3501 zero values). Can be unsorted.
3502 Y - array[N], values to fit.
3503 N - number of points. If N is less than length of X/Y, only
3504 leading N elements are used.
3505 CnstrLeft- optional equality constraint for model value at the left
3506 boundary (at X=0). Specify NAN (Not-a-Number) if you do
3507 not need constraint on the model value at X=0 (in C++ you
3508 can pass alglib::fp_nan as parameter, in C# it will be
3509 Double.NaN).
3510 See below, section "EQUALITY CONSTRAINTS" for more
3511 information about constraints.
3512 CnstrRight- optional equality constraint for model value at X=infinity.
3513 Specify NAN (Not-a-Number) if you do not need constraint
3514 on the model value (in C++ you can pass alglib::fp_nan as
3515 parameter, in C# it will be Double.NaN).
3516 See below, section "EQUALITY CONSTRAINTS" for more
3517 information about constraints.
3518
3519OUTPUT PARAMETERS:
3520 A,B,C,D,G- parameters of 5PL model
3521 Rep - fitting report. This structure has many fields, but ONLY
3522 ONES LISTED BELOW ARE SET:
3523 * Rep.IterationsCount - number of iterations performed
3524 * Rep.RMSError - root-mean-square error
3525 * Rep.AvgError - average absolute error
3526 * Rep.AvgRelError - average relative error (calculated for
3527 non-zero Y-values)
3528 * Rep.MaxError - maximum absolute error
3529 * Rep.R2 - coefficient of determination, R-squared. This
3530 coefficient is calculated as R2=1-RSS/TSS (in case
3531 of nonlinear regression there are multiple ways to
3532 define R2, each of them giving different results).
3533
3534NOTE: after you obtained coefficients, you can evaluate model with
3535 LogisticCalc5() function.
3536
3537NOTE: if you need better control over fitting process than provided by this
3538 function, you may use LogisticFit45X().
3539
3540NOTE: step is automatically scaled according to scale of parameters being
3541 fitted before we compare its length with EpsX. Thus, this function
3542 can be used to fit data with very small or very large values without
3543 changing EpsX.
3544
3545EQUALITY CONSTRAINTS ON PARAMETERS
3546
35475PL solver supports equality constraints on model values at the left
3548boundary (X=0) and right boundary (X=infinity). These constraints are
3549completely optional and you can specify both of them, only one - or no
3550constraints at all.
3551
3552Parameter CnstrLeft contains left constraint (or NAN for unconstrained
3553fitting), and CnstrRight contains right one.
3554
3555Unlike 4PL one, 5PL model is NOT symmetric with respect to change in sign
3556of B. Thus, negative B's are possible, and left constraint may constrain
3557parameter A (for positive B's) - or parameter D (for negative B's).
3558Similarly changes meaning of right constraint.
3559
3560You do not have to decide what parameter to constrain - algorithm will
3561automatically determine correct parameters as fitting progresses. However,
3562question highlighted above is important when you interpret fitting results.
3563
3564
3565 -- ALGLIB PROJECT --
3566 Copyright 14.02.2014 by Bochkanov Sergey
3567*************************************************************************/
3568void logisticfit5ec(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const double cnstrleft, const double cnstrright, double &a, double &b, double &c, double &d, double &g, lsfitreport &rep);
3569
3570
3571/*************************************************************************
3572This is "expert" 4PL/5PL fitting function, which can be used if you need
3573better control over fitting process than provided by LogisticFit4() or
3574LogisticFit5().
3575
3576This function fits model of the form
3577
3578 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) (4PL model)
3579
3580or
3581
3582 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) (5PL model)
3583
3584Here:
3585 * A, D - unconstrained
3586 * B>=0 for 4PL, unconstrained for 5PL
3587 * C>0
3588 * G>0 (if present)
3589
3590INPUT PARAMETERS:
3591 X - array[N], stores X-values.
3592 MUST include only non-negative numbers (but may include
3593 zero values). Can be unsorted.
3594 Y - array[N], values to fit.
3595 N - number of points. If N is less than length of X/Y, only
3596 leading N elements are used.
3597 CnstrLeft- optional equality constraint for model value at the left
3598 boundary (at X=0). Specify NAN (Not-a-Number) if you do
3599 not need constraint on the model value at X=0 (in C++ you
3600 can pass alglib::fp_nan as parameter, in C# it will be
3601 Double.NaN).
3602 See below, section "EQUALITY CONSTRAINTS" for more
3603 information about constraints.
3604 CnstrRight- optional equality constraint for model value at X=infinity.
3605 Specify NAN (Not-a-Number) if you do not need constraint
3606 on the model value (in C++ you can pass alglib::fp_nan as
3607 parameter, in C# it will be Double.NaN).
3608 See below, section "EQUALITY CONSTRAINTS" for more
3609 information about constraints.
3610 Is4PL - whether 4PL or 5PL models are fitted
3611 LambdaV - regularization coefficient, LambdaV>=0.
3612 Set it to zero unless you know what you are doing.
3613 EpsX - stopping condition (step size), EpsX>=0.
3614 Zero value means that small step is automatically chosen.
3615 See notes below for more information.
3616 RsCnt - number of repeated restarts from random points. 4PL/5PL
3617 models are prone to problem of bad local extrema. Utilizing
3618 multiple random restarts allows us to improve algorithm
3619 convergence.
3620 RsCnt>=0.
3621 Zero value means that function automatically choose small
3622 amount of restarts (recommended).
3623
3624OUTPUT PARAMETERS:
3625 A, B, C, D- parameters of 4PL model
3626 G - parameter of 5PL model; for Is4PL=True, G=1 is returned.
3627 Rep - fitting report. This structure has many fields, but ONLY
3628 ONES LISTED BELOW ARE SET:
3629 * Rep.IterationsCount - number of iterations performed
3630 * Rep.RMSError - root-mean-square error
3631 * Rep.AvgError - average absolute error
3632 * Rep.AvgRelError - average relative error (calculated for
3633 non-zero Y-values)
3634 * Rep.MaxError - maximum absolute error
3635 * Rep.R2 - coefficient of determination, R-squared. This
3636 coefficient is calculated as R2=1-RSS/TSS (in case
3637 of nonlinear regression there are multiple ways to
3638 define R2, each of them giving different results).
3639
3640NOTE: after you obtained coefficients, you can evaluate model with
3641 LogisticCalc5() function.
3642
3643NOTE: step is automatically scaled according to scale of parameters being
3644 fitted before we compare its length with EpsX. Thus, this function
3645 can be used to fit data with very small or very large values without
3646 changing EpsX.
3647
3648EQUALITY CONSTRAINTS ON PARAMETERS
3649
36504PL/5PL solver supports equality constraints on model values at the left
3651boundary (X=0) and right boundary (X=infinity). These constraints are
3652completely optional and you can specify both of them, only one - or no
3653constraints at all.
3654
3655Parameter CnstrLeft contains left constraint (or NAN for unconstrained
3656fitting), and CnstrRight contains right one. For 4PL, left constraint
3657ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on
3658D. That's because 4PL model is normalized in such way that B>=0.
3659
3660For 5PL model things are different. Unlike 4PL one, 5PL model is NOT
3661symmetric with respect to change in sign of B. Thus, negative B's are
3662possible, and left constraint may constrain parameter A (for positive B's)
3663- or parameter D (for negative B's). Similarly changes meaning of right
3664constraint.
3665
3666You do not have to decide what parameter to constrain - algorithm will
3667automatically determine correct parameters as fitting progresses. However,
3668question highlighted above is important when you interpret fitting results.
3669
3670
3671 -- ALGLIB PROJECT --
3672 Copyright 14.02.2014 by Bochkanov Sergey
3673*************************************************************************/
3674void logisticfit45x(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const double cnstrleft, const double cnstrright, const bool is4pl, const double lambdav, const double epsx, const ae_int_t rscnt, double &a, double &b, double &c, double &d, double &g, lsfitreport &rep);
3675
3676
3677/*************************************************************************
3678Weghted rational least squares fitting using Floater-Hormann rational
3679functions with optimal D chosen from [0,9], with constraints and
3680individual weights.
3681
3682Equidistant grid with M node on [min(x),max(x)] is used to build basis
3683functions. Different values of D are tried, optimal D (least WEIGHTED root
3684mean square error) is chosen. Task is linear, so linear least squares
3685solver is used. Complexity of this computational scheme is O(N*M^2)
3686(mostly dominated by the least squares solver).
3687
3688SEE ALSO
3689* BarycentricFitFloaterHormann(), "lightweight" fitting without invididual
3690 weights and constraints.
3691
3692COMMERCIAL EDITION OF ALGLIB:
3693
3694 ! Commercial version of ALGLIB includes two important improvements of
3695 ! this function, which can be used from C++ and C#:
3696 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
3697 ! * multithreading support
3698 !
3699 ! Intel MKL gives approximately constant (with respect to number of
3700 ! worker threads) acceleration factor which depends on CPU being used,
3701 ! problem size and "baseline" ALGLIB edition which is used for
3702 ! comparison.
3703 !
3704 ! Speed-up provided by multithreading greatly depends on problem size
3705 ! - only large problems (number of coefficients is more than 500) can be
3706 ! efficiently multithreaded.
3707 !
3708 ! Generally, commercial ALGLIB is several times faster than open-source
3709 ! generic C edition, and many times faster than open-source C# edition.
3710 !
3711 ! We recommend you to read 'Working with commercial version' section of
3712 ! ALGLIB Reference Manual in order to find out how to use performance-
3713 ! related features provided by commercial edition of ALGLIB.
3714
3715INPUT PARAMETERS:
3716 X - points, array[0..N-1].
3717 Y - function values, array[0..N-1].
3718 W - weights, array[0..N-1]
3719 Each summand in square sum of approximation deviations from
3720 given values is multiplied by the square of corresponding
3721 weight. Fill it by 1's if you don't want to solve weighted
3722 task.
3723 N - number of points, N>0.
3724 XC - points where function values/derivatives are constrained,
3725 array[0..K-1].
3726 YC - values of constraints, array[0..K-1]
3727 DC - array[0..K-1], types of constraints:
3728 * DC[i]=0 means that S(XC[i])=YC[i]
3729 * DC[i]=1 means that S'(XC[i])=YC[i]
3730 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
3731 K - number of constraints, 0<=K<M.
3732 K=0 means no constraints (XC/YC/DC are not used in such cases)
3733 M - number of basis functions ( = number_of_nodes), M>=2.
3734
3735OUTPUT PARAMETERS:
3736 Info- same format as in LSFitLinearWC() subroutine.
3737 * Info>0 task is solved
3738 * Info<=0 an error occured:
3739 -4 means inconvergence of internal SVD
3740 -3 means inconsistent constraints
3741 -1 means another errors in parameters passed
3742 (N<=0, for example)
3743 B - barycentric interpolant.
3744 Rep - report, same format as in LSFitLinearWC() subroutine.
3745 Following fields are set:
3746 * DBest best value of the D parameter
3747 * RMSError rms error on the (X,Y).
3748 * AvgError average error on the (X,Y).
3749 * AvgRelError average relative error on the non-zero Y
3750 * MaxError maximum error
3751 NON-WEIGHTED ERRORS ARE CALCULATED
3752
3753IMPORTANT:
3754 this subroutine doesn't calculate task's condition number for K<>0.
3755
3756SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
3757
3758Setting constraints can lead to undesired results, like ill-conditioned
3759behavior, or inconsistency being detected. From the other side, it allows
3760us to improve quality of the fit. Here we summarize our experience with
3761constrained barycentric interpolants:
3762* excessive constraints can be inconsistent. Floater-Hormann basis
3763 functions aren't as flexible as splines (although they are very smooth).
3764* the more evenly constraints are spread across [min(x),max(x)], the more
3765 chances that they will be consistent
3766* the greater is M (given fixed constraints), the more chances that
3767 constraints will be consistent
3768* in the general case, consistency of constraints IS NOT GUARANTEED.
3769* in the several special cases, however, we CAN guarantee consistency.
3770* one of this cases is constraints on the function VALUES at the interval
3771 boundaries. Note that consustency of the constraints on the function
3772 DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines
3773 which are more flexible).
3774* another special case is ONE constraint on the function value (OR, but
3775 not AND, derivative) anywhere in the interval
3776
3777Our final recommendation is to use constraints WHEN AND ONLY WHEN you
3778can't solve your task without them. Anything beyond special cases given
3779above is not guaranteed and may result in inconsistency.
3780
3781 -- ALGLIB PROJECT --
3782 Copyright 18.08.2009 by Bochkanov Sergey
3783*************************************************************************/
3784void barycentricfitfloaterhormannwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep);
3785void smp_barycentricfitfloaterhormannwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep);
3786
3787
3788/*************************************************************************
3789Rational least squares fitting using Floater-Hormann rational functions
3790with optimal D chosen from [0,9].
3791
3792Equidistant grid with M node on [min(x),max(x)] is used to build basis
3793functions. Different values of D are tried, optimal D (least root mean
3794square error) is chosen. Task is linear, so linear least squares solver
3795is used. Complexity of this computational scheme is O(N*M^2) (mostly
3796dominated by the least squares solver).
3797
3798COMMERCIAL EDITION OF ALGLIB:
3799
3800 ! Commercial version of ALGLIB includes two important improvements of
3801 ! this function, which can be used from C++ and C#:
3802 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
3803 ! * multithreading support
3804 !
3805 ! Intel MKL gives approximately constant (with respect to number of
3806 ! worker threads) acceleration factor which depends on CPU being used,
3807 ! problem size and "baseline" ALGLIB edition which is used for
3808 ! comparison.
3809 !
3810 ! Speed-up provided by multithreading greatly depends on problem size
3811 ! - only large problems (number of coefficients is more than 500) can be
3812 ! efficiently multithreaded.
3813 !
3814 ! Generally, commercial ALGLIB is several times faster than open-source
3815 ! generic C edition, and many times faster than open-source C# edition.
3816 !
3817 ! We recommend you to read 'Working with commercial version' section of
3818 ! ALGLIB Reference Manual in order to find out how to use performance-
3819 ! related features provided by commercial edition of ALGLIB.
3820
3821INPUT PARAMETERS:
3822 X - points, array[0..N-1].
3823 Y - function values, array[0..N-1].
3824 N - number of points, N>0.
3825 M - number of basis functions ( = number_of_nodes), M>=2.
3826
3827OUTPUT PARAMETERS:
3828 Info- same format as in LSFitLinearWC() subroutine.
3829 * Info>0 task is solved
3830 * Info<=0 an error occured:
3831 -4 means inconvergence of internal SVD
3832 -3 means inconsistent constraints
3833 B - barycentric interpolant.
3834 Rep - report, same format as in LSFitLinearWC() subroutine.
3835 Following fields are set:
3836 * DBest best value of the D parameter
3837 * RMSError rms error on the (X,Y).
3838 * AvgError average error on the (X,Y).
3839 * AvgRelError average relative error on the non-zero Y
3840 * MaxError maximum error
3841 NON-WEIGHTED ERRORS ARE CALCULATED
3842
3843 -- ALGLIB PROJECT --
3844 Copyright 18.08.2009 by Bochkanov Sergey
3845*************************************************************************/
3846void barycentricfitfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep);
3847void smp_barycentricfitfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep);
3848
3849
3850/*************************************************************************
3851Fitting by penalized cubic spline.
3852
3853Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
3854basis functions. Basis functions are cubic splines with natural boundary
3855conditions. Problem is regularized by adding non-linearity penalty to the
3856usual least squares penalty function:
3857
3858 S(x) = arg min { LS + P }, where
3859 LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
3860 P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
3861 rho - tunable constant given by user
3862 C - automatically determined scale parameter,
3863 makes penalty invariant with respect to scaling of X, Y, W.
3864
3865COMMERCIAL EDITION OF ALGLIB:
3866
3867 ! Commercial version of ALGLIB includes two important improvements of
3868 ! this function, which can be used from C++ and C#:
3869 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
3870 ! * multithreading support
3871 !
3872 ! Intel MKL gives approximately constant (with respect to number of
3873 ! worker threads) acceleration factor which depends on CPU being used,
3874 ! problem size and "baseline" ALGLIB edition which is used for
3875 ! comparison.
3876 !
3877 ! Speed-up provided by multithreading greatly depends on problem size
3878 ! - only large problems (number of coefficients is more than 500) can be
3879 ! efficiently multithreaded.
3880 !
3881 ! Generally, commercial ALGLIB is several times faster than open-source
3882 ! generic C edition, and many times faster than open-source C# edition.
3883 !
3884 ! We recommend you to read 'Working with commercial version' section of
3885 ! ALGLIB Reference Manual in order to find out how to use performance-
3886 ! related features provided by commercial edition of ALGLIB.
3887
3888INPUT PARAMETERS:
3889 X - points, array[0..N-1].
3890 Y - function values, array[0..N-1].
3891 N - number of points (optional):
3892 * N>0
3893 * if given, only first N elements of X/Y are processed
3894 * if not given, automatically determined from X/Y sizes
3895 M - number of basis functions ( = number_of_nodes), M>=4.
3896 Rho - regularization constant passed by user. It penalizes
3897 nonlinearity in the regression spline. It is logarithmically
3898 scaled, i.e. actual value of regularization constant is
3899 calculated as 10^Rho. It is automatically scaled so that:
3900 * Rho=2.0 corresponds to moderate amount of nonlinearity
3901 * generally, it should be somewhere in the [-8.0,+8.0]
3902 If you do not want to penalize nonlineary,
3903 pass small Rho. Values as low as -15 should work.
3904
3905OUTPUT PARAMETERS:
3906 Info- same format as in LSFitLinearWC() subroutine.
3907 * Info>0 task is solved
3908 * Info<=0 an error occured:
3909 -4 means inconvergence of internal SVD or
3910 Cholesky decomposition; problem may be
3911 too ill-conditioned (very rare)
3912 S - spline interpolant.
3913 Rep - Following fields are set:
3914 * RMSError rms error on the (X,Y).
3915 * AvgError average error on the (X,Y).
3916 * AvgRelError average relative error on the non-zero Y
3917 * MaxError maximum error
3918 NON-WEIGHTED ERRORS ARE CALCULATED
3919
3920IMPORTANT:
3921 this subroitine doesn't calculate task's condition number for K<>0.
3922
3923NOTE 1: additional nodes are added to the spline outside of the fitting
3924interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
3925for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
3926it is natural to force linearity outside of this interval.
3927
3928NOTE 2: function automatically sorts points, so caller may pass unsorted
3929array.
3930
3931 -- ALGLIB PROJECT --
3932 Copyright 18.08.2009 by Bochkanov Sergey
3933*************************************************************************/
3934void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
3935void smp_spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
3936void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
3937void smp_spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
3938
3939
3940/*************************************************************************
3941Weighted fitting by penalized cubic spline.
3942
3943Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
3944basis functions. Basis functions are cubic splines with natural boundary
3945conditions. Problem is regularized by adding non-linearity penalty to the
3946usual least squares penalty function:
3947
3948 S(x) = arg min { LS + P }, where
3949 LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty
3950 P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty
3951 rho - tunable constant given by user
3952 C - automatically determined scale parameter,
3953 makes penalty invariant with respect to scaling of X, Y, W.
3954
3955COMMERCIAL EDITION OF ALGLIB:
3956
3957 ! Commercial version of ALGLIB includes two important improvements of
3958 ! this function, which can be used from C++ and C#:
3959 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
3960 ! * multithreading support
3961 !
3962 ! Intel MKL gives approximately constant (with respect to number of
3963 ! worker threads) acceleration factor which depends on CPU being used,
3964 ! problem size and "baseline" ALGLIB edition which is used for
3965 ! comparison.
3966 !
3967 ! Speed-up provided by multithreading greatly depends on problem size
3968 ! - only large problems (number of coefficients is more than 500) can be
3969 ! efficiently multithreaded.
3970 !
3971 ! Generally, commercial ALGLIB is several times faster than open-source
3972 ! generic C edition, and many times faster than open-source C# edition.
3973 !
3974 ! We recommend you to read 'Working with commercial version' section of
3975 ! ALGLIB Reference Manual in order to find out how to use performance-
3976 ! related features provided by commercial edition of ALGLIB.
3977
3978INPUT PARAMETERS:
3979 X - points, array[0..N-1].
3980 Y - function values, array[0..N-1].
3981 W - weights, array[0..N-1]
3982 Each summand in square sum of approximation deviations from
3983 given values is multiplied by the square of corresponding
3984 weight. Fill it by 1's if you don't want to solve weighted
3985 problem.
3986 N - number of points (optional):
3987 * N>0
3988 * if given, only first N elements of X/Y/W are processed
3989 * if not given, automatically determined from X/Y/W sizes
3990 M - number of basis functions ( = number_of_nodes), M>=4.
3991 Rho - regularization constant passed by user. It penalizes
3992 nonlinearity in the regression spline. It is logarithmically
3993 scaled, i.e. actual value of regularization constant is
3994 calculated as 10^Rho. It is automatically scaled so that:
3995 * Rho=2.0 corresponds to moderate amount of nonlinearity
3996 * generally, it should be somewhere in the [-8.0,+8.0]
3997 If you do not want to penalize nonlineary,
3998 pass small Rho. Values as low as -15 should work.
3999
4000OUTPUT PARAMETERS:
4001 Info- same format as in LSFitLinearWC() subroutine.
4002 * Info>0 task is solved
4003 * Info<=0 an error occured:
4004 -4 means inconvergence of internal SVD or
4005 Cholesky decomposition; problem may be
4006 too ill-conditioned (very rare)
4007 S - spline interpolant.
4008 Rep - Following fields are set:
4009 * RMSError rms error on the (X,Y).
4010 * AvgError average error on the (X,Y).
4011 * AvgRelError average relative error on the non-zero Y
4012 * MaxError maximum error
4013 NON-WEIGHTED ERRORS ARE CALCULATED
4014
4015IMPORTANT:
4016 this subroitine doesn't calculate task's condition number for K<>0.
4017
4018NOTE 1: additional nodes are added to the spline outside of the fitting
4019interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done
4020for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so
4021it is natural to force linearity outside of this interval.
4022
4023NOTE 2: function automatically sorts points, so caller may pass unsorted
4024array.
4025
4026 -- ALGLIB PROJECT --
4027 Copyright 19.10.2010 by Bochkanov Sergey
4028*************************************************************************/
4029void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4030void smp_spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4031void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4032void smp_spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4033
4034
4035/*************************************************************************
4036Weighted fitting by cubic spline, with constraints on function values or
4037derivatives.
4038
4039Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build
4040basis functions. Basis functions are cubic splines with continuous second
4041derivatives and non-fixed first derivatives at interval ends. Small
4042regularizing term is used when solving constrained tasks (to improve
4043stability).
4044
4045Task is linear, so linear least squares solver is used. Complexity of this
4046computational scheme is O(N*M^2), mostly dominated by least squares solver
4047
4048SEE ALSO
4049 Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible,
4050 less smooth)
4051 Spline1DFitCubic() - "lightweight" fitting by cubic splines,
4052 without invididual weights and constraints
4053
4054COMMERCIAL EDITION OF ALGLIB:
4055
4056 ! Commercial version of ALGLIB includes two important improvements of
4057 ! this function, which can be used from C++ and C#:
4058 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4059 ! * multithreading support
4060 !
4061 ! Intel MKL gives approximately constant (with respect to number of
4062 ! worker threads) acceleration factor which depends on CPU being used,
4063 ! problem size and "baseline" ALGLIB edition which is used for
4064 ! comparison.
4065 !
4066 ! Speed-up provided by multithreading greatly depends on problem size
4067 ! - only large problems (number of coefficients is more than 500) can be
4068 ! efficiently multithreaded.
4069 !
4070 ! Generally, commercial ALGLIB is several times faster than open-source
4071 ! generic C edition, and many times faster than open-source C# edition.
4072 !
4073 ! We recommend you to read 'Working with commercial version' section of
4074 ! ALGLIB Reference Manual in order to find out how to use performance-
4075 ! related features provided by commercial edition of ALGLIB.
4076
4077INPUT PARAMETERS:
4078 X - points, array[0..N-1].
4079 Y - function values, array[0..N-1].
4080 W - weights, array[0..N-1]
4081 Each summand in square sum of approximation deviations from
4082 given values is multiplied by the square of corresponding
4083 weight. Fill it by 1's if you don't want to solve weighted
4084 task.
4085 N - number of points (optional):
4086 * N>0
4087 * if given, only first N elements of X/Y/W are processed
4088 * if not given, automatically determined from X/Y/W sizes
4089 XC - points where spline values/derivatives are constrained,
4090 array[0..K-1].
4091 YC - values of constraints, array[0..K-1]
4092 DC - array[0..K-1], types of constraints:
4093 * DC[i]=0 means that S(XC[i])=YC[i]
4094 * DC[i]=1 means that S'(XC[i])=YC[i]
4095 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
4096 K - number of constraints (optional):
4097 * 0<=K<M.
4098 * K=0 means no constraints (XC/YC/DC are not used)
4099 * if given, only first K elements of XC/YC/DC are used
4100 * if not given, automatically determined from XC/YC/DC
4101 M - number of basis functions ( = number_of_nodes+2), M>=4.
4102
4103OUTPUT PARAMETERS:
4104 Info- same format as in LSFitLinearWC() subroutine.
4105 * Info>0 task is solved
4106 * Info<=0 an error occured:
4107 -4 means inconvergence of internal SVD
4108 -3 means inconsistent constraints
4109 S - spline interpolant.
4110 Rep - report, same format as in LSFitLinearWC() subroutine.
4111 Following fields are set:
4112 * RMSError rms error on the (X,Y).
4113 * AvgError average error on the (X,Y).
4114 * AvgRelError average relative error on the non-zero Y
4115 * MaxError maximum error
4116 NON-WEIGHTED ERRORS ARE CALCULATED
4117
4118IMPORTANT:
4119 this subroitine doesn't calculate task's condition number for K<>0.
4120
4121
4122ORDER OF POINTS
4123
4124Subroutine automatically sorts points, so caller may pass unsorted array.
4125
4126SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
4127
4128Setting constraints can lead to undesired results, like ill-conditioned
4129behavior, or inconsistency being detected. From the other side, it allows
4130us to improve quality of the fit. Here we summarize our experience with
4131constrained regression splines:
4132* excessive constraints can be inconsistent. Splines are piecewise cubic
4133 functions, and it is easy to create an example, where large number of
4134 constraints concentrated in small area will result in inconsistency.
4135 Just because spline is not flexible enough to satisfy all of them. And
4136 same constraints spread across the [min(x),max(x)] will be perfectly
4137 consistent.
4138* the more evenly constraints are spread across [min(x),max(x)], the more
4139 chances that they will be consistent
4140* the greater is M (given fixed constraints), the more chances that
4141 constraints will be consistent
4142* in the general case, consistency of constraints IS NOT GUARANTEED.
4143* in the several special cases, however, we CAN guarantee consistency.
4144* one of this cases is constraints on the function values AND/OR its
4145 derivatives at the interval boundaries.
4146* another special case is ONE constraint on the function value (OR, but
4147 not AND, derivative) anywhere in the interval
4148
4149Our final recommendation is to use constraints WHEN AND ONLY WHEN you
4150can't solve your task without them. Anything beyond special cases given
4151above is not guaranteed and may result in inconsistency.
4152
4153
4154 -- ALGLIB PROJECT --
4155 Copyright 18.08.2009 by Bochkanov Sergey
4156*************************************************************************/
4157void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4158void smp_spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4159void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4160void smp_spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4161
4162
4163/*************************************************************************
4164Weighted fitting by Hermite spline, with constraints on function values
4165or first derivatives.
4166
4167Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build
4168basis functions. Basis functions are Hermite splines. Small regularizing
4169term is used when solving constrained tasks (to improve stability).
4170
4171Task is linear, so linear least squares solver is used. Complexity of this
4172computational scheme is O(N*M^2), mostly dominated by least squares solver
4173
4174SEE ALSO
4175 Spline1DFitCubicWC() - fitting by Cubic splines (less flexible,
4176 more smooth)
4177 Spline1DFitHermite() - "lightweight" Hermite fitting, without
4178 invididual weights and constraints
4179
4180COMMERCIAL EDITION OF ALGLIB:
4181
4182 ! Commercial version of ALGLIB includes two important improvements of
4183 ! this function, which can be used from C++ and C#:
4184 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4185 ! * multithreading support
4186 !
4187 ! Intel MKL gives approximately constant (with respect to number of
4188 ! worker threads) acceleration factor which depends on CPU being used,
4189 ! problem size and "baseline" ALGLIB edition which is used for
4190 ! comparison.
4191 !
4192 ! Speed-up provided by multithreading greatly depends on problem size
4193 ! - only large problems (number of coefficients is more than 500) can be
4194 ! efficiently multithreaded.
4195 !
4196 ! Generally, commercial ALGLIB is several times faster than open-source
4197 ! generic C edition, and many times faster than open-source C# edition.
4198 !
4199 ! We recommend you to read 'Working with commercial version' section of
4200 ! ALGLIB Reference Manual in order to find out how to use performance-
4201 ! related features provided by commercial edition of ALGLIB.
4202
4203INPUT PARAMETERS:
4204 X - points, array[0..N-1].
4205 Y - function values, array[0..N-1].
4206 W - weights, array[0..N-1]
4207 Each summand in square sum of approximation deviations from
4208 given values is multiplied by the square of corresponding
4209 weight. Fill it by 1's if you don't want to solve weighted
4210 task.
4211 N - number of points (optional):
4212 * N>0
4213 * if given, only first N elements of X/Y/W are processed
4214 * if not given, automatically determined from X/Y/W sizes
4215 XC - points where spline values/derivatives are constrained,
4216 array[0..K-1].
4217 YC - values of constraints, array[0..K-1]
4218 DC - array[0..K-1], types of constraints:
4219 * DC[i]=0 means that S(XC[i])=YC[i]
4220 * DC[i]=1 means that S'(XC[i])=YC[i]
4221 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS
4222 K - number of constraints (optional):
4223 * 0<=K<M.
4224 * K=0 means no constraints (XC/YC/DC are not used)
4225 * if given, only first K elements of XC/YC/DC are used
4226 * if not given, automatically determined from XC/YC/DC
4227 M - number of basis functions (= 2 * number of nodes),
4228 M>=4,
4229 M IS EVEN!
4230
4231OUTPUT PARAMETERS:
4232 Info- same format as in LSFitLinearW() subroutine:
4233 * Info>0 task is solved
4234 * Info<=0 an error occured:
4235 -4 means inconvergence of internal SVD
4236 -3 means inconsistent constraints
4237 -2 means odd M was passed (which is not supported)
4238 -1 means another errors in parameters passed
4239 (N<=0, for example)
4240 S - spline interpolant.
4241 Rep - report, same format as in LSFitLinearW() subroutine.
4242 Following fields are set:
4243 * RMSError rms error on the (X,Y).
4244 * AvgError average error on the (X,Y).
4245 * AvgRelError average relative error on the non-zero Y
4246 * MaxError maximum error
4247 NON-WEIGHTED ERRORS ARE CALCULATED
4248
4249IMPORTANT:
4250 this subroitine doesn't calculate task's condition number for K<>0.
4251
4252IMPORTANT:
4253 this subroitine supports only even M's
4254
4255
4256ORDER OF POINTS
4257
4258Subroutine automatically sorts points, so caller may pass unsorted array.
4259
4260SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES:
4261
4262Setting constraints can lead to undesired results, like ill-conditioned
4263behavior, or inconsistency being detected. From the other side, it allows
4264us to improve quality of the fit. Here we summarize our experience with
4265constrained regression splines:
4266* excessive constraints can be inconsistent. Splines are piecewise cubic
4267 functions, and it is easy to create an example, where large number of
4268 constraints concentrated in small area will result in inconsistency.
4269 Just because spline is not flexible enough to satisfy all of them. And
4270 same constraints spread across the [min(x),max(x)] will be perfectly
4271 consistent.
4272* the more evenly constraints are spread across [min(x),max(x)], the more
4273 chances that they will be consistent
4274* the greater is M (given fixed constraints), the more chances that
4275 constraints will be consistent
4276* in the general case, consistency of constraints is NOT GUARANTEED.
4277* in the several special cases, however, we can guarantee consistency.
4278* one of this cases is M>=4 and constraints on the function value
4279 (AND/OR its derivative) at the interval boundaries.
4280* another special case is M>=4 and ONE constraint on the function value
4281 (OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)]
4282
4283Our final recommendation is to use constraints WHEN AND ONLY when you
4284can't solve your task without them. Anything beyond special cases given
4285above is not guaranteed and may result in inconsistency.
4286
4287 -- ALGLIB PROJECT --
4288 Copyright 18.08.2009 by Bochkanov Sergey
4289*************************************************************************/
4290void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4291void smp_spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4292void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4293void smp_spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4294
4295
4296/*************************************************************************
4297Least squares fitting by cubic spline.
4298
4299This subroutine is "lightweight" alternative for more complex and feature-
4300rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information
4301about subroutine parameters (we don't duplicate it here because of length)
4302
4303COMMERCIAL EDITION OF ALGLIB:
4304
4305 ! Commercial version of ALGLIB includes two important improvements of
4306 ! this function, which can be used from C++ and C#:
4307 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4308 ! * multithreading support
4309 !
4310 ! Intel MKL gives approximately constant (with respect to number of
4311 ! worker threads) acceleration factor which depends on CPU being used,
4312 ! problem size and "baseline" ALGLIB edition which is used for
4313 ! comparison.
4314 !
4315 ! Speed-up provided by multithreading greatly depends on problem size
4316 ! - only large problems (number of coefficients is more than 500) can be
4317 ! efficiently multithreaded.
4318 !
4319 ! Generally, commercial ALGLIB is several times faster than open-source
4320 ! generic C edition, and many times faster than open-source C# edition.
4321 !
4322 ! We recommend you to read 'Working with commercial version' section of
4323 ! ALGLIB Reference Manual in order to find out how to use performance-
4324 ! related features provided by commercial edition of ALGLIB.
4325
4326 -- ALGLIB PROJECT --
4327 Copyright 18.08.2009 by Bochkanov Sergey
4328*************************************************************************/
4329void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4330void smp_spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4331void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4332void smp_spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4333
4334
4335/*************************************************************************
4336Least squares fitting by Hermite spline.
4337
4338This subroutine is "lightweight" alternative for more complex and feature-
4339rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for
4340more information about subroutine parameters (we don't duplicate it here
4341because of length).
4342
4343COMMERCIAL EDITION OF ALGLIB:
4344
4345 ! Commercial version of ALGLIB includes two important improvements of
4346 ! this function, which can be used from C++ and C#:
4347 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4348 ! * multithreading support
4349 !
4350 ! Intel MKL gives approximately constant (with respect to number of
4351 ! worker threads) acceleration factor which depends on CPU being used,
4352 ! problem size and "baseline" ALGLIB edition which is used for
4353 ! comparison.
4354 !
4355 ! Speed-up provided by multithreading greatly depends on problem size
4356 ! - only large problems (number of coefficients is more than 500) can be
4357 ! efficiently multithreaded.
4358 !
4359 ! Generally, commercial ALGLIB is several times faster than open-source
4360 ! generic C edition, and many times faster than open-source C# edition.
4361 !
4362 ! We recommend you to read 'Working with commercial version' section of
4363 ! ALGLIB Reference Manual in order to find out how to use performance-
4364 ! related features provided by commercial edition of ALGLIB.
4365
4366 -- ALGLIB PROJECT --
4367 Copyright 18.08.2009 by Bochkanov Sergey
4368*************************************************************************/
4369void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4370void smp_spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4371void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4372void smp_spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep);
4373
4374
4375/*************************************************************************
4376Weighted linear least squares fitting.
4377
4378QR decomposition is used to reduce task to MxM, then triangular solver or
4379SVD-based solver is used depending on condition number of the system. It
4380allows to maximize speed and retain decent accuracy.
4381
4382IMPORTANT: if you want to perform polynomial fitting, it may be more
4383 convenient to use PolynomialFit() function. This function gives
4384 best results on polynomial problems and solves numerical
4385 stability issues which arise when you fit high-degree
4386 polynomials to your data.
4387
4388COMMERCIAL EDITION OF ALGLIB:
4389
4390 ! Commercial version of ALGLIB includes two important improvements of
4391 ! this function, which can be used from C++ and C#:
4392 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4393 ! * multithreading support
4394 !
4395 ! Intel MKL gives approximately constant (with respect to number of
4396 ! worker threads) acceleration factor which depends on CPU being used,
4397 ! problem size and "baseline" ALGLIB edition which is used for
4398 ! comparison.
4399 !
4400 ! Speed-up provided by multithreading greatly depends on problem size
4401 ! - only large problems (number of coefficients is more than 500) can be
4402 ! efficiently multithreaded.
4403 !
4404 ! Generally, commercial ALGLIB is several times faster than open-source
4405 ! generic C edition, and many times faster than open-source C# edition.
4406 !
4407 ! We recommend you to read 'Working with commercial version' section of
4408 ! ALGLIB Reference Manual in order to find out how to use performance-
4409 ! related features provided by commercial edition of ALGLIB.
4410
4411INPUT PARAMETERS:
4412 Y - array[0..N-1] Function values in N points.
4413 W - array[0..N-1] Weights corresponding to function values.
4414 Each summand in square sum of approximation deviations
4415 from given values is multiplied by the square of
4416 corresponding weight.
4417 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
4418 FMatrix[I, J] - value of J-th basis function in I-th point.
4419 N - number of points used. N>=1.
4420 M - number of basis functions, M>=1.
4421
4422OUTPUT PARAMETERS:
4423 Info - error code:
4424 * -4 internal SVD decomposition subroutine failed (very
4425 rare and for degenerate systems only)
4426 * -1 incorrect N/M were specified
4427 * 1 task is solved
4428 C - decomposition coefficients, array[0..M-1]
4429 Rep - fitting report. Following fields are set:
4430 * Rep.TaskRCond reciprocal of condition number
4431 * R2 non-adjusted coefficient of determination
4432 (non-weighted)
4433 * RMSError rms error on the (X,Y).
4434 * AvgError average error on the (X,Y).
4435 * AvgRelError average relative error on the non-zero Y
4436 * MaxError maximum error
4437 NON-WEIGHTED ERRORS ARE CALCULATED
4438
4439ERRORS IN PARAMETERS
4440
4441This solver also calculates different kinds of errors in parameters and
4442fills corresponding fields of report:
4443* Rep.CovPar covariance matrix for parameters, array[K,K].
4444* Rep.ErrPar errors in parameters, array[K],
4445 errpar = sqrt(diag(CovPar))
4446* Rep.ErrCurve vector of fit errors - standard deviations of empirical
4447 best-fit curve from "ideal" best-fit curve built with
4448 infinite number of samples, array[N].
4449 errcurve = sqrt(diag(F*CovPar*F')),
4450 where F is functions matrix.
4451* Rep.Noise vector of per-point estimates of noise, array[N]
4452
4453NOTE: noise in the data is estimated as follows:
4454 * for fitting without user-supplied weights all points are
4455 assumed to have same level of noise, which is estimated from
4456 the data
4457 * for fitting with user-supplied weights we assume that noise
4458 level in I-th point is inversely proportional to Ith weight.
4459 Coefficient of proportionality is estimated from the data.
4460
4461NOTE: we apply small amount of regularization when we invert squared
4462 Jacobian and calculate covariance matrix. It guarantees that
4463 algorithm won't divide by zero during inversion, but skews
4464 error estimates a bit (fractional error is about 10^-9).
4465
4466 However, we believe that this difference is insignificant for
4467 all practical purposes except for the situation when you want
4468 to compare ALGLIB results with "reference" implementation up
4469 to the last significant digit.
4470
4471NOTE: covariance matrix is estimated using correction for degrees
4472 of freedom (covariances are divided by N-M instead of dividing
4473 by N).
4474
4475 -- ALGLIB --
4476 Copyright 17.08.2009 by Bochkanov Sergey
4477*************************************************************************/
4478void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4479void smp_lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4480void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4481void smp_lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4482
4483
4484/*************************************************************************
4485Weighted constained linear least squares fitting.
4486
4487This is variation of LSFitLinearW(), which searchs for min|A*x=b| given
4488that K additional constaints C*x=bc are satisfied. It reduces original
4489task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW()
4490is called.
4491
4492IMPORTANT: if you want to perform polynomial fitting, it may be more
4493 convenient to use PolynomialFit() function. This function gives
4494 best results on polynomial problems and solves numerical
4495 stability issues which arise when you fit high-degree
4496 polynomials to your data.
4497
4498COMMERCIAL EDITION OF ALGLIB:
4499
4500 ! Commercial version of ALGLIB includes two important improvements of
4501 ! this function, which can be used from C++ and C#:
4502 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4503 ! * multithreading support
4504 !
4505 ! Intel MKL gives approximately constant (with respect to number of
4506 ! worker threads) acceleration factor which depends on CPU being used,
4507 ! problem size and "baseline" ALGLIB edition which is used for
4508 ! comparison.
4509 !
4510 ! Speed-up provided by multithreading greatly depends on problem size
4511 ! - only large problems (number of coefficients is more than 500) can be
4512 ! efficiently multithreaded.
4513 !
4514 ! Generally, commercial ALGLIB is several times faster than open-source
4515 ! generic C edition, and many times faster than open-source C# edition.
4516 !
4517 ! We recommend you to read 'Working with commercial version' section of
4518 ! ALGLIB Reference Manual in order to find out how to use performance-
4519 ! related features provided by commercial edition of ALGLIB.
4520
4521INPUT PARAMETERS:
4522 Y - array[0..N-1] Function values in N points.
4523 W - array[0..N-1] Weights corresponding to function values.
4524 Each summand in square sum of approximation deviations
4525 from given values is multiplied by the square of
4526 corresponding weight.
4527 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
4528 FMatrix[I,J] - value of J-th basis function in I-th point.
4529 CMatrix - a table of constaints, array[0..K-1,0..M].
4530 I-th row of CMatrix corresponds to I-th linear constraint:
4531 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M]
4532 N - number of points used. N>=1.
4533 M - number of basis functions, M>=1.
4534 K - number of constraints, 0 <= K < M
4535 K=0 corresponds to absence of constraints.
4536
4537OUTPUT PARAMETERS:
4538 Info - error code:
4539 * -4 internal SVD decomposition subroutine failed (very
4540 rare and for degenerate systems only)
4541 * -3 either too many constraints (M or more),
4542 degenerate constraints (some constraints are
4543 repetead twice) or inconsistent constraints were
4544 specified.
4545 * 1 task is solved
4546 C - decomposition coefficients, array[0..M-1]
4547 Rep - fitting report. Following fields are set:
4548 * R2 non-adjusted coefficient of determination
4549 (non-weighted)
4550 * RMSError rms error on the (X,Y).
4551 * AvgError average error on the (X,Y).
4552 * AvgRelError average relative error on the non-zero Y
4553 * MaxError maximum error
4554 NON-WEIGHTED ERRORS ARE CALCULATED
4555
4556IMPORTANT:
4557 this subroitine doesn't calculate task's condition number for K<>0.
4558
4559ERRORS IN PARAMETERS
4560
4561This solver also calculates different kinds of errors in parameters and
4562fills corresponding fields of report:
4563* Rep.CovPar covariance matrix for parameters, array[K,K].
4564* Rep.ErrPar errors in parameters, array[K],
4565 errpar = sqrt(diag(CovPar))
4566* Rep.ErrCurve vector of fit errors - standard deviations of empirical
4567 best-fit curve from "ideal" best-fit curve built with
4568 infinite number of samples, array[N].
4569 errcurve = sqrt(diag(F*CovPar*F')),
4570 where F is functions matrix.
4571* Rep.Noise vector of per-point estimates of noise, array[N]
4572
4573IMPORTANT: errors in parameters are calculated without taking into
4574 account boundary/linear constraints! Presence of constraints
4575 changes distribution of errors, but there is no easy way to
4576 account for constraints when you calculate covariance matrix.
4577
4578NOTE: noise in the data is estimated as follows:
4579 * for fitting without user-supplied weights all points are
4580 assumed to have same level of noise, which is estimated from
4581 the data
4582 * for fitting with user-supplied weights we assume that noise
4583 level in I-th point is inversely proportional to Ith weight.
4584 Coefficient of proportionality is estimated from the data.
4585
4586NOTE: we apply small amount of regularization when we invert squared
4587 Jacobian and calculate covariance matrix. It guarantees that
4588 algorithm won't divide by zero during inversion, but skews
4589 error estimates a bit (fractional error is about 10^-9).
4590
4591 However, we believe that this difference is insignificant for
4592 all practical purposes except for the situation when you want
4593 to compare ALGLIB results with "reference" implementation up
4594 to the last significant digit.
4595
4596NOTE: covariance matrix is estimated using correction for degrees
4597 of freedom (covariances are divided by N-M instead of dividing
4598 by N).
4599
4600 -- ALGLIB --
4601 Copyright 07.09.2009 by Bochkanov Sergey
4602*************************************************************************/
4603void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4604void smp_lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4605void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4606void smp_lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4607
4608
4609/*************************************************************************
4610Linear least squares fitting.
4611
4612QR decomposition is used to reduce task to MxM, then triangular solver or
4613SVD-based solver is used depending on condition number of the system. It
4614allows to maximize speed and retain decent accuracy.
4615
4616IMPORTANT: if you want to perform polynomial fitting, it may be more
4617 convenient to use PolynomialFit() function. This function gives
4618 best results on polynomial problems and solves numerical
4619 stability issues which arise when you fit high-degree
4620 polynomials to your data.
4621
4622COMMERCIAL EDITION OF ALGLIB:
4623
4624 ! Commercial version of ALGLIB includes two important improvements of
4625 ! this function, which can be used from C++ and C#:
4626 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4627 ! * multithreading support
4628 !
4629 ! Intel MKL gives approximately constant (with respect to number of
4630 ! worker threads) acceleration factor which depends on CPU being used,
4631 ! problem size and "baseline" ALGLIB edition which is used for
4632 ! comparison.
4633 !
4634 ! Speed-up provided by multithreading greatly depends on problem size
4635 ! - only large problems (number of coefficients is more than 500) can be
4636 ! efficiently multithreaded.
4637 !
4638 ! Generally, commercial ALGLIB is several times faster than open-source
4639 ! generic C edition, and many times faster than open-source C# edition.
4640 !
4641 ! We recommend you to read 'Working with commercial version' section of
4642 ! ALGLIB Reference Manual in order to find out how to use performance-
4643 ! related features provided by commercial edition of ALGLIB.
4644
4645INPUT PARAMETERS:
4646 Y - array[0..N-1] Function values in N points.
4647 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
4648 FMatrix[I, J] - value of J-th basis function in I-th point.
4649 N - number of points used. N>=1.
4650 M - number of basis functions, M>=1.
4651
4652OUTPUT PARAMETERS:
4653 Info - error code:
4654 * -4 internal SVD decomposition subroutine failed (very
4655 rare and for degenerate systems only)
4656 * 1 task is solved
4657 C - decomposition coefficients, array[0..M-1]
4658 Rep - fitting report. Following fields are set:
4659 * Rep.TaskRCond reciprocal of condition number
4660 * R2 non-adjusted coefficient of determination
4661 (non-weighted)
4662 * RMSError rms error on the (X,Y).
4663 * AvgError average error on the (X,Y).
4664 * AvgRelError average relative error on the non-zero Y
4665 * MaxError maximum error
4666 NON-WEIGHTED ERRORS ARE CALCULATED
4667
4668ERRORS IN PARAMETERS
4669
4670This solver also calculates different kinds of errors in parameters and
4671fills corresponding fields of report:
4672* Rep.CovPar covariance matrix for parameters, array[K,K].
4673* Rep.ErrPar errors in parameters, array[K],
4674 errpar = sqrt(diag(CovPar))
4675* Rep.ErrCurve vector of fit errors - standard deviations of empirical
4676 best-fit curve from "ideal" best-fit curve built with
4677 infinite number of samples, array[N].
4678 errcurve = sqrt(diag(F*CovPar*F')),
4679 where F is functions matrix.
4680* Rep.Noise vector of per-point estimates of noise, array[N]
4681
4682NOTE: noise in the data is estimated as follows:
4683 * for fitting without user-supplied weights all points are
4684 assumed to have same level of noise, which is estimated from
4685 the data
4686 * for fitting with user-supplied weights we assume that noise
4687 level in I-th point is inversely proportional to Ith weight.
4688 Coefficient of proportionality is estimated from the data.
4689
4690NOTE: we apply small amount of regularization when we invert squared
4691 Jacobian and calculate covariance matrix. It guarantees that
4692 algorithm won't divide by zero during inversion, but skews
4693 error estimates a bit (fractional error is about 10^-9).
4694
4695 However, we believe that this difference is insignificant for
4696 all practical purposes except for the situation when you want
4697 to compare ALGLIB results with "reference" implementation up
4698 to the last significant digit.
4699
4700NOTE: covariance matrix is estimated using correction for degrees
4701 of freedom (covariances are divided by N-M instead of dividing
4702 by N).
4703
4704 -- ALGLIB --
4705 Copyright 17.08.2009 by Bochkanov Sergey
4706*************************************************************************/
4707void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4708void smp_lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4709void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4710void smp_lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4711
4712
4713/*************************************************************************
4714Constained linear least squares fitting.
4715
4716This is variation of LSFitLinear(), which searchs for min|A*x=b| given
4717that K additional constaints C*x=bc are satisfied. It reduces original
4718task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear()
4719is called.
4720
4721IMPORTANT: if you want to perform polynomial fitting, it may be more
4722 convenient to use PolynomialFit() function. This function gives
4723 best results on polynomial problems and solves numerical
4724 stability issues which arise when you fit high-degree
4725 polynomials to your data.
4726
4727COMMERCIAL EDITION OF ALGLIB:
4728
4729 ! Commercial version of ALGLIB includes two important improvements of
4730 ! this function, which can be used from C++ and C#:
4731 ! * Intel MKL support (lightweight Intel MKL is shipped with ALGLIB)
4732 ! * multithreading support
4733 !
4734 ! Intel MKL gives approximately constant (with respect to number of
4735 ! worker threads) acceleration factor which depends on CPU being used,
4736 ! problem size and "baseline" ALGLIB edition which is used for
4737 ! comparison.
4738 !
4739 ! Speed-up provided by multithreading greatly depends on problem size
4740 ! - only large problems (number of coefficients is more than 500) can be
4741 ! efficiently multithreaded.
4742 !
4743 ! Generally, commercial ALGLIB is several times faster than open-source
4744 ! generic C edition, and many times faster than open-source C# edition.
4745 !
4746 ! We recommend you to read 'Working with commercial version' section of
4747 ! ALGLIB Reference Manual in order to find out how to use performance-
4748 ! related features provided by commercial edition of ALGLIB.
4749
4750INPUT PARAMETERS:
4751 Y - array[0..N-1] Function values in N points.
4752 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1].
4753 FMatrix[I,J] - value of J-th basis function in I-th point.
4754 CMatrix - a table of constaints, array[0..K-1,0..M].
4755 I-th row of CMatrix corresponds to I-th linear constraint:
4756 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M]
4757 N - number of points used. N>=1.
4758 M - number of basis functions, M>=1.
4759 K - number of constraints, 0 <= K < M
4760 K=0 corresponds to absence of constraints.
4761
4762OUTPUT PARAMETERS:
4763 Info - error code:
4764 * -4 internal SVD decomposition subroutine failed (very
4765 rare and for degenerate systems only)
4766 * -3 either too many constraints (M or more),
4767 degenerate constraints (some constraints are
4768 repetead twice) or inconsistent constraints were
4769 specified.
4770 * 1 task is solved
4771 C - decomposition coefficients, array[0..M-1]
4772 Rep - fitting report. Following fields are set:
4773 * R2 non-adjusted coefficient of determination
4774 (non-weighted)
4775 * RMSError rms error on the (X,Y).
4776 * AvgError average error on the (X,Y).
4777 * AvgRelError average relative error on the non-zero Y
4778 * MaxError maximum error
4779 NON-WEIGHTED ERRORS ARE CALCULATED
4780
4781IMPORTANT:
4782 this subroitine doesn't calculate task's condition number for K<>0.
4783
4784ERRORS IN PARAMETERS
4785
4786This solver also calculates different kinds of errors in parameters and
4787fills corresponding fields of report:
4788* Rep.CovPar covariance matrix for parameters, array[K,K].
4789* Rep.ErrPar errors in parameters, array[K],
4790 errpar = sqrt(diag(CovPar))
4791* Rep.ErrCurve vector of fit errors - standard deviations of empirical
4792 best-fit curve from "ideal" best-fit curve built with
4793 infinite number of samples, array[N].
4794 errcurve = sqrt(diag(F*CovPar*F')),
4795 where F is functions matrix.
4796* Rep.Noise vector of per-point estimates of noise, array[N]
4797
4798IMPORTANT: errors in parameters are calculated without taking into
4799 account boundary/linear constraints! Presence of constraints
4800 changes distribution of errors, but there is no easy way to
4801 account for constraints when you calculate covariance matrix.
4802
4803NOTE: noise in the data is estimated as follows:
4804 * for fitting without user-supplied weights all points are
4805 assumed to have same level of noise, which is estimated from
4806 the data
4807 * for fitting with user-supplied weights we assume that noise
4808 level in I-th point is inversely proportional to Ith weight.
4809 Coefficient of proportionality is estimated from the data.
4810
4811NOTE: we apply small amount of regularization when we invert squared
4812 Jacobian and calculate covariance matrix. It guarantees that
4813 algorithm won't divide by zero during inversion, but skews
4814 error estimates a bit (fractional error is about 10^-9).
4815
4816 However, we believe that this difference is insignificant for
4817 all practical purposes except for the situation when you want
4818 to compare ALGLIB results with "reference" implementation up
4819 to the last significant digit.
4820
4821NOTE: covariance matrix is estimated using correction for degrees
4822 of freedom (covariances are divided by N-M instead of dividing
4823 by N).
4824
4825 -- ALGLIB --
4826 Copyright 07.09.2009 by Bochkanov Sergey
4827*************************************************************************/
4828void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4829void smp_lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4830void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4831void smp_lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, const real_2d_array &cmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
4832
4833
4834/*************************************************************************
4835Weighted nonlinear least squares fitting using function values only.
4836
4837Combination of numerical differentiation and secant updates is used to
4838obtain function Jacobian.
4839
4840Nonlinear task min(F(c)) is solved, where
4841
4842 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
4843
4844 * N is a number of points,
4845 * M is a dimension of a space points belong to,
4846 * K is a dimension of a space of parameters being fitted,
4847 * w is an N-dimensional vector of weight coefficients,
4848 * x is a set of N points, each of them is an M-dimensional vector,
4849 * c is a K-dimensional vector of parameters being fitted
4850
4851This subroutine uses only f(c,x[i]).
4852
4853INPUT PARAMETERS:
4854 X - array[0..N-1,0..M-1], points (one row = one point)
4855 Y - array[0..N-1], function values.
4856 W - weights, array[0..N-1]
4857 C - array[0..K-1], initial approximation to the solution,
4858 N - number of points, N>1
4859 M - dimension of space
4860 K - number of parameters being fitted
4861 DiffStep- numerical differentiation step;
4862 should not be very small or large;
4863 large = loss of accuracy
4864 small = growth of round-off errors
4865
4866OUTPUT PARAMETERS:
4867 State - structure which stores algorithm state
4868
4869 -- ALGLIB --
4870 Copyright 18.10.2008 by Bochkanov Sergey
4871*************************************************************************/
4872void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const double diffstep, lsfitstate &state);
4873void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const double diffstep, lsfitstate &state);
4874
4875
4876/*************************************************************************
4877Nonlinear least squares fitting using function values only.
4878
4879Combination of numerical differentiation and secant updates is used to
4880obtain function Jacobian.
4881
4882Nonlinear task min(F(c)) is solved, where
4883
4884 F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2,
4885
4886 * N is a number of points,
4887 * M is a dimension of a space points belong to,
4888 * K is a dimension of a space of parameters being fitted,
4889 * w is an N-dimensional vector of weight coefficients,
4890 * x is a set of N points, each of them is an M-dimensional vector,
4891 * c is a K-dimensional vector of parameters being fitted
4892
4893This subroutine uses only f(c,x[i]).
4894
4895INPUT PARAMETERS:
4896 X - array[0..N-1,0..M-1], points (one row = one point)
4897 Y - array[0..N-1], function values.
4898 C - array[0..K-1], initial approximation to the solution,
4899 N - number of points, N>1
4900 M - dimension of space
4901 K - number of parameters being fitted
4902 DiffStep- numerical differentiation step;
4903 should not be very small or large;
4904 large = loss of accuracy
4905 small = growth of round-off errors
4906
4907OUTPUT PARAMETERS:
4908 State - structure which stores algorithm state
4909
4910 -- ALGLIB --
4911 Copyright 18.10.2008 by Bochkanov Sergey
4912*************************************************************************/
4913void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const double diffstep, lsfitstate &state);
4914void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const double diffstep, lsfitstate &state);
4915
4916
4917/*************************************************************************
4918Weighted nonlinear least squares fitting using gradient only.
4919
4920Nonlinear task min(F(c)) is solved, where
4921
4922 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
4923
4924 * N is a number of points,
4925 * M is a dimension of a space points belong to,
4926 * K is a dimension of a space of parameters being fitted,
4927 * w is an N-dimensional vector of weight coefficients,
4928 * x is a set of N points, each of them is an M-dimensional vector,
4929 * c is a K-dimensional vector of parameters being fitted
4930
4931This subroutine uses only f(c,x[i]) and its gradient.
4932
4933INPUT PARAMETERS:
4934 X - array[0..N-1,0..M-1], points (one row = one point)
4935 Y - array[0..N-1], function values.
4936 W - weights, array[0..N-1]
4937 C - array[0..K-1], initial approximation to the solution,
4938 N - number of points, N>1
4939 M - dimension of space
4940 K - number of parameters being fitted
4941 CheapFG - boolean flag, which is:
4942 * True if both function and gradient calculation complexity
4943 are less than O(M^2). An improved algorithm can
4944 be used which corresponds to FGJ scheme from
4945 MINLM unit.
4946 * False otherwise.
4947 Standard Jacibian-bases Levenberg-Marquardt algo
4948 will be used (FJ scheme).
4949
4950OUTPUT PARAMETERS:
4951 State - structure which stores algorithm state
4952
4953See also:
4954 LSFitResults
4955 LSFitCreateFG (fitting without weights)
4956 LSFitCreateWFGH (fitting using Hessian)
4957 LSFitCreateFGH (fitting using Hessian, without weights)
4958
4959 -- ALGLIB --
4960 Copyright 17.08.2009 by Bochkanov Sergey
4961*************************************************************************/
4962void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const bool cheapfg, lsfitstate &state);
4963void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const bool cheapfg, lsfitstate &state);
4964
4965
4966/*************************************************************************
4967Nonlinear least squares fitting using gradient only, without individual
4968weights.
4969
4970Nonlinear task min(F(c)) is solved, where
4971
4972 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
4973
4974 * N is a number of points,
4975 * M is a dimension of a space points belong to,
4976 * K is a dimension of a space of parameters being fitted,
4977 * x is a set of N points, each of them is an M-dimensional vector,
4978 * c is a K-dimensional vector of parameters being fitted
4979
4980This subroutine uses only f(c,x[i]) and its gradient.
4981
4982INPUT PARAMETERS:
4983 X - array[0..N-1,0..M-1], points (one row = one point)
4984 Y - array[0..N-1], function values.
4985 C - array[0..K-1], initial approximation to the solution,
4986 N - number of points, N>1
4987 M - dimension of space
4988 K - number of parameters being fitted
4989 CheapFG - boolean flag, which is:
4990 * True if both function and gradient calculation complexity
4991 are less than O(M^2). An improved algorithm can
4992 be used which corresponds to FGJ scheme from
4993 MINLM unit.
4994 * False otherwise.
4995 Standard Jacibian-bases Levenberg-Marquardt algo
4996 will be used (FJ scheme).
4997
4998OUTPUT PARAMETERS:
4999 State - structure which stores algorithm state
5000
5001 -- ALGLIB --
5002 Copyright 17.08.2009 by Bochkanov Sergey
5003*************************************************************************/
5004void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const bool cheapfg, lsfitstate &state);
5005void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const bool cheapfg, lsfitstate &state);
5006
5007
5008/*************************************************************************
5009Weighted nonlinear least squares fitting using gradient/Hessian.
5010
5011Nonlinear task min(F(c)) is solved, where
5012
5013 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2,
5014
5015 * N is a number of points,
5016 * M is a dimension of a space points belong to,
5017 * K is a dimension of a space of parameters being fitted,
5018 * w is an N-dimensional vector of weight coefficients,
5019 * x is a set of N points, each of them is an M-dimensional vector,
5020 * c is a K-dimensional vector of parameters being fitted
5021
5022This subroutine uses f(c,x[i]), its gradient and its Hessian.
5023
5024INPUT PARAMETERS:
5025 X - array[0..N-1,0..M-1], points (one row = one point)
5026 Y - array[0..N-1], function values.
5027 W - weights, array[0..N-1]
5028 C - array[0..K-1], initial approximation to the solution,
5029 N - number of points, N>1
5030 M - dimension of space
5031 K - number of parameters being fitted
5032
5033OUTPUT PARAMETERS:
5034 State - structure which stores algorithm state
5035
5036 -- ALGLIB --
5037 Copyright 17.08.2009 by Bochkanov Sergey
5038*************************************************************************/
5039void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfitstate &state);
5040void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, lsfitstate &state);
5041
5042
5043/*************************************************************************
5044Nonlinear least squares fitting using gradient/Hessian, without individial
5045weights.
5046
5047Nonlinear task min(F(c)) is solved, where
5048
5049 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2,
5050
5051 * N is a number of points,
5052 * M is a dimension of a space points belong to,
5053 * K is a dimension of a space of parameters being fitted,
5054 * x is a set of N points, each of them is an M-dimensional vector,
5055 * c is a K-dimensional vector of parameters being fitted
5056
5057This subroutine uses f(c,x[i]), its gradient and its Hessian.
5058
5059INPUT PARAMETERS:
5060 X - array[0..N-1,0..M-1], points (one row = one point)
5061 Y - array[0..N-1], function values.
5062 C - array[0..K-1], initial approximation to the solution,
5063 N - number of points, N>1
5064 M - dimension of space
5065 K - number of parameters being fitted
5066
5067OUTPUT PARAMETERS:
5068 State - structure which stores algorithm state
5069
5070
5071 -- ALGLIB --
5072 Copyright 17.08.2009 by Bochkanov Sergey
5073*************************************************************************/
5074void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfitstate &state);
5075void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, lsfitstate &state);
5076
5077
5078/*************************************************************************
5079Stopping conditions for nonlinear least squares fitting.
5080
5081INPUT PARAMETERS:
5082 State - structure which stores algorithm state
5083 EpsX - >=0
5084 The subroutine finishes its work if on k+1-th iteration
5085 the condition |v|<=EpsX is fulfilled, where:
5086 * |.| means Euclidian norm
5087 * v - scaled step vector, v[i]=dx[i]/s[i]
5088 * dx - ste pvector, dx=X(k+1)-X(k)
5089 * s - scaling coefficients set by LSFitSetScale()
5090 MaxIts - maximum number of iterations. If MaxIts=0, the number of
5091 iterations is unlimited. Only Levenberg-Marquardt
5092 iterations are counted (L-BFGS/CG iterations are NOT
5093 counted because their cost is very low compared to that of
5094 LM).
5095
5096NOTE
5097
5098Passing EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
5099stopping criterion selection (according to the scheme used by MINLM unit).
5100
5101
5102 -- ALGLIB --
5103 Copyright 17.08.2009 by Bochkanov Sergey
5104*************************************************************************/
5105void lsfitsetcond(const lsfitstate &state, const double epsx, const ae_int_t maxits);
5106
5107
5108/*************************************************************************
5109This function sets maximum step length
5110
5111INPUT PARAMETERS:
5112 State - structure which stores algorithm state
5113 StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
5114 want to limit step length.
5115
5116Use this subroutine when you optimize target function which contains exp()
5117or other fast growing functions, and optimization algorithm makes too
5118large steps which leads to overflow. This function allows us to reject
5119steps that are too large (and therefore expose us to the possible
5120overflow) without actually calculating function value at the x+stp*d.
5121
5122NOTE: non-zero StpMax leads to moderate performance degradation because
5123intermediate step of preconditioned L-BFGS optimization is incompatible
5124with limits on step size.
5125
5126 -- ALGLIB --
5127 Copyright 02.04.2010 by Bochkanov Sergey
5128*************************************************************************/
5129void lsfitsetstpmax(const lsfitstate &state, const double stpmax);
5130
5131
5132/*************************************************************************
5133This function turns on/off reporting.
5134
5135INPUT PARAMETERS:
5136 State - structure which stores algorithm state
5137 NeedXRep- whether iteration reports are needed or not
5138
5139When reports are needed, State.C (current parameters) and State.F (current
5140value of fitting function) are reported.
5141
5142
5143 -- ALGLIB --
5144 Copyright 15.08.2010 by Bochkanov Sergey
5145*************************************************************************/
5146void lsfitsetxrep(const lsfitstate &state, const bool needxrep);
5147
5148
5149/*************************************************************************
5150This function sets scaling coefficients for underlying optimizer.
5151
5152ALGLIB optimizers use scaling matrices to test stopping conditions (step
5153size and gradient are scaled before comparison with tolerances). Scale of
5154the I-th variable is a translation invariant measure of:
5155a) "how large" the variable is
5156b) how large the step should be to make significant changes in the function
5157
5158Generally, scale is NOT considered to be a form of preconditioner. But LM
5159optimizer is unique in that it uses scaling matrix both in the stopping
5160condition tests and as Marquardt damping factor.
5161
5162Proper scaling is very important for the algorithm performance. It is less
5163important for the quality of results, but still has some influence (it is
5164easier to converge when variables are properly scaled, so premature
5165stopping is possible when very badly scalled variables are combined with
5166relaxed stopping conditions).
5167
5168INPUT PARAMETERS:
5169 State - structure stores algorithm state
5170 S - array[N], non-zero scaling coefficients
5171 S[i] may be negative, sign doesn't matter.
5172
5173 -- ALGLIB --
5174 Copyright 14.01.2011 by Bochkanov Sergey
5175*************************************************************************/
5176void lsfitsetscale(const lsfitstate &state, const real_1d_array &s);
5177
5178
5179/*************************************************************************
5180This function sets boundary constraints for underlying optimizer
5181
5182Boundary constraints are inactive by default (after initial creation).
5183They are preserved until explicitly turned off with another SetBC() call.
5184
5185INPUT PARAMETERS:
5186 State - structure stores algorithm state
5187 BndL - lower bounds, array[K].
5188 If some (all) variables are unbounded, you may specify
5189 very small number or -INF (latter is recommended because
5190 it will allow solver to use better algorithm).
5191 BndU - upper bounds, array[K].
5192 If some (all) variables are unbounded, you may specify
5193 very large number or +INF (latter is recommended because
5194 it will allow solver to use better algorithm).
5195
5196NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
5197variable will be "frozen" at X[i]=BndL[i]=BndU[i].
5198
5199NOTE 2: unlike other constrained optimization algorithms, this solver has
5200following useful properties:
5201* bound constraints are always satisfied exactly
5202* function is evaluated only INSIDE area specified by bound constraints
5203
5204 -- ALGLIB --
5205 Copyright 14.01.2011 by Bochkanov Sergey
5206*************************************************************************/
5207void lsfitsetbc(const lsfitstate &state, const real_1d_array &bndl, const real_1d_array &bndu);
5208
5209
5210/*************************************************************************
5211This function sets linear constraints for underlying optimizer
5212
5213Linear constraints are inactive by default (after initial creation).
5214They are preserved until explicitly turned off with another SetLC() call.
5215
5216INPUT PARAMETERS:
5217 State - structure stores algorithm state
5218 C - linear constraints, array[K,N+1].
5219 Each row of C represents one constraint, either equality
5220 or inequality (see below):
5221 * first N elements correspond to coefficients,
5222 * last element corresponds to the right part.
5223 All elements of C (including right part) must be finite.
5224 CT - type of constraints, array[K]:
5225 * if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1]
5226 * if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1]
5227 * if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1]
5228 K - number of equality/inequality constraints, K>=0:
5229 * if given, only leading K elements of C/CT are used
5230 * if not given, automatically determined from sizes of C/CT
5231
5232IMPORTANT: if you have linear constraints, it is strongly recommended to
5233 set scale of variables with lsfitsetscale(). QP solver which is
5234 used to calculate linearly constrained steps heavily relies on
5235 good scaling of input problems.
5236
5237NOTE: linear (non-box) constraints are satisfied only approximately -
5238 there always exists some violation due to numerical errors and
5239 algorithmic limitations.
5240
5241NOTE: general linear constraints add significant overhead to solution
5242 process. Although solver performs roughly same amount of iterations
5243 (when compared with similar box-only constrained problem), each
5244 iteration now involves solution of linearly constrained QP
5245 subproblem, which requires ~3-5 times more Cholesky decompositions.
5246 Thus, if you can reformulate your problem in such way this it has
5247 only box constraints, it may be beneficial to do so.
5248
5249 -- ALGLIB --
5250 Copyright 29.04.2017 by Bochkanov Sergey
5251*************************************************************************/
5252void lsfitsetlc(const lsfitstate &state, const real_2d_array &c, const integer_1d_array &ct, const ae_int_t k);
5253void lsfitsetlc(const lsfitstate &state, const real_2d_array &c, const integer_1d_array &ct);
5254
5255
5256/*************************************************************************
5257This function provides reverse communication interface
5258Reverse communication interface is not documented or recommended to use.
5259See below for functions which provide better documented API
5260*************************************************************************/
5261bool lsfititeration(const lsfitstate &state);
5262
5263
5264/*************************************************************************
5265This family of functions is used to launcn iterations of nonlinear fitter
5266
5267These functions accept following parameters:
5268 state - algorithm state
5269 func - callback which calculates function (or merit function)
5270 value func at given point x
5271 grad - callback which calculates function (or merit function)
5272 value func and gradient grad at given point x
5273 hess - callback which calculates function (or merit function)
5274 value func, gradient grad and Hessian hess at given point x
5275 rep - optional callback which is called after each iteration
5276 can be NULL
5277 ptr - optional pointer which is passed to func/grad/hess/jac/rep
5278 can be NULL
5279
5280NOTES:
5281
52821. this algorithm is somewhat unusual because it works with parameterized
5283 function f(C,X), where X is a function argument (we have many points
5284 which are characterized by different argument values), and C is a
5285 parameter to fit.
5286
5287 For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then
5288 x will be argument, and {c0,c1} will be parameters.
5289
5290 It is important to understand that this algorithm finds minimum in the
5291 space of function PARAMETERS (not arguments), so it needs derivatives
5292 of f() with respect to C, not X.
5293
5294 In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1}
5295 instead of {df/dx} = {c0}.
5296
52972. Callback functions accept C as the first parameter, and X as the second
5298
52993. If state was created with LSFitCreateFG(), algorithm needs just
5300 function and its gradient, but if state was created with
5301 LSFitCreateFGH(), algorithm will need function, gradient and Hessian.
5302
5303 According to the said above, there ase several versions of this
5304 function, which accept different sets of callbacks.
5305
5306 This flexibility opens way to subtle errors - you may create state with
5307 LSFitCreateFGH() (optimization using Hessian), but call function which
5308 does not accept Hessian. So when algorithm will request Hessian, there
5309 will be no callback to call. In this case exception will be thrown.
5310
5311 Be careful to avoid such errors because there is no way to find them at
5312 compile time - you can see them at runtime only.
5313
5314 -- ALGLIB --
5315 Copyright 17.08.2009 by Bochkanov Sergey
5316
5317*************************************************************************/
5318void lsfitfit(lsfitstate &state,
5319 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr),
5320 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
5321 void *ptr = NULL);
5322void lsfitfit(lsfitstate &state,
5323 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr),
5324 void (*grad)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, void *ptr),
5325 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
5326 void *ptr = NULL);
5327void lsfitfit(lsfitstate &state,
5328 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr),
5329 void (*grad)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, void *ptr),
5330 void (*hess)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, real_2d_array &hess, void *ptr),
5331 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL,
5332 void *ptr = NULL);
5333
5334
5335/*************************************************************************
5336Nonlinear least squares fitting results.
5337
5338Called after return from LSFitFit().
5339
5340INPUT PARAMETERS:
5341 State - algorithm state
5342
5343OUTPUT PARAMETERS:
5344 Info - completion code:
5345 * -7 gradient verification failed.
5346 See LSFitSetGradientCheck() for more information.
5347 * 2 relative step is no more than EpsX.
5348 * 5 MaxIts steps was taken
5349 * 7 stopping conditions are too stringent,
5350 further improvement is impossible
5351 C - array[0..K-1], solution
5352 Rep - optimization report. On success following fields are set:
5353 * R2 non-adjusted coefficient of determination
5354 (non-weighted)
5355 * RMSError rms error on the (X,Y).
5356 * AvgError average error on the (X,Y).
5357 * AvgRelError average relative error on the non-zero Y
5358 * MaxError maximum error
5359 NON-WEIGHTED ERRORS ARE CALCULATED
5360 * WRMSError weighted rms error on the (X,Y).
5361
5362ERRORS IN PARAMETERS
5363
5364This solver also calculates different kinds of errors in parameters and
5365fills corresponding fields of report:
5366* Rep.CovPar covariance matrix for parameters, array[K,K].
5367* Rep.ErrPar errors in parameters, array[K],
5368 errpar = sqrt(diag(CovPar))
5369* Rep.ErrCurve vector of fit errors - standard deviations of empirical
5370 best-fit curve from "ideal" best-fit curve built with
5371 infinite number of samples, array[N].
5372 errcurve = sqrt(diag(J*CovPar*J')),
5373 where J is Jacobian matrix.
5374* Rep.Noise vector of per-point estimates of noise, array[N]
5375
5376IMPORTANT: errors in parameters are calculated without taking into
5377 account boundary/linear constraints! Presence of constraints
5378 changes distribution of errors, but there is no easy way to
5379 account for constraints when you calculate covariance matrix.
5380
5381NOTE: noise in the data is estimated as follows:
5382 * for fitting without user-supplied weights all points are
5383 assumed to have same level of noise, which is estimated from
5384 the data
5385 * for fitting with user-supplied weights we assume that noise
5386 level in I-th point is inversely proportional to Ith weight.
5387 Coefficient of proportionality is estimated from the data.
5388
5389NOTE: we apply small amount of regularization when we invert squared
5390 Jacobian and calculate covariance matrix. It guarantees that
5391 algorithm won't divide by zero during inversion, but skews
5392 error estimates a bit (fractional error is about 10^-9).
5393
5394 However, we believe that this difference is insignificant for
5395 all practical purposes except for the situation when you want
5396 to compare ALGLIB results with "reference" implementation up
5397 to the last significant digit.
5398
5399NOTE: covariance matrix is estimated using correction for degrees
5400 of freedom (covariances are divided by N-M instead of dividing
5401 by N).
5402
5403 -- ALGLIB --
5404 Copyright 17.08.2009 by Bochkanov Sergey
5405*************************************************************************/
5406void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c, lsfitreport &rep);
5407
5408
5409/*************************************************************************
5410This subroutine turns on verification of the user-supplied analytic
5411gradient:
5412* user calls this subroutine before fitting begins
5413* LSFitFit() is called
5414* prior to actual fitting, for each point in data set X_i and each
5415 component of parameters being fited C_j algorithm performs following
5416 steps:
5417 * two trial steps are made to C_j-TestStep*S[j] and C_j+TestStep*S[j],
5418 where C_j is j-th parameter and S[j] is a scale of j-th parameter
5419 * if needed, steps are bounded with respect to constraints on C[]
5420 * F(X_i|C) is evaluated at these trial points
5421 * we perform one more evaluation in the middle point of the interval
5422 * we build cubic model using function values and derivatives at trial
5423 points and we compare its prediction with actual value in the middle
5424 point
5425 * in case difference between prediction and actual value is higher than
5426 some predetermined threshold, algorithm stops with completion code -7;
5427 Rep.VarIdx is set to index of the parameter with incorrect derivative.
5428* after verification is over, algorithm proceeds to the actual optimization.
5429
5430NOTE 1: verification needs N*K (points count * parameters count) gradient
5431 evaluations. It is very costly and you should use it only for low
5432 dimensional problems, when you want to be sure that you've
5433 correctly calculated analytic derivatives. You should not use it
5434 in the production code (unless you want to check derivatives
5435 provided by some third party).
5436
5437NOTE 2: you should carefully choose TestStep. Value which is too large
5438 (so large that function behaviour is significantly non-cubic) will
5439 lead to false alarms. You may use different step for different
5440 parameters by means of setting scale with LSFitSetScale().
5441
5442NOTE 3: this function may lead to false positives. In case it reports that
5443 I-th derivative was calculated incorrectly, you may decrease test
5444 step and try one more time - maybe your function changes too
5445 sharply and your step is too large for such rapidly chanding
5446 function.
5447
5448NOTE 4: this function works only for optimizers created with LSFitCreateWFG()
5449 or LSFitCreateFG() constructors.
5450
5451INPUT PARAMETERS:
5452 State - structure used to store algorithm state
5453 TestStep - verification step:
5454 * TestStep=0 turns verification off
5455 * TestStep>0 activates verification
5456
5457 -- ALGLIB --
5458 Copyright 15.06.2012 by Bochkanov Sergey
5459*************************************************************************/
5460void lsfitsetgradientcheck(const lsfitstate &state, const double teststep);
5461
5462
5463
5464/*************************************************************************
5465Fits minimum circumscribed (MCC) circle (or NX-dimensional sphere) to data
5466(a set of points in NX-dimensional space).
5467
5468INPUT PARAMETERS:
5469 XY - array[NPoints,NX] (or larger), contains dataset.
5470 One row = one point in NX-dimensional space.
5471 NPoints - dataset size, NPoints>0
5472 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on)
5473
5474OUTPUT PARAMETERS:
5475 CX - central point for a sphere
5476 RHi - radius
5477
5478NOTE: this function is an easy-to-use wrapper around more powerful "expert"
5479 function nsfitspherex().
5480
5481 This wrapper is optimized for ease of use and stability - at the
5482 cost of somewhat lower performance (we have to use very tight
5483 stopping criteria for inner optimizer because we want to make sure
5484 that it will converge on any dataset).
5485
5486 If you are ready to experiment with settings of "expert" function,
5487 you can achieve ~2-4x speedup over standard "bulletproof" settings.
5488
5489
5490 -- ALGLIB --
5491 Copyright 14.04.2017 by Bochkanov Sergey
5492*************************************************************************/
5493void nsfitspheremcc(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rhi);
5494
5495
5496/*************************************************************************
5497Fits maximum inscribed circle (or NX-dimensional sphere) to data (a set of
5498points in NX-dimensional space).
5499
5500INPUT PARAMETERS:
5501 XY - array[NPoints,NX] (or larger), contains dataset.
5502 One row = one point in NX-dimensional space.
5503 NPoints - dataset size, NPoints>0
5504 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on)
5505
5506OUTPUT PARAMETERS:
5507 CX - central point for a sphere
5508 RLo - radius
5509
5510NOTE: this function is an easy-to-use wrapper around more powerful "expert"
5511 function nsfitspherex().
5512
5513 This wrapper is optimized for ease of use and stability - at the
5514 cost of somewhat lower performance (we have to use very tight
5515 stopping criteria for inner optimizer because we want to make sure
5516 that it will converge on any dataset).
5517
5518 If you are ready to experiment with settings of "expert" function,
5519 you can achieve ~2-4x speedup over standard "bulletproof" settings.
5520
5521
5522 -- ALGLIB --
5523 Copyright 14.04.2017 by Bochkanov Sergey
5524*************************************************************************/
5525void nsfitspheremic(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo);
5526
5527
5528/*************************************************************************
5529Fits minimum zone circle (or NX-dimensional sphere) to data (a set of
5530points in NX-dimensional space).
5531
5532INPUT PARAMETERS:
5533 XY - array[NPoints,NX] (or larger), contains dataset.
5534 One row = one point in NX-dimensional space.
5535 NPoints - dataset size, NPoints>0
5536 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on)
5537
5538OUTPUT PARAMETERS:
5539 CX - central point for a sphere
5540 RLo - radius of inscribed circle
5541 RHo - radius of circumscribed circle
5542
5543NOTE: this function is an easy-to-use wrapper around more powerful "expert"
5544 function nsfitspherex().
5545
5546 This wrapper is optimized for ease of use and stability - at the
5547 cost of somewhat lower performance (we have to use very tight
5548 stopping criteria for inner optimizer because we want to make sure
5549 that it will converge on any dataset).
5550
5551 If you are ready to experiment with settings of "expert" function,
5552 you can achieve ~2-4x speedup over standard "bulletproof" settings.
5553
5554
5555 -- ALGLIB --
5556 Copyright 14.04.2017 by Bochkanov Sergey
5557*************************************************************************/
5558void nsfitspheremzc(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo, double &rhi);
5559
5560
5561/*************************************************************************
5562Fitting minimum circumscribed, maximum inscribed or minimum zone circles
5563(or NX-dimensional spheres) to data (a set of points in NX-dimensional
5564space).
5565
5566This is expert function which allows to tweak many parameters of
5567underlying nonlinear solver:
5568* stopping criteria for inner iterations
5569* number of outer iterations
5570* penalty coefficient used to handle nonlinear constraints (we convert
5571 unconstrained nonsmooth optimization problem ivolving max() and/or min()
5572 operations to quadratically constrained smooth one).
5573
5574You may tweak all these parameters or only some of them, leaving other
5575ones at their default state - just specify zero value, and solver will
5576fill it with appropriate default one.
5577
5578These comments also include some discussion of approach used to handle
5579such unusual fitting problem, its stability, drawbacks of alternative
5580methods, and convergence properties.
5581
5582INPUT PARAMETERS:
5583 XY - array[NPoints,NX] (or larger), contains dataset.
5584 One row = one point in NX-dimensional space.
5585 NPoints - dataset size, NPoints>0
5586 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on)
5587 ProblemType-used to encode problem type:
5588 * 1 for minimum circumscribed circle/sphere fitting (MCC)
5589 * 2 for maximum inscribed circle/sphere fitting (MIC)
5590 * 3 for minimum zone circle fitting (difference between
5591 Rhi and Rlo is minimized), denoted as MZC
5592 EpsX - stopping condition for NLC optimizer:
5593 * must be non-negative
5594 * use 0 to choose default value (1.0E-12 is used by default)
5595 * you may specify larger values, up to 1.0E-6, if you want
5596 to speed-up solver; NLC solver performs several
5597 preconditioned outer iterations, so final result
5598 typically has precision much better than EpsX.
5599 AULIts - number of outer iterations performed by NLC optimizer:
5600 * must be non-negative
5601 * use 0 to choose default value (20 is used by default)
5602 * you may specify values smaller than 20 if you want to
5603 speed up solver; 10 often results in good combination of
5604 precision and speed; sometimes you may get good results
5605 with just 6 outer iterations.
5606 Penalty - penalty coefficient for NLC optimizer:
5607 * must be non-negative
5608 * use 0 to choose default value (1.0E6 in current version)
5609 * it should be really large, 1.0E6...1.0E7 is a good value
5610 to start from;
5611 * generally, default value is good enough
5612
5613OUTPUT PARAMETERS:
5614 CX - central point for a sphere
5615 RLo - radius:
5616 * for ProblemType=2,3, radius of the inscribed sphere
5617 * for ProblemType=1 - zero
5618 RHo - radius:
5619 * for ProblemType=1,3, radius of the circumscribed sphere
5620 * for ProblemType=2 - zero
5621
5622NOTE: ON THE UNIQUENESS OF SOLUTIONS
5623
5624ALGLIB provides solution to several related circle fitting problems: MCC
5625(minimum circumscribed), MIC (maximum inscribed) and MZC (minimum zone)
5626fitting.
5627
5628It is important to note that among these problems only MCC is convex and
5629has unique solution independently from starting point.
5630
5631As for MIC, it may (or may not, depending on dataset properties) have
5632multiple solutions, and it always has one degenerate solution C=infinity
5633which corresponds to infinitely large radius. Thus, there are no guarantees
5634that solution to MIC returned by this solver will be the best one (and no
5635one can provide you with such guarantee because problem is NP-hard). The
5636only guarantee you have is that this solution is locally optimal, i.e. it
5637can not be improved by infinitesimally small tweaks in the parameters.
5638
5639It is also possible to "run away" to infinity when started from bad
5640initial point located outside of point cloud (or when point cloud does not
5641span entire circumference/surface of the sphere).
5642
5643Finally, MZC (minimum zone circle) stands somewhere between MCC and MIC in
5644stability. It is somewhat regularized by "circumscribed" term of the merit
5645function; however, solutions to MZC may be non-unique, and in some unlucky
5646cases it is also possible to "run away to infinity".
5647
5648
5649NOTE: ON THE NONLINEARLY CONSTRAINED PROGRAMMING APPROACH
5650
5651The problem formulation for MCC (minimum circumscribed circle; for the
5652sake of simplicity we omit MZC and MIC here) is:
5653
5654 [ [ ]2 ]
5655 min [ max [ XY[i]-C ] ]
5656 C [ i [ ] ]
5657
5658i.e. it is unconstrained nonsmooth optimization problem of finding "best"
5659central point, with radius R being unambiguously determined from C. In
5660order to move away from non-smoothness we use following reformulation:
5661
5662 [ ] [ ]2
5663 min [ R ] subject to R>=0, [ XY[i]-C ] <= R^2
5664 C,R [ ] [ ]
5665
5666i.e. it becomes smooth quadratically constrained optimization problem with
5667linear target function. Such problem statement is 100% equivalent to the
5668original nonsmooth one, but much easier to approach. We solve it with
5669MinNLC solver provided by ALGLIB.
5670
5671
5672NOTE: ON INSTABILITY OF SEQUENTIAL LINEAR PROGRAMMING APPROACJ
5673
5674ALGLIB has nonlinearly constrained solver which proved to be stable on
5675such problems. However, some authors proposed to linearize constraints in
5676the vicinity of current approximation (Ci,Ri) and to get next approximate
5677solution (Ci+1,Ri+1) as solution to linear programming problem. Obviously,
5678LP problems are easier than nonlinearly constrained ones.
5679
5680Indeed, SLP approach to MCC/MIC/MZC resulted in ~10-20x increase in
5681performance (when compared with NLC solver). However, it turned out that
5682in some cases linearized model fails to predict correct direction for next
5683step and tells us that we converged to solution even when we are still 2-4
5684digits of precision away from it.
5685
5686It is important that it is not failure of LP solver - it is failure of the
5687linear model; even when solved exactly, it fails to handle subtle
5688nonlinearities which arise near the solution. We validated it by comparing
5689results returned by ALGLIB linear solver with that of MATLAB.
5690
5691In our experiments with SLP solver:
5692* MCC failed most often, at both realistic and synthetic datasets
5693* MIC sometimes failed, but sometimes succeeded
5694* MZC often succeeded; our guess is that presence of two independent sets
5695 of constraints (one set for Rlo and another one for Rhi) and two terms
5696 in the target function (Rlo and Rhi) regularizes task, so when linear
5697 model fails to handle nonlinearities from Rlo, it uses Rhi as a hint
5698 (and vice versa).
5699
5700Because SLP approach failed to achieve stable results, we do not include
5701it in ALGLIB.
5702
5703
5704 -- ALGLIB --
5705 Copyright 14.04.2017 by Bochkanov Sergey
5706*************************************************************************/
5707void nsfitspherex(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, const ae_int_t problemtype, const double epsx, const ae_int_t aulits, const double penalty, real_1d_array &cx, double &rlo, double &rhi);
5708
5709/*************************************************************************
5710This subroutine calculates the value of the bilinear or bicubic spline at
5711the given point X.
5712
5713Input parameters:
5714 C - coefficients table.
5715 Built by BuildBilinearSpline or BuildBicubicSpline.
5716 X, Y- point
5717
5718Result:
5719 S(x,y)
5720
5721 -- ALGLIB PROJECT --
5722 Copyright 05.07.2007 by Bochkanov Sergey
5723*************************************************************************/
5724double spline2dcalc(const spline2dinterpolant &c, const double x, const double y);
5725
5726
5727/*************************************************************************
5728This subroutine calculates the value of the bilinear or bicubic spline at
5729the given point X and its derivatives.
5730
5731Input parameters:
5732 C - spline interpolant.
5733 X, Y- point
5734
5735Output parameters:
5736 F - S(x,y)
5737 FX - dS(x,y)/dX
5738 FY - dS(x,y)/dY
5739 FXY - d2S(x,y)/dXdY
5740
5741 -- ALGLIB PROJECT --
5742 Copyright 05.07.2007 by Bochkanov Sergey
5743*************************************************************************/
5744void spline2ddiff(const spline2dinterpolant &c, const double x, const double y, double &f, double &fx, double &fy, double &fxy);
5745
5746
5747/*************************************************************************
5748This subroutine performs linear transformation of the spline argument.
5749
5750Input parameters:
5751 C - spline interpolant
5752 AX, BX - transformation coefficients: x = A*t + B
5753 AY, BY - transformation coefficients: y = A*u + B
5754Result:
5755 C - transformed spline
5756
5757 -- ALGLIB PROJECT --
5758 Copyright 30.06.2007 by Bochkanov Sergey
5759*************************************************************************/
5760void spline2dlintransxy(const spline2dinterpolant &c, const double ax, const double bx, const double ay, const double by);
5761
5762
5763/*************************************************************************
5764This subroutine performs linear transformation of the spline.
5765
5766Input parameters:
5767 C - spline interpolant.
5768 A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B
5769
5770Output parameters:
5771 C - transformed spline
5772
5773 -- ALGLIB PROJECT --
5774 Copyright 30.06.2007 by Bochkanov Sergey
5775*************************************************************************/
5776void spline2dlintransf(const spline2dinterpolant &c, const double a, const double b);
5777
5778
5779/*************************************************************************
5780This subroutine makes the copy of the spline model.
5781
5782Input parameters:
5783 C - spline interpolant
5784
5785Output parameters:
5786 CC - spline copy
5787
5788 -- ALGLIB PROJECT --
5789 Copyright 29.06.2007 by Bochkanov Sergey
5790*************************************************************************/
5791void spline2dcopy(const spline2dinterpolant &c, spline2dinterpolant &cc);
5792
5793
5794/*************************************************************************
5795Bicubic spline resampling
5796
5797Input parameters:
5798 A - function values at the old grid,
5799 array[0..OldHeight-1, 0..OldWidth-1]
5800 OldHeight - old grid height, OldHeight>1
5801 OldWidth - old grid width, OldWidth>1
5802 NewHeight - new grid height, NewHeight>1
5803 NewWidth - new grid width, NewWidth>1
5804
5805Output parameters:
5806 B - function values at the new grid,
5807 array[0..NewHeight-1, 0..NewWidth-1]
5808
5809 -- ALGLIB routine --
5810 15 May, 2007
5811 Copyright by Bochkanov Sergey
5812*************************************************************************/
5813void spline2dresamplebicubic(const real_2d_array &a, const ae_int_t oldheight, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, const ae_int_t newwidth);
5814
5815
5816/*************************************************************************
5817Bilinear spline resampling
5818
5819Input parameters:
5820 A - function values at the old grid,
5821 array[0..OldHeight-1, 0..OldWidth-1]
5822 OldHeight - old grid height, OldHeight>1
5823 OldWidth - old grid width, OldWidth>1
5824 NewHeight - new grid height, NewHeight>1
5825 NewWidth - new grid width, NewWidth>1
5826
5827Output parameters:
5828 B - function values at the new grid,
5829 array[0..NewHeight-1, 0..NewWidth-1]
5830
5831 -- ALGLIB routine --
5832 09.07.2007
5833 Copyright by Bochkanov Sergey
5834*************************************************************************/
5835void spline2dresamplebilinear(const real_2d_array &a, const ae_int_t oldheight, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, const ae_int_t newwidth);
5836
5837
5838/*************************************************************************
5839This subroutine builds bilinear vector-valued spline.
5840
5841Input parameters:
5842 X - spline abscissas, array[0..N-1]
5843 Y - spline ordinates, array[0..M-1]
5844 F - function values, array[0..M*N*D-1]:
5845 * first D elements store D values at (X[0],Y[0])
5846 * next D elements store D values at (X[1],Y[0])
5847 * general form - D function values at (X[i],Y[j]) are stored
5848 at F[D*(J*N+I)...D*(J*N+I)+D-1].
5849 M,N - grid size, M>=2, N>=2
5850 D - vector dimension, D>=1
5851
5852Output parameters:
5853 C - spline interpolant
5854
5855 -- ALGLIB PROJECT --
5856 Copyright 16.04.2012 by Bochkanov Sergey
5857*************************************************************************/
5858void spline2dbuildbilinearv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &f, const ae_int_t d, spline2dinterpolant &c);
5859
5860
5861/*************************************************************************
5862This subroutine builds bicubic vector-valued spline.
5863
5864Input parameters:
5865 X - spline abscissas, array[0..N-1]
5866 Y - spline ordinates, array[0..M-1]
5867 F - function values, array[0..M*N*D-1]:
5868 * first D elements store D values at (X[0],Y[0])
5869 * next D elements store D values at (X[1],Y[0])
5870 * general form - D function values at (X[i],Y[j]) are stored
5871 at F[D*(J*N+I)...D*(J*N+I)+D-1].
5872 M,N - grid size, M>=2, N>=2
5873 D - vector dimension, D>=1
5874
5875Output parameters:
5876 C - spline interpolant
5877
5878 -- ALGLIB PROJECT --
5879 Copyright 16.04.2012 by Bochkanov Sergey
5880*************************************************************************/
5881void spline2dbuildbicubicv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &f, const ae_int_t d, spline2dinterpolant &c);
5882
5883
5884/*************************************************************************
5885This subroutine calculates bilinear or bicubic vector-valued spline at the
5886given point (X,Y).
5887
5888INPUT PARAMETERS:
5889 C - spline interpolant.
5890 X, Y- point
5891 F - output buffer, possibly preallocated array. In case array size
5892 is large enough to store result, it is not reallocated. Array
5893 which is too short will be reallocated
5894
5895OUTPUT PARAMETERS:
5896 F - array[D] (or larger) which stores function values
5897
5898 -- ALGLIB PROJECT --
5899 Copyright 16.04.2012 by Bochkanov Sergey
5900*************************************************************************/
5901void spline2dcalcvbuf(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f);
5902
5903
5904/*************************************************************************
5905This subroutine calculates bilinear or bicubic vector-valued spline at the
5906given point (X,Y).
5907
5908INPUT PARAMETERS:
5909 C - spline interpolant.
5910 X, Y- point
5911
5912OUTPUT PARAMETERS:
5913 F - array[D] which stores function values. F is out-parameter and
5914 it is reallocated after call to this function. In case you
5915 want to reuse previously allocated F, you may use
5916 Spline2DCalcVBuf(), which reallocates F only when it is too
5917 small.
5918
5919 -- ALGLIB PROJECT --
5920 Copyright 16.04.2012 by Bochkanov Sergey
5921*************************************************************************/
5922void spline2dcalcv(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f);
5923
5924
5925/*************************************************************************
5926This subroutine unpacks two-dimensional spline into the coefficients table
5927
5928Input parameters:
5929 C - spline interpolant.
5930
5931Result:
5932 M, N- grid size (x-axis and y-axis)
5933 D - number of components
5934 Tbl - coefficients table, unpacked format,
5935 D - components: [0..(N-1)*(M-1)*D-1, 0..19].
5936 For T=0..D-1 (component index), I = 0...N-2 (x index),
5937 J=0..M-2 (y index):
5938 K := T + I*D + J*D*(N-1)
5939
5940 K-th row stores decomposition for T-th component of the
5941 vector-valued function
5942
5943 Tbl[K,0] = X[i]
5944 Tbl[K,1] = X[i+1]
5945 Tbl[K,2] = Y[j]
5946 Tbl[K,3] = Y[j+1]
5947 Tbl[K,4] = C00
5948 Tbl[K,5] = C01
5949 Tbl[K,6] = C02
5950 Tbl[K,7] = C03
5951 Tbl[K,8] = C10
5952 Tbl[K,9] = C11
5953 ...
5954 Tbl[K,19] = C33
5955 On each grid square spline is equals to:
5956 S(x) = SUM(c[i,j]*(t^i)*(u^j), i=0..3, j=0..3)
5957 t = x-x[j]
5958 u = y-y[i]
5959
5960 -- ALGLIB PROJECT --
5961 Copyright 16.04.2012 by Bochkanov Sergey
5962*************************************************************************/
5963void spline2dunpackv(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, ae_int_t &d, real_2d_array &tbl);
5964
5965
5966/*************************************************************************
5967This subroutine was deprecated in ALGLIB 3.6.0
5968
5969We recommend you to switch to Spline2DBuildBilinearV(), which is more
5970flexible and accepts its arguments in more convenient order.
5971
5972 -- ALGLIB PROJECT --
5973 Copyright 05.07.2007 by Bochkanov Sergey
5974*************************************************************************/
5975void spline2dbuildbilinear(const real_1d_array &x, const real_1d_array &y, const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpolant &c);
5976
5977
5978/*************************************************************************
5979This subroutine was deprecated in ALGLIB 3.6.0
5980
5981We recommend you to switch to Spline2DBuildBicubicV(), which is more
5982flexible and accepts its arguments in more convenient order.
5983
5984 -- ALGLIB PROJECT --
5985 Copyright 05.07.2007 by Bochkanov Sergey
5986*************************************************************************/
5987void spline2dbuildbicubic(const real_1d_array &x, const real_1d_array &y, const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpolant &c);
5988
5989
5990/*************************************************************************
5991This subroutine was deprecated in ALGLIB 3.6.0
5992
5993We recommend you to switch to Spline2DUnpackV(), which is more flexible
5994and accepts its arguments in more convenient order.
5995
5996 -- ALGLIB PROJECT --
5997 Copyright 29.06.2007 by Bochkanov Sergey
5998*************************************************************************/
5999void spline2dunpack(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, real_2d_array &tbl);
6000
6001
6002
6003/*************************************************************************
6004This function serializes data structure to string.
6005
6006Important properties of s_out:
6007* it contains alphanumeric characters, dots, underscores, minus signs
6008* these symbols are grouped into words, which are separated by spaces
6009 and Windows-style (CR+LF) newlines
6010* although serializer uses spaces and CR+LF as separators, you can
6011 replace any separator character by arbitrary combination of spaces,
6012 tabs, Windows or Unix newlines. It allows flexible reformatting of
6013 the string in case you want to include it into text or XML file.
6014 But you should not insert separators into the middle of the "words"
6015 nor you should change case of letters.
6016* s_out can be freely moved between 32-bit and 64-bit systems, little
6017 and big endian machines, and so on. You can serialize structure on
6018 32-bit machine and unserialize it on 64-bit one (or vice versa), or
6019 serialize it on SPARC and unserialize on x86. You can also
6020 serialize it in C++ version of ALGLIB and unserialize in C# one,
6021 and vice versa.
6022*************************************************************************/
6023void rbfserialize(rbfmodel &obj, std::string &s_out);
6024
6025
6026/*************************************************************************
6027This function unserializes data structure from string.
6028*************************************************************************/
6029void rbfunserialize(const std::string &s_in, rbfmodel &obj);
6030
6031
6032
6033
6034/*************************************************************************
6035This function serializes data structure to C++ stream.
6036
6037Data stream generated by this function is same as string representation
6038generated by string version of serializer - alphanumeric characters,
6039dots, underscores, minus signs, which are grouped into words separated by
6040spaces and CR+LF.
6041
6042We recommend you to read comments on string version of serializer to find
6043out more about serialization of AlGLIB objects.
6044*************************************************************************/
6045void rbfserialize(rbfmodel &obj, std::ostream &s_out);
6046
6047
6048/*************************************************************************
6049This function unserializes data structure from stream.
6050*************************************************************************/
6051void rbfunserialize(const std::istream &s_in, rbfmodel &obj);
6052
6053
6054/*************************************************************************
6055This function creates RBF model for a scalar (NY=1) or vector (NY>1)
6056function in a NX-dimensional space (NX>=1).
6057
6058Newly created model is empty. It can be used for interpolation right after
6059creation, but it just returns zeros. You have to add points to the model,
6060tune interpolation settings, and then call model construction function
6061rbfbuildmodel() which will update model according to your specification.
6062
6063USAGE:
60641. User creates model with rbfcreate()
60652. User adds dataset with rbfsetpoints() (points do NOT have to be on a
6066 regular grid) or rbfsetpointsandscales().
60673. (OPTIONAL) User chooses polynomial term by calling:
6068 * rbflinterm() to set linear term
6069 * rbfconstterm() to set constant term
6070 * rbfzeroterm() to set zero term
6071 By default, linear term is used.
60724. User tweaks algorithm properties with rbfsetalgohierarchical() method
6073 (or chooses one of the legacy algorithms - QNN (rbfsetalgoqnn) or ML
6074 (rbfsetalgomultilayer)).
60755. User calls rbfbuildmodel() function which rebuilds model according to
6076 the specification
60776. User may call rbfcalc() to calculate model value at the specified point,
6078 rbfgridcalc() to calculate model values at the points of the regular
6079 grid. User may extract model coefficients with rbfunpack() call.
6080
6081IMPORTANT: we recommend you to use latest model construction algorithm -
6082 hierarchical RBFs, which is activated by rbfsetalgohierarchical()
6083 function. This algorithm is the fastest one, and most memory-
6084 efficient.
6085 However, it is incompatible with older versions of ALGLIB
6086 (pre-3.11). So, if you serialize hierarchical model, you will
6087 be unable to load it in pre-3.11 ALGLIB. Other model types (QNN
6088 and RBF-ML) are still backward-compatible.
6089
6090INPUT PARAMETERS:
6091 NX - dimension of the space, NX>=1
6092 NY - function dimension, NY>=1
6093
6094OUTPUT PARAMETERS:
6095 S - RBF model (initially equals to zero)
6096
6097NOTE 1: memory requirements. RBF models require amount of memory which is
6098 proportional to the number of data points. Some additional memory
6099 is allocated during model construction, but most of this memory is
6100 freed after model coefficients are calculated. Amount of this
6101 additional memory depends on model construction algorithm being
6102 used.
6103
6104NOTE 2: prior to ALGLIB version 3.11, RBF models supported only NX=2 or
6105 NX=3. Any attempt to create single-dimensional or more than
6106 3-dimensional RBF model resulted in exception.
6107
6108 ALGLIB 3.11 supports any NX>0, but models created with NX!=2 and
6109 NX!=3 are incompatible with (a) older versions of ALGLIB, (b) old
6110 model construction algorithms (QNN or RBF-ML).
6111
6112 So, if you create a model with NX=2 or NX=3, then, depending on
6113 specific model construction algorithm being chosen, you will (QNN
6114 and RBF-ML) or will not (HierarchicalRBF) get backward compatibility
6115 with older versions of ALGLIB. You have a choice here.
6116
6117 However, if you create a model with NX neither 2 nor 3, you have
6118 no backward compatibility from the start, and you are forced to
6119 use hierarchical RBFs and ALGLIB 3.11 or later.
6120
6121 -- ALGLIB --
6122 Copyright 13.12.2011, 20.06.2016 by Bochkanov Sergey
6123*************************************************************************/
6124void rbfcreate(const ae_int_t nx, const ae_int_t ny, rbfmodel &s);
6125
6126
6127/*************************************************************************
6128This function creates buffer structure which can be used to perform
6129parallel RBF model evaluations (with one RBF model instance being
6130used from multiple threads, as long as different threads use different
6131instances of buffer).
6132
6133This buffer object can be used with rbftscalcbuf() function (here "ts"
6134stands for "thread-safe", "buf" is a suffix which denotes function which
6135reuses previously allocated output space).
6136
6137How to use it:
6138* create RBF model structure with rbfcreate()
6139* load data, tune parameters
6140* call rbfbuildmodel()
6141* call rbfcreatecalcbuffer(), once per thread working with RBF model (you
6142 should call this function only AFTER call to rbfbuildmodel(), see below
6143 for more information)
6144* call rbftscalcbuf() from different threads, with each thread working
6145 with its own copy of buffer object.
6146
6147INPUT PARAMETERS
6148 S - RBF model
6149
6150OUTPUT PARAMETERS
6151 Buf - external buffer.
6152
6153
6154IMPORTANT: buffer object should be used only with RBF model object which
6155 was used to initialize buffer. Any attempt to use buffer with
6156 different object is dangerous - you may get memory violation
6157 error because sizes of internal arrays do not fit to dimensions
6158 of RBF structure.
6159
6160IMPORTANT: you should call this function only for model which was built
6161 with rbfbuildmodel() function, after successful invocation of
6162 rbfbuildmodel(). Sizes of some internal structures are
6163 determined only after model is built, so buffer object created
6164 before model construction stage will be useless (and any
6165 attempt to use it will result in exception).
6166
6167 -- ALGLIB --
6168 Copyright 02.04.2016 by Sergey Bochkanov
6169*************************************************************************/
6170void rbfcreatecalcbuffer(const rbfmodel &s, rbfcalcbuffer &buf);
6171
6172
6173/*************************************************************************
6174This function adds dataset.
6175
6176This function overrides results of the previous calls, i.e. multiple calls
6177of this function will result in only the last set being added.
6178
6179IMPORTANT: ALGLIB version 3.11 and later allows you to specify a set of
6180 per-dimension scales. Interpolation radii are multiplied by the
6181 scale vector. It may be useful if you have mixed spatio-temporal
6182 data (say, a set of 3D slices recorded at different times).
6183 You should call rbfsetpointsandscales() function to use this
6184 feature.
6185
6186INPUT PARAMETERS:
6187 S - RBF model, initialized by rbfcreate() call.
6188 XY - points, array[N,NX+NY]. One row corresponds to one point
6189 in the dataset. First NX elements are coordinates, next
6190 NY elements are function values. Array may be larger than
6191 specified, in this case only leading [N,NX+NY] elements
6192 will be used.
6193 N - number of points in the dataset
6194
6195After you've added dataset and (optionally) tuned algorithm settings you
6196should call rbfbuildmodel() in order to build a model for you.
6197
6198NOTE: dataset added by this function is not saved during model serialization.
6199 MODEL ITSELF is serialized, but data used to build it are not.
6200
6201 So, if you 1) add dataset to empty RBF model, 2) serialize and
6202 unserialize it, then you will get an empty RBF model with no dataset
6203 being attached.
6204
6205 From the other side, if you call rbfbuildmodel() between (1) and (2),
6206 then after (2) you will get your fully constructed RBF model - but
6207 again with no dataset attached, so subsequent calls to rbfbuildmodel()
6208 will produce empty model.
6209
6210
6211 -- ALGLIB --
6212 Copyright 13.12.2011 by Bochkanov Sergey
6213*************************************************************************/
6214void rbfsetpoints(const rbfmodel &s, const real_2d_array &xy, const ae_int_t n);
6215void rbfsetpoints(const rbfmodel &s, const real_2d_array &xy);
6216
6217
6218/*************************************************************************
6219This function adds dataset and a vector of per-dimension scales.
6220
6221It may be useful if you have mixed spatio-temporal data - say, a set of 3D
6222slices recorded at different times. Such data typically require different
6223RBF radii for spatial and temporal dimensions. ALGLIB solves this problem
6224by specifying single RBF radius, which is (optionally) multiplied by the
6225scale vector.
6226
6227This function overrides results of the previous calls, i.e. multiple calls
6228of this function will result in only the last set being added.
6229
6230IMPORTANT: only HierarchicalRBF algorithm can work with scaled points. So,
6231 using this function results in RBF models which can be used in
6232 ALGLIB 3.11 or later. Previous versions of the library will be
6233 unable to unserialize models produced by HierarchicalRBF algo.
6234
6235 Any attempt to use this function with RBF-ML or QNN algorithms
6236 will result in -3 error code being returned (incorrect
6237 algorithm).
6238
6239INPUT PARAMETERS:
6240 R - RBF model, initialized by rbfcreate() call.
6241 XY - points, array[N,NX+NY]. One row corresponds to one point
6242 in the dataset. First NX elements are coordinates, next
6243 NY elements are function values. Array may be larger than
6244 specified, in this case only leading [N,NX+NY] elements
6245 will be used.
6246 N - number of points in the dataset
6247 S - array[NX], scale vector, S[i]>0.
6248
6249After you've added dataset and (optionally) tuned algorithm settings you
6250should call rbfbuildmodel() in order to build a model for you.
6251
6252NOTE: dataset added by this function is not saved during model serialization.
6253 MODEL ITSELF is serialized, but data used to build it are not.
6254
6255 So, if you 1) add dataset to empty RBF model, 2) serialize and
6256 unserialize it, then you will get an empty RBF model with no dataset
6257 being attached.
6258
6259 From the other side, if you call rbfbuildmodel() between (1) and (2),
6260 then after (2) you will get your fully constructed RBF model - but
6261 again with no dataset attached, so subsequent calls to rbfbuildmodel()
6262 will produce empty model.
6263
6264
6265 -- ALGLIB --
6266 Copyright 20.06.2016 by Bochkanov Sergey
6267*************************************************************************/
6268void rbfsetpointsandscales(const rbfmodel &r, const real_2d_array &xy, const ae_int_t n, const real_1d_array &s);
6269void rbfsetpointsandscales(const rbfmodel &r, const real_2d_array &xy, const real_1d_array &s);
6270
6271
6272/*************************************************************************
6273DEPRECATED:since version 3.11 ALGLIB includes new RBF model construction
6274 algorithm, Hierarchical RBF. This algorithm is faster and
6275 requires less memory than QNN and RBF-ML. It is especially good
6276 for large-scale interpolation problems. So, we recommend you to
6277 consider Hierarchical RBF as default option.
6278
6279==========================================================================
6280
6281This function sets RBF interpolation algorithm. ALGLIB supports several
6282RBF algorithms with different properties.
6283
6284This algorithm is called RBF-QNN and it is good for point sets with
6285following properties:
6286a) all points are distinct
6287b) all points are well separated.
6288c) points distribution is approximately uniform. There is no "contour
6289 lines", clusters of points, or other small-scale structures.
6290
6291Algorithm description:
62921) interpolation centers are allocated to data points
62932) interpolation radii are calculated as distances to the nearest centers
6294 times Q coefficient (where Q is a value from [0.75,1.50]).
62953) after performing (2) radii are transformed in order to avoid situation
6296 when single outlier has very large radius and influences many points
6297 across all dataset. Transformation has following form:
6298 new_r[i] = min(r[i],Z*median(r[]))
6299 where r[i] is I-th radius, median() is a median radius across entire
6300 dataset, Z is user-specified value which controls amount of deviation
6301 from median radius.
6302
6303When (a) is violated, we will be unable to build RBF model. When (b) or
6304(c) are violated, model will be built, but interpolation quality will be
6305low. See http://www.alglib.net/interpolation/ for more information on this
6306subject.
6307
6308This algorithm is used by default.
6309
6310Additional Q parameter controls smoothness properties of the RBF basis:
6311* Q<0.75 will give perfectly conditioned basis, but terrible smoothness
6312 properties (RBF interpolant will have sharp peaks around function values)
6313* Q around 1.0 gives good balance between smoothness and condition number
6314* Q>1.5 will lead to badly conditioned systems and slow convergence of the
6315 underlying linear solver (although smoothness will be very good)
6316* Q>2.0 will effectively make optimizer useless because it won't converge
6317 within reasonable amount of iterations. It is possible to set such large
6318 Q, but it is advised not to do so.
6319
6320INPUT PARAMETERS:
6321 S - RBF model, initialized by RBFCreate() call
6322 Q - Q parameter, Q>0, recommended value - 1.0
6323 Z - Z parameter, Z>0, recommended value - 5.0
6324
6325NOTE: this function has some serialization-related subtleties. We
6326 recommend you to study serialization examples from ALGLIB Reference
6327 Manual if you want to perform serialization of your models.
6328
6329
6330 -- ALGLIB --
6331 Copyright 13.12.2011 by Bochkanov Sergey
6332*************************************************************************/
6333void rbfsetalgoqnn(const rbfmodel &s, const double q, const double z);
6334void rbfsetalgoqnn(const rbfmodel &s);
6335
6336
6337/*************************************************************************
6338DEPRECATED:since version 3.11 ALGLIB includes new RBF model construction
6339 algorithm, Hierarchical RBF. This algorithm is faster and
6340 requires less memory than QNN and RBF-ML. It is especially good
6341 for large-scale interpolation problems. So, we recommend you to
6342 consider Hierarchical RBF as default option.
6343
6344==========================================================================
6345
6346This function sets RBF interpolation algorithm. ALGLIB supports several
6347RBF algorithms with different properties.
6348
6349This algorithm is called RBF-ML. It builds multilayer RBF model, i.e.
6350model with subsequently decreasing radii, which allows us to combine
6351smoothness (due to large radii of the first layers) with exactness (due
6352to small radii of the last layers) and fast convergence.
6353
6354Internally RBF-ML uses many different means of acceleration, from sparse
6355matrices to KD-trees, which results in algorithm whose working time is
6356roughly proportional to N*log(N)*Density*RBase^2*NLayers, where N is a
6357number of points, Density is an average density if points per unit of the
6358interpolation space, RBase is an initial radius, NLayers is a number of
6359layers.
6360
6361RBF-ML is good for following kinds of interpolation problems:
63621. "exact" problems (perfect fit) with well separated points
63632. least squares problems with arbitrary distribution of points (algorithm
6364 gives perfect fit where it is possible, and resorts to least squares
6365 fit in the hard areas).
63663. noisy problems where we want to apply some controlled amount of
6367 smoothing.
6368
6369INPUT PARAMETERS:
6370 S - RBF model, initialized by RBFCreate() call
6371 RBase - RBase parameter, RBase>0
6372 NLayers - NLayers parameter, NLayers>0, recommended value to start
6373 with - about 5.
6374 LambdaV - regularization value, can be useful when solving problem
6375 in the least squares sense. Optimal lambda is problem-
6376 dependent and require trial and error. In our experience,
6377 good lambda can be as large as 0.1, and you can use 0.001
6378 as initial guess.
6379 Default value - 0.01, which is used when LambdaV is not
6380 given. You can specify zero value, but it is not
6381 recommended to do so.
6382
6383TUNING ALGORITHM
6384
6385In order to use this algorithm you have to choose three parameters:
6386* initial radius RBase
6387* number of layers in the model NLayers
6388* regularization coefficient LambdaV
6389
6390Initial radius is easy to choose - you can pick any number several times
6391larger than the average distance between points. Algorithm won't break
6392down if you choose radius which is too large (model construction time will
6393increase, but model will be built correctly).
6394
6395Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used
6396by the last layer) will be smaller than the typical distance between
6397points. In case model error is too large, you can increase number of
6398layers. Having more layers will make model construction and evaluation
6399proportionally slower, but it will allow you to have model which precisely
6400fits your data. From the other side, if you want to suppress noise, you
6401can DECREASE number of layers to make your model less flexible.
6402
6403Regularization coefficient LambdaV controls smoothness of the individual
6404models built for each layer. We recommend you to use default value in case
6405you don't want to tune this parameter, because having non-zero LambdaV
6406accelerates and stabilizes internal iterative algorithm. In case you want
6407to suppress noise you can use LambdaV as additional parameter (larger
6408value = more smoothness) to tune.
6409
6410TYPICAL ERRORS
6411
64121. Using initial radius which is too large. Memory requirements of the
6413 RBF-ML are roughly proportional to N*Density*RBase^2 (where Density is
6414 an average density of points per unit of the interpolation space). In
6415 the extreme case of the very large RBase we will need O(N^2) units of
6416 memory - and many layers in order to decrease radius to some reasonably
6417 small value.
6418
64192. Using too small number of layers - RBF models with large radius are not
6420 flexible enough to reproduce small variations in the target function.
6421 You need many layers with different radii, from large to small, in
6422 order to have good model.
6423
64243. Using initial radius which is too small. You will get model with
6425 "holes" in the areas which are too far away from interpolation centers.
6426 However, algorithm will work correctly (and quickly) in this case.
6427
64284. Using too many layers - you will get too large and too slow model. This
6429 model will perfectly reproduce your function, but maybe you will be
6430 able to achieve similar results with less layers (and less memory).
6431
6432 -- ALGLIB --
6433 Copyright 02.03.2012 by Bochkanov Sergey
6434*************************************************************************/
6435void rbfsetalgomultilayer(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const double lambdav);
6436void rbfsetalgomultilayer(const rbfmodel &s, const double rbase, const ae_int_t nlayers);
6437
6438
6439/*************************************************************************
6440This function sets RBF interpolation algorithm. ALGLIB supports several
6441RBF algorithms with different properties.
6442
6443This algorithm is called Hierarchical RBF. It similar to its previous
6444incarnation, RBF-ML, i.e. it also builds a sequence of models with
6445decreasing radii. However, it uses more economical way of building upper
6446layers (ones with large radii), which results in faster model construction
6447and evaluation, as well as smaller memory footprint during construction.
6448
6449This algorithm has following important features:
6450* ability to handle millions of points
6451* controllable smoothing via nonlinearity penalization
6452* support for NX-dimensional models with NX=1 or NX>3 (unlike QNN or RBF-ML)
6453* support for specification of per-dimensional radii via scale vector,
6454 which is set by means of rbfsetpointsandscales() function. This feature
6455 is useful if you solve spatio-temporal interpolation problems, where
6456 different radii are required for spatial and temporal dimensions.
6457
6458Running times are roughly proportional to:
6459* N*log(N)*NLayers - for model construction
6460* N*NLayers - for model evaluation
6461You may see that running time does not depend on search radius or points
6462density, just on number of layers in the hierarchy.
6463
6464IMPORTANT: this model construction algorithm was introduced in ALGLIB 3.11
6465 and produces models which are INCOMPATIBLE with previous
6466 versions of ALGLIB. You can not unserialize models produced
6467 with this function in ALGLIB 3.10 or earlier.
6468
6469INPUT PARAMETERS:
6470 S - RBF model, initialized by rbfcreate() call
6471 RBase - RBase parameter, RBase>0
6472 NLayers - NLayers parameter, NLayers>0, recommended value to start
6473 with - about 5.
6474 LambdaNS- >=0, nonlinearity penalty coefficient, negative values are
6475 not allowed. This parameter adds controllable smoothing to
6476 the problem, which may reduce noise. Specification of non-
6477 zero lambda means that in addition to fitting error solver
6478 will also minimize LambdaNS*|S''(x)|^2 (appropriately
6479 generalized to multiple dimensions.
6480
6481 Specification of exactly zero value means that no penalty
6482 is added (we do not even evaluate matrix of second
6483 derivatives which is necessary for smoothing).
6484
6485 Calculation of nonlinearity penalty is costly - it results
6486 in several-fold increase of model construction time.
6487 Evaluation time remains the same.
6488
6489 Optimal lambda is problem-dependent and requires trial
6490 and error. Good value to start from is 1e-5...1e-6,
6491 which corresponds to slightly noticeable smoothing of the
6492 function. Value 1e-2 usually means that quite heavy
6493 smoothing is applied.
6494
6495TUNING ALGORITHM
6496
6497In order to use this algorithm you have to choose three parameters:
6498* initial radius RBase
6499* number of layers in the model NLayers
6500* penalty coefficient LambdaNS
6501
6502Initial radius is easy to choose - you can pick any number several times
6503larger than the average distance between points. Algorithm won't break
6504down if you choose radius which is too large (model construction time will
6505increase, but model will be built correctly).
6506
6507Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used
6508by the last layer) will be smaller than the typical distance between
6509points. In case model error is too large, you can increase number of
6510layers. Having more layers will make model construction and evaluation
6511proportionally slower, but it will allow you to have model which precisely
6512fits your data. From the other side, if you want to suppress noise, you
6513can DECREASE number of layers to make your model less flexible (or specify
6514non-zero LambdaNS).
6515
6516TYPICAL ERRORS
6517
65181. Using too small number of layers - RBF models with large radius are not
6519 flexible enough to reproduce small variations in the target function.
6520 You need many layers with different radii, from large to small, in
6521 order to have good model.
6522
65232. Using initial radius which is too small. You will get model with
6524 "holes" in the areas which are too far away from interpolation centers.
6525 However, algorithm will work correctly (and quickly) in this case.
6526
6527 -- ALGLIB --
6528 Copyright 20.06.2016 by Bochkanov Sergey
6529*************************************************************************/
6530void rbfsetalgohierarchical(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const double lambdans);
6531
6532
6533/*************************************************************************
6534This function sets linear term (model is a sum of radial basis functions
6535plus linear polynomial). This function won't have effect until next call
6536to RBFBuildModel().
6537
6538INPUT PARAMETERS:
6539 S - RBF model, initialized by RBFCreate() call
6540
6541NOTE: this function has some serialization-related subtleties. We
6542 recommend you to study serialization examples from ALGLIB Reference
6543 Manual if you want to perform serialization of your models.
6544
6545 -- ALGLIB --
6546 Copyright 13.12.2011 by Bochkanov Sergey
6547*************************************************************************/
6548void rbfsetlinterm(const rbfmodel &s);
6549
6550
6551/*************************************************************************
6552This function sets constant term (model is a sum of radial basis functions
6553plus constant). This function won't have effect until next call to
6554RBFBuildModel().
6555
6556INPUT PARAMETERS:
6557 S - RBF model, initialized by RBFCreate() call
6558
6559NOTE: this function has some serialization-related subtleties. We
6560 recommend you to study serialization examples from ALGLIB Reference
6561 Manual if you want to perform serialization of your models.
6562
6563 -- ALGLIB --
6564 Copyright 13.12.2011 by Bochkanov Sergey
6565*************************************************************************/
6566void rbfsetconstterm(const rbfmodel &s);
6567
6568
6569/*************************************************************************
6570This function sets zero term (model is a sum of radial basis functions
6571without polynomial term). This function won't have effect until next call
6572to RBFBuildModel().
6573
6574INPUT PARAMETERS:
6575 S - RBF model, initialized by RBFCreate() call
6576
6577NOTE: this function has some serialization-related subtleties. We
6578 recommend you to study serialization examples from ALGLIB Reference
6579 Manual if you want to perform serialization of your models.
6580
6581 -- ALGLIB --
6582 Copyright 13.12.2011 by Bochkanov Sergey
6583*************************************************************************/
6584void rbfsetzeroterm(const rbfmodel &s);
6585
6586
6587/*************************************************************************
6588This function sets basis function type, which can be:
6589* 0 for classic Gaussian
6590* 1 for fast and compact bell-like basis function, which becomes exactly
6591 zero at distance equal to 3*R (default option).
6592
6593INPUT PARAMETERS:
6594 S - RBF model, initialized by RBFCreate() call
6595 BF - basis function type:
6596 * 0 - classic Gaussian
6597 * 1 - fast and compact one
6598
6599 -- ALGLIB --
6600 Copyright 01.02.2017 by Bochkanov Sergey
6601*************************************************************************/
6602void rbfsetv2bf(const rbfmodel &s, const ae_int_t bf);
6603
6604
6605/*************************************************************************
6606This function sets stopping criteria of the underlying linear solver for
6607hierarchical (version 2) RBF constructor.
6608
6609INPUT PARAMETERS:
6610 S - RBF model, initialized by RBFCreate() call
6611 MaxIts - this criterion will stop algorithm after MaxIts iterations.
6612 Typically a few hundreds iterations is required, with 400
6613 being a good default value to start experimentation.
6614 Zero value means that default value will be selected.
6615
6616 -- ALGLIB --
6617 Copyright 01.02.2017 by Bochkanov Sergey
6618*************************************************************************/
6619void rbfsetv2its(const rbfmodel &s, const ae_int_t maxits);
6620
6621
6622/*************************************************************************
6623This function sets support radius parameter of hierarchical (version 2)
6624RBF constructor.
6625
6626Hierarchical RBF model achieves great speed-up by removing from the model
6627excessive (too dense) nodes. Say, if you have RBF radius equal to 1 meter,
6628and two nodes are just 1 millimeter apart, you may remove one of them
6629without reducing model quality.
6630
6631Support radius parameter is used to justify which points need removal, and
6632which do not. If two points are less than SUPPORT_R*CUR_RADIUS units of
6633distance apart, one of them is removed from the model. The larger support
6634radius is, the faster model construction AND evaluation are. However,
6635too large values result in "bumpy" models.
6636
6637INPUT PARAMETERS:
6638 S - RBF model, initialized by RBFCreate() call
6639 R - support radius coefficient, >=0.
6640 Recommended values are [0.1,0.4] range, with 0.1 being
6641 default value.
6642
6643 -- ALGLIB --
6644 Copyright 01.02.2017 by Bochkanov Sergey
6645*************************************************************************/
6646void rbfsetv2supportr(const rbfmodel &s, const double r);
6647
6648
6649/*************************************************************************
6650This function builds RBF model and returns report (contains some
6651information which can be used for evaluation of the algorithm properties).
6652
6653Call to this function modifies RBF model by calculating its centers/radii/
6654weights and saving them into RBFModel structure. Initially RBFModel
6655contain zero coefficients, but after call to this function we will have
6656coefficients which were calculated in order to fit our dataset.
6657
6658After you called this function you can call RBFCalc(), RBFGridCalc() and
6659other model calculation functions.
6660
6661INPUT PARAMETERS:
6662 S - RBF model, initialized by RBFCreate() call
6663 Rep - report:
6664 * Rep.TerminationType:
6665 * -5 - non-distinct basis function centers were detected,
6666 interpolation aborted; only QNN returns this
6667 error code, other algorithms can handle non-
6668 distinct nodes.
6669 * -4 - nonconvergence of the internal SVD solver
6670 * -3 incorrect model construction algorithm was chosen:
6671 QNN or RBF-ML, combined with one of the incompatible
6672 features - NX=1 or NX>3; points with per-dimension
6673 scales.
6674 * 1 - successful termination
6675
6676 Fields which are set only by modern RBF solvers (hierarchical
6677 or nonnegative; older solvers like QNN and ML initialize these
6678 fields by NANs):
6679 * rep.rmserror - root-mean-square error at nodes
6680 * rep.maxerror - maximum error at nodes
6681
6682 Fields are used for debugging purposes:
6683 * Rep.IterationsCount - iterations count of the LSQR solver
6684 * Rep.NMV - number of matrix-vector products
6685 * Rep.ARows - rows count for the system matrix
6686 * Rep.ACols - columns count for the system matrix
6687 * Rep.ANNZ - number of significantly non-zero elements
6688 (elements above some algorithm-determined threshold)
6689
6690NOTE: failure to build model will leave current state of the structure
6691unchanged.
6692
6693 -- ALGLIB --
6694 Copyright 13.12.2011 by Bochkanov Sergey
6695*************************************************************************/
6696void rbfbuildmodel(const rbfmodel &s, rbfreport &rep);
6697
6698
6699/*************************************************************************
6700This function calculates values of the RBF model in the given point.
6701
6702IMPORTANT: this function works only with modern (hierarchical) RBFs. It
6703 can not be used with legacy (version 1) RBFs because older RBF
6704 code does not support 1-dimensional models.
6705
6706This function should be used when we have NY=1 (scalar function) and NX=1
6707(1-dimensional space). If you have 3-dimensional space, use rbfcalc3(). If
6708you have 2-dimensional space, use rbfcalc3(). If you have general
6709situation (NX-dimensional space, NY-dimensional function) you should use
6710generic rbfcalc().
6711
6712If you want to perform parallel model evaluation from multiple threads,
6713use rbftscalcbuf() with per-thread buffer object.
6714
6715This function returns 0.0 when:
6716* model is not initialized
6717* NX<>1
6718* NY<>1
6719
6720INPUT PARAMETERS:
6721 S - RBF model
6722 X0 - X-coordinate, finite number
6723
6724RESULT:
6725 value of the model or 0.0 (as defined above)
6726
6727 -- ALGLIB --
6728 Copyright 13.12.2011 by Bochkanov Sergey
6729*************************************************************************/
6730double rbfcalc1(const rbfmodel &s, const double x0);
6731
6732
6733/*************************************************************************
6734This function calculates values of the RBF model in the given point.
6735
6736This function should be used when we have NY=1 (scalar function) and NX=2
6737(2-dimensional space). If you have 3-dimensional space, use rbfcalc3(). If
6738you have general situation (NX-dimensional space, NY-dimensional function)
6739you should use generic rbfcalc().
6740
6741If you want to calculate function values many times, consider using
6742rbfgridcalc2v(), which is far more efficient than many subsequent calls to
6743rbfcalc2().
6744
6745If you want to perform parallel model evaluation from multiple threads,
6746use rbftscalcbuf() with per-thread buffer object.
6747
6748This function returns 0.0 when:
6749* model is not initialized
6750* NX<>2
6751 *NY<>1
6752
6753INPUT PARAMETERS:
6754 S - RBF model
6755 X0 - first coordinate, finite number
6756 X1 - second coordinate, finite number
6757
6758RESULT:
6759 value of the model or 0.0 (as defined above)
6760
6761 -- ALGLIB --
6762 Copyright 13.12.2011 by Bochkanov Sergey
6763*************************************************************************/
6764double rbfcalc2(const rbfmodel &s, const double x0, const double x1);
6765
6766
6767/*************************************************************************
6768This function calculates value of the RBF model in the given point.
6769
6770This function should be used when we have NY=1 (scalar function) and NX=3
6771(3-dimensional space). If you have 2-dimensional space, use rbfcalc2(). If
6772you have general situation (NX-dimensional space, NY-dimensional function)
6773you should use generic rbfcalc().
6774
6775If you want to calculate function values many times, consider using
6776rbfgridcalc3v(), which is far more efficient than many subsequent calls to
6777rbfcalc3().
6778
6779If you want to perform parallel model evaluation from multiple threads,
6780use rbftscalcbuf() with per-thread buffer object.
6781
6782This function returns 0.0 when:
6783* model is not initialized
6784* NX<>3
6785 *NY<>1
6786
6787INPUT PARAMETERS:
6788 S - RBF model
6789 X0 - first coordinate, finite number
6790 X1 - second coordinate, finite number
6791 X2 - third coordinate, finite number
6792
6793RESULT:
6794 value of the model or 0.0 (as defined above)
6795
6796 -- ALGLIB --
6797 Copyright 13.12.2011 by Bochkanov Sergey
6798*************************************************************************/
6799double rbfcalc3(const rbfmodel &s, const double x0, const double x1, const double x2);
6800
6801
6802/*************************************************************************
6803This function calculates values of the RBF model at the given point.
6804
6805This is general function which can be used for arbitrary NX (dimension of
6806the space of arguments) and NY (dimension of the function itself). However
6807when you have NY=1 you may find more convenient to use rbfcalc2() or
6808rbfcalc3().
6809
6810If you want to perform parallel model evaluation from multiple threads,
6811use rbftscalcbuf() with per-thread buffer object.
6812
6813This function returns 0.0 when model is not initialized.
6814
6815INPUT PARAMETERS:
6816 S - RBF model
6817 X - coordinates, array[NX].
6818 X may have more than NX elements, in this case only
6819 leading NX will be used.
6820
6821OUTPUT PARAMETERS:
6822 Y - function value, array[NY]. Y is out-parameter and
6823 reallocated after call to this function. In case you want
6824 to reuse previously allocated Y, you may use RBFCalcBuf(),
6825 which reallocates Y only when it is too small.
6826
6827 -- ALGLIB --
6828 Copyright 13.12.2011 by Bochkanov Sergey
6829*************************************************************************/
6830void rbfcalc(const rbfmodel &s, const real_1d_array &x, real_1d_array &y);
6831
6832
6833/*************************************************************************
6834This function calculates values of the RBF model at the given point.
6835
6836Same as rbfcalc(), but does not reallocate Y when in is large enough to
6837store function values.
6838
6839If you want to perform parallel model evaluation from multiple threads,
6840use rbftscalcbuf() with per-thread buffer object.
6841
6842INPUT PARAMETERS:
6843 S - RBF model
6844 X - coordinates, array[NX].
6845 X may have more than NX elements, in this case only
6846 leading NX will be used.
6847 Y - possibly preallocated array
6848
6849OUTPUT PARAMETERS:
6850 Y - function value, array[NY]. Y is not reallocated when it
6851 is larger than NY.
6852
6853 -- ALGLIB --
6854 Copyright 13.12.2011 by Bochkanov Sergey
6855*************************************************************************/
6856void rbfcalcbuf(const rbfmodel &s, const real_1d_array &x, real_1d_array &y);
6857
6858
6859/*************************************************************************
6860This function calculates values of the RBF model at the given point, using
6861external buffer object (internal temporaries of RBF model are not
6862modified).
6863
6864This function allows to use same RBF model object in different threads,
6865assuming that different threads use different instances of buffer
6866structure.
6867
6868INPUT PARAMETERS:
6869 S - RBF model, may be shared between different threads
6870 Buf - buffer object created for this particular instance of RBF
6871 model with rbfcreatecalcbuffer().
6872 X - coordinates, array[NX].
6873 X may have more than NX elements, in this case only
6874 leading NX will be used.
6875 Y - possibly preallocated array
6876
6877OUTPUT PARAMETERS:
6878 Y - function value, array[NY]. Y is not reallocated when it
6879 is larger than NY.
6880
6881 -- ALGLIB --
6882 Copyright 13.12.2011 by Bochkanov Sergey
6883*************************************************************************/
6884void rbftscalcbuf(const rbfmodel &s, const rbfcalcbuffer &buf, const real_1d_array &x, real_1d_array &y);
6885
6886
6887/*************************************************************************
6888This is legacy function for gridded calculation of RBF model.
6889
6890It is superseded by rbfgridcalc2v() and rbfgridcalc2vsubset() functions.
6891
6892 -- ALGLIB --
6893 Copyright 13.12.2011 by Bochkanov Sergey
6894*************************************************************************/
6895void rbfgridcalc2(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, real_2d_array &y);
6896
6897
6898/*************************************************************************
6899This function calculates values of the RBF model at the regular grid,
6900which has N0*N1 points, with Point[I,J] = (X0[I], X1[J]). Vector-valued
6901RBF models are supported.
6902
6903This function returns 0.0 when:
6904* model is not initialized
6905* NX<>2
6906
6907FOR USERS OF COMMERCIAL EDITION:
6908
6909 ! Commercial version of ALGLIB includes multicore support (C++ and C#
6910 ! computational cores) for this function.
6911 !
6912 ! Parallel processing gives close-to-linear speedup on multicore systems,
6913 ! assuming that problem is large enough to be divided between cores.
6914 ! You should solve at least 200x200 problem to get nearly-linear speed-
6915 ! up (high efficiency).
6916 !
6917 ! Parallel processing is implemented only for modern (hierarchical)
6918 ! RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still
6919 ! processed serially.
6920 !
6921 ! In order to use multicore features you have to:
6922 ! * use commercial version of ALGLIB
6923 ! * call this function with "smp_" prefix, which indicates that
6924 ! multicore code will be used (for multicore support)
6925 !
6926 ! This note is given for users of commercial edition; if you use GPL
6927 ! edition, you still will be able to call smp-version of this function,
6928 ! but all computations will be done serially.
6929 !
6930 ! We recommend you to carefully read ALGLIB Reference Manual, section
6931 ! called 'SMP support', before using parallel version of this function.
6932
6933INPUT PARAMETERS:
6934 S - RBF model, used in read-only mode, can be shared between
6935 multiple invocations of this function from multiple
6936 threads.
6937
6938 X0 - array of grid nodes, first coordinates, array[N0].
6939 Must be ordered by ascending. Exception is generated
6940 if the array is not correctly ordered.
6941 N0 - grid size (number of nodes) in the first dimension
6942
6943 X1 - array of grid nodes, second coordinates, array[N1]
6944 Must be ordered by ascending. Exception is generated
6945 if the array is not correctly ordered.
6946 N1 - grid size (number of nodes) in the second dimension
6947
6948OUTPUT PARAMETERS:
6949 Y - function values, array[NY*N0*N1], where NY is a number of
6950 "output" vector values (this function supports vector-
6951 valued RBF models). Y is out-variable and is reallocated
6952 by this function.
6953 Y[K+NY*(I0+I1*N0)]=F_k(X0[I0],X1[I1]), for:
6954 * K=0...NY-1
6955 * I0=0...N0-1
6956 * I1=0...N1-1
6957
6958NOTE: this function supports weakly ordered grid nodes, i.e. you may have
6959 X[i]=X[i+1] for some i. It does not provide you any performance
6960 benefits due to duplication of points, just convenience and
6961 flexibility.
6962
6963NOTE: this function is re-entrant, i.e. you may use same rbfmodel
6964 structure in multiple threads calling this function for different
6965 grids.
6966
6967NOTE: if you need function values on some subset of regular grid, which
6968 may be described as "several compact and dense islands", you may
6969 use rbfgridcalc2vsubset().
6970
6971 -- ALGLIB --
6972 Copyright 27.01.2017 by Bochkanov Sergey
6973*************************************************************************/
6974void rbfgridcalc2v(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, real_1d_array &y);
6975void smp_rbfgridcalc2v(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, real_1d_array &y);
6976
6977
6978/*************************************************************************
6979This function calculates values of the RBF model at some subset of regular
6980grid:
6981* grid has N0*N1 points, with Point[I,J] = (X0[I], X1[J])
6982* only values at some subset of this grid are required
6983Vector-valued RBF models are supported.
6984
6985This function returns 0.0 when:
6986* model is not initialized
6987* NX<>2
6988
6989FOR USERS OF COMMERCIAL EDITION:
6990
6991 ! Commercial version of ALGLIB includes multicore support (C++ and C#
6992 ! computational cores) for this function.
6993 !
6994 ! Parallel processing gives close-to-linear speedup on multicore systems,
6995 ! assuming that problem is large enough to be divided between cores.
6996 ! You should solve at least 200x200 problem to get nearly-linear speed-
6997 ! up (high efficiency).
6998 !
6999 ! Parallel processing is implemented only for modern (hierarchical)
7000 ! RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still
7001 ! processed serially.
7002 !
7003 ! In order to use multicore features you have to:
7004 ! * use commercial version of ALGLIB
7005 ! * call this function with "smp_" prefix, which indicates that
7006 ! multicore code will be used (for multicore support)
7007 !
7008 ! This note is given for users of commercial edition; if you use GPL
7009 ! edition, you still will be able to call smp-version of this function,
7010 ! but all computations will be done serially.
7011 !
7012 ! We recommend you to carefully read ALGLIB Reference Manual, section
7013 ! called 'SMP support', before using parallel version of this function.
7014
7015INPUT PARAMETERS:
7016 S - RBF model, used in read-only mode, can be shared between
7017 multiple invocations of this function from multiple
7018 threads.
7019
7020 X0 - array of grid nodes, first coordinates, array[N0].
7021 Must be ordered by ascending. Exception is generated
7022 if the array is not correctly ordered.
7023 N0 - grid size (number of nodes) in the first dimension
7024
7025 X1 - array of grid nodes, second coordinates, array[N1]
7026 Must be ordered by ascending. Exception is generated
7027 if the array is not correctly ordered.
7028 N1 - grid size (number of nodes) in the second dimension
7029
7030 FlagY - array[N0*N1]:
7031 * Y[I0+I1*N0] corresponds to node (X0[I0],X1[I1])
7032 * it is a "bitmap" array which contains False for nodes
7033 which are NOT calculated, and True for nodes which are
7034 required.
7035
7036OUTPUT PARAMETERS:
7037 Y - function values, array[NY*N0*N1*N2], where NY is a number
7038 of "output" vector values (this function supports vector-
7039 valued RBF models):
7040 * Y[K+NY*(I0+I1*N0)]=F_k(X0[I0],X1[I1]),
7041 for K=0...NY-1, I0=0...N0-1, I1=0...N1-1.
7042 * elements of Y[] which correspond to FlagY[]=True are
7043 loaded by model values (which may be exactly zero for
7044 some nodes).
7045 * elements of Y[] which correspond to FlagY[]=False MAY be
7046 initialized by zeros OR may be calculated. This function
7047 processes grid as a hierarchy of nested blocks and
7048 micro-rows. If just one element of micro-row is required,
7049 entire micro-row (up to 8 nodes in the current version,
7050 but no promises) is calculated.
7051
7052NOTE: this function supports weakly ordered grid nodes, i.e. you may have
7053 X[i]=X[i+1] for some i. It does not provide you any performance
7054 benefits due to duplication of points, just convenience and
7055 flexibility.
7056
7057NOTE: this function is re-entrant, i.e. you may use same rbfmodel
7058 structure in multiple threads calling this function for different
7059 grids.
7060
7061 -- ALGLIB --
7062 Copyright 04.03.2016 by Bochkanov Sergey
7063*************************************************************************/
7064void rbfgridcalc2vsubset(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const boolean_1d_array &flagy, real_1d_array &y);
7065void smp_rbfgridcalc2vsubset(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const boolean_1d_array &flagy, real_1d_array &y);
7066
7067
7068/*************************************************************************
7069This function calculates values of the RBF model at the regular grid,
7070which has N0*N1*N2 points, with Point[I,J,K] = (X0[I], X1[J], X2[K]).
7071Vector-valued RBF models are supported.
7072
7073This function returns 0.0 when:
7074* model is not initialized
7075* NX<>3
7076
7077FOR USERS OF COMMERCIAL EDITION:
7078
7079 ! Commercial version of ALGLIB includes multicore support (C++ and C#
7080 ! computational cores) for this function.
7081 !
7082 ! Parallel processing gives close-to-linear speedup on multicore systems,
7083 ! assuming that problem is large enough to be divided between cores.
7084 ! You should solve at least 50x50x50 problem to get nearly-linear speed-
7085 ! up (high efficiency).
7086 !
7087 ! In order to use multicore features you have to:
7088 ! * use commercial version of ALGLIB
7089 ! * call this function with "smp_" prefix, which indicates that
7090 ! multicore code will be used (for multicore support)
7091 !
7092 ! This note is given for users of commercial edition; if you use GPL
7093 ! edition, you still will be able to call smp-version of this function,
7094 ! but all computations will be done serially.
7095 !
7096 ! We recommend you to carefully read ALGLIB Reference Manual, section
7097 ! called 'SMP support', before using parallel version of this function.
7098
7099INPUT PARAMETERS:
7100 S - RBF model, used in read-only mode, can be shared between
7101 multiple invocations of this function from multiple
7102 threads.
7103
7104 X0 - array of grid nodes, first coordinates, array[N0].
7105 Must be ordered by ascending. Exception is generated
7106 if the array is not correctly ordered.
7107 N0 - grid size (number of nodes) in the first dimension
7108
7109 X1 - array of grid nodes, second coordinates, array[N1]
7110 Must be ordered by ascending. Exception is generated
7111 if the array is not correctly ordered.
7112 N1 - grid size (number of nodes) in the second dimension
7113
7114 X2 - array of grid nodes, third coordinates, array[N2]
7115 Must be ordered by ascending. Exception is generated
7116 if the array is not correctly ordered.
7117 N2 - grid size (number of nodes) in the third dimension
7118
7119OUTPUT PARAMETERS:
7120 Y - function values, array[NY*N0*N1*N2], where NY is a number
7121 of "output" vector values (this function supports vector-
7122 valued RBF models). Y is out-variable and is reallocated
7123 by this function.
7124 Y[K+NY*(I0+I1*N0+I2*N0*N1)]=F_k(X0[I0],X1[I1],X2[I2]), for:
7125 * K=0...NY-1
7126 * I0=0...N0-1
7127 * I1=0...N1-1
7128 * I2=0...N2-1
7129
7130NOTE: this function supports weakly ordered grid nodes, i.e. you may have
7131 X[i]=X[i+1] for some i. It does not provide you any performance
7132 benefits due to duplication of points, just convenience and
7133 flexibility.
7134
7135NOTE: this function is re-entrant, i.e. you may use same rbfmodel
7136 structure in multiple threads calling this function for different
7137 grids.
7138
7139NOTE: if you need function values on some subset of regular grid, which
7140 may be described as "several compact and dense islands", you may
7141 use rbfgridcalc3vsubset().
7142
7143 -- ALGLIB --
7144 Copyright 04.03.2016 by Bochkanov Sergey
7145*************************************************************************/
7146void rbfgridcalc3v(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y);
7147void smp_rbfgridcalc3v(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y);
7148
7149
7150/*************************************************************************
7151This function calculates values of the RBF model at some subset of regular
7152grid:
7153* grid has N0*N1*N2 points, with Point[I,J,K] = (X0[I], X1[J], X2[K])
7154* only values at some subset of this grid are required
7155Vector-valued RBF models are supported.
7156
7157This function returns 0.0 when:
7158* model is not initialized
7159* NX<>3
7160
7161FOR USERS OF COMMERCIAL EDITION:
7162
7163 ! Commercial version of ALGLIB includes multicore support (C++ and C#
7164 ! computational cores) for this function.
7165 !
7166 ! Parallel processing gives close-to-linear speedup on multicore systems,
7167 ! assuming that problem is large enough to be divided between cores.
7168 ! You should solve at least 50x50x50 problem to get nearly-linear speed-
7169 ! up (high efficiency).
7170 !
7171 ! In order to use multicore features you have to:
7172 ! * use commercial version of ALGLIB
7173 ! * call this function with "smp_" prefix, which indicates that
7174 ! multicore code will be used (for multicore support)
7175 !
7176 ! This note is given for users of commercial edition; if you use GPL
7177 ! edition, you still will be able to call smp-version of this function,
7178 ! but all computations will be done serially.
7179 !
7180 ! We recommend you to carefully read ALGLIB Reference Manual, section
7181 ! called 'SMP support', before using parallel version of this function.
7182
7183INPUT PARAMETERS:
7184 S - RBF model, used in read-only mode, can be shared between
7185 multiple invocations of this function from multiple
7186 threads.
7187
7188 X0 - array of grid nodes, first coordinates, array[N0].
7189 Must be ordered by ascending. Exception is generated
7190 if the array is not correctly ordered.
7191 N0 - grid size (number of nodes) in the first dimension
7192
7193 X1 - array of grid nodes, second coordinates, array[N1]
7194 Must be ordered by ascending. Exception is generated
7195 if the array is not correctly ordered.
7196 N1 - grid size (number of nodes) in the second dimension
7197
7198 X2 - array of grid nodes, third coordinates, array[N2]
7199 Must be ordered by ascending. Exception is generated
7200 if the array is not correctly ordered.
7201 N2 - grid size (number of nodes) in the third dimension
7202
7203 FlagY - array[N0*N1*N2]:
7204 * Y[I0+I1*N0+I2*N0*N1] corresponds to node (X0[I0],X1[I1],X2[I2])
7205 * it is a "bitmap" array which contains False for nodes
7206 which are NOT calculated, and True for nodes which are
7207 required.
7208
7209OUTPUT PARAMETERS:
7210 Y - function values, array[NY*N0*N1*N2], where NY is a number
7211 of "output" vector values (this function supports vector-
7212 valued RBF models):
7213 * Y[K+NY*(I0+I1*N0+I2*N0*N1)]=F_k(X0[I0],X1[I1],X2[I2]),
7214 for K=0...NY-1, I0=0...N0-1, I1=0...N1-1, I2=0...N2-1.
7215 * elements of Y[] which correspond to FlagY[]=True are
7216 loaded by model values (which may be exactly zero for
7217 some nodes).
7218 * elements of Y[] which correspond to FlagY[]=False MAY be
7219 initialized by zeros OR may be calculated. This function
7220 processes grid as a hierarchy of nested blocks and
7221 micro-rows. If just one element of micro-row is required,
7222 entire micro-row (up to 8 nodes in the current version,
7223 but no promises) is calculated.
7224
7225NOTE: this function supports weakly ordered grid nodes, i.e. you may have
7226 X[i]=X[i+1] for some i. It does not provide you any performance
7227 benefits due to duplication of points, just convenience and
7228 flexibility.
7229
7230NOTE: this function is re-entrant, i.e. you may use same rbfmodel
7231 structure in multiple threads calling this function for different
7232 grids.
7233
7234 -- ALGLIB --
7235 Copyright 04.03.2016 by Bochkanov Sergey
7236*************************************************************************/
7237void rbfgridcalc3vsubset(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const real_1d_array &x2, const ae_int_t n2, const boolean_1d_array &flagy, real_1d_array &y);
7238void smp_rbfgridcalc3vsubset(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, const real_1d_array &x2, const ae_int_t n2, const boolean_1d_array &flagy, real_1d_array &y);
7239
7240
7241/*************************************************************************
7242This function "unpacks" RBF model by extracting its coefficients.
7243
7244INPUT PARAMETERS:
7245 S - RBF model
7246
7247OUTPUT PARAMETERS:
7248 NX - dimensionality of argument
7249 NY - dimensionality of the target function
7250 XWR - model information, array[NC,NX+NY+1].
7251 One row of the array corresponds to one basis function:
7252 * first NX columns - coordinates of the center
7253 * next NY columns - weights, one per dimension of the
7254 function being modelled
7255 For ModelVersion=1:
7256 * last column - radius, same for all dimensions of
7257 the function being modelled
7258 For ModelVersion=2:
7259 * last NX columns - radii, one per dimension
7260 NC - number of the centers
7261 V - polynomial term , array[NY,NX+1]. One row per one
7262 dimension of the function being modelled. First NX
7263 elements are linear coefficients, V[NX] is equal to the
7264 constant part.
7265 ModelVersion-version of the RBF model:
7266 * 1 - for models created by QNN and RBF-ML algorithms,
7267 compatible with ALGLIB 3.10 or earlier.
7268 * 2 - for models created by HierarchicalRBF, requires
7269 ALGLIB 3.11 or later
7270
7271 -- ALGLIB --
7272 Copyright 13.12.2011 by Bochkanov Sergey
7273*************************************************************************/
7274void rbfunpack(const rbfmodel &s, ae_int_t &nx, ae_int_t &ny, real_2d_array &xwr, ae_int_t &nc, real_2d_array &v, ae_int_t &modelversion);
7275
7276
7277/*************************************************************************
7278This function returns model version.
7279
7280INPUT PARAMETERS:
7281 S - RBF model
7282
7283RESULT:
7284 * 1 - for models created by QNN and RBF-ML algorithms,
7285 compatible with ALGLIB 3.10 or earlier.
7286 * 2 - for models created by HierarchicalRBF, requires
7287 ALGLIB 3.11 or later
7288
7289 -- ALGLIB --
7290 Copyright 06.07.2016 by Bochkanov Sergey
7291*************************************************************************/
7292ae_int_t rbfgetmodelversion(const rbfmodel &s);
7293}
7294
7296//
7297// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
7298//
7300namespace alglib_impl
7301{
7302double idwcalc(idwinterpolant* z,
7303 /* Real */ ae_vector* x,
7304 ae_state *_state);
7305void idwbuildmodifiedshepard(/* Real */ ae_matrix* xy,
7306 ae_int_t n,
7307 ae_int_t nx,
7308 ae_int_t d,
7309 ae_int_t nq,
7310 ae_int_t nw,
7311 idwinterpolant* z,
7312 ae_state *_state);
7313void idwbuildmodifiedshepardr(/* Real */ ae_matrix* xy,
7314 ae_int_t n,
7315 ae_int_t nx,
7316 double r,
7317 idwinterpolant* z,
7318 ae_state *_state);
7319void idwbuildnoisy(/* Real */ ae_matrix* xy,
7320 ae_int_t n,
7321 ae_int_t nx,
7322 ae_int_t d,
7323 ae_int_t nq,
7324 ae_int_t nw,
7325 idwinterpolant* z,
7326 ae_state *_state);
7327void _idwinterpolant_init(void* _p, ae_state *_state);
7328void _idwinterpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7329void _idwinterpolant_clear(void* _p);
7330void _idwinterpolant_destroy(void* _p);
7331double barycentriccalc(barycentricinterpolant* b,
7332 double t,
7333 ae_state *_state);
7334void barycentricdiff1(barycentricinterpolant* b,
7335 double t,
7336 double* f,
7337 double* df,
7338 ae_state *_state);
7339void barycentricdiff2(barycentricinterpolant* b,
7340 double t,
7341 double* f,
7342 double* df,
7343 double* d2f,
7344 ae_state *_state);
7345void barycentriclintransx(barycentricinterpolant* b,
7346 double ca,
7347 double cb,
7348 ae_state *_state);
7349void barycentriclintransy(barycentricinterpolant* b,
7350 double ca,
7351 double cb,
7352 ae_state *_state);
7353void barycentricunpack(barycentricinterpolant* b,
7354 ae_int_t* n,
7355 /* Real */ ae_vector* x,
7356 /* Real */ ae_vector* y,
7357 /* Real */ ae_vector* w,
7358 ae_state *_state);
7359void barycentricbuildxyw(/* Real */ ae_vector* x,
7360 /* Real */ ae_vector* y,
7361 /* Real */ ae_vector* w,
7362 ae_int_t n,
7363 barycentricinterpolant* b,
7364 ae_state *_state);
7365void barycentricbuildfloaterhormann(/* Real */ ae_vector* x,
7366 /* Real */ ae_vector* y,
7367 ae_int_t n,
7368 ae_int_t d,
7369 barycentricinterpolant* b,
7370 ae_state *_state);
7371void barycentriccopy(barycentricinterpolant* b,
7372 barycentricinterpolant* b2,
7373 ae_state *_state);
7374void _barycentricinterpolant_init(void* _p, ae_state *_state);
7375void _barycentricinterpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7376void _barycentricinterpolant_clear(void* _p);
7377void _barycentricinterpolant_destroy(void* _p);
7378void spline1dbuildlinear(/* Real */ ae_vector* x,
7379 /* Real */ ae_vector* y,
7380 ae_int_t n,
7381 spline1dinterpolant* c,
7382 ae_state *_state);
7383void spline1dbuildcubic(/* Real */ ae_vector* x,
7384 /* Real */ ae_vector* y,
7385 ae_int_t n,
7386 ae_int_t boundltype,
7387 double boundl,
7388 ae_int_t boundrtype,
7389 double boundr,
7390 spline1dinterpolant* c,
7391 ae_state *_state);
7392void spline1dgriddiffcubic(/* Real */ ae_vector* x,
7393 /* Real */ ae_vector* y,
7394 ae_int_t n,
7395 ae_int_t boundltype,
7396 double boundl,
7397 ae_int_t boundrtype,
7398 double boundr,
7399 /* Real */ ae_vector* d,
7400 ae_state *_state);
7401void spline1dgriddiff2cubic(/* Real */ ae_vector* x,
7402 /* Real */ ae_vector* y,
7403 ae_int_t n,
7404 ae_int_t boundltype,
7405 double boundl,
7406 ae_int_t boundrtype,
7407 double boundr,
7408 /* Real */ ae_vector* d1,
7409 /* Real */ ae_vector* d2,
7410 ae_state *_state);
7411void spline1dconvcubic(/* Real */ ae_vector* x,
7412 /* Real */ ae_vector* y,
7413 ae_int_t n,
7414 ae_int_t boundltype,
7415 double boundl,
7416 ae_int_t boundrtype,
7417 double boundr,
7418 /* Real */ ae_vector* x2,
7419 ae_int_t n2,
7420 /* Real */ ae_vector* y2,
7421 ae_state *_state);
7422void spline1dconvdiffcubic(/* Real */ ae_vector* x,
7423 /* Real */ ae_vector* y,
7424 ae_int_t n,
7425 ae_int_t boundltype,
7426 double boundl,
7427 ae_int_t boundrtype,
7428 double boundr,
7429 /* Real */ ae_vector* x2,
7430 ae_int_t n2,
7431 /* Real */ ae_vector* y2,
7432 /* Real */ ae_vector* d2,
7433 ae_state *_state);
7434void spline1dconvdiff2cubic(/* Real */ ae_vector* x,
7435 /* Real */ ae_vector* y,
7436 ae_int_t n,
7437 ae_int_t boundltype,
7438 double boundl,
7439 ae_int_t boundrtype,
7440 double boundr,
7441 /* Real */ ae_vector* x2,
7442 ae_int_t n2,
7443 /* Real */ ae_vector* y2,
7444 /* Real */ ae_vector* d2,
7445 /* Real */ ae_vector* dd2,
7446 ae_state *_state);
7447void spline1dbuildcatmullrom(/* Real */ ae_vector* x,
7448 /* Real */ ae_vector* y,
7449 ae_int_t n,
7450 ae_int_t boundtype,
7451 double tension,
7452 spline1dinterpolant* c,
7453 ae_state *_state);
7454void spline1dbuildhermite(/* Real */ ae_vector* x,
7455 /* Real */ ae_vector* y,
7456 /* Real */ ae_vector* d,
7457 ae_int_t n,
7458 spline1dinterpolant* c,
7459 ae_state *_state);
7460void spline1dbuildakima(/* Real */ ae_vector* x,
7461 /* Real */ ae_vector* y,
7462 ae_int_t n,
7463 spline1dinterpolant* c,
7464 ae_state *_state);
7465double spline1dcalc(spline1dinterpolant* c, double x, ae_state *_state);
7466void spline1ddiff(spline1dinterpolant* c,
7467 double x,
7468 double* s,
7469 double* ds,
7470 double* d2s,
7471 ae_state *_state);
7472void spline1dcopy(spline1dinterpolant* c,
7473 spline1dinterpolant* cc,
7474 ae_state *_state);
7475void spline1dunpack(spline1dinterpolant* c,
7476 ae_int_t* n,
7477 /* Real */ ae_matrix* tbl,
7478 ae_state *_state);
7479void spline1dlintransx(spline1dinterpolant* c,
7480 double a,
7481 double b,
7482 ae_state *_state);
7483void spline1dlintransy(spline1dinterpolant* c,
7484 double a,
7485 double b,
7486 ae_state *_state);
7487double spline1dintegrate(spline1dinterpolant* c,
7488 double x,
7489 ae_state *_state);
7490void spline1dconvdiffinternal(/* Real */ ae_vector* xold,
7491 /* Real */ ae_vector* yold,
7492 /* Real */ ae_vector* dold,
7493 ae_int_t n,
7494 /* Real */ ae_vector* x2,
7495 ae_int_t n2,
7496 /* Real */ ae_vector* y,
7497 ae_bool needy,
7498 /* Real */ ae_vector* d1,
7499 ae_bool needd1,
7500 /* Real */ ae_vector* d2,
7501 ae_bool needd2,
7502 ae_state *_state);
7503void spline1drootsandextrema(spline1dinterpolant* c,
7504 /* Real */ ae_vector* r,
7505 ae_int_t* nr,
7506 ae_bool* dr,
7507 /* Real */ ae_vector* e,
7508 /* Integer */ ae_vector* et,
7509 ae_int_t* ne,
7510 ae_bool* de,
7511 ae_state *_state);
7512void heapsortdpoints(/* Real */ ae_vector* x,
7513 /* Real */ ae_vector* y,
7514 /* Real */ ae_vector* d,
7515 ae_int_t n,
7516 ae_state *_state);
7517void solvepolinom2(double p0,
7518 double m0,
7519 double p1,
7520 double m1,
7521 double* x0,
7522 double* x1,
7523 ae_int_t* nr,
7524 ae_state *_state);
7525void solvecubicpolinom(double pa,
7526 double ma,
7527 double pb,
7528 double mb,
7529 double a,
7530 double b,
7531 double* x0,
7532 double* x1,
7533 double* x2,
7534 double* ex0,
7535 double* ex1,
7536 ae_int_t* nr,
7537 ae_int_t* ne,
7538 /* Real */ ae_vector* tempdata,
7539 ae_state *_state);
7540ae_int_t bisectmethod(double pa,
7541 double ma,
7542 double pb,
7543 double mb,
7544 double a,
7545 double b,
7546 double* x,
7547 ae_state *_state);
7548void spline1dbuildmonotone(/* Real */ ae_vector* x,
7549 /* Real */ ae_vector* y,
7550 ae_int_t n,
7551 spline1dinterpolant* c,
7552 ae_state *_state);
7553void _spline1dinterpolant_init(void* _p, ae_state *_state);
7554void _spline1dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7555void _spline1dinterpolant_clear(void* _p);
7556void _spline1dinterpolant_destroy(void* _p);
7557void pspline2build(/* Real */ ae_matrix* xy,
7558 ae_int_t n,
7559 ae_int_t st,
7560 ae_int_t pt,
7561 pspline2interpolant* p,
7562 ae_state *_state);
7563void pspline3build(/* Real */ ae_matrix* xy,
7564 ae_int_t n,
7565 ae_int_t st,
7566 ae_int_t pt,
7567 pspline3interpolant* p,
7568 ae_state *_state);
7569void pspline2buildperiodic(/* Real */ ae_matrix* xy,
7570 ae_int_t n,
7571 ae_int_t st,
7572 ae_int_t pt,
7573 pspline2interpolant* p,
7574 ae_state *_state);
7575void pspline3buildperiodic(/* Real */ ae_matrix* xy,
7576 ae_int_t n,
7577 ae_int_t st,
7578 ae_int_t pt,
7579 pspline3interpolant* p,
7580 ae_state *_state);
7581void pspline2parametervalues(pspline2interpolant* p,
7582 ae_int_t* n,
7583 /* Real */ ae_vector* t,
7584 ae_state *_state);
7585void pspline3parametervalues(pspline3interpolant* p,
7586 ae_int_t* n,
7587 /* Real */ ae_vector* t,
7588 ae_state *_state);
7589void pspline2calc(pspline2interpolant* p,
7590 double t,
7591 double* x,
7592 double* y,
7593 ae_state *_state);
7594void pspline3calc(pspline3interpolant* p,
7595 double t,
7596 double* x,
7597 double* y,
7598 double* z,
7599 ae_state *_state);
7600void pspline2tangent(pspline2interpolant* p,
7601 double t,
7602 double* x,
7603 double* y,
7604 ae_state *_state);
7605void pspline3tangent(pspline3interpolant* p,
7606 double t,
7607 double* x,
7608 double* y,
7609 double* z,
7610 ae_state *_state);
7611void pspline2diff(pspline2interpolant* p,
7612 double t,
7613 double* x,
7614 double* dx,
7615 double* y,
7616 double* dy,
7617 ae_state *_state);
7618void pspline3diff(pspline3interpolant* p,
7619 double t,
7620 double* x,
7621 double* dx,
7622 double* y,
7623 double* dy,
7624 double* z,
7625 double* dz,
7626 ae_state *_state);
7627void pspline2diff2(pspline2interpolant* p,
7628 double t,
7629 double* x,
7630 double* dx,
7631 double* d2x,
7632 double* y,
7633 double* dy,
7634 double* d2y,
7635 ae_state *_state);
7636void pspline3diff2(pspline3interpolant* p,
7637 double t,
7638 double* x,
7639 double* dx,
7640 double* d2x,
7641 double* y,
7642 double* dy,
7643 double* d2y,
7644 double* z,
7645 double* dz,
7646 double* d2z,
7647 ae_state *_state);
7648double pspline2arclength(pspline2interpolant* p,
7649 double a,
7650 double b,
7651 ae_state *_state);
7652double pspline3arclength(pspline3interpolant* p,
7653 double a,
7654 double b,
7655 ae_state *_state);
7656void parametricrdpfixed(/* Real */ ae_matrix* x,
7657 ae_int_t n,
7658 ae_int_t d,
7659 ae_int_t stopm,
7660 double stopeps,
7661 /* Real */ ae_matrix* x2,
7662 /* Integer */ ae_vector* idx2,
7663 ae_int_t* nsections,
7664 ae_state *_state);
7665void _pspline2interpolant_init(void* _p, ae_state *_state);
7666void _pspline2interpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7667void _pspline2interpolant_clear(void* _p);
7668void _pspline2interpolant_destroy(void* _p);
7669void _pspline3interpolant_init(void* _p, ae_state *_state);
7670void _pspline3interpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7671void _pspline3interpolant_clear(void* _p);
7672void _pspline3interpolant_destroy(void* _p);
7673double spline3dcalc(spline3dinterpolant* c,
7674 double x,
7675 double y,
7676 double z,
7677 ae_state *_state);
7678void spline3dlintransxyz(spline3dinterpolant* c,
7679 double ax,
7680 double bx,
7681 double ay,
7682 double by,
7683 double az,
7684 double bz,
7685 ae_state *_state);
7686void spline3dlintransf(spline3dinterpolant* c,
7687 double a,
7688 double b,
7689 ae_state *_state);
7690void spline3dcopy(spline3dinterpolant* c,
7691 spline3dinterpolant* cc,
7692 ae_state *_state);
7693void spline3dresampletrilinear(/* Real */ ae_vector* a,
7694 ae_int_t oldzcount,
7695 ae_int_t oldycount,
7696 ae_int_t oldxcount,
7697 ae_int_t newzcount,
7698 ae_int_t newycount,
7699 ae_int_t newxcount,
7700 /* Real */ ae_vector* b,
7701 ae_state *_state);
7702void spline3dbuildtrilinearv(/* Real */ ae_vector* x,
7703 ae_int_t n,
7704 /* Real */ ae_vector* y,
7705 ae_int_t m,
7706 /* Real */ ae_vector* z,
7707 ae_int_t l,
7708 /* Real */ ae_vector* f,
7709 ae_int_t d,
7710 spline3dinterpolant* c,
7711 ae_state *_state);
7712void spline3dcalcvbuf(spline3dinterpolant* c,
7713 double x,
7714 double y,
7715 double z,
7716 /* Real */ ae_vector* f,
7717 ae_state *_state);
7718void spline3dcalcv(spline3dinterpolant* c,
7719 double x,
7720 double y,
7721 double z,
7722 /* Real */ ae_vector* f,
7723 ae_state *_state);
7724void spline3dunpackv(spline3dinterpolant* c,
7725 ae_int_t* n,
7726 ae_int_t* m,
7727 ae_int_t* l,
7728 ae_int_t* d,
7729 ae_int_t* stype,
7730 /* Real */ ae_matrix* tbl,
7731 ae_state *_state);
7732void _spline3dinterpolant_init(void* _p, ae_state *_state);
7733void _spline3dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state);
7734void _spline3dinterpolant_clear(void* _p);
7735void _spline3dinterpolant_destroy(void* _p);
7736void polynomialbar2cheb(barycentricinterpolant* p,
7737 double a,
7738 double b,
7739 /* Real */ ae_vector* t,
7740 ae_state *_state);
7741void polynomialcheb2bar(/* Real */ ae_vector* t,
7742 ae_int_t n,
7743 double a,
7744 double b,
7745 barycentricinterpolant* p,
7746 ae_state *_state);
7747void polynomialbar2pow(barycentricinterpolant* p,
7748 double c,
7749 double s,
7750 /* Real */ ae_vector* a,
7751 ae_state *_state);
7752void polynomialpow2bar(/* Real */ ae_vector* a,
7753 ae_int_t n,
7754 double c,
7755 double s,
7756 barycentricinterpolant* p,
7757 ae_state *_state);
7758void polynomialbuild(/* Real */ ae_vector* x,
7759 /* Real */ ae_vector* y,
7760 ae_int_t n,
7761 barycentricinterpolant* p,
7762 ae_state *_state);
7763void polynomialbuildeqdist(double a,
7764 double b,
7765 /* Real */ ae_vector* y,
7766 ae_int_t n,
7767 barycentricinterpolant* p,
7768 ae_state *_state);
7769void polynomialbuildcheb1(double a,
7770 double b,
7771 /* Real */ ae_vector* y,
7772 ae_int_t n,
7773 barycentricinterpolant* p,
7774 ae_state *_state);
7775void polynomialbuildcheb2(double a,
7776 double b,
7777 /* Real */ ae_vector* y,
7778 ae_int_t n,
7779 barycentricinterpolant* p,
7780 ae_state *_state);
7781double polynomialcalceqdist(double a,
7782 double b,
7783 /* Real */ ae_vector* f,
7784 ae_int_t n,
7785 double t,
7786 ae_state *_state);
7787double polynomialcalccheb1(double a,
7788 double b,
7789 /* Real */ ae_vector* f,
7790 ae_int_t n,
7791 double t,
7792 ae_state *_state);
7793double polynomialcalccheb2(double a,
7794 double b,
7795 /* Real */ ae_vector* f,
7796 ae_int_t n,
7797 double t,
7798 ae_state *_state);
7799void lstfitpiecewiselinearrdpfixed(/* Real */ ae_vector* x,
7800 /* Real */ ae_vector* y,
7801 ae_int_t n,
7802 ae_int_t m,
7803 /* Real */ ae_vector* x2,
7804 /* Real */ ae_vector* y2,
7805 ae_int_t* nsections,
7806 ae_state *_state);
7807void lstfitpiecewiselinearrdp(/* Real */ ae_vector* x,
7808 /* Real */ ae_vector* y,
7809 ae_int_t n,
7810 double eps,
7811 /* Real */ ae_vector* x2,
7812 /* Real */ ae_vector* y2,
7813 ae_int_t* nsections,
7814 ae_state *_state);
7815void polynomialfit(/* Real */ ae_vector* x,
7816 /* Real */ ae_vector* y,
7817 ae_int_t n,
7818 ae_int_t m,
7819 ae_int_t* info,
7820 barycentricinterpolant* p,
7821 polynomialfitreport* rep,
7822 ae_state *_state);
7823void _pexec_polynomialfit(/* Real */ ae_vector* x,
7824 /* Real */ ae_vector* y,
7825 ae_int_t n,
7826 ae_int_t m,
7827 ae_int_t* info,
7828 barycentricinterpolant* p,
7829 polynomialfitreport* rep, ae_state *_state);
7830void polynomialfitwc(/* Real */ ae_vector* x,
7831 /* Real */ ae_vector* y,
7832 /* Real */ ae_vector* w,
7833 ae_int_t n,
7834 /* Real */ ae_vector* xc,
7835 /* Real */ ae_vector* yc,
7836 /* Integer */ ae_vector* dc,
7837 ae_int_t k,
7838 ae_int_t m,
7839 ae_int_t* info,
7840 barycentricinterpolant* p,
7841 polynomialfitreport* rep,
7842 ae_state *_state);
7843void _pexec_polynomialfitwc(/* Real */ ae_vector* x,
7844 /* Real */ ae_vector* y,
7845 /* Real */ ae_vector* w,
7846 ae_int_t n,
7847 /* Real */ ae_vector* xc,
7848 /* Real */ ae_vector* yc,
7849 /* Integer */ ae_vector* dc,
7850 ae_int_t k,
7851 ae_int_t m,
7852 ae_int_t* info,
7853 barycentricinterpolant* p,
7854 polynomialfitreport* rep, ae_state *_state);
7855double logisticcalc4(double x,
7856 double a,
7857 double b,
7858 double c,
7859 double d,
7860 ae_state *_state);
7861double logisticcalc5(double x,
7862 double a,
7863 double b,
7864 double c,
7865 double d,
7866 double g,
7867 ae_state *_state);
7868void logisticfit4(/* Real */ ae_vector* x,
7869 /* Real */ ae_vector* y,
7870 ae_int_t n,
7871 double* a,
7872 double* b,
7873 double* c,
7874 double* d,
7875 lsfitreport* rep,
7876 ae_state *_state);
7877void logisticfit4ec(/* Real */ ae_vector* x,
7878 /* Real */ ae_vector* y,
7879 ae_int_t n,
7880 double cnstrleft,
7881 double cnstrright,
7882 double* a,
7883 double* b,
7884 double* c,
7885 double* d,
7886 lsfitreport* rep,
7887 ae_state *_state);
7888void logisticfit5(/* Real */ ae_vector* x,
7889 /* Real */ ae_vector* y,
7890 ae_int_t n,
7891 double* a,
7892 double* b,
7893 double* c,
7894 double* d,
7895 double* g,
7896 lsfitreport* rep,
7897 ae_state *_state);
7898void logisticfit5ec(/* Real */ ae_vector* x,
7899 /* Real */ ae_vector* y,
7900 ae_int_t n,
7901 double cnstrleft,
7902 double cnstrright,
7903 double* a,
7904 double* b,
7905 double* c,
7906 double* d,
7907 double* g,
7908 lsfitreport* rep,
7909 ae_state *_state);
7910void logisticfit45x(/* Real */ ae_vector* x,
7911 /* Real */ ae_vector* y,
7912 ae_int_t n,
7913 double cnstrleft,
7914 double cnstrright,
7915 ae_bool is4pl,
7916 double lambdav,
7917 double epsx,
7918 ae_int_t rscnt,
7919 double* a,
7920 double* b,
7921 double* c,
7922 double* d,
7923 double* g,
7924 lsfitreport* rep,
7925 ae_state *_state);
7926void barycentricfitfloaterhormannwc(/* Real */ ae_vector* x,
7927 /* Real */ ae_vector* y,
7928 /* Real */ ae_vector* w,
7929 ae_int_t n,
7930 /* Real */ ae_vector* xc,
7931 /* Real */ ae_vector* yc,
7932 /* Integer */ ae_vector* dc,
7933 ae_int_t k,
7934 ae_int_t m,
7935 ae_int_t* info,
7936 barycentricinterpolant* b,
7937 barycentricfitreport* rep,
7938 ae_state *_state);
7939void _pexec_barycentricfitfloaterhormannwc(/* Real */ ae_vector* x,
7940 /* Real */ ae_vector* y,
7941 /* Real */ ae_vector* w,
7942 ae_int_t n,
7943 /* Real */ ae_vector* xc,
7944 /* Real */ ae_vector* yc,
7945 /* Integer */ ae_vector* dc,
7946 ae_int_t k,
7947 ae_int_t m,
7948 ae_int_t* info,
7949 barycentricinterpolant* b,
7950 barycentricfitreport* rep, ae_state *_state);
7951void barycentricfitfloaterhormann(/* Real */ ae_vector* x,
7952 /* Real */ ae_vector* y,
7953 ae_int_t n,
7954 ae_int_t m,
7955 ae_int_t* info,
7956 barycentricinterpolant* b,
7957 barycentricfitreport* rep,
7958 ae_state *_state);
7959void _pexec_barycentricfitfloaterhormann(/* Real */ ae_vector* x,
7960 /* Real */ ae_vector* y,
7961 ae_int_t n,
7962 ae_int_t m,
7963 ae_int_t* info,
7964 barycentricinterpolant* b,
7965 barycentricfitreport* rep, ae_state *_state);
7966void spline1dfitpenalized(/* Real */ ae_vector* x,
7967 /* Real */ ae_vector* y,
7968 ae_int_t n,
7969 ae_int_t m,
7970 double rho,
7971 ae_int_t* info,
7972 spline1dinterpolant* s,
7973 spline1dfitreport* rep,
7974 ae_state *_state);
7975void _pexec_spline1dfitpenalized(/* Real */ ae_vector* x,
7976 /* Real */ ae_vector* y,
7977 ae_int_t n,
7978 ae_int_t m,
7979 double rho,
7980 ae_int_t* info,
7981 spline1dinterpolant* s,
7982 spline1dfitreport* rep, ae_state *_state);
7983void spline1dfitpenalizedw(/* Real */ ae_vector* x,
7984 /* Real */ ae_vector* y,
7985 /* Real */ ae_vector* w,
7986 ae_int_t n,
7987 ae_int_t m,
7988 double rho,
7989 ae_int_t* info,
7990 spline1dinterpolant* s,
7991 spline1dfitreport* rep,
7992 ae_state *_state);
7993void _pexec_spline1dfitpenalizedw(/* Real */ ae_vector* x,
7994 /* Real */ ae_vector* y,
7995 /* Real */ ae_vector* w,
7996 ae_int_t n,
7997 ae_int_t m,
7998 double rho,
7999 ae_int_t* info,
8000 spline1dinterpolant* s,
8001 spline1dfitreport* rep, ae_state *_state);
8002void spline1dfitcubicwc(/* Real */ ae_vector* x,
8003 /* Real */ ae_vector* y,
8004 /* Real */ ae_vector* w,
8005 ae_int_t n,
8006 /* Real */ ae_vector* xc,
8007 /* Real */ ae_vector* yc,
8008 /* Integer */ ae_vector* dc,
8009 ae_int_t k,
8010 ae_int_t m,
8011 ae_int_t* info,
8012 spline1dinterpolant* s,
8013 spline1dfitreport* rep,
8014 ae_state *_state);
8015void _pexec_spline1dfitcubicwc(/* Real */ ae_vector* x,
8016 /* Real */ ae_vector* y,
8017 /* Real */ ae_vector* w,
8018 ae_int_t n,
8019 /* Real */ ae_vector* xc,
8020 /* Real */ ae_vector* yc,
8021 /* Integer */ ae_vector* dc,
8022 ae_int_t k,
8023 ae_int_t m,
8024 ae_int_t* info,
8025 spline1dinterpolant* s,
8026 spline1dfitreport* rep, ae_state *_state);
8027void spline1dfithermitewc(/* Real */ ae_vector* x,
8028 /* Real */ ae_vector* y,
8029 /* Real */ ae_vector* w,
8030 ae_int_t n,
8031 /* Real */ ae_vector* xc,
8032 /* Real */ ae_vector* yc,
8033 /* Integer */ ae_vector* dc,
8034 ae_int_t k,
8035 ae_int_t m,
8036 ae_int_t* info,
8037 spline1dinterpolant* s,
8038 spline1dfitreport* rep,
8039 ae_state *_state);
8040void _pexec_spline1dfithermitewc(/* Real */ ae_vector* x,
8041 /* Real */ ae_vector* y,
8042 /* Real */ ae_vector* w,
8043 ae_int_t n,
8044 /* Real */ ae_vector* xc,
8045 /* Real */ ae_vector* yc,
8046 /* Integer */ ae_vector* dc,
8047 ae_int_t k,
8048 ae_int_t m,
8049 ae_int_t* info,
8050 spline1dinterpolant* s,
8051 spline1dfitreport* rep, ae_state *_state);
8052void spline1dfitcubic(/* Real */ ae_vector* x,
8053 /* Real */ ae_vector* y,
8054 ae_int_t n,
8055 ae_int_t m,
8056 ae_int_t* info,
8057 spline1dinterpolant* s,
8058 spline1dfitreport* rep,
8059 ae_state *_state);
8060void _pexec_spline1dfitcubic(/* Real */ ae_vector* x,
8061 /* Real */ ae_vector* y,
8062 ae_int_t n,
8063 ae_int_t m,
8064 ae_int_t* info,
8065 spline1dinterpolant* s,
8066 spline1dfitreport* rep, ae_state *_state);
8067void spline1dfithermite(/* Real */ ae_vector* x,
8068 /* Real */ ae_vector* y,
8069 ae_int_t n,
8070 ae_int_t m,
8071 ae_int_t* info,
8072 spline1dinterpolant* s,
8073 spline1dfitreport* rep,
8074 ae_state *_state);
8075void _pexec_spline1dfithermite(/* Real */ ae_vector* x,
8076 /* Real */ ae_vector* y,
8077 ae_int_t n,
8078 ae_int_t m,
8079 ae_int_t* info,
8080 spline1dinterpolant* s,
8081 spline1dfitreport* rep, ae_state *_state);
8082void lsfitlinearw(/* Real */ ae_vector* y,
8083 /* Real */ ae_vector* w,
8084 /* Real */ ae_matrix* fmatrix,
8085 ae_int_t n,
8086 ae_int_t m,
8087 ae_int_t* info,
8088 /* Real */ ae_vector* c,
8089 lsfitreport* rep,
8090 ae_state *_state);
8091void _pexec_lsfitlinearw(/* Real */ ae_vector* y,
8092 /* Real */ ae_vector* w,
8093 /* Real */ ae_matrix* fmatrix,
8094 ae_int_t n,
8095 ae_int_t m,
8096 ae_int_t* info,
8097 /* Real */ ae_vector* c,
8098 lsfitreport* rep, ae_state *_state);
8099void lsfitlinearwc(/* Real */ ae_vector* y,
8100 /* Real */ ae_vector* w,
8101 /* Real */ ae_matrix* fmatrix,
8102 /* Real */ ae_matrix* cmatrix,
8103 ae_int_t n,
8104 ae_int_t m,
8105 ae_int_t k,
8106 ae_int_t* info,
8107 /* Real */ ae_vector* c,
8108 lsfitreport* rep,
8109 ae_state *_state);
8110void _pexec_lsfitlinearwc(/* Real */ ae_vector* y,
8111 /* Real */ ae_vector* w,
8112 /* Real */ ae_matrix* fmatrix,
8113 /* Real */ ae_matrix* cmatrix,
8114 ae_int_t n,
8115 ae_int_t m,
8116 ae_int_t k,
8117 ae_int_t* info,
8118 /* Real */ ae_vector* c,
8119 lsfitreport* rep, ae_state *_state);
8120void lsfitlinear(/* Real */ ae_vector* y,
8121 /* Real */ ae_matrix* fmatrix,
8122 ae_int_t n,
8123 ae_int_t m,
8124 ae_int_t* info,
8125 /* Real */ ae_vector* c,
8126 lsfitreport* rep,
8127 ae_state *_state);
8128void _pexec_lsfitlinear(/* Real */ ae_vector* y,
8129 /* Real */ ae_matrix* fmatrix,
8130 ae_int_t n,
8131 ae_int_t m,
8132 ae_int_t* info,
8133 /* Real */ ae_vector* c,
8134 lsfitreport* rep, ae_state *_state);
8135void lsfitlinearc(/* Real */ ae_vector* y,
8136 /* Real */ ae_matrix* fmatrix,
8137 /* Real */ ae_matrix* cmatrix,
8138 ae_int_t n,
8139 ae_int_t m,
8140 ae_int_t k,
8141 ae_int_t* info,
8142 /* Real */ ae_vector* c,
8143 lsfitreport* rep,
8144 ae_state *_state);
8145void _pexec_lsfitlinearc(/* Real */ ae_vector* y,
8146 /* Real */ ae_matrix* fmatrix,
8147 /* Real */ ae_matrix* cmatrix,
8148 ae_int_t n,
8149 ae_int_t m,
8150 ae_int_t k,
8151 ae_int_t* info,
8152 /* Real */ ae_vector* c,
8153 lsfitreport* rep, ae_state *_state);
8154void lsfitcreatewf(/* Real */ ae_matrix* x,
8155 /* Real */ ae_vector* y,
8156 /* Real */ ae_vector* w,
8157 /* Real */ ae_vector* c,
8158 ae_int_t n,
8159 ae_int_t m,
8160 ae_int_t k,
8161 double diffstep,
8162 lsfitstate* state,
8163 ae_state *_state);
8164void lsfitcreatef(/* Real */ ae_matrix* x,
8165 /* Real */ ae_vector* y,
8166 /* Real */ ae_vector* c,
8167 ae_int_t n,
8168 ae_int_t m,
8169 ae_int_t k,
8170 double diffstep,
8171 lsfitstate* state,
8172 ae_state *_state);
8173void lsfitcreatewfg(/* Real */ ae_matrix* x,
8174 /* Real */ ae_vector* y,
8175 /* Real */ ae_vector* w,
8176 /* Real */ ae_vector* c,
8177 ae_int_t n,
8178 ae_int_t m,
8179 ae_int_t k,
8180 ae_bool cheapfg,
8181 lsfitstate* state,
8182 ae_state *_state);
8183void lsfitcreatefg(/* Real */ ae_matrix* x,
8184 /* Real */ ae_vector* y,
8185 /* Real */ ae_vector* c,
8186 ae_int_t n,
8187 ae_int_t m,
8188 ae_int_t k,
8189 ae_bool cheapfg,
8190 lsfitstate* state,
8191 ae_state *_state);
8192void lsfitcreatewfgh(/* Real */ ae_matrix* x,
8193 /* Real */ ae_vector* y,
8194 /* Real */ ae_vector* w,
8195 /* Real */ ae_vector* c,
8196 ae_int_t n,
8197 ae_int_t m,
8198 ae_int_t k,
8199 lsfitstate* state,
8200 ae_state *_state);
8201void lsfitcreatefgh(/* Real */ ae_matrix* x,
8202 /* Real */ ae_vector* y,
8203 /* Real */ ae_vector* c,
8204 ae_int_t n,
8205 ae_int_t m,
8206 ae_int_t k,
8207 lsfitstate* state,
8208 ae_state *_state);
8209void lsfitsetcond(lsfitstate* state,
8210 double epsx,
8211 ae_int_t maxits,
8212 ae_state *_state);
8213void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state);
8214void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state);
8215void lsfitsetscale(lsfitstate* state,
8216 /* Real */ ae_vector* s,
8217 ae_state *_state);
8218void lsfitsetbc(lsfitstate* state,
8219 /* Real */ ae_vector* bndl,
8220 /* Real */ ae_vector* bndu,
8221 ae_state *_state);
8222void lsfitsetlc(lsfitstate* state,
8223 /* Real */ ae_matrix* c,
8224 /* Integer */ ae_vector* ct,
8225 ae_int_t k,
8226 ae_state *_state);
8227ae_bool lsfititeration(lsfitstate* state, ae_state *_state);
8228void lsfitresults(lsfitstate* state,
8229 ae_int_t* info,
8230 /* Real */ ae_vector* c,
8231 lsfitreport* rep,
8232 ae_state *_state);
8233void lsfitsetgradientcheck(lsfitstate* state,
8234 double teststep,
8235 ae_state *_state);
8236void lsfitscalexy(/* Real */ ae_vector* x,
8237 /* Real */ ae_vector* y,
8238 /* Real */ ae_vector* w,
8239 ae_int_t n,
8240 /* Real */ ae_vector* xc,
8241 /* Real */ ae_vector* yc,
8242 /* Integer */ ae_vector* dc,
8243 ae_int_t k,
8244 double* xa,
8245 double* xb,
8246 double* sa,
8247 double* sb,
8248 /* Real */ ae_vector* xoriginal,
8249 /* Real */ ae_vector* yoriginal,
8250 ae_state *_state);
8251void _polynomialfitreport_init(void* _p, ae_state *_state);
8252void _polynomialfitreport_init_copy(void* _dst, void* _src, ae_state *_state);
8253void _polynomialfitreport_clear(void* _p);
8254void _polynomialfitreport_destroy(void* _p);
8255void _barycentricfitreport_init(void* _p, ae_state *_state);
8256void _barycentricfitreport_init_copy(void* _dst, void* _src, ae_state *_state);
8257void _barycentricfitreport_clear(void* _p);
8258void _barycentricfitreport_destroy(void* _p);
8259void _spline1dfitreport_init(void* _p, ae_state *_state);
8260void _spline1dfitreport_init_copy(void* _dst, void* _src, ae_state *_state);
8261void _spline1dfitreport_clear(void* _p);
8262void _spline1dfitreport_destroy(void* _p);
8263void _lsfitreport_init(void* _p, ae_state *_state);
8264void _lsfitreport_init_copy(void* _dst, void* _src, ae_state *_state);
8265void _lsfitreport_clear(void* _p);
8266void _lsfitreport_destroy(void* _p);
8267void _lsfitstate_init(void* _p, ae_state *_state);
8268void _lsfitstate_init_copy(void* _dst, void* _src, ae_state *_state);
8269void _lsfitstate_clear(void* _p);
8270void _lsfitstate_destroy(void* _p);
8271void rbfv2create(ae_int_t nx,
8272 ae_int_t ny,
8273 rbfv2model* s,
8274 ae_state *_state);
8275void rbfv2createcalcbuffer(rbfv2model* s,
8276 rbfv2calcbuffer* buf,
8277 ae_state *_state);
8278void rbfv2buildhierarchical(/* Real */ ae_matrix* x,
8279 /* Real */ ae_matrix* y,
8280 ae_int_t n,
8281 /* Real */ ae_vector* scalevec,
8282 ae_int_t aterm,
8283 ae_int_t nh,
8284 double rbase,
8285 double lambdans,
8286 ae_bool nonnegative,
8287 ae_int_t nnmaxits,
8288 rbfv2model* s,
8289 rbfv2report* rep,
8290 ae_state *_state);
8291void rbfv2alloc(ae_serializer* s, rbfv2model* model, ae_state *_state);
8292void rbfv2serialize(ae_serializer* s, rbfv2model* model, ae_state *_state);
8293void rbfv2unserialize(ae_serializer* s,
8294 rbfv2model* model,
8295 ae_state *_state);
8296double rbfv2farradius(ae_int_t bf, ae_state *_state);
8297double rbfv2nearradius(ae_int_t bf, ae_state *_state);
8298double rbfv2basisfunc(ae_int_t bf, double d2, ae_state *_state);
8299void rbfv2basisfuncdiff2(ae_int_t bf,
8300 double d2,
8301 double* f,
8302 double* df,
8303 double* d2f,
8304 ae_state *_state);
8305double rbfv2calc1(rbfv2model* s, double x0, ae_state *_state);
8306double rbfv2calc2(rbfv2model* s, double x0, double x1, ae_state *_state);
8307double rbfv2calc3(rbfv2model* s,
8308 double x0,
8309 double x1,
8310 double x2,
8311 ae_state *_state);
8312void rbfv2calcbuf(rbfv2model* s,
8313 /* Real */ ae_vector* x,
8314 /* Real */ ae_vector* y,
8315 ae_state *_state);
8316void rbfv2tscalcbuf(rbfv2model* s,
8317 rbfv2calcbuffer* buf,
8318 /* Real */ ae_vector* x,
8319 /* Real */ ae_vector* y,
8320 ae_state *_state);
8321void rbfv2gridcalc2(rbfv2model* s,
8322 /* Real */ ae_vector* x0,
8323 ae_int_t n0,
8324 /* Real */ ae_vector* x1,
8325 ae_int_t n1,
8326 /* Real */ ae_matrix* y,
8327 ae_state *_state);
8328void rbfv2gridcalcvx(rbfv2model* s,
8329 /* Real */ ae_vector* x0,
8330 ae_int_t n0,
8331 /* Real */ ae_vector* x1,
8332 ae_int_t n1,
8333 /* Real */ ae_vector* x2,
8334 ae_int_t n2,
8335 /* Real */ ae_vector* x3,
8336 ae_int_t n3,
8337 /* Boolean */ ae_vector* flagy,
8338 ae_bool sparsey,
8339 /* Real */ ae_vector* y,
8340 ae_state *_state);
8341void rbfv2partialgridcalcrec(rbfv2model* s,
8342 /* Real */ ae_vector* x0,
8343 ae_int_t n0,
8344 /* Real */ ae_vector* x1,
8345 ae_int_t n1,
8346 /* Real */ ae_vector* x2,
8347 ae_int_t n2,
8348 /* Real */ ae_vector* x3,
8349 ae_int_t n3,
8350 /* Integer */ ae_vector* blocks0,
8351 ae_int_t block0a,
8352 ae_int_t block0b,
8353 /* Integer */ ae_vector* blocks1,
8354 ae_int_t block1a,
8355 ae_int_t block1b,
8356 /* Integer */ ae_vector* blocks2,
8357 ae_int_t block2a,
8358 ae_int_t block2b,
8359 /* Integer */ ae_vector* blocks3,
8360 ae_int_t block3a,
8361 ae_int_t block3b,
8362 /* Boolean */ ae_vector* flagy,
8363 ae_bool sparsey,
8364 ae_int_t levelidx,
8365 double avgfuncpernode,
8366 ae_shared_pool* bufpool,
8367 /* Real */ ae_vector* y,
8368 ae_state *_state);
8369void rbfv2unpack(rbfv2model* s,
8370 ae_int_t* nx,
8371 ae_int_t* ny,
8372 /* Real */ ae_matrix* xwr,
8373 ae_int_t* nc,
8374 /* Real */ ae_matrix* v,
8375 ae_state *_state);
8376void _rbfv2calcbuffer_init(void* _p, ae_state *_state);
8377void _rbfv2calcbuffer_init_copy(void* _dst, void* _src, ae_state *_state);
8378void _rbfv2calcbuffer_clear(void* _p);
8379void _rbfv2calcbuffer_destroy(void* _p);
8380void _rbfv2model_init(void* _p, ae_state *_state);
8381void _rbfv2model_init_copy(void* _dst, void* _src, ae_state *_state);
8382void _rbfv2model_clear(void* _p);
8383void _rbfv2model_destroy(void* _p);
8384void _rbfv2gridcalcbuffer_init(void* _p, ae_state *_state);
8385void _rbfv2gridcalcbuffer_init_copy(void* _dst, void* _src, ae_state *_state);
8386void _rbfv2gridcalcbuffer_clear(void* _p);
8387void _rbfv2gridcalcbuffer_destroy(void* _p);
8388void _rbfv2report_init(void* _p, ae_state *_state);
8389void _rbfv2report_init_copy(void* _dst, void* _src, ae_state *_state);
8390void _rbfv2report_clear(void* _p);
8391void _rbfv2report_destroy(void* _p);
8392void nsfitspheremcc(/* Real */ ae_matrix* xy,
8393 ae_int_t npoints,
8394 ae_int_t nx,
8395 /* Real */ ae_vector* cx,
8396 double* rhi,
8397 ae_state *_state);
8398void nsfitspheremic(/* Real */ ae_matrix* xy,
8399 ae_int_t npoints,
8400 ae_int_t nx,
8401 /* Real */ ae_vector* cx,
8402 double* rlo,
8403 ae_state *_state);
8404void nsfitspheremzc(/* Real */ ae_matrix* xy,
8405 ae_int_t npoints,
8406 ae_int_t nx,
8407 /* Real */ ae_vector* cx,
8408 double* rlo,
8409 double* rhi,
8410 ae_state *_state);
8411void nsfitspherex(/* Real */ ae_matrix* xy,
8412 ae_int_t npoints,
8413 ae_int_t nx,
8414 ae_int_t problemtype,
8415 double epsx,
8416 ae_int_t aulits,
8417 double penalty,
8418 /* Real */ ae_vector* cx,
8419 double* rlo,
8420 double* rhi,
8421 ae_state *_state);
8422void nsfitsphereinternal(/* Real */ ae_matrix* xy,
8423 ae_int_t npoints,
8424 ae_int_t nx,
8425 ae_int_t problemtype,
8426 ae_int_t solvertype,
8427 double epsx,
8428 ae_int_t aulits,
8429 double penalty,
8430 /* Real */ ae_vector* cx,
8431 double* rlo,
8432 double* rhi,
8433 nsfitinternalreport* rep,
8434 ae_state *_state);
8435void _nsfitinternalreport_init(void* _p, ae_state *_state);
8436void _nsfitinternalreport_init_copy(void* _dst, void* _src, ae_state *_state);
8437void _nsfitinternalreport_clear(void* _p);
8438void _nsfitinternalreport_destroy(void* _p);
8439double spline2dcalc(spline2dinterpolant* c,
8440 double x,
8441 double y,
8442 ae_state *_state);
8443void spline2ddiff(spline2dinterpolant* c,
8444 double x,
8445 double y,
8446 double* f,
8447 double* fx,
8448 double* fy,
8449 double* fxy,
8450 ae_state *_state);
8451void spline2dlintransxy(spline2dinterpolant* c,
8452 double ax,
8453 double bx,
8454 double ay,
8455 double by,
8456 ae_state *_state);
8457void spline2dlintransf(spline2dinterpolant* c,
8458 double a,
8459 double b,
8460 ae_state *_state);
8461void spline2dcopy(spline2dinterpolant* c,
8462 spline2dinterpolant* cc,
8463 ae_state *_state);
8464void spline2dresamplebicubic(/* Real */ ae_matrix* a,
8465 ae_int_t oldheight,
8466 ae_int_t oldwidth,
8467 /* Real */ ae_matrix* b,
8468 ae_int_t newheight,
8469 ae_int_t newwidth,
8470 ae_state *_state);
8471void spline2dresamplebilinear(/* Real */ ae_matrix* a,
8472 ae_int_t oldheight,
8473 ae_int_t oldwidth,
8474 /* Real */ ae_matrix* b,
8475 ae_int_t newheight,
8476 ae_int_t newwidth,
8477 ae_state *_state);
8478void spline2dbuildbilinearv(/* Real */ ae_vector* x,
8479 ae_int_t n,
8480 /* Real */ ae_vector* y,
8481 ae_int_t m,
8482 /* Real */ ae_vector* f,
8483 ae_int_t d,
8484 spline2dinterpolant* c,
8485 ae_state *_state);
8486void spline2dbuildbicubicv(/* Real */ ae_vector* x,
8487 ae_int_t n,
8488 /* Real */ ae_vector* y,
8489 ae_int_t m,
8490 /* Real */ ae_vector* f,
8491 ae_int_t d,
8492 spline2dinterpolant* c,
8493 ae_state *_state);
8494void spline2dcalcvbuf(spline2dinterpolant* c,
8495 double x,
8496 double y,
8497 /* Real */ ae_vector* f,
8498 ae_state *_state);
8499void spline2dcalcv(spline2dinterpolant* c,
8500 double x,
8501 double y,
8502 /* Real */ ae_vector* f,
8503 ae_state *_state);
8504void spline2dunpackv(spline2dinterpolant* c,
8505 ae_int_t* m,
8506 ae_int_t* n,
8507 ae_int_t* d,
8508 /* Real */ ae_matrix* tbl,
8509 ae_state *_state);
8510void spline2dbuildbilinear(/* Real */ ae_vector* x,
8511 /* Real */ ae_vector* y,
8512 /* Real */ ae_matrix* f,
8513 ae_int_t m,
8514 ae_int_t n,
8515 spline2dinterpolant* c,
8516 ae_state *_state);
8517void spline2dbuildbicubic(/* Real */ ae_vector* x,
8518 /* Real */ ae_vector* y,
8519 /* Real */ ae_matrix* f,
8520 ae_int_t m,
8521 ae_int_t n,
8522 spline2dinterpolant* c,
8523 ae_state *_state);
8524void spline2dunpack(spline2dinterpolant* c,
8525 ae_int_t* m,
8526 ae_int_t* n,
8527 /* Real */ ae_matrix* tbl,
8528 ae_state *_state);
8529void _spline2dinterpolant_init(void* _p, ae_state *_state);
8530void _spline2dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state);
8531void _spline2dinterpolant_clear(void* _p);
8532void _spline2dinterpolant_destroy(void* _p);
8533void rbfv1create(ae_int_t nx,
8534 ae_int_t ny,
8535 rbfv1model* s,
8536 ae_state *_state);
8537void rbfv1createcalcbuffer(rbfv1model* s,
8538 rbfv1calcbuffer* buf,
8539 ae_state *_state);
8540void rbfv1buildmodel(/* Real */ ae_matrix* x,
8541 /* Real */ ae_matrix* y,
8542 ae_int_t n,
8543 ae_int_t aterm,
8544 ae_int_t algorithmtype,
8545 ae_int_t nlayers,
8546 double radvalue,
8547 double radzvalue,
8548 double lambdav,
8549 double epsort,
8550 double epserr,
8551 ae_int_t maxits,
8552 rbfv1model* s,
8553 rbfv1report* rep,
8554 ae_state *_state);
8555void rbfv1alloc(ae_serializer* s, rbfv1model* model, ae_state *_state);
8556void rbfv1serialize(ae_serializer* s, rbfv1model* model, ae_state *_state);
8557void rbfv1unserialize(ae_serializer* s,
8558 rbfv1model* model,
8559 ae_state *_state);
8560double rbfv1calc2(rbfv1model* s, double x0, double x1, ae_state *_state);
8561double rbfv1calc3(rbfv1model* s,
8562 double x0,
8563 double x1,
8564 double x2,
8565 ae_state *_state);
8566void rbfv1calcbuf(rbfv1model* s,
8567 /* Real */ ae_vector* x,
8568 /* Real */ ae_vector* y,
8569 ae_state *_state);
8570void rbfv1tscalcbuf(rbfv1model* s,
8571 rbfv1calcbuffer* buf,
8572 /* Real */ ae_vector* x,
8573 /* Real */ ae_vector* y,
8574 ae_state *_state);
8575void rbfv1gridcalc2(rbfv1model* s,
8576 /* Real */ ae_vector* x0,
8577 ae_int_t n0,
8578 /* Real */ ae_vector* x1,
8579 ae_int_t n1,
8580 /* Real */ ae_matrix* y,
8581 ae_state *_state);
8582void rbfv1gridcalc3vrec(rbfv1model* s,
8583 /* Real */ ae_vector* x0,
8584 ae_int_t n0,
8585 /* Real */ ae_vector* x1,
8586 ae_int_t n1,
8587 /* Real */ ae_vector* x2,
8588 ae_int_t n2,
8589 /* Integer */ ae_vector* blocks0,
8590 ae_int_t block0a,
8591 ae_int_t block0b,
8592 /* Integer */ ae_vector* blocks1,
8593 ae_int_t block1a,
8594 ae_int_t block1b,
8595 /* Integer */ ae_vector* blocks2,
8596 ae_int_t block2a,
8597 ae_int_t block2b,
8598 /* Boolean */ ae_vector* flagy,
8599 ae_bool sparsey,
8600 double searchradius,
8601 double avgfuncpernode,
8602 ae_shared_pool* bufpool,
8603 /* Real */ ae_vector* y,
8604 ae_state *_state);
8605void rbfv1unpack(rbfv1model* s,
8606 ae_int_t* nx,
8607 ae_int_t* ny,
8608 /* Real */ ae_matrix* xwr,
8609 ae_int_t* nc,
8610 /* Real */ ae_matrix* v,
8611 ae_state *_state);
8612void _rbfv1calcbuffer_init(void* _p, ae_state *_state);
8613void _rbfv1calcbuffer_init_copy(void* _dst, void* _src, ae_state *_state);
8614void _rbfv1calcbuffer_clear(void* _p);
8615void _rbfv1calcbuffer_destroy(void* _p);
8616void _rbfv1model_init(void* _p, ae_state *_state);
8617void _rbfv1model_init_copy(void* _dst, void* _src, ae_state *_state);
8618void _rbfv1model_clear(void* _p);
8619void _rbfv1model_destroy(void* _p);
8620void _gridcalc3v1buf_init(void* _p, ae_state *_state);
8621void _gridcalc3v1buf_init_copy(void* _dst, void* _src, ae_state *_state);
8622void _gridcalc3v1buf_clear(void* _p);
8623void _gridcalc3v1buf_destroy(void* _p);
8624void _rbfv1report_init(void* _p, ae_state *_state);
8625void _rbfv1report_init_copy(void* _dst, void* _src, ae_state *_state);
8626void _rbfv1report_clear(void* _p);
8627void _rbfv1report_destroy(void* _p);
8628void rbfcreate(ae_int_t nx, ae_int_t ny, rbfmodel* s, ae_state *_state);
8629void rbfcreatecalcbuffer(rbfmodel* s,
8630 rbfcalcbuffer* buf,
8631 ae_state *_state);
8632void rbfsetpoints(rbfmodel* s,
8633 /* Real */ ae_matrix* xy,
8634 ae_int_t n,
8635 ae_state *_state);
8636void rbfsetpointsandscales(rbfmodel* r,
8637 /* Real */ ae_matrix* xy,
8638 ae_int_t n,
8639 /* Real */ ae_vector* s,
8640 ae_state *_state);
8641void rbfsetalgoqnn(rbfmodel* s, double q, double z, ae_state *_state);
8642void rbfsetalgomultilayer(rbfmodel* s,
8643 double rbase,
8644 ae_int_t nlayers,
8645 double lambdav,
8646 ae_state *_state);
8647void rbfsetalgohierarchical(rbfmodel* s,
8648 double rbase,
8649 ae_int_t nlayers,
8650 double lambdans,
8651 ae_state *_state);
8652void rbfsetlinterm(rbfmodel* s, ae_state *_state);
8653void rbfsetconstterm(rbfmodel* s, ae_state *_state);
8654void rbfsetzeroterm(rbfmodel* s, ae_state *_state);
8655void rbfsetv2bf(rbfmodel* s, ae_int_t bf, ae_state *_state);
8656void rbfsetv2its(rbfmodel* s, ae_int_t maxits, ae_state *_state);
8657void rbfsetv2supportr(rbfmodel* s, double r, ae_state *_state);
8658void rbfsetcond(rbfmodel* s,
8659 double epsort,
8660 double epserr,
8661 ae_int_t maxits,
8662 ae_state *_state);
8663void rbfbuildmodel(rbfmodel* s, rbfreport* rep, ae_state *_state);
8664double rbfcalc1(rbfmodel* s, double x0, ae_state *_state);
8665double rbfcalc2(rbfmodel* s, double x0, double x1, ae_state *_state);
8666double rbfcalc3(rbfmodel* s,
8667 double x0,
8668 double x1,
8669 double x2,
8670 ae_state *_state);
8671void rbfcalc(rbfmodel* s,
8672 /* Real */ ae_vector* x,
8673 /* Real */ ae_vector* y,
8674 ae_state *_state);
8675void rbfcalcbuf(rbfmodel* s,
8676 /* Real */ ae_vector* x,
8677 /* Real */ ae_vector* y,
8678 ae_state *_state);
8679void rbftscalcbuf(rbfmodel* s,
8680 rbfcalcbuffer* buf,
8681 /* Real */ ae_vector* x,
8682 /* Real */ ae_vector* y,
8683 ae_state *_state);
8684void rbfgridcalc2(rbfmodel* s,
8685 /* Real */ ae_vector* x0,
8686 ae_int_t n0,
8687 /* Real */ ae_vector* x1,
8688 ae_int_t n1,
8689 /* Real */ ae_matrix* y,
8690 ae_state *_state);
8691void rbfgridcalc2v(rbfmodel* s,
8692 /* Real */ ae_vector* x0,
8693 ae_int_t n0,
8694 /* Real */ ae_vector* x1,
8695 ae_int_t n1,
8696 /* Real */ ae_vector* y,
8697 ae_state *_state);
8698void _pexec_rbfgridcalc2v(rbfmodel* s,
8699 /* Real */ ae_vector* x0,
8700 ae_int_t n0,
8701 /* Real */ ae_vector* x1,
8702 ae_int_t n1,
8703 /* Real */ ae_vector* y, ae_state *_state);
8704void rbfgridcalc2vsubset(rbfmodel* s,
8705 /* Real */ ae_vector* x0,
8706 ae_int_t n0,
8707 /* Real */ ae_vector* x1,
8708 ae_int_t n1,
8709 /* Boolean */ ae_vector* flagy,
8710 /* Real */ ae_vector* y,
8711 ae_state *_state);
8712void _pexec_rbfgridcalc2vsubset(rbfmodel* s,
8713 /* Real */ ae_vector* x0,
8714 ae_int_t n0,
8715 /* Real */ ae_vector* x1,
8716 ae_int_t n1,
8717 /* Boolean */ ae_vector* flagy,
8718 /* Real */ ae_vector* y, ae_state *_state);
8719void rbfgridcalc3v(rbfmodel* s,
8720 /* Real */ ae_vector* x0,
8721 ae_int_t n0,
8722 /* Real */ ae_vector* x1,
8723 ae_int_t n1,
8724 /* Real */ ae_vector* x2,
8725 ae_int_t n2,
8726 /* Real */ ae_vector* y,
8727 ae_state *_state);
8728void _pexec_rbfgridcalc3v(rbfmodel* s,
8729 /* Real */ ae_vector* x0,
8730 ae_int_t n0,
8731 /* Real */ ae_vector* x1,
8732 ae_int_t n1,
8733 /* Real */ ae_vector* x2,
8734 ae_int_t n2,
8735 /* Real */ ae_vector* y, ae_state *_state);
8736void rbfgridcalc3vsubset(rbfmodel* s,
8737 /* Real */ ae_vector* x0,
8738 ae_int_t n0,
8739 /* Real */ ae_vector* x1,
8740 ae_int_t n1,
8741 /* Real */ ae_vector* x2,
8742 ae_int_t n2,
8743 /* Boolean */ ae_vector* flagy,
8744 /* Real */ ae_vector* y,
8745 ae_state *_state);
8746void _pexec_rbfgridcalc3vsubset(rbfmodel* s,
8747 /* Real */ ae_vector* x0,
8748 ae_int_t n0,
8749 /* Real */ ae_vector* x1,
8750 ae_int_t n1,
8751 /* Real */ ae_vector* x2,
8752 ae_int_t n2,
8753 /* Boolean */ ae_vector* flagy,
8754 /* Real */ ae_vector* y, ae_state *_state);
8755void rbfgridcalc2vx(rbfmodel* s,
8756 /* Real */ ae_vector* x0,
8757 ae_int_t n0,
8758 /* Real */ ae_vector* x1,
8759 ae_int_t n1,
8760 /* Boolean */ ae_vector* flagy,
8761 ae_bool sparsey,
8762 /* Real */ ae_vector* y,
8763 ae_state *_state);
8764void rbfgridcalc3vx(rbfmodel* s,
8765 /* Real */ ae_vector* x0,
8766 ae_int_t n0,
8767 /* Real */ ae_vector* x1,
8768 ae_int_t n1,
8769 /* Real */ ae_vector* x2,
8770 ae_int_t n2,
8771 /* Boolean */ ae_vector* flagy,
8772 ae_bool sparsey,
8773 /* Real */ ae_vector* y,
8774 ae_state *_state);
8775void rbfunpack(rbfmodel* s,
8776 ae_int_t* nx,
8777 ae_int_t* ny,
8778 /* Real */ ae_matrix* xwr,
8779 ae_int_t* nc,
8780 /* Real */ ae_matrix* v,
8781 ae_int_t* modelversion,
8782 ae_state *_state);
8783ae_int_t rbfgetmodelversion(rbfmodel* s, ae_state *_state);
8784void rbfalloc(ae_serializer* s, rbfmodel* model, ae_state *_state);
8785void rbfserialize(ae_serializer* s, rbfmodel* model, ae_state *_state);
8786void rbfunserialize(ae_serializer* s, rbfmodel* model, ae_state *_state);
8787void _rbfcalcbuffer_init(void* _p, ae_state *_state);
8788void _rbfcalcbuffer_init_copy(void* _dst, void* _src, ae_state *_state);
8789void _rbfcalcbuffer_clear(void* _p);
8790void _rbfcalcbuffer_destroy(void* _p);
8791void _rbfmodel_init(void* _p, ae_state *_state);
8792void _rbfmodel_init_copy(void* _dst, void* _src, ae_state *_state);
8793void _rbfmodel_clear(void* _p);
8794void _rbfmodel_destroy(void* _p);
8795void _rbfreport_init(void* _p, ae_state *_state);
8796void _rbfreport_init_copy(void* _dst, void* _src, ae_state *_state);
8797void _rbfreport_clear(void* _p);
8798void _rbfreport_destroy(void* _p);
8799
8800}
8801#endif
8802