1 /************************************************************************* 2 ALGLIB 3.15.0 (source code generated 2019-02-20) 3 Copyright (c) Sergey Bochkanov (ALGLIB project). 4 5 >>> SOURCE LICENSE >>> 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation (www.fsf.org); either version 2 of the 9 License, or (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 A copy of the GNU General Public License is available at 17 http://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 "optimization.h" 27 #include "solvers.h" 28 #include "specialfunctions.h" 29 #include "integration.h" 30 31 ///////////////////////////////////////////////////////////////////////// 32 // 33 // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES) 34 // 35 ///////////////////////////////////////////////////////////////////////// 36 namespace alglib_impl 37 { 38 #if defined(AE_COMPILE_IDW) || !defined(AE_PARTIAL_BUILD) 39 typedef struct 40 { 41 ae_vector x; 42 ae_vector y; 43 ae_vector tsyw; 44 ae_vector tsw; 45 ae_matrix tsxy; 46 ae_vector tsdist; 47 kdtreerequestbuffer requestbuffer; 48 } idwcalcbuffer; 49 typedef struct 50 { 51 ae_int_t nx; 52 ae_int_t ny; 53 ae_vector globalprior; 54 ae_int_t algotype; 55 ae_int_t nlayers; 56 double r0; 57 double rdecay; 58 double lambda0; 59 double lambdalast; 60 double lambdadecay; 61 double shepardp; 62 kdtree tree; 63 ae_int_t npoints; 64 ae_vector shepardxy; 65 idwcalcbuffer buffer; 66 } idwmodel; 67 typedef struct 68 { 69 ae_int_t priortermtype; 70 ae_vector priortermval; 71 ae_int_t algotype; 72 ae_int_t nlayers; 73 double r0; 74 double rdecay; 75 double lambda0; 76 double lambdalast; 77 double lambdadecay; 78 double shepardp; 79 ae_vector xy; 80 ae_int_t npoints; 81 ae_int_t nx; 82 ae_int_t ny; 83 ae_matrix tmpxy; 84 ae_matrix tmplayers; 85 ae_vector tmptags; 86 ae_vector tmpdist; 87 ae_vector tmpx; 88 ae_vector tmpwy; 89 ae_vector tmpw; 90 kdtree tmptree; 91 ae_vector tmpmean; 92 } idwbuilder; 93 typedef struct 94 { 95 double rmserror; 96 double avgerror; 97 double maxerror; 98 double r2; 99 } idwreport; 100 #endif 101 #if defined(AE_COMPILE_RATINT) || !defined(AE_PARTIAL_BUILD) 102 typedef struct 103 { 104 ae_int_t n; 105 double sy; 106 ae_vector x; 107 ae_vector y; 108 ae_vector w; 109 } barycentricinterpolant; 110 #endif 111 #if defined(AE_COMPILE_FITSPHERE) || !defined(AE_PARTIAL_BUILD) 112 typedef struct 113 { 114 ae_int_t nfev; 115 ae_int_t iterationscount; 116 } fitsphereinternalreport; 117 #endif 118 #if defined(AE_COMPILE_INTFITSERV) || !defined(AE_PARTIAL_BUILD) 119 #endif 120 #if defined(AE_COMPILE_SPLINE1D) || !defined(AE_PARTIAL_BUILD) 121 typedef struct 122 { 123 ae_bool periodic; 124 ae_int_t n; 125 ae_int_t k; 126 ae_int_t continuity; 127 ae_vector x; 128 ae_vector c; 129 } spline1dinterpolant; 130 typedef struct 131 { 132 double taskrcond; 133 double rmserror; 134 double avgerror; 135 double avgrelerror; 136 double maxerror; 137 } spline1dfitreport; 138 #endif 139 #if defined(AE_COMPILE_PARAMETRIC) || !defined(AE_PARTIAL_BUILD) 140 typedef struct 141 { 142 ae_int_t n; 143 ae_bool periodic; 144 ae_vector p; 145 spline1dinterpolant x; 146 spline1dinterpolant y; 147 } pspline2interpolant; 148 typedef struct 149 { 150 ae_int_t n; 151 ae_bool periodic; 152 ae_vector p; 153 spline1dinterpolant x; 154 spline1dinterpolant y; 155 spline1dinterpolant z; 156 } pspline3interpolant; 157 #endif 158 #if defined(AE_COMPILE_SPLINE3D) || !defined(AE_PARTIAL_BUILD) 159 typedef struct 160 { 161 ae_int_t k; 162 ae_int_t stype; 163 ae_int_t n; 164 ae_int_t m; 165 ae_int_t l; 166 ae_int_t d; 167 ae_vector x; 168 ae_vector y; 169 ae_vector z; 170 ae_vector f; 171 } spline3dinterpolant; 172 #endif 173 #if defined(AE_COMPILE_POLINT) || !defined(AE_PARTIAL_BUILD) 174 #endif 175 #if defined(AE_COMPILE_LSFIT) || !defined(AE_PARTIAL_BUILD) 176 typedef struct 177 { 178 double taskrcond; 179 double rmserror; 180 double avgerror; 181 double avgrelerror; 182 double maxerror; 183 } polynomialfitreport; 184 typedef struct 185 { 186 double taskrcond; 187 ae_int_t dbest; 188 double rmserror; 189 double avgerror; 190 double avgrelerror; 191 double maxerror; 192 } barycentricfitreport; 193 typedef struct 194 { 195 double taskrcond; 196 ae_int_t iterationscount; 197 ae_int_t varidx; 198 double rmserror; 199 double avgerror; 200 double avgrelerror; 201 double maxerror; 202 double wrmserror; 203 ae_matrix covpar; 204 ae_vector errpar; 205 ae_vector errcurve; 206 ae_vector noise; 207 double r2; 208 } lsfitreport; 209 typedef struct 210 { 211 ae_int_t optalgo; 212 ae_int_t m; 213 ae_int_t k; 214 double epsx; 215 ae_int_t maxits; 216 double stpmax; 217 ae_bool xrep; 218 ae_vector c0; 219 ae_vector c1; 220 ae_vector s; 221 ae_vector bndl; 222 ae_vector bndu; 223 ae_matrix taskx; 224 ae_vector tasky; 225 ae_int_t npoints; 226 ae_vector taskw; 227 ae_int_t nweights; 228 ae_int_t wkind; 229 ae_int_t wits; 230 double diffstep; 231 double teststep; 232 ae_matrix cleic; 233 ae_int_t nec; 234 ae_int_t nic; 235 ae_bool xupdated; 236 ae_bool needf; 237 ae_bool needfg; 238 ae_bool needfgh; 239 ae_int_t pointindex; 240 ae_vector x; 241 ae_vector c; 242 double f; 243 ae_vector g; 244 ae_matrix h; 245 ae_vector wcur; 246 ae_vector tmpct; 247 ae_vector tmp; 248 ae_vector tmpf; 249 ae_matrix tmpjac; 250 ae_matrix tmpjacw; 251 double tmpnoise; 252 matinvreport invrep; 253 ae_int_t repiterationscount; 254 ae_int_t repterminationtype; 255 ae_int_t repvaridx; 256 double reprmserror; 257 double repavgerror; 258 double repavgrelerror; 259 double repmaxerror; 260 double repwrmserror; 261 lsfitreport rep; 262 minlmstate optstate; 263 minlmreport optrep; 264 ae_int_t prevnpt; 265 ae_int_t prevalgo; 266 rcommstate rstate; 267 } lsfitstate; 268 #endif 269 #if defined(AE_COMPILE_RBFV2) || !defined(AE_PARTIAL_BUILD) 270 typedef struct 271 { 272 ae_vector x; 273 ae_vector curboxmin; 274 ae_vector curboxmax; 275 double curdist2; 276 ae_vector x123; 277 ae_vector y123; 278 } rbfv2calcbuffer; 279 typedef struct 280 { 281 ae_int_t ny; 282 ae_int_t nx; 283 ae_int_t bf; 284 ae_int_t nh; 285 ae_vector ri; 286 ae_vector s; 287 ae_vector kdroots; 288 ae_vector kdnodes; 289 ae_vector kdsplits; 290 ae_vector kdboxmin; 291 ae_vector kdboxmax; 292 ae_vector cw; 293 ae_matrix v; 294 double lambdareg; 295 ae_int_t maxits; 296 double supportr; 297 ae_int_t basisfunction; 298 rbfv2calcbuffer calcbuf; 299 } rbfv2model; 300 typedef struct 301 { 302 rbfv2calcbuffer calcbuf; 303 ae_vector cx; 304 ae_vector rx; 305 ae_vector ry; 306 ae_vector tx; 307 ae_vector ty; 308 ae_vector rf; 309 } rbfv2gridcalcbuffer; 310 typedef struct 311 { 312 ae_int_t terminationtype; 313 double maxerror; 314 double rmserror; 315 } rbfv2report; 316 #endif 317 #if defined(AE_COMPILE_SPLINE2D) || !defined(AE_PARTIAL_BUILD) 318 typedef struct 319 { 320 ae_int_t stype; 321 ae_int_t n; 322 ae_int_t m; 323 ae_int_t d; 324 ae_vector x; 325 ae_vector y; 326 ae_vector f; 327 } spline2dinterpolant; 328 typedef struct 329 { 330 ae_int_t priorterm; 331 double priortermval; 332 ae_int_t areatype; 333 double xa; 334 double xb; 335 double ya; 336 double yb; 337 ae_int_t gridtype; 338 ae_int_t kx; 339 ae_int_t ky; 340 double smoothing; 341 ae_int_t nlayers; 342 ae_int_t solvertype; 343 double lambdabase; 344 ae_vector xy; 345 ae_int_t npoints; 346 ae_int_t d; 347 double sx; 348 double sy; 349 ae_bool adddegreeoffreedom; 350 ae_int_t interfacesize; 351 ae_int_t lsqrcnt; 352 ae_int_t maxcoresize; 353 } spline2dbuilder; 354 typedef struct 355 { 356 double rmserror; 357 double avgerror; 358 double maxerror; 359 double r2; 360 } spline2dfitreport; 361 typedef struct 362 { 363 ae_int_t blockwidth; 364 ae_int_t kx; 365 ae_int_t ky; 366 ae_int_t npoints; 367 ae_int_t nrows; 368 ae_int_t ndenserows; 369 ae_int_t ndensebatches; 370 ae_int_t d; 371 ae_int_t maxbatch; 372 ae_matrix vals; 373 ae_vector batches; 374 ae_vector batchbases; 375 double lambdareg; 376 ae_vector tmp0; 377 ae_vector tmp1; 378 ae_matrix tmp2; 379 } spline2dxdesignmatrix; 380 typedef struct 381 { 382 linlsqrstate solver; 383 linlsqrreport solverrep; 384 ae_matrix blockata; 385 ae_matrix trsmbuf2; 386 ae_matrix cholbuf2; 387 ae_vector cholbuf1; 388 ae_vector tmp0; 389 ae_vector tmp1; 390 } spline2dblockllsbuf; 391 typedef struct 392 { 393 spline2dxdesignmatrix xdesignmatrix; 394 ae_vector tmp0; 395 ae_vector tmpz; 396 spline2dfitreport dummyrep; 397 spline2dinterpolant localmodel; 398 spline2dblockllsbuf blockllsbuf; 399 } spline2dfastddmbuf; 400 #endif 401 #if defined(AE_COMPILE_RBFV1) || !defined(AE_PARTIAL_BUILD) 402 typedef struct 403 { 404 ae_vector calcbufxcx; 405 ae_matrix calcbufx; 406 ae_vector calcbuftags; 407 kdtreerequestbuffer requestbuffer; 408 } rbfv1calcbuffer; 409 typedef struct 410 { 411 ae_int_t ny; 412 ae_int_t nx; 413 ae_int_t nc; 414 ae_int_t nl; 415 kdtree tree; 416 ae_matrix xc; 417 ae_matrix wr; 418 double rmax; 419 ae_matrix v; 420 ae_vector calcbufxcx; 421 ae_matrix calcbufx; 422 ae_vector calcbuftags; 423 } rbfv1model; 424 typedef struct 425 { 426 ae_vector tx; 427 ae_vector cx; 428 ae_vector ty; 429 ae_vector flag0; 430 ae_vector flag1; 431 ae_vector flag2; 432 ae_vector flag12; 433 ae_vector expbuf0; 434 ae_vector expbuf1; 435 ae_vector expbuf2; 436 kdtreerequestbuffer requestbuf; 437 ae_matrix calcbufx; 438 ae_vector calcbuftags; 439 } gridcalc3v1buf; 440 typedef struct 441 { 442 ae_int_t arows; 443 ae_int_t acols; 444 ae_int_t annz; 445 ae_int_t iterationscount; 446 ae_int_t nmv; 447 ae_int_t terminationtype; 448 } rbfv1report; 449 #endif 450 #if defined(AE_COMPILE_RBF) || !defined(AE_PARTIAL_BUILD) 451 typedef struct 452 { 453 ae_int_t modelversion; 454 rbfv1calcbuffer bufv1; 455 rbfv2calcbuffer bufv2; 456 } rbfcalcbuffer; 457 typedef struct 458 { 459 ae_int_t nx; 460 ae_int_t ny; 461 ae_int_t modelversion; 462 rbfv1model model1; 463 rbfv2model model2; 464 double lambdav; 465 double radvalue; 466 double radzvalue; 467 ae_int_t nlayers; 468 ae_int_t aterm; 469 ae_int_t algorithmtype; 470 double epsort; 471 double epserr; 472 ae_int_t maxits; 473 ae_int_t nnmaxits; 474 ae_int_t n; 475 ae_matrix x; 476 ae_matrix y; 477 ae_bool hasscale; 478 ae_vector s; 479 ae_int_t progress10000; 480 ae_bool terminationrequest; 481 } rbfmodel; 482 typedef struct 483 { 484 double rmserror; 485 double maxerror; 486 ae_int_t arows; 487 ae_int_t acols; 488 ae_int_t annz; 489 ae_int_t iterationscount; 490 ae_int_t nmv; 491 ae_int_t terminationtype; 492 } rbfreport; 493 #endif 494 #if defined(AE_COMPILE_INTCOMP) || !defined(AE_PARTIAL_BUILD) 495 #endif 496 497 } 498 499 ///////////////////////////////////////////////////////////////////////// 500 // 501 // THIS SECTION CONTAINS C++ INTERFACE 502 // 503 ///////////////////////////////////////////////////////////////////////// 504 namespace alglib 505 { 506 507 #if defined(AE_COMPILE_IDW) || !defined(AE_PARTIAL_BUILD) 508 /************************************************************************* 509 Buffer object which is used to perform evaluation requests in the 510 multithreaded mode (multiple threads working with same IDW object). 511 512 This object should be created with idwcreatecalcbuffer(). 513 *************************************************************************/ 514 class _idwcalcbuffer_owner 515 { 516 public: 517 _idwcalcbuffer_owner(); 518 _idwcalcbuffer_owner(const _idwcalcbuffer_owner &rhs); 519 _idwcalcbuffer_owner& operator=(const _idwcalcbuffer_owner &rhs); 520 virtual ~_idwcalcbuffer_owner(); 521 alglib_impl::idwcalcbuffer* c_ptr(); 522 alglib_impl::idwcalcbuffer* c_ptr() const; 523 protected: 524 alglib_impl::idwcalcbuffer *p_struct; 525 }; 526 class idwcalcbuffer : public _idwcalcbuffer_owner 527 { 528 public: 529 idwcalcbuffer(); 530 idwcalcbuffer(const idwcalcbuffer &rhs); 531 idwcalcbuffer& operator=(const idwcalcbuffer &rhs); 532 virtual ~idwcalcbuffer(); 533 534 }; 535 536 537 /************************************************************************* 538 IDW (Inverse Distance Weighting) model object. 539 *************************************************************************/ 540 class _idwmodel_owner 541 { 542 public: 543 _idwmodel_owner(); 544 _idwmodel_owner(const _idwmodel_owner &rhs); 545 _idwmodel_owner& operator=(const _idwmodel_owner &rhs); 546 virtual ~_idwmodel_owner(); 547 alglib_impl::idwmodel* c_ptr(); 548 alglib_impl::idwmodel* c_ptr() const; 549 protected: 550 alglib_impl::idwmodel *p_struct; 551 }; 552 class idwmodel : public _idwmodel_owner 553 { 554 public: 555 idwmodel(); 556 idwmodel(const idwmodel &rhs); 557 idwmodel& operator=(const idwmodel &rhs); 558 virtual ~idwmodel(); 559 560 }; 561 562 563 /************************************************************************* 564 Builder object used to generate IDW (Inverse Distance Weighting) model. 565 *************************************************************************/ 566 class _idwbuilder_owner 567 { 568 public: 569 _idwbuilder_owner(); 570 _idwbuilder_owner(const _idwbuilder_owner &rhs); 571 _idwbuilder_owner& operator=(const _idwbuilder_owner &rhs); 572 virtual ~_idwbuilder_owner(); 573 alglib_impl::idwbuilder* c_ptr(); 574 alglib_impl::idwbuilder* c_ptr() const; 575 protected: 576 alglib_impl::idwbuilder *p_struct; 577 }; 578 class idwbuilder : public _idwbuilder_owner 579 { 580 public: 581 idwbuilder(); 582 idwbuilder(const idwbuilder &rhs); 583 idwbuilder& operator=(const idwbuilder &rhs); 584 virtual ~idwbuilder(); 585 586 }; 587 588 589 /************************************************************************* 590 IDW fitting report: 591 rmserror RMS error 592 avgerror average error 593 maxerror maximum error 594 r2 coefficient of determination, R-squared, 1-RSS/TSS 595 *************************************************************************/ 596 class _idwreport_owner 597 { 598 public: 599 _idwreport_owner(); 600 _idwreport_owner(const _idwreport_owner &rhs); 601 _idwreport_owner& operator=(const _idwreport_owner &rhs); 602 virtual ~_idwreport_owner(); 603 alglib_impl::idwreport* c_ptr(); 604 alglib_impl::idwreport* c_ptr() const; 605 protected: 606 alglib_impl::idwreport *p_struct; 607 }; 608 class idwreport : public _idwreport_owner 609 { 610 public: 611 idwreport(); 612 idwreport(const idwreport &rhs); 613 idwreport& operator=(const idwreport &rhs); 614 virtual ~idwreport(); 615 double &rmserror; 616 double &avgerror; 617 double &maxerror; 618 double &r2; 619 620 }; 621 #endif 622 623 #if defined(AE_COMPILE_RATINT) || !defined(AE_PARTIAL_BUILD) 624 /************************************************************************* 625 Barycentric interpolant. 626 *************************************************************************/ 627 class _barycentricinterpolant_owner 628 { 629 public: 630 _barycentricinterpolant_owner(); 631 _barycentricinterpolant_owner(const _barycentricinterpolant_owner &rhs); 632 _barycentricinterpolant_owner& operator=(const _barycentricinterpolant_owner &rhs); 633 virtual ~_barycentricinterpolant_owner(); 634 alglib_impl::barycentricinterpolant* c_ptr(); 635 alglib_impl::barycentricinterpolant* c_ptr() const; 636 protected: 637 alglib_impl::barycentricinterpolant *p_struct; 638 }; 639 class barycentricinterpolant : public _barycentricinterpolant_owner 640 { 641 public: 642 barycentricinterpolant(); 643 barycentricinterpolant(const barycentricinterpolant &rhs); 644 barycentricinterpolant& operator=(const barycentricinterpolant &rhs); 645 virtual ~barycentricinterpolant(); 646 647 }; 648 #endif 649 650 #if defined(AE_COMPILE_FITSPHERE) || !defined(AE_PARTIAL_BUILD) 651 652 #endif 653 654 #if defined(AE_COMPILE_INTFITSERV) || !defined(AE_PARTIAL_BUILD) 655 656 #endif 657 658 #if defined(AE_COMPILE_SPLINE1D) || !defined(AE_PARTIAL_BUILD) 659 /************************************************************************* 660 1-dimensional spline interpolant 661 *************************************************************************/ 662 class _spline1dinterpolant_owner 663 { 664 public: 665 _spline1dinterpolant_owner(); 666 _spline1dinterpolant_owner(const _spline1dinterpolant_owner &rhs); 667 _spline1dinterpolant_owner& operator=(const _spline1dinterpolant_owner &rhs); 668 virtual ~_spline1dinterpolant_owner(); 669 alglib_impl::spline1dinterpolant* c_ptr(); 670 alglib_impl::spline1dinterpolant* c_ptr() const; 671 protected: 672 alglib_impl::spline1dinterpolant *p_struct; 673 }; 674 class spline1dinterpolant : public _spline1dinterpolant_owner 675 { 676 public: 677 spline1dinterpolant(); 678 spline1dinterpolant(const spline1dinterpolant &rhs); 679 spline1dinterpolant& operator=(const spline1dinterpolant &rhs); 680 virtual ~spline1dinterpolant(); 681 682 }; 683 684 685 /************************************************************************* 686 Spline fitting report: 687 RMSError RMS error 688 AvgError average error 689 AvgRelError average relative error (for non-zero Y[I]) 690 MaxError maximum error 691 692 Fields below are filled by obsolete functions (Spline1DFitCubic, 693 Spline1DFitHermite). Modern fitting functions do NOT fill these fields: 694 TaskRCond reciprocal of task's condition number 695 *************************************************************************/ 696 class _spline1dfitreport_owner 697 { 698 public: 699 _spline1dfitreport_owner(); 700 _spline1dfitreport_owner(const _spline1dfitreport_owner &rhs); 701 _spline1dfitreport_owner& operator=(const _spline1dfitreport_owner &rhs); 702 virtual ~_spline1dfitreport_owner(); 703 alglib_impl::spline1dfitreport* c_ptr(); 704 alglib_impl::spline1dfitreport* c_ptr() const; 705 protected: 706 alglib_impl::spline1dfitreport *p_struct; 707 }; 708 class spline1dfitreport : public _spline1dfitreport_owner 709 { 710 public: 711 spline1dfitreport(); 712 spline1dfitreport(const spline1dfitreport &rhs); 713 spline1dfitreport& operator=(const spline1dfitreport &rhs); 714 virtual ~spline1dfitreport(); 715 double &taskrcond; 716 double &rmserror; 717 double &avgerror; 718 double &avgrelerror; 719 double &maxerror; 720 721 }; 722 #endif 723 724 #if defined(AE_COMPILE_PARAMETRIC) || !defined(AE_PARTIAL_BUILD) 725 /************************************************************************* 726 Parametric spline inteprolant: 2-dimensional curve. 727 728 You should not try to access its members directly - use PSpline2XXXXXXXX() 729 functions instead. 730 *************************************************************************/ 731 class _pspline2interpolant_owner 732 { 733 public: 734 _pspline2interpolant_owner(); 735 _pspline2interpolant_owner(const _pspline2interpolant_owner &rhs); 736 _pspline2interpolant_owner& operator=(const _pspline2interpolant_owner &rhs); 737 virtual ~_pspline2interpolant_owner(); 738 alglib_impl::pspline2interpolant* c_ptr(); 739 alglib_impl::pspline2interpolant* c_ptr() const; 740 protected: 741 alglib_impl::pspline2interpolant *p_struct; 742 }; 743 class pspline2interpolant : public _pspline2interpolant_owner 744 { 745 public: 746 pspline2interpolant(); 747 pspline2interpolant(const pspline2interpolant &rhs); 748 pspline2interpolant& operator=(const pspline2interpolant &rhs); 749 virtual ~pspline2interpolant(); 750 751 }; 752 753 754 /************************************************************************* 755 Parametric spline inteprolant: 3-dimensional curve. 756 757 You should not try to access its members directly - use PSpline3XXXXXXXX() 758 functions instead. 759 *************************************************************************/ 760 class _pspline3interpolant_owner 761 { 762 public: 763 _pspline3interpolant_owner(); 764 _pspline3interpolant_owner(const _pspline3interpolant_owner &rhs); 765 _pspline3interpolant_owner& operator=(const _pspline3interpolant_owner &rhs); 766 virtual ~_pspline3interpolant_owner(); 767 alglib_impl::pspline3interpolant* c_ptr(); 768 alglib_impl::pspline3interpolant* c_ptr() const; 769 protected: 770 alglib_impl::pspline3interpolant *p_struct; 771 }; 772 class pspline3interpolant : public _pspline3interpolant_owner 773 { 774 public: 775 pspline3interpolant(); 776 pspline3interpolant(const pspline3interpolant &rhs); 777 pspline3interpolant& operator=(const pspline3interpolant &rhs); 778 virtual ~pspline3interpolant(); 779 780 }; 781 #endif 782 783 #if defined(AE_COMPILE_SPLINE3D) || !defined(AE_PARTIAL_BUILD) 784 /************************************************************************* 785 3-dimensional spline inteprolant 786 *************************************************************************/ 787 class _spline3dinterpolant_owner 788 { 789 public: 790 _spline3dinterpolant_owner(); 791 _spline3dinterpolant_owner(const _spline3dinterpolant_owner &rhs); 792 _spline3dinterpolant_owner& operator=(const _spline3dinterpolant_owner &rhs); 793 virtual ~_spline3dinterpolant_owner(); 794 alglib_impl::spline3dinterpolant* c_ptr(); 795 alglib_impl::spline3dinterpolant* c_ptr() const; 796 protected: 797 alglib_impl::spline3dinterpolant *p_struct; 798 }; 799 class spline3dinterpolant : public _spline3dinterpolant_owner 800 { 801 public: 802 spline3dinterpolant(); 803 spline3dinterpolant(const spline3dinterpolant &rhs); 804 spline3dinterpolant& operator=(const spline3dinterpolant &rhs); 805 virtual ~spline3dinterpolant(); 806 807 }; 808 #endif 809 810 #if defined(AE_COMPILE_POLINT) || !defined(AE_PARTIAL_BUILD) 811 812 #endif 813 814 #if defined(AE_COMPILE_LSFIT) || !defined(AE_PARTIAL_BUILD) 815 /************************************************************************* 816 Polynomial fitting report: 817 TaskRCond reciprocal of task's condition number 818 RMSError RMS error 819 AvgError average error 820 AvgRelError average relative error (for non-zero Y[I]) 821 MaxError maximum error 822 *************************************************************************/ 823 class _polynomialfitreport_owner 824 { 825 public: 826 _polynomialfitreport_owner(); 827 _polynomialfitreport_owner(const _polynomialfitreport_owner &rhs); 828 _polynomialfitreport_owner& operator=(const _polynomialfitreport_owner &rhs); 829 virtual ~_polynomialfitreport_owner(); 830 alglib_impl::polynomialfitreport* c_ptr(); 831 alglib_impl::polynomialfitreport* c_ptr() const; 832 protected: 833 alglib_impl::polynomialfitreport *p_struct; 834 }; 835 class polynomialfitreport : public _polynomialfitreport_owner 836 { 837 public: 838 polynomialfitreport(); 839 polynomialfitreport(const polynomialfitreport &rhs); 840 polynomialfitreport& operator=(const polynomialfitreport &rhs); 841 virtual ~polynomialfitreport(); 842 double &taskrcond; 843 double &rmserror; 844 double &avgerror; 845 double &avgrelerror; 846 double &maxerror; 847 848 }; 849 850 851 /************************************************************************* 852 Barycentric fitting report: 853 RMSError RMS error 854 AvgError average error 855 AvgRelError average relative error (for non-zero Y[I]) 856 MaxError maximum error 857 TaskRCond reciprocal of task's condition number 858 *************************************************************************/ 859 class _barycentricfitreport_owner 860 { 861 public: 862 _barycentricfitreport_owner(); 863 _barycentricfitreport_owner(const _barycentricfitreport_owner &rhs); 864 _barycentricfitreport_owner& operator=(const _barycentricfitreport_owner &rhs); 865 virtual ~_barycentricfitreport_owner(); 866 alglib_impl::barycentricfitreport* c_ptr(); 867 alglib_impl::barycentricfitreport* c_ptr() const; 868 protected: 869 alglib_impl::barycentricfitreport *p_struct; 870 }; 871 class barycentricfitreport : public _barycentricfitreport_owner 872 { 873 public: 874 barycentricfitreport(); 875 barycentricfitreport(const barycentricfitreport &rhs); 876 barycentricfitreport& operator=(const barycentricfitreport &rhs); 877 virtual ~barycentricfitreport(); 878 double &taskrcond; 879 ae_int_t &dbest; 880 double &rmserror; 881 double &avgerror; 882 double &avgrelerror; 883 double &maxerror; 884 885 }; 886 887 888 /************************************************************************* 889 Least squares fitting report. This structure contains informational fields 890 which are set by fitting functions provided by this unit. 891 892 Different functions initialize different sets of fields, so you should 893 read documentation on specific function you used in order to know which 894 fields are initialized. 895 896 TaskRCond reciprocal of task's condition number 897 IterationsCount number of internal iterations 898 899 VarIdx if user-supplied gradient contains errors which were 900 detected by nonlinear fitter, this field is set to 901 index of the first component of gradient which is 902 suspected to be spoiled by bugs. 903 904 RMSError RMS error 905 AvgError average error 906 AvgRelError average relative error (for non-zero Y[I]) 907 MaxError maximum error 908 909 WRMSError weighted RMS error 910 911 CovPar covariance matrix for parameters, filled by some solvers 912 ErrPar vector of errors in parameters, filled by some solvers 913 ErrCurve vector of fit errors - variability of the best-fit 914 curve, filled by some solvers. 915 Noise vector of per-point noise estimates, filled by 916 some solvers. 917 R2 coefficient of determination (non-weighted, non-adjusted), 918 filled by some solvers. 919 *************************************************************************/ 920 class _lsfitreport_owner 921 { 922 public: 923 _lsfitreport_owner(); 924 _lsfitreport_owner(const _lsfitreport_owner &rhs); 925 _lsfitreport_owner& operator=(const _lsfitreport_owner &rhs); 926 virtual ~_lsfitreport_owner(); 927 alglib_impl::lsfitreport* c_ptr(); 928 alglib_impl::lsfitreport* c_ptr() const; 929 protected: 930 alglib_impl::lsfitreport *p_struct; 931 }; 932 class lsfitreport : public _lsfitreport_owner 933 { 934 public: 935 lsfitreport(); 936 lsfitreport(const lsfitreport &rhs); 937 lsfitreport& operator=(const lsfitreport &rhs); 938 virtual ~lsfitreport(); 939 double &taskrcond; 940 ae_int_t &iterationscount; 941 ae_int_t &varidx; 942 double &rmserror; 943 double &avgerror; 944 double &avgrelerror; 945 double &maxerror; 946 double &wrmserror; 947 real_2d_array covpar; 948 real_1d_array errpar; 949 real_1d_array errcurve; 950 real_1d_array noise; 951 double &r2; 952 953 }; 954 955 956 /************************************************************************* 957 Nonlinear fitter. 958 959 You should use ALGLIB functions to work with fitter. 960 Never try to access its fields directly! 961 *************************************************************************/ 962 class _lsfitstate_owner 963 { 964 public: 965 _lsfitstate_owner(); 966 _lsfitstate_owner(const _lsfitstate_owner &rhs); 967 _lsfitstate_owner& operator=(const _lsfitstate_owner &rhs); 968 virtual ~_lsfitstate_owner(); 969 alglib_impl::lsfitstate* c_ptr(); 970 alglib_impl::lsfitstate* c_ptr() const; 971 protected: 972 alglib_impl::lsfitstate *p_struct; 973 }; 974 class lsfitstate : public _lsfitstate_owner 975 { 976 public: 977 lsfitstate(); 978 lsfitstate(const lsfitstate &rhs); 979 lsfitstate& operator=(const lsfitstate &rhs); 980 virtual ~lsfitstate(); 981 ae_bool &needf; 982 ae_bool &needfg; 983 ae_bool &needfgh; 984 ae_bool &xupdated; 985 real_1d_array c; 986 double &f; 987 real_1d_array g; 988 real_2d_array h; 989 real_1d_array x; 990 991 }; 992 #endif 993 994 #if defined(AE_COMPILE_RBFV2) || !defined(AE_PARTIAL_BUILD) 995 996 #endif 997 998 #if defined(AE_COMPILE_SPLINE2D) || !defined(AE_PARTIAL_BUILD) 999 /************************************************************************* 1000 2-dimensional spline inteprolant 1001 *************************************************************************/ 1002 class _spline2dinterpolant_owner 1003 { 1004 public: 1005 _spline2dinterpolant_owner(); 1006 _spline2dinterpolant_owner(const _spline2dinterpolant_owner &rhs); 1007 _spline2dinterpolant_owner& operator=(const _spline2dinterpolant_owner &rhs); 1008 virtual ~_spline2dinterpolant_owner(); 1009 alglib_impl::spline2dinterpolant* c_ptr(); 1010 alglib_impl::spline2dinterpolant* c_ptr() const; 1011 protected: 1012 alglib_impl::spline2dinterpolant *p_struct; 1013 }; 1014 class spline2dinterpolant : public _spline2dinterpolant_owner 1015 { 1016 public: 1017 spline2dinterpolant(); 1018 spline2dinterpolant(const spline2dinterpolant &rhs); 1019 spline2dinterpolant& operator=(const spline2dinterpolant &rhs); 1020 virtual ~spline2dinterpolant(); 1021 1022 }; 1023 1024 1025 /************************************************************************* 1026 Nonlinear least squares solver used to fit 2D splines to data 1027 *************************************************************************/ 1028 class _spline2dbuilder_owner 1029 { 1030 public: 1031 _spline2dbuilder_owner(); 1032 _spline2dbuilder_owner(const _spline2dbuilder_owner &rhs); 1033 _spline2dbuilder_owner& operator=(const _spline2dbuilder_owner &rhs); 1034 virtual ~_spline2dbuilder_owner(); 1035 alglib_impl::spline2dbuilder* c_ptr(); 1036 alglib_impl::spline2dbuilder* c_ptr() const; 1037 protected: 1038 alglib_impl::spline2dbuilder *p_struct; 1039 }; 1040 class spline2dbuilder : public _spline2dbuilder_owner 1041 { 1042 public: 1043 spline2dbuilder(); 1044 spline2dbuilder(const spline2dbuilder &rhs); 1045 spline2dbuilder& operator=(const spline2dbuilder &rhs); 1046 virtual ~spline2dbuilder(); 1047 1048 }; 1049 1050 1051 /************************************************************************* 1052 Spline 2D fitting report: 1053 rmserror RMS error 1054 avgerror average error 1055 maxerror maximum error 1056 r2 coefficient of determination, R-squared, 1-RSS/TSS 1057 *************************************************************************/ 1058 class _spline2dfitreport_owner 1059 { 1060 public: 1061 _spline2dfitreport_owner(); 1062 _spline2dfitreport_owner(const _spline2dfitreport_owner &rhs); 1063 _spline2dfitreport_owner& operator=(const _spline2dfitreport_owner &rhs); 1064 virtual ~_spline2dfitreport_owner(); 1065 alglib_impl::spline2dfitreport* c_ptr(); 1066 alglib_impl::spline2dfitreport* c_ptr() const; 1067 protected: 1068 alglib_impl::spline2dfitreport *p_struct; 1069 }; 1070 class spline2dfitreport : public _spline2dfitreport_owner 1071 { 1072 public: 1073 spline2dfitreport(); 1074 spline2dfitreport(const spline2dfitreport &rhs); 1075 spline2dfitreport& operator=(const spline2dfitreport &rhs); 1076 virtual ~spline2dfitreport(); 1077 double &rmserror; 1078 double &avgerror; 1079 double &maxerror; 1080 double &r2; 1081 1082 }; 1083 #endif 1084 1085 #if defined(AE_COMPILE_RBFV1) || !defined(AE_PARTIAL_BUILD) 1086 1087 #endif 1088 1089 #if defined(AE_COMPILE_RBF) || !defined(AE_PARTIAL_BUILD) 1090 /************************************************************************* 1091 Buffer object which is used to perform nearest neighbor requests in the 1092 multithreaded mode (multiple threads working with same KD-tree object). 1093 1094 This object should be created with KDTreeCreateBuffer(). 1095 *************************************************************************/ 1096 class _rbfcalcbuffer_owner 1097 { 1098 public: 1099 _rbfcalcbuffer_owner(); 1100 _rbfcalcbuffer_owner(const _rbfcalcbuffer_owner &rhs); 1101 _rbfcalcbuffer_owner& operator=(const _rbfcalcbuffer_owner &rhs); 1102 virtual ~_rbfcalcbuffer_owner(); 1103 alglib_impl::rbfcalcbuffer* c_ptr(); 1104 alglib_impl::rbfcalcbuffer* c_ptr() const; 1105 protected: 1106 alglib_impl::rbfcalcbuffer *p_struct; 1107 }; 1108 class rbfcalcbuffer : public _rbfcalcbuffer_owner 1109 { 1110 public: 1111 rbfcalcbuffer(); 1112 rbfcalcbuffer(const rbfcalcbuffer &rhs); 1113 rbfcalcbuffer& operator=(const rbfcalcbuffer &rhs); 1114 virtual ~rbfcalcbuffer(); 1115 1116 }; 1117 1118 1119 /************************************************************************* 1120 RBF model. 1121 1122 Never try to directly work with fields of this object - always use ALGLIB 1123 functions to use this object. 1124 *************************************************************************/ 1125 class _rbfmodel_owner 1126 { 1127 public: 1128 _rbfmodel_owner(); 1129 _rbfmodel_owner(const _rbfmodel_owner &rhs); 1130 _rbfmodel_owner& operator=(const _rbfmodel_owner &rhs); 1131 virtual ~_rbfmodel_owner(); 1132 alglib_impl::rbfmodel* c_ptr(); 1133 alglib_impl::rbfmodel* c_ptr() const; 1134 protected: 1135 alglib_impl::rbfmodel *p_struct; 1136 }; 1137 class rbfmodel : public _rbfmodel_owner 1138 { 1139 public: 1140 rbfmodel(); 1141 rbfmodel(const rbfmodel &rhs); 1142 rbfmodel& operator=(const rbfmodel &rhs); 1143 virtual ~rbfmodel(); 1144 1145 }; 1146 1147 1148 /************************************************************************* 1149 RBF solution report: 1150 * TerminationType - termination type, positive values - success, 1151 non-positive - failure. 1152 1153 Fields which are set by modern RBF solvers (hierarchical): 1154 * RMSError - root-mean-square error; NAN for old solvers (ML, QNN) 1155 * MaxError - maximum error; NAN for old solvers (ML, QNN) 1156 *************************************************************************/ 1157 class _rbfreport_owner 1158 { 1159 public: 1160 _rbfreport_owner(); 1161 _rbfreport_owner(const _rbfreport_owner &rhs); 1162 _rbfreport_owner& operator=(const _rbfreport_owner &rhs); 1163 virtual ~_rbfreport_owner(); 1164 alglib_impl::rbfreport* c_ptr(); 1165 alglib_impl::rbfreport* c_ptr() const; 1166 protected: 1167 alglib_impl::rbfreport *p_struct; 1168 }; 1169 class rbfreport : public _rbfreport_owner 1170 { 1171 public: 1172 rbfreport(); 1173 rbfreport(const rbfreport &rhs); 1174 rbfreport& operator=(const rbfreport &rhs); 1175 virtual ~rbfreport(); 1176 double &rmserror; 1177 double &maxerror; 1178 ae_int_t &arows; 1179 ae_int_t &acols; 1180 ae_int_t &annz; 1181 ae_int_t &iterationscount; 1182 ae_int_t &nmv; 1183 ae_int_t &terminationtype; 1184 1185 }; 1186 #endif 1187 1188 #if defined(AE_COMPILE_INTCOMP) || !defined(AE_PARTIAL_BUILD) 1189 1190 #endif 1191 1192 #if defined(AE_COMPILE_IDW) || !defined(AE_PARTIAL_BUILD) 1193 /************************************************************************* 1194 This function serializes data structure to string. 1195 1196 Important properties of s_out: 1197 * it contains alphanumeric characters, dots, underscores, minus signs 1198 * these symbols are grouped into words, which are separated by spaces 1199 and Windows-style (CR+LF) newlines 1200 * although serializer uses spaces and CR+LF as separators, you can 1201 replace any separator character by arbitrary combination of spaces, 1202 tabs, Windows or Unix newlines. It allows flexible reformatting of 1203 the string in case you want to include it into text or XML file. 1204 But you should not insert separators into the middle of the "words" 1205 nor you should change case of letters. 1206 * s_out can be freely moved between 32-bit and 64-bit systems, little 1207 and big endian machines, and so on. You can serialize structure on 1208 32-bit machine and unserialize it on 64-bit one (or vice versa), or 1209 serialize it on SPARC and unserialize on x86. You can also 1210 serialize it in C++ version of ALGLIB and unserialize in C# one, 1211 and vice versa. 1212 *************************************************************************/ 1213 void idwserialize(idwmodel &obj, std::string &s_out); 1214 1215 1216 /************************************************************************* 1217 This function unserializes data structure from string. 1218 *************************************************************************/ 1219 void idwunserialize(const std::string &s_in, idwmodel &obj); 1220 1221 1222 1223 1224 /************************************************************************* 1225 This function serializes data structure to C++ stream. 1226 1227 Data stream generated by this function is same as string representation 1228 generated by string version of serializer - alphanumeric characters, 1229 dots, underscores, minus signs, which are grouped into words separated by 1230 spaces and CR+LF. 1231 1232 We recommend you to read comments on string version of serializer to find 1233 out more about serialization of AlGLIB objects. 1234 *************************************************************************/ 1235 void idwserialize(idwmodel &obj, std::ostream &s_out); 1236 1237 1238 /************************************************************************* 1239 This function unserializes data structure from stream. 1240 *************************************************************************/ 1241 void idwunserialize(const std::istream &s_in, idwmodel &obj); 1242 1243 1244 /************************************************************************* 1245 This function creates buffer structure which can be used to perform 1246 parallel IDW model evaluations (with one IDW model instance being 1247 used from multiple threads, as long as different threads use different 1248 instances of buffer). 1249 1250 This buffer object can be used with idwtscalcbuf() function (here "ts" 1251 stands for "thread-safe", "buf" is a suffix which denotes function which 1252 reuses previously allocated output space). 1253 1254 How to use it: 1255 * create IDW model structure or load it from file 1256 * call idwcreatecalcbuffer(), once per thread working with IDW model (you 1257 should call this function only AFTER model initialization, see below for 1258 more information) 1259 * call idwtscalcbuf() from different threads, with each thread working 1260 with its own copy of buffer object. 1261 1262 INPUT PARAMETERS 1263 S - IDW model 1264 1265 OUTPUT PARAMETERS 1266 Buf - external buffer. 1267 1268 1269 IMPORTANT: buffer object should be used only with IDW model object which 1270 was used to initialize buffer. Any attempt to use buffer with 1271 different object is dangerous - you may get memory violation 1272 error because sizes of internal arrays do not fit to dimensions 1273 of the IDW structure. 1274 1275 IMPORTANT: you should call this function only for model which was built 1276 with model builder (or unserialized from file). Sizes of some 1277 internal structures are determined only after model is built, 1278 so buffer object created before model construction stage will 1279 be useless (and any attempt to use it will result in exception). 1280 1281 -- ALGLIB -- 1282 Copyright 22.10.2018 by Sergey Bochkanov 1283 *************************************************************************/ 1284 void idwcreatecalcbuffer(const idwmodel &s, idwcalcbuffer &buf, const xparams _xparams = alglib::xdefault); 1285 1286 1287 /************************************************************************* 1288 This subroutine creates builder object used to generate IDW model from 1289 irregularly sampled (scattered) dataset. Multidimensional scalar/vector- 1290 -valued are supported. 1291 1292 Builder object is used to fit model to data as follows: 1293 * builder object is created with idwbuildercreate() function 1294 * dataset is added with idwbuildersetpoints() function 1295 * one of the modern IDW algorithms is chosen with either: 1296 * idwbuildersetalgomstab() - Multilayer STABilized algorithm (interpolation) 1297 Alternatively, one of the textbook algorithms can be chosen (not recommended): 1298 * idwbuildersetalgotextbookshepard() - textbook Shepard algorithm 1299 * idwbuildersetalgotextbookmodshepard()-textbook modified Shepard algorithm 1300 * finally, model construction is performed with idwfit() function. 1301 1302 ! COMMERCIAL EDITION OF ALGLIB: 1303 ! 1304 ! Commercial Edition of ALGLIB includes following important improvements 1305 ! of this function: 1306 ! * high-performance native backend with same C# interface (C# version) 1307 ! * multithreading support (C++ and C# versions) 1308 ! 1309 ! We recommend you to read 'Working with commercial version' section of 1310 ! ALGLIB Reference Manual in order to find out how to use performance- 1311 ! related features provided by commercial edition of ALGLIB. 1312 1313 INPUT PARAMETERS: 1314 NX - dimensionality of the argument, NX>=1 1315 NY - dimensionality of the function being modeled, NY>=1; 1316 NY=1 corresponds to classic scalar function, NY>=1 corresponds 1317 to vector-valued function. 1318 1319 OUTPUT PARAMETERS: 1320 State- builder object 1321 1322 -- ALGLIB PROJECT -- 1323 Copyright 22.10.2018 by Bochkanov Sergey 1324 *************************************************************************/ 1325 void idwbuildercreate(const ae_int_t nx, const ae_int_t ny, idwbuilder &state, const xparams _xparams = alglib::xdefault); 1326 1327 1328 /************************************************************************* 1329 This function changes number of layers used by IDW-MSTAB algorithm. 1330 1331 The more layers you have, the finer details can be reproduced with IDW 1332 model. The less layers you have, the less memory and CPU time is consumed 1333 by the model. 1334 1335 Memory consumption grows linearly with layers count, running time grows 1336 sub-linearly. 1337 1338 The default number of layers is 16, which allows you to reproduce details 1339 at distance down to SRad/65536. You will rarely need to change it. 1340 1341 INPUT PARAMETERS: 1342 State - builder object 1343 NLayers - NLayers>=1, the number of layers used by the model. 1344 1345 -- ALGLIB -- 1346 Copyright 22.10.2018 by Bochkanov Sergey 1347 *************************************************************************/ 1348 void idwbuildersetnlayers(const idwbuilder &state, const ae_int_t nlayers, const xparams _xparams = alglib::xdefault); 1349 1350 1351 /************************************************************************* 1352 This function adds dataset to the builder object. 1353 1354 This function overrides results of the previous calls, i.e. multiple calls 1355 of this function will result in only the last set being added. 1356 1357 INPUT PARAMETERS: 1358 State - builder object 1359 XY - points, array[N,NX+NY]. One row corresponds to one point 1360 in the dataset. First NX elements are coordinates, next 1361 NY elements are function values. Array may be larger than 1362 specified, in this case only leading [N,NX+NY] elements 1363 will be used. 1364 N - number of points in the dataset, N>=0. 1365 1366 -- ALGLIB -- 1367 Copyright 22.10.2018 by Bochkanov Sergey 1368 *************************************************************************/ 1369 void idwbuildersetpoints(const idwbuilder &state, const real_2d_array &xy, const ae_int_t n, const xparams _xparams = alglib::xdefault); 1370 void idwbuildersetpoints(const idwbuilder &state, const real_2d_array &xy, const xparams _xparams = alglib::xdefault); 1371 1372 1373 /************************************************************************* 1374 This function sets IDW model construction algorithm to the Multilayer 1375 Stabilized IDW method (IDW-MSTAB), a latest incarnation of the inverse 1376 distance weighting interpolation which fixes shortcomings of the original 1377 and modified Shepard's variants. 1378 1379 The distinctive features of IDW-MSTAB are: 1380 1) exact interpolation is pursued (as opposed to fitting and noise 1381 suppression) 1382 2) improved robustness when compared with that of other algorithms: 1383 * MSTAB shows almost no strange fitting artifacts like ripples and 1384 sharp spikes (unlike N-dimensional splines and HRBFs) 1385 * MSTAB does not return function values far from the interval spanned 1386 by the dataset; say, if all your points have |f|<=1, you can be sure 1387 that model value won't deviate too much from [-1,+1] 1388 3) good model construction time competing with that of HRBFs and bicubic 1389 splines 1390 4) ability to work with any number of dimensions, starting from NX=1 1391 1392 The drawbacks of IDW-MSTAB (and all IDW algorithms in general) are: 1393 1) dependence of the model evaluation time on the search radius 1394 2) bad extrapolation properties, models built by this method are usually 1395 conservative in their predictions 1396 1397 Thus, IDW-MSTAB is a good "default" option if you want to perform 1398 scattered multidimensional interpolation. Although it has its drawbacks, 1399 it is easy to use and robust, which makes it a good first step. 1400 1401 1402 INPUT PARAMETERS: 1403 State - builder object 1404 SRad - initial search radius, SRad>0 is required. A model value 1405 is obtained by "smart" averaging of the dataset points 1406 within search radius. 1407 1408 NOTE 1: IDW interpolation can correctly handle ANY dataset, including 1409 datasets with non-distinct points. In case non-distinct points are 1410 found, an average value for this point will be calculated. 1411 1412 NOTE 2: the memory requirements for model storage are O(NPoints*NLayers). 1413 The model construction needs twice as much memory as model storage. 1414 1415 NOTE 3: by default 16 IDW layers are built which is enough for most cases. 1416 You can change this parameter with idwbuildersetnlayers() method. 1417 Larger values may be necessary if you need to reproduce extrafine 1418 details at distances smaller than SRad/65536. Smaller value may 1419 be necessary if you have to save memory and computing time, and 1420 ready to sacrifice some model quality. 1421 1422 1423 ALGORITHM DESCRIPTION 1424 1425 ALGLIB implementation of IDW is somewhat similar to the modified Shepard's 1426 method (one with search radius R) but overcomes several of its drawbacks, 1427 namely: 1428 1) a tendency to show stepwise behavior for uniform datasets 1429 2) a tendency to show terrible interpolation properties for highly 1430 nonuniform datasets which often arise in geospatial tasks 1431 (function values are densely sampled across multiple separated 1432 "tracks") 1433 1434 IDW-MSTAB method performs several passes over dataset and builds a sequence 1435 of progressively refined IDW models (layers), which starts from one with 1436 largest search radius SRad and continues to smaller search radii until 1437 required number of layers is built. Highest layers reproduce global 1438 behavior of the target function at larger distances whilst lower layers 1439 reproduce fine details at smaller distances. 1440 1441 Each layer is an IDW model built with following modifications: 1442 * weights go to zero when distance approach to the current search radius 1443 * an additional regularizing term is added to the distance: w=1/(d^2+lambda) 1444 * an additional fictional term with unit weight and zero function value is 1445 added in order to promote continuity properties at the isolated and 1446 boundary points 1447 1448 By default, 16 layers is built, which is enough for most cases. You can 1449 change this parameter with idwbuildersetnlayers() method. 1450 1451 -- ALGLIB -- 1452 Copyright 22.10.2018 by Bochkanov Sergey 1453 *************************************************************************/ 1454 void idwbuildersetalgomstab(const idwbuilder &state, const double srad, const xparams _xparams = alglib::xdefault); 1455 1456 1457 /************************************************************************* 1458 This function sets IDW model construction algorithm to the textbook 1459 Shepard's algorithm with custom (user-specified) power parameter. 1460 1461 IMPORTANT: we do NOT recommend using textbook IDW algorithms because they 1462 have terrible interpolation properties. Use MSTAB in all cases. 1463 1464 INPUT PARAMETERS: 1465 State - builder object 1466 P - power parameter, P>0; good value to start with is 2.0 1467 1468 NOTE 1: IDW interpolation can correctly handle ANY dataset, including 1469 datasets with non-distinct points. In case non-distinct points are 1470 found, an average value for this point will be calculated. 1471 1472 -- ALGLIB -- 1473 Copyright 22.10.2018 by Bochkanov Sergey 1474 *************************************************************************/ 1475 void idwbuildersetalgotextbookshepard(const idwbuilder &state, const double p, const xparams _xparams = alglib::xdefault); 1476 1477 1478 /************************************************************************* 1479 This function sets IDW model construction algorithm to the 'textbook' 1480 modified Shepard's algorithm with user-specified search radius. 1481 1482 IMPORTANT: we do NOT recommend using textbook IDW algorithms because they 1483 have terrible interpolation properties. Use MSTAB in all cases. 1484 1485 INPUT PARAMETERS: 1486 State - builder object 1487 R - search radius 1488 1489 NOTE 1: IDW interpolation can correctly handle ANY dataset, including 1490 datasets with non-distinct points. In case non-distinct points are 1491 found, an average value for this point will be calculated. 1492 1493 -- ALGLIB -- 1494 Copyright 22.10.2018 by Bochkanov Sergey 1495 *************************************************************************/ 1496 void idwbuildersetalgotextbookmodshepard(const idwbuilder &state, const double r, const xparams _xparams = alglib::xdefault); 1497 1498 1499 /************************************************************************* 1500 This function sets prior term (model value at infinity) as user-specified 1501 value. 1502 1503 INPUT PARAMETERS: 1504 S - spline builder 1505 V - value for user-defined prior 1506 1507 NOTE: for vector-valued models all components of the prior are set to same 1508 user-specified value 1509 1510 -- ALGLIB -- 1511 Copyright 29.10.2018 by Bochkanov Sergey 1512 *************************************************************************/ 1513 void idwbuildersetuserterm(const idwbuilder &state, const double v, const xparams _xparams = alglib::xdefault); 1514 1515 1516 /************************************************************************* 1517 This function sets constant prior term (model value at infinity). 1518 1519 Constant prior term is determined as mean value over dataset. 1520 1521 INPUT PARAMETERS: 1522 S - spline builder 1523 1524 -- ALGLIB -- 1525 Copyright 29.10.2018 by Bochkanov Sergey 1526 *************************************************************************/ 1527 void idwbuildersetconstterm(const idwbuilder &state, const xparams _xparams = alglib::xdefault); 1528 1529 1530 /************************************************************************* 1531 This function sets zero prior term (model value at infinity). 1532 1533 INPUT PARAMETERS: 1534 S - spline builder 1535 1536 -- ALGLIB -- 1537 Copyright 29.10.2018 by Bochkanov Sergey 1538 *************************************************************************/ 1539 void idwbuildersetzeroterm(const idwbuilder &state, const xparams _xparams = alglib::xdefault); 1540 1541 1542 /************************************************************************* 1543 IDW interpolation: scalar target, 1-dimensional argument 1544 1545 NOTE: this function modifies internal temporaries of the IDW model, thus 1546 IT IS NOT THREAD-SAFE! If you want to perform parallel model 1547 evaluation from the multiple threads, use idwtscalcbuf() with per- 1548 thread buffer object. 1549 1550 INPUT PARAMETERS: 1551 S - IDW interpolant built with IDW builder 1552 X0 - argument value 1553 1554 Result: 1555 IDW interpolant S(X0) 1556 1557 -- ALGLIB -- 1558 Copyright 22.10.2018 by Bochkanov Sergey 1559 *************************************************************************/ 1560 double idwcalc1(const idwmodel &s, const double x0, const xparams _xparams = alglib::xdefault); 1561 1562 1563 /************************************************************************* 1564 IDW interpolation: scalar target, 2-dimensional argument 1565 1566 NOTE: this function modifies internal temporaries of the IDW model, thus 1567 IT IS NOT THREAD-SAFE! If you want to perform parallel model 1568 evaluation from the multiple threads, use idwtscalcbuf() with per- 1569 thread buffer object. 1570 1571 INPUT PARAMETERS: 1572 S - IDW interpolant built with IDW builder 1573 X0, X1 - argument value 1574 1575 Result: 1576 IDW interpolant S(X0,X1) 1577 1578 -- ALGLIB -- 1579 Copyright 22.10.2018 by Bochkanov Sergey 1580 *************************************************************************/ 1581 double idwcalc2(const idwmodel &s, const double x0, const double x1, const xparams _xparams = alglib::xdefault); 1582 1583 1584 /************************************************************************* 1585 IDW interpolation: scalar target, 3-dimensional argument 1586 1587 NOTE: this function modifies internal temporaries of the IDW model, thus 1588 IT IS NOT THREAD-SAFE! If you want to perform parallel model 1589 evaluation from the multiple threads, use idwtscalcbuf() with per- 1590 thread buffer object. 1591 1592 INPUT PARAMETERS: 1593 S - IDW interpolant built with IDW builder 1594 X0,X1,X2- argument value 1595 1596 Result: 1597 IDW interpolant S(X0,X1,X2) 1598 1599 -- ALGLIB -- 1600 Copyright 22.10.2018 by Bochkanov Sergey 1601 *************************************************************************/ 1602 double idwcalc3(const idwmodel &s, const double x0, const double x1, const double x2, const xparams _xparams = alglib::xdefault); 1603 1604 1605 /************************************************************************* 1606 This function calculates values of the IDW model at the given point. 1607 1608 This is general function which can be used for arbitrary NX (dimension of 1609 the space of arguments) and NY (dimension of the function itself). However 1610 when you have NY=1 you may find more convenient to use idwcalc1(), 1611 idwcalc2() or idwcalc3(). 1612 1613 NOTE: this function modifies internal temporaries of the IDW model, thus 1614 IT IS NOT THREAD-SAFE! If you want to perform parallel model 1615 evaluation from the multiple threads, use idwtscalcbuf() with per- 1616 thread buffer object. 1617 1618 INPUT PARAMETERS: 1619 S - IDW model 1620 X - coordinates, array[NX]. X may have more than NX elements, 1621 in this case only leading NX will be used. 1622 1623 OUTPUT PARAMETERS: 1624 Y - function value, array[NY]. Y is out-parameter and will be 1625 reallocated after call to this function. In case you want 1626 to reuse previously allocated Y, you may use idwcalcbuf(), 1627 which reallocates Y only when it is too small. 1628 1629 -- ALGLIB -- 1630 Copyright 22.10.2018 by Bochkanov Sergey 1631 *************************************************************************/ 1632 void idwcalc(const idwmodel &s, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 1633 1634 1635 /************************************************************************* 1636 This function calculates values of the IDW model at the given point. 1637 1638 Same as idwcalc(), but does not reallocate Y when in is large enough to 1639 store function values. 1640 1641 NOTE: this function modifies internal temporaries of the IDW model, thus 1642 IT IS NOT THREAD-SAFE! If you want to perform parallel model 1643 evaluation from the multiple threads, use idwtscalcbuf() with per- 1644 thread buffer object. 1645 1646 INPUT PARAMETERS: 1647 S - IDW model 1648 X - coordinates, array[NX]. X may have more than NX elements, 1649 in this case only leading NX will be used. 1650 Y - possibly preallocated array 1651 1652 OUTPUT PARAMETERS: 1653 Y - function value, array[NY]. Y is not reallocated when it 1654 is larger than NY. 1655 1656 -- ALGLIB -- 1657 Copyright 22.10.2018 by Bochkanov Sergey 1658 *************************************************************************/ 1659 void idwcalcbuf(const idwmodel &s, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 1660 1661 1662 /************************************************************************* 1663 This function calculates values of the IDW model at the given point, using 1664 external buffer object (internal temporaries of IDW model are not 1665 modified). 1666 1667 This function allows to use same IDW model object in different threads, 1668 assuming that different threads use different instances of the buffer 1669 structure. 1670 1671 INPUT PARAMETERS: 1672 S - IDW model, may be shared between different threads 1673 Buf - buffer object created for this particular instance of IDW 1674 model with idwcreatecalcbuffer(). 1675 X - coordinates, array[NX]. X may have more than NX elements, 1676 in this case only leading NX will be used. 1677 Y - possibly preallocated array 1678 1679 OUTPUT PARAMETERS: 1680 Y - function value, array[NY]. Y is not reallocated when it 1681 is larger than NY. 1682 1683 -- ALGLIB -- 1684 Copyright 13.12.2011 by Bochkanov Sergey 1685 *************************************************************************/ 1686 void idwtscalcbuf(const idwmodel &s, const idwcalcbuffer &buf, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 1687 1688 1689 /************************************************************************* 1690 This function fits IDW model to the dataset using current IDW construction 1691 algorithm. A model being built and fitting report are returned. 1692 1693 INPUT PARAMETERS: 1694 State - builder object 1695 1696 OUTPUT PARAMETERS: 1697 Model - an IDW model built with current algorithm 1698 Rep - model fitting report, fields of this structure contain 1699 information about average fitting errors. 1700 1701 NOTE: although IDW-MSTAB algorithm is an interpolation method, i.e. it 1702 tries to fit the model exactly, it can handle datasets with non- 1703 distinct points which can not be fit exactly; in such cases least- 1704 squares fitting is performed. 1705 1706 -- ALGLIB -- 1707 Copyright 22.10.2018 by Bochkanov Sergey 1708 *************************************************************************/ 1709 void idwfit(const idwbuilder &state, idwmodel &model, idwreport &rep, const xparams _xparams = alglib::xdefault); 1710 #endif 1711 1712 #if defined(AE_COMPILE_RATINT) || !defined(AE_PARTIAL_BUILD) 1713 /************************************************************************* 1714 Rational interpolation using barycentric formula 1715 1716 F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i])) 1717 1718 Input parameters: 1719 B - barycentric interpolant built with one of model building 1720 subroutines. 1721 T - interpolation point 1722 1723 Result: 1724 barycentric interpolant F(t) 1725 1726 -- ALGLIB -- 1727 Copyright 17.08.2009 by Bochkanov Sergey 1728 *************************************************************************/ 1729 double barycentriccalc(const barycentricinterpolant &b, const double t, const xparams _xparams = alglib::xdefault); 1730 1731 1732 /************************************************************************* 1733 Differentiation of barycentric interpolant: first derivative. 1734 1735 Algorithm used in this subroutine is very robust and should not fail until 1736 provided with values too close to MaxRealNumber (usually MaxRealNumber/N 1737 or greater will overflow). 1738 1739 INPUT PARAMETERS: 1740 B - barycentric interpolant built with one of model building 1741 subroutines. 1742 T - interpolation point 1743 1744 OUTPUT PARAMETERS: 1745 F - barycentric interpolant at T 1746 DF - first derivative 1747 1748 NOTE 1749 1750 1751 -- ALGLIB -- 1752 Copyright 17.08.2009 by Bochkanov Sergey 1753 *************************************************************************/ 1754 void barycentricdiff1(const barycentricinterpolant &b, const double t, double &f, double &df, const xparams _xparams = alglib::xdefault); 1755 1756 1757 /************************************************************************* 1758 Differentiation of barycentric interpolant: first/second derivatives. 1759 1760 INPUT PARAMETERS: 1761 B - barycentric interpolant built with one of model building 1762 subroutines. 1763 T - interpolation point 1764 1765 OUTPUT PARAMETERS: 1766 F - barycentric interpolant at T 1767 DF - first derivative 1768 D2F - second derivative 1769 1770 NOTE: this algorithm may fail due to overflow/underflor if used on data 1771 whose values are close to MaxRealNumber or MinRealNumber. Use more robust 1772 BarycentricDiff1() subroutine in such cases. 1773 1774 1775 -- ALGLIB -- 1776 Copyright 17.08.2009 by Bochkanov Sergey 1777 *************************************************************************/ 1778 void barycentricdiff2(const barycentricinterpolant &b, const double t, double &f, double &df, double &d2f, const xparams _xparams = alglib::xdefault); 1779 1780 1781 /************************************************************************* 1782 This subroutine performs linear transformation of the argument. 1783 1784 INPUT PARAMETERS: 1785 B - rational interpolant in barycentric form 1786 CA, CB - transformation coefficients: x = CA*t + CB 1787 1788 OUTPUT PARAMETERS: 1789 B - transformed interpolant with X replaced by T 1790 1791 -- ALGLIB PROJECT -- 1792 Copyright 19.08.2009 by Bochkanov Sergey 1793 *************************************************************************/ 1794 void barycentriclintransx(const barycentricinterpolant &b, const double ca, const double cb, const xparams _xparams = alglib::xdefault); 1795 1796 1797 /************************************************************************* 1798 This subroutine performs linear transformation of the barycentric 1799 interpolant. 1800 1801 INPUT PARAMETERS: 1802 B - rational interpolant in barycentric form 1803 CA, CB - transformation coefficients: B2(x) = CA*B(x) + CB 1804 1805 OUTPUT PARAMETERS: 1806 B - transformed interpolant 1807 1808 -- ALGLIB PROJECT -- 1809 Copyright 19.08.2009 by Bochkanov Sergey 1810 *************************************************************************/ 1811 void barycentriclintransy(const barycentricinterpolant &b, const double ca, const double cb, const xparams _xparams = alglib::xdefault); 1812 1813 1814 /************************************************************************* 1815 Extracts X/Y/W arrays from rational interpolant 1816 1817 INPUT PARAMETERS: 1818 B - barycentric interpolant 1819 1820 OUTPUT PARAMETERS: 1821 N - nodes count, N>0 1822 X - interpolation nodes, array[0..N-1] 1823 F - function values, array[0..N-1] 1824 W - barycentric weights, array[0..N-1] 1825 1826 -- ALGLIB -- 1827 Copyright 17.08.2009 by Bochkanov Sergey 1828 *************************************************************************/ 1829 void barycentricunpack(const barycentricinterpolant &b, ae_int_t &n, real_1d_array &x, real_1d_array &y, real_1d_array &w, const xparams _xparams = alglib::xdefault); 1830 1831 1832 /************************************************************************* 1833 Rational interpolant from X/Y/W arrays 1834 1835 F(t) = SUM(i=0,n-1,w[i]*f[i]/(t-x[i])) / SUM(i=0,n-1,w[i]/(t-x[i])) 1836 1837 INPUT PARAMETERS: 1838 X - interpolation nodes, array[0..N-1] 1839 F - function values, array[0..N-1] 1840 W - barycentric weights, array[0..N-1] 1841 N - nodes count, N>0 1842 1843 OUTPUT PARAMETERS: 1844 B - barycentric interpolant built from (X, Y, W) 1845 1846 -- ALGLIB -- 1847 Copyright 17.08.2009 by Bochkanov Sergey 1848 *************************************************************************/ 1849 void barycentricbuildxyw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, barycentricinterpolant &b, const xparams _xparams = alglib::xdefault); 1850 1851 1852 /************************************************************************* 1853 Rational interpolant without poles 1854 1855 The subroutine constructs the rational interpolating function without real 1856 poles (see 'Barycentric rational interpolation with no poles and high 1857 rates of approximation', Michael S. Floater. and Kai Hormann, for more 1858 information on this subject). 1859 1860 Input parameters: 1861 X - interpolation nodes, array[0..N-1]. 1862 Y - function values, array[0..N-1]. 1863 N - number of nodes, N>0. 1864 D - order of the interpolation scheme, 0 <= D <= N-1. 1865 D<0 will cause an error. 1866 D>=N it will be replaced with D=N-1. 1867 if you don't know what D to choose, use small value about 3-5. 1868 1869 Output parameters: 1870 B - barycentric interpolant. 1871 1872 Note: 1873 this algorithm always succeeds and calculates the weights with close 1874 to machine precision. 1875 1876 -- ALGLIB PROJECT -- 1877 Copyright 17.06.2007 by Bochkanov Sergey 1878 *************************************************************************/ 1879 void barycentricbuildfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t d, barycentricinterpolant &b, const xparams _xparams = alglib::xdefault); 1880 #endif 1881 1882 #if defined(AE_COMPILE_FITSPHERE) || !defined(AE_PARTIAL_BUILD) 1883 /************************************************************************* 1884 Fits least squares (LS) circle (or NX-dimensional sphere) to data (a set 1885 of points in NX-dimensional space). 1886 1887 Least squares circle minimizes sum of squared deviations between distances 1888 from points to the center and some "candidate" radius, which is also 1889 fitted to the data. 1890 1891 INPUT PARAMETERS: 1892 XY - array[NPoints,NX] (or larger), contains dataset. 1893 One row = one point in NX-dimensional space. 1894 NPoints - dataset size, NPoints>0 1895 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on) 1896 1897 OUTPUT PARAMETERS: 1898 CX - central point for a sphere 1899 R - radius 1900 1901 -- ALGLIB -- 1902 Copyright 07.05.2018 by Bochkanov Sergey 1903 *************************************************************************/ 1904 void fitspherels(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &r, const xparams _xparams = alglib::xdefault); 1905 1906 1907 /************************************************************************* 1908 Fits minimum circumscribed (MC) circle (or NX-dimensional sphere) to data 1909 (a set of points in NX-dimensional space). 1910 1911 INPUT PARAMETERS: 1912 XY - array[NPoints,NX] (or larger), contains dataset. 1913 One row = one point in NX-dimensional space. 1914 NPoints - dataset size, NPoints>0 1915 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on) 1916 1917 OUTPUT PARAMETERS: 1918 CX - central point for a sphere 1919 RHi - radius 1920 1921 NOTE: this function is an easy-to-use wrapper around more powerful "expert" 1922 function fitspherex(). 1923 1924 This wrapper is optimized for ease of use and stability - at the 1925 cost of somewhat lower performance (we have to use very tight 1926 stopping criteria for inner optimizer because we want to make sure 1927 that it will converge on any dataset). 1928 1929 If you are ready to experiment with settings of "expert" function, 1930 you can achieve ~2-4x speedup over standard "bulletproof" settings. 1931 1932 1933 -- ALGLIB -- 1934 Copyright 14.04.2017 by Bochkanov Sergey 1935 *************************************************************************/ 1936 void fitspheremc(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rhi, const xparams _xparams = alglib::xdefault); 1937 1938 1939 /************************************************************************* 1940 Fits maximum inscribed circle (or NX-dimensional sphere) to data (a set of 1941 points in NX-dimensional space). 1942 1943 INPUT PARAMETERS: 1944 XY - array[NPoints,NX] (or larger), contains dataset. 1945 One row = one point in NX-dimensional space. 1946 NPoints - dataset size, NPoints>0 1947 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on) 1948 1949 OUTPUT PARAMETERS: 1950 CX - central point for a sphere 1951 RLo - radius 1952 1953 NOTE: this function is an easy-to-use wrapper around more powerful "expert" 1954 function fitspherex(). 1955 1956 This wrapper is optimized for ease of use and stability - at the 1957 cost of somewhat lower performance (we have to use very tight 1958 stopping criteria for inner optimizer because we want to make sure 1959 that it will converge on any dataset). 1960 1961 If you are ready to experiment with settings of "expert" function, 1962 you can achieve ~2-4x speedup over standard "bulletproof" settings. 1963 1964 1965 -- ALGLIB -- 1966 Copyright 14.04.2017 by Bochkanov Sergey 1967 *************************************************************************/ 1968 void fitspheremi(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo, const xparams _xparams = alglib::xdefault); 1969 1970 1971 /************************************************************************* 1972 Fits minimum zone circle (or NX-dimensional sphere) to data (a set of 1973 points in NX-dimensional space). 1974 1975 INPUT PARAMETERS: 1976 XY - array[NPoints,NX] (or larger), contains dataset. 1977 One row = one point in NX-dimensional space. 1978 NPoints - dataset size, NPoints>0 1979 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on) 1980 1981 OUTPUT PARAMETERS: 1982 CX - central point for a sphere 1983 RLo - radius of inscribed circle 1984 RHo - radius of circumscribed circle 1985 1986 NOTE: this function is an easy-to-use wrapper around more powerful "expert" 1987 function fitspherex(). 1988 1989 This wrapper is optimized for ease of use and stability - at the 1990 cost of somewhat lower performance (we have to use very tight 1991 stopping criteria for inner optimizer because we want to make sure 1992 that it will converge on any dataset). 1993 1994 If you are ready to experiment with settings of "expert" function, 1995 you can achieve ~2-4x speedup over standard "bulletproof" settings. 1996 1997 1998 -- ALGLIB -- 1999 Copyright 14.04.2017 by Bochkanov Sergey 2000 *************************************************************************/ 2001 void fitspheremz(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo, double &rhi, const xparams _xparams = alglib::xdefault); 2002 2003 2004 /************************************************************************* 2005 Fitting minimum circumscribed, maximum inscribed or minimum zone circles 2006 (or NX-dimensional spheres) to data (a set of points in NX-dimensional 2007 space). 2008 2009 This is expert function which allows to tweak many parameters of 2010 underlying nonlinear solver: 2011 * stopping criteria for inner iterations 2012 * number of outer iterations 2013 * penalty coefficient used to handle nonlinear constraints (we convert 2014 unconstrained nonsmooth optimization problem ivolving max() and/or min() 2015 operations to quadratically constrained smooth one). 2016 2017 You may tweak all these parameters or only some of them, leaving other 2018 ones at their default state - just specify zero value, and solver will 2019 fill it with appropriate default one. 2020 2021 These comments also include some discussion of approach used to handle 2022 such unusual fitting problem, its stability, drawbacks of alternative 2023 methods, and convergence properties. 2024 2025 INPUT PARAMETERS: 2026 XY - array[NPoints,NX] (or larger), contains dataset. 2027 One row = one point in NX-dimensional space. 2028 NPoints - dataset size, NPoints>0 2029 NX - space dimensionality, NX>0 (1, 2, 3, 4, 5 and so on) 2030 ProblemType-used to encode problem type: 2031 * 0 for least squares circle 2032 * 1 for minimum circumscribed circle/sphere fitting (MC) 2033 * 2 for maximum inscribed circle/sphere fitting (MI) 2034 * 3 for minimum zone circle fitting (difference between 2035 Rhi and Rlo is minimized), denoted as MZ 2036 EpsX - stopping condition for NLC optimizer: 2037 * must be non-negative 2038 * use 0 to choose default value (1.0E-12 is used by default) 2039 * you may specify larger values, up to 1.0E-6, if you want 2040 to speed-up solver; NLC solver performs several 2041 preconditioned outer iterations, so final result 2042 typically has precision much better than EpsX. 2043 AULIts - number of outer iterations performed by NLC optimizer: 2044 * must be non-negative 2045 * use 0 to choose default value (20 is used by default) 2046 * you may specify values smaller than 20 if you want to 2047 speed up solver; 10 often results in good combination of 2048 precision and speed; sometimes you may get good results 2049 with just 6 outer iterations. 2050 Ignored for ProblemType=0. 2051 Penalty - penalty coefficient for NLC optimizer: 2052 * must be non-negative 2053 * use 0 to choose default value (1.0E6 in current version) 2054 * it should be really large, 1.0E6...1.0E7 is a good value 2055 to start from; 2056 * generally, default value is good enough 2057 Ignored for ProblemType=0. 2058 2059 OUTPUT PARAMETERS: 2060 CX - central point for a sphere 2061 RLo - radius: 2062 * for ProblemType=2,3, radius of the inscribed sphere 2063 * for ProblemType=0 - radius of the least squares sphere 2064 * for ProblemType=1 - zero 2065 RHo - radius: 2066 * for ProblemType=1,3, radius of the circumscribed sphere 2067 * for ProblemType=0 - radius of the least squares sphere 2068 * for ProblemType=2 - zero 2069 2070 NOTE: ON THE UNIQUENESS OF SOLUTIONS 2071 2072 ALGLIB provides solution to several related circle fitting problems: MC 2073 (minimum circumscribed), MI (maximum inscribed) and MZ (minimum zone) 2074 fitting, LS (least squares) fitting. 2075 2076 It is important to note that among these problems only MC and LS are 2077 convex and have unique solution independently from starting point. 2078 2079 As for MI, it may (or may not, depending on dataset properties) have 2080 multiple solutions, and it always has one degenerate solution C=infinity 2081 which corresponds to infinitely large radius. Thus, there are no guarantees 2082 that solution to MI returned by this solver will be the best one (and no 2083 one can provide you with such guarantee because problem is NP-hard). The 2084 only guarantee you have is that this solution is locally optimal, i.e. it 2085 can not be improved by infinitesimally small tweaks in the parameters. 2086 2087 It is also possible to "run away" to infinity when started from bad 2088 initial point located outside of point cloud (or when point cloud does not 2089 span entire circumference/surface of the sphere). 2090 2091 Finally, MZ (minimum zone circle) stands somewhere between MC and MI in 2092 stability. It is somewhat regularized by "circumscribed" term of the merit 2093 function; however, solutions to MZ may be non-unique, and in some unlucky 2094 cases it is also possible to "run away to infinity". 2095 2096 2097 NOTE: ON THE NONLINEARLY CONSTRAINED PROGRAMMING APPROACH 2098 2099 The problem formulation for MC (minimum circumscribed circle; for the 2100 sake of simplicity we omit MZ and MI here) is: 2101 2102 [ [ ]2 ] 2103 min [ max [ XY[i]-C ] ] 2104 C [ i [ ] ] 2105 2106 i.e. it is unconstrained nonsmooth optimization problem of finding "best" 2107 central point, with radius R being unambiguously determined from C. In 2108 order to move away from non-smoothness we use following reformulation: 2109 2110 [ ] [ ]2 2111 min [ R ] subject to R>=0, [ XY[i]-C ] <= R^2 2112 C,R [ ] [ ] 2113 2114 i.e. it becomes smooth quadratically constrained optimization problem with 2115 linear target function. Such problem statement is 100% equivalent to the 2116 original nonsmooth one, but much easier to approach. We solve it with 2117 MinNLC solver provided by ALGLIB. 2118 2119 2120 NOTE: ON INSTABILITY OF SEQUENTIAL LINEARIZATION APPROACH 2121 2122 ALGLIB has nonlinearly constrained solver which proved to be stable on 2123 such problems. However, some authors proposed to linearize constraints in 2124 the vicinity of current approximation (Ci,Ri) and to get next approximate 2125 solution (Ci+1,Ri+1) as solution to linear programming problem. Obviously, 2126 LP problems are easier than nonlinearly constrained ones. 2127 2128 Indeed, such approach to MC/MI/MZ resulted in ~10-20x increase in 2129 performance (when compared with NLC solver). However, it turned out that 2130 in some cases linearized model fails to predict correct direction for next 2131 step and tells us that we converged to solution even when we are still 2-4 2132 digits of precision away from it. 2133 2134 It is important that it is not failure of LP solver - it is failure of the 2135 linear model; even when solved exactly, it fails to handle subtle 2136 nonlinearities which arise near the solution. We validated it by comparing 2137 results returned by ALGLIB linear solver with that of MATLAB. 2138 2139 In our experiments with linearization: 2140 * MC failed most often, at both realistic and synthetic datasets 2141 * MI sometimes failed, but sometimes succeeded 2142 * MZ often succeeded; our guess is that presence of two independent sets 2143 of constraints (one set for Rlo and another one for Rhi) and two terms 2144 in the target function (Rlo and Rhi) regularizes task, so when linear 2145 model fails to handle nonlinearities from Rlo, it uses Rhi as a hint 2146 (and vice versa). 2147 2148 Because linearization approach failed to achieve stable results, we do not 2149 include it in ALGLIB. 2150 2151 2152 -- ALGLIB -- 2153 Copyright 14.04.2017 by Bochkanov Sergey 2154 *************************************************************************/ 2155 void fitspherex(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, const xparams _xparams = alglib::xdefault); 2156 #endif 2157 2158 #if defined(AE_COMPILE_INTFITSERV) || !defined(AE_PARTIAL_BUILD) 2159 2160 #endif 2161 2162 #if defined(AE_COMPILE_SPLINE1D) || !defined(AE_PARTIAL_BUILD) 2163 /************************************************************************* 2164 This subroutine builds linear spline interpolant 2165 2166 INPUT PARAMETERS: 2167 X - spline nodes, array[0..N-1] 2168 Y - function values, array[0..N-1] 2169 N - points count (optional): 2170 * N>=2 2171 * if given, only first N points are used to build spline 2172 * if not given, automatically detected from X/Y sizes 2173 (len(X) must be equal to len(Y)) 2174 2175 OUTPUT PARAMETERS: 2176 C - spline interpolant 2177 2178 2179 ORDER OF POINTS 2180 2181 Subroutine automatically sorts points, so caller may pass unsorted array. 2182 2183 -- ALGLIB PROJECT -- 2184 Copyright 24.06.2007 by Bochkanov Sergey 2185 *************************************************************************/ 2186 void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2187 void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2188 2189 2190 /************************************************************************* 2191 This subroutine builds cubic spline interpolant. 2192 2193 INPUT PARAMETERS: 2194 X - spline nodes, array[0..N-1]. 2195 Y - function values, array[0..N-1]. 2196 2197 OPTIONAL PARAMETERS: 2198 N - points count: 2199 * N>=2 2200 * if given, only first N points are used to build spline 2201 * if not given, automatically detected from X/Y sizes 2202 (len(X) must be equal to len(Y)) 2203 BoundLType - boundary condition type for the left boundary 2204 BoundL - left boundary condition (first or second derivative, 2205 depending on the BoundLType) 2206 BoundRType - boundary condition type for the right boundary 2207 BoundR - right boundary condition (first or second derivative, 2208 depending on the BoundRType) 2209 2210 OUTPUT PARAMETERS: 2211 C - spline interpolant 2212 2213 ORDER OF POINTS 2214 2215 Subroutine automatically sorts points, so caller may pass unsorted array. 2216 2217 SETTING BOUNDARY VALUES: 2218 2219 The BoundLType/BoundRType parameters can have the following values: 2220 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2221 In this case: 2222 * both BoundLType and BoundRType must be equal to -1. 2223 * BoundL/BoundR are ignored 2224 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2225 * 0, which corresponds to the parabolically terminated spline 2226 (BoundL and/or BoundR are ignored). 2227 * 1, which corresponds to the first derivative boundary condition 2228 * 2, which corresponds to the second derivative boundary condition 2229 * by default, BoundType=0 is used 2230 2231 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2232 2233 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2234 However, this subroutine doesn't require you to specify equal values for 2235 the first and last points - it automatically forces them to be equal by 2236 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2237 Y[last_point]. However it is recommended to pass consistent values of Y[], 2238 i.e. to make Y[first_point]=Y[last_point]. 2239 2240 -- ALGLIB PROJECT -- 2241 Copyright 23.06.2007 by Bochkanov Sergey 2242 *************************************************************************/ 2243 void 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, const xparams _xparams = alglib::xdefault); 2244 void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2245 2246 2247 /************************************************************************* 2248 This function solves following problem: given table y[] of function values 2249 at nodes x[], it calculates and returns table of function derivatives d[] 2250 (calculated at the same nodes x[]). 2251 2252 This function yields same result as Spline1DBuildCubic() call followed by 2253 sequence of Spline1DDiff() calls, but it can be several times faster when 2254 called for ordered X[] and X2[]. 2255 2256 INPUT PARAMETERS: 2257 X - spline nodes 2258 Y - function values 2259 2260 OPTIONAL PARAMETERS: 2261 N - points count: 2262 * N>=2 2263 * if given, only first N points are used 2264 * if not given, automatically detected from X/Y sizes 2265 (len(X) must be equal to len(Y)) 2266 BoundLType - boundary condition type for the left boundary 2267 BoundL - left boundary condition (first or second derivative, 2268 depending on the BoundLType) 2269 BoundRType - boundary condition type for the right boundary 2270 BoundR - right boundary condition (first or second derivative, 2271 depending on the BoundRType) 2272 2273 OUTPUT PARAMETERS: 2274 D - derivative values at X[] 2275 2276 ORDER OF POINTS 2277 2278 Subroutine automatically sorts points, so caller may pass unsorted array. 2279 Derivative values are correctly reordered on return, so D[I] is always 2280 equal to S'(X[I]) independently of points order. 2281 2282 SETTING BOUNDARY VALUES: 2283 2284 The BoundLType/BoundRType parameters can have the following values: 2285 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2286 In this case: 2287 * both BoundLType and BoundRType must be equal to -1. 2288 * BoundL/BoundR are ignored 2289 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2290 * 0, which corresponds to the parabolically terminated spline 2291 (BoundL and/or BoundR are ignored). 2292 * 1, which corresponds to the first derivative boundary condition 2293 * 2, which corresponds to the second derivative boundary condition 2294 * by default, BoundType=0 is used 2295 2296 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2297 2298 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2299 However, this subroutine doesn't require you to specify equal values for 2300 the first and last points - it automatically forces them to be equal by 2301 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2302 Y[last_point]. However it is recommended to pass consistent values of Y[], 2303 i.e. to make Y[first_point]=Y[last_point]. 2304 2305 -- ALGLIB PROJECT -- 2306 Copyright 03.09.2010 by Bochkanov Sergey 2307 *************************************************************************/ 2308 void 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, const xparams _xparams = alglib::xdefault); 2309 void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, real_1d_array &d, const xparams _xparams = alglib::xdefault); 2310 2311 2312 /************************************************************************* 2313 This function solves following problem: given table y[] of function values 2314 at nodes x[], it calculates and returns tables of first and second 2315 function derivatives d1[] and d2[] (calculated at the same nodes x[]). 2316 2317 This function yields same result as Spline1DBuildCubic() call followed by 2318 sequence of Spline1DDiff() calls, but it can be several times faster when 2319 called for ordered X[] and X2[]. 2320 2321 INPUT PARAMETERS: 2322 X - spline nodes 2323 Y - function values 2324 2325 OPTIONAL PARAMETERS: 2326 N - points count: 2327 * N>=2 2328 * if given, only first N points are used 2329 * if not given, automatically detected from X/Y sizes 2330 (len(X) must be equal to len(Y)) 2331 BoundLType - boundary condition type for the left boundary 2332 BoundL - left boundary condition (first or second derivative, 2333 depending on the BoundLType) 2334 BoundRType - boundary condition type for the right boundary 2335 BoundR - right boundary condition (first or second derivative, 2336 depending on the BoundRType) 2337 2338 OUTPUT PARAMETERS: 2339 D1 - S' values at X[] 2340 D2 - S'' values at X[] 2341 2342 ORDER OF POINTS 2343 2344 Subroutine automatically sorts points, so caller may pass unsorted array. 2345 Derivative values are correctly reordered on return, so D[I] is always 2346 equal to S'(X[I]) independently of points order. 2347 2348 SETTING BOUNDARY VALUES: 2349 2350 The BoundLType/BoundRType parameters can have the following values: 2351 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2352 In this case: 2353 * both BoundLType and BoundRType must be equal to -1. 2354 * BoundL/BoundR are ignored 2355 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2356 * 0, which corresponds to the parabolically terminated spline 2357 (BoundL and/or BoundR are ignored). 2358 * 1, which corresponds to the first derivative boundary condition 2359 * 2, which corresponds to the second derivative boundary condition 2360 * by default, BoundType=0 is used 2361 2362 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2363 2364 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2365 However, this subroutine doesn't require you to specify equal values for 2366 the first and last points - it automatically forces them to be equal by 2367 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2368 Y[last_point]. However it is recommended to pass consistent values of Y[], 2369 i.e. to make Y[first_point]=Y[last_point]. 2370 2371 -- ALGLIB PROJECT -- 2372 Copyright 03.09.2010 by Bochkanov Sergey 2373 *************************************************************************/ 2374 void 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, const xparams _xparams = alglib::xdefault); 2375 void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, real_1d_array &d1, real_1d_array &d2, const xparams _xparams = alglib::xdefault); 2376 2377 2378 /************************************************************************* 2379 This function solves following problem: given table y[] of function values 2380 at old nodes x[] and new nodes x2[], it calculates and returns table of 2381 function values y2[] (calculated at x2[]). 2382 2383 This function yields same result as Spline1DBuildCubic() call followed by 2384 sequence of Spline1DDiff() calls, but it can be several times faster when 2385 called for ordered X[] and X2[]. 2386 2387 INPUT PARAMETERS: 2388 X - old spline nodes 2389 Y - function values 2390 X2 - new spline nodes 2391 2392 OPTIONAL PARAMETERS: 2393 N - points count: 2394 * N>=2 2395 * if given, only first N points from X/Y are used 2396 * if not given, automatically detected from X/Y sizes 2397 (len(X) must be equal to len(Y)) 2398 BoundLType - boundary condition type for the left boundary 2399 BoundL - left boundary condition (first or second derivative, 2400 depending on the BoundLType) 2401 BoundRType - boundary condition type for the right boundary 2402 BoundR - right boundary condition (first or second derivative, 2403 depending on the BoundRType) 2404 N2 - new points count: 2405 * N2>=2 2406 * if given, only first N2 points from X2 are used 2407 * if not given, automatically detected from X2 size 2408 2409 OUTPUT PARAMETERS: 2410 F2 - function values at X2[] 2411 2412 ORDER OF POINTS 2413 2414 Subroutine automatically sorts points, so caller may pass unsorted array. 2415 Function values are correctly reordered on return, so F2[I] is always 2416 equal to S(X2[I]) independently of points order. 2417 2418 SETTING BOUNDARY VALUES: 2419 2420 The BoundLType/BoundRType parameters can have the following values: 2421 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2422 In this case: 2423 * both BoundLType and BoundRType must be equal to -1. 2424 * BoundL/BoundR are ignored 2425 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2426 * 0, which corresponds to the parabolically terminated spline 2427 (BoundL and/or BoundR are ignored). 2428 * 1, which corresponds to the first derivative boundary condition 2429 * 2, which corresponds to the second derivative boundary condition 2430 * by default, BoundType=0 is used 2431 2432 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2433 2434 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2435 However, this subroutine doesn't require you to specify equal values for 2436 the first and last points - it automatically forces them to be equal by 2437 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2438 Y[last_point]. However it is recommended to pass consistent values of Y[], 2439 i.e. to make Y[first_point]=Y[last_point]. 2440 2441 -- ALGLIB PROJECT -- 2442 Copyright 03.09.2010 by Bochkanov Sergey 2443 *************************************************************************/ 2444 void 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, const xparams _xparams = alglib::xdefault); 2445 void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, const real_1d_array &x2, real_1d_array &y2, const xparams _xparams = alglib::xdefault); 2446 2447 2448 /************************************************************************* 2449 This function solves following problem: given table y[] of function values 2450 at old nodes x[] and new nodes x2[], it calculates and returns table of 2451 function values y2[] and derivatives d2[] (calculated at x2[]). 2452 2453 This function yields same result as Spline1DBuildCubic() call followed by 2454 sequence of Spline1DDiff() calls, but it can be several times faster when 2455 called for ordered X[] and X2[]. 2456 2457 INPUT PARAMETERS: 2458 X - old spline nodes 2459 Y - function values 2460 X2 - new spline nodes 2461 2462 OPTIONAL PARAMETERS: 2463 N - points count: 2464 * N>=2 2465 * if given, only first N points from X/Y are used 2466 * if not given, automatically detected from X/Y sizes 2467 (len(X) must be equal to len(Y)) 2468 BoundLType - boundary condition type for the left boundary 2469 BoundL - left boundary condition (first or second derivative, 2470 depending on the BoundLType) 2471 BoundRType - boundary condition type for the right boundary 2472 BoundR - right boundary condition (first or second derivative, 2473 depending on the BoundRType) 2474 N2 - new points count: 2475 * N2>=2 2476 * if given, only first N2 points from X2 are used 2477 * if not given, automatically detected from X2 size 2478 2479 OUTPUT PARAMETERS: 2480 F2 - function values at X2[] 2481 D2 - first derivatives at X2[] 2482 2483 ORDER OF POINTS 2484 2485 Subroutine automatically sorts points, so caller may pass unsorted array. 2486 Function values are correctly reordered on return, so F2[I] is always 2487 equal to S(X2[I]) independently of points order. 2488 2489 SETTING BOUNDARY VALUES: 2490 2491 The BoundLType/BoundRType parameters can have the following values: 2492 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2493 In this case: 2494 * both BoundLType and BoundRType must be equal to -1. 2495 * BoundL/BoundR are ignored 2496 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2497 * 0, which corresponds to the parabolically terminated spline 2498 (BoundL and/or BoundR are ignored). 2499 * 1, which corresponds to the first derivative boundary condition 2500 * 2, which corresponds to the second derivative boundary condition 2501 * by default, BoundType=0 is used 2502 2503 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2504 2505 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2506 However, this subroutine doesn't require you to specify equal values for 2507 the first and last points - it automatically forces them to be equal by 2508 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2509 Y[last_point]. However it is recommended to pass consistent values of Y[], 2510 i.e. to make Y[first_point]=Y[last_point]. 2511 2512 -- ALGLIB PROJECT -- 2513 Copyright 03.09.2010 by Bochkanov Sergey 2514 *************************************************************************/ 2515 void 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, const xparams _xparams = alglib::xdefault); 2516 void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, const real_1d_array &x2, real_1d_array &y2, real_1d_array &d2, const xparams _xparams = alglib::xdefault); 2517 2518 2519 /************************************************************************* 2520 This function solves following problem: given table y[] of function values 2521 at old nodes x[] and new nodes x2[], it calculates and returns table of 2522 function values y2[], first and second derivatives d2[] and dd2[] 2523 (calculated at x2[]). 2524 2525 This function yields same result as Spline1DBuildCubic() call followed by 2526 sequence of Spline1DDiff() calls, but it can be several times faster when 2527 called for ordered X[] and X2[]. 2528 2529 INPUT PARAMETERS: 2530 X - old spline nodes 2531 Y - function values 2532 X2 - new spline nodes 2533 2534 OPTIONAL PARAMETERS: 2535 N - points count: 2536 * N>=2 2537 * if given, only first N points from X/Y are used 2538 * if not given, automatically detected from X/Y sizes 2539 (len(X) must be equal to len(Y)) 2540 BoundLType - boundary condition type for the left boundary 2541 BoundL - left boundary condition (first or second derivative, 2542 depending on the BoundLType) 2543 BoundRType - boundary condition type for the right boundary 2544 BoundR - right boundary condition (first or second derivative, 2545 depending on the BoundRType) 2546 N2 - new points count: 2547 * N2>=2 2548 * if given, only first N2 points from X2 are used 2549 * if not given, automatically detected from X2 size 2550 2551 OUTPUT PARAMETERS: 2552 F2 - function values at X2[] 2553 D2 - first derivatives at X2[] 2554 DD2 - second derivatives at X2[] 2555 2556 ORDER OF POINTS 2557 2558 Subroutine automatically sorts points, so caller may pass unsorted array. 2559 Function values are correctly reordered on return, so F2[I] is always 2560 equal to S(X2[I]) independently of points order. 2561 2562 SETTING BOUNDARY VALUES: 2563 2564 The BoundLType/BoundRType parameters can have the following values: 2565 * -1, which corresonds to the periodic (cyclic) boundary conditions. 2566 In this case: 2567 * both BoundLType and BoundRType must be equal to -1. 2568 * BoundL/BoundR are ignored 2569 * Y[last] is ignored (it is assumed to be equal to Y[first]). 2570 * 0, which corresponds to the parabolically terminated spline 2571 (BoundL and/or BoundR are ignored). 2572 * 1, which corresponds to the first derivative boundary condition 2573 * 2, which corresponds to the second derivative boundary condition 2574 * by default, BoundType=0 is used 2575 2576 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2577 2578 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2579 However, this subroutine doesn't require you to specify equal values for 2580 the first and last points - it automatically forces them to be equal by 2581 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2582 Y[last_point]. However it is recommended to pass consistent values of Y[], 2583 i.e. to make Y[first_point]=Y[last_point]. 2584 2585 -- ALGLIB PROJECT -- 2586 Copyright 03.09.2010 by Bochkanov Sergey 2587 *************************************************************************/ 2588 void 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, const xparams _xparams = alglib::xdefault); 2589 void 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, const xparams _xparams = alglib::xdefault); 2590 2591 2592 /************************************************************************* 2593 This subroutine builds Catmull-Rom spline interpolant. 2594 2595 INPUT PARAMETERS: 2596 X - spline nodes, array[0..N-1]. 2597 Y - function values, array[0..N-1]. 2598 2599 OPTIONAL PARAMETERS: 2600 N - points count: 2601 * N>=2 2602 * if given, only first N points are used to build spline 2603 * if not given, automatically detected from X/Y sizes 2604 (len(X) must be equal to len(Y)) 2605 BoundType - boundary condition type: 2606 * -1 for periodic boundary condition 2607 * 0 for parabolically terminated spline (default) 2608 Tension - tension parameter: 2609 * tension=0 corresponds to classic Catmull-Rom spline (default) 2610 * 0<tension<1 corresponds to more general form - cardinal spline 2611 2612 OUTPUT PARAMETERS: 2613 C - spline interpolant 2614 2615 2616 ORDER OF POINTS 2617 2618 Subroutine automatically sorts points, so caller may pass unsorted array. 2619 2620 PROBLEMS WITH PERIODIC BOUNDARY CONDITIONS: 2621 2622 Problems with periodic boundary conditions have Y[first_point]=Y[last_point]. 2623 However, this subroutine doesn't require you to specify equal values for 2624 the first and last points - it automatically forces them to be equal by 2625 copying Y[first_point] (corresponds to the leftmost, minimal X[]) to 2626 Y[last_point]. However it is recommended to pass consistent values of Y[], 2627 i.e. to make Y[first_point]=Y[last_point]. 2628 2629 -- ALGLIB PROJECT -- 2630 Copyright 23.06.2007 by Bochkanov Sergey 2631 *************************************************************************/ 2632 void 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, const xparams _xparams = alglib::xdefault); 2633 void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2634 2635 2636 /************************************************************************* 2637 This subroutine builds Hermite spline interpolant. 2638 2639 INPUT PARAMETERS: 2640 X - spline nodes, array[0..N-1] 2641 Y - function values, array[0..N-1] 2642 D - derivatives, array[0..N-1] 2643 N - points count (optional): 2644 * N>=2 2645 * if given, only first N points are used to build spline 2646 * if not given, automatically detected from X/Y sizes 2647 (len(X) must be equal to len(Y)) 2648 2649 OUTPUT PARAMETERS: 2650 C - spline interpolant. 2651 2652 2653 ORDER OF POINTS 2654 2655 Subroutine automatically sorts points, so caller may pass unsorted array. 2656 2657 -- ALGLIB PROJECT -- 2658 Copyright 23.06.2007 by Bochkanov Sergey 2659 *************************************************************************/ 2660 void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, const real_1d_array &d, const ae_int_t n, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2661 void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, const real_1d_array &d, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2662 2663 2664 /************************************************************************* 2665 This subroutine builds Akima spline interpolant 2666 2667 INPUT PARAMETERS: 2668 X - spline nodes, array[0..N-1] 2669 Y - function values, array[0..N-1] 2670 N - points count (optional): 2671 * N>=2 2672 * if given, only first N points are used to build spline 2673 * if not given, automatically detected from X/Y sizes 2674 (len(X) must be equal to len(Y)) 2675 2676 OUTPUT PARAMETERS: 2677 C - spline interpolant 2678 2679 2680 ORDER OF POINTS 2681 2682 Subroutine automatically sorts points, so caller may pass unsorted array. 2683 2684 -- ALGLIB PROJECT -- 2685 Copyright 24.06.2007 by Bochkanov Sergey 2686 *************************************************************************/ 2687 void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2688 void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2689 2690 2691 /************************************************************************* 2692 This subroutine calculates the value of the spline at the given point X. 2693 2694 INPUT PARAMETERS: 2695 C - spline interpolant 2696 X - point 2697 2698 Result: 2699 S(x) 2700 2701 -- ALGLIB PROJECT -- 2702 Copyright 23.06.2007 by Bochkanov Sergey 2703 *************************************************************************/ 2704 double spline1dcalc(const spline1dinterpolant &c, const double x, const xparams _xparams = alglib::xdefault); 2705 2706 2707 /************************************************************************* 2708 This subroutine differentiates the spline. 2709 2710 INPUT PARAMETERS: 2711 C - spline interpolant. 2712 X - point 2713 2714 Result: 2715 S - S(x) 2716 DS - S'(x) 2717 D2S - S''(x) 2718 2719 -- ALGLIB PROJECT -- 2720 Copyright 24.06.2007 by Bochkanov Sergey 2721 *************************************************************************/ 2722 void spline1ddiff(const spline1dinterpolant &c, const double x, double &s, double &ds, double &d2s, const xparams _xparams = alglib::xdefault); 2723 2724 2725 /************************************************************************* 2726 This subroutine unpacks the spline into the coefficients table. 2727 2728 INPUT PARAMETERS: 2729 C - spline interpolant. 2730 X - point 2731 2732 OUTPUT PARAMETERS: 2733 Tbl - coefficients table, unpacked format, array[0..N-2, 0..5]. 2734 For I = 0...N-2: 2735 Tbl[I,0] = X[i] 2736 Tbl[I,1] = X[i+1] 2737 Tbl[I,2] = C0 2738 Tbl[I,3] = C1 2739 Tbl[I,4] = C2 2740 Tbl[I,5] = C3 2741 On [x[i], x[i+1]] spline is equals to: 2742 S(x) = C0 + C1*t + C2*t^2 + C3*t^3 2743 t = x-x[i] 2744 2745 NOTE: 2746 You can rebuild spline with Spline1DBuildHermite() function, which 2747 accepts as inputs function values and derivatives at nodes, which are 2748 easy to calculate when you have coefficients. 2749 2750 -- ALGLIB PROJECT -- 2751 Copyright 29.06.2007 by Bochkanov Sergey 2752 *************************************************************************/ 2753 void spline1dunpack(const spline1dinterpolant &c, ae_int_t &n, real_2d_array &tbl, const xparams _xparams = alglib::xdefault); 2754 2755 2756 /************************************************************************* 2757 This subroutine performs linear transformation of the spline argument. 2758 2759 INPUT PARAMETERS: 2760 C - spline interpolant. 2761 A, B- transformation coefficients: x = A*t + B 2762 Result: 2763 C - transformed spline 2764 2765 -- ALGLIB PROJECT -- 2766 Copyright 30.06.2007 by Bochkanov Sergey 2767 *************************************************************************/ 2768 void spline1dlintransx(const spline1dinterpolant &c, const double a, const double b, const xparams _xparams = alglib::xdefault); 2769 2770 2771 /************************************************************************* 2772 This subroutine performs linear transformation of the spline. 2773 2774 INPUT PARAMETERS: 2775 C - spline interpolant. 2776 A, B- transformation coefficients: S2(x) = A*S(x) + B 2777 Result: 2778 C - transformed spline 2779 2780 -- ALGLIB PROJECT -- 2781 Copyright 30.06.2007 by Bochkanov Sergey 2782 *************************************************************************/ 2783 void spline1dlintransy(const spline1dinterpolant &c, const double a, const double b, const xparams _xparams = alglib::xdefault); 2784 2785 2786 /************************************************************************* 2787 This subroutine integrates the spline. 2788 2789 INPUT PARAMETERS: 2790 C - spline interpolant. 2791 X - right bound of the integration interval [a, x], 2792 here 'a' denotes min(x[]) 2793 Result: 2794 integral(S(t)dt,a,x) 2795 2796 -- ALGLIB PROJECT -- 2797 Copyright 23.06.2007 by Bochkanov Sergey 2798 *************************************************************************/ 2799 double spline1dintegrate(const spline1dinterpolant &c, const double x, const xparams _xparams = alglib::xdefault); 2800 2801 2802 /************************************************************************* 2803 Fitting by penalized cubic spline. 2804 2805 Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build 2806 basis functions. Basis functions are cubic splines with natural boundary 2807 conditions. Problem is regularized by adding non-linearity penalty to the 2808 usual least squares penalty function: 2809 2810 S(x) = arg min { LS + P }, where 2811 LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty 2812 P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty 2813 rho - tunable constant given by user 2814 C - automatically determined scale parameter, 2815 makes penalty invariant with respect to scaling of X, Y, W. 2816 2817 ! COMMERCIAL EDITION OF ALGLIB: 2818 ! 2819 ! Commercial Edition of ALGLIB includes following important improvements 2820 ! of this function: 2821 ! * high-performance native backend with same C# interface (C# version) 2822 ! * multithreading support (C++ and C# versions) 2823 ! * hardware vendor (Intel) implementations of linear algebra primitives 2824 ! (C++ and C# versions, x86/x64 platform) 2825 ! 2826 ! We recommend you to read 'Working with commercial version' section of 2827 ! ALGLIB Reference Manual in order to find out how to use performance- 2828 ! related features provided by commercial edition of ALGLIB. 2829 2830 INPUT PARAMETERS: 2831 X - points, array[0..N-1]. 2832 Y - function values, array[0..N-1]. 2833 N - number of points (optional): 2834 * N>0 2835 * if given, only first N elements of X/Y are processed 2836 * if not given, automatically determined from X/Y sizes 2837 M - number of basis functions ( = number_of_nodes), M>=4. 2838 Rho - regularization constant passed by user. It penalizes 2839 nonlinearity in the regression spline. It is logarithmically 2840 scaled, i.e. actual value of regularization constant is 2841 calculated as 10^Rho. It is automatically scaled so that: 2842 * Rho=2.0 corresponds to moderate amount of nonlinearity 2843 * generally, it should be somewhere in the [-8.0,+8.0] 2844 If you do not want to penalize nonlineary, 2845 pass small Rho. Values as low as -15 should work. 2846 2847 OUTPUT PARAMETERS: 2848 Info- same format as in LSFitLinearWC() subroutine. 2849 * Info>0 task is solved 2850 * Info<=0 an error occured: 2851 -4 means inconvergence of internal SVD or 2852 Cholesky decomposition; problem may be 2853 too ill-conditioned (very rare) 2854 S - spline interpolant. 2855 Rep - Following fields are set: 2856 * RMSError rms error on the (X,Y). 2857 * AvgError average error on the (X,Y). 2858 * AvgRelError average relative error on the non-zero Y 2859 * MaxError maximum error 2860 NON-WEIGHTED ERRORS ARE CALCULATED 2861 2862 IMPORTANT: 2863 this subroitine doesn't calculate task's condition number for K<>0. 2864 2865 NOTE 1: additional nodes are added to the spline outside of the fitting 2866 interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done 2867 for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so 2868 it is natural to force linearity outside of this interval. 2869 2870 NOTE 2: function automatically sorts points, so caller may pass unsorted 2871 array. 2872 2873 -- ALGLIB PROJECT -- 2874 Copyright 18.08.2009 by Bochkanov Sergey 2875 *************************************************************************/ 2876 void 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, const xparams _xparams = alglib::xdefault); 2877 void 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, const xparams _xparams = alglib::xdefault); 2878 2879 2880 /************************************************************************* 2881 Weighted fitting by penalized cubic spline. 2882 2883 Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build 2884 basis functions. Basis functions are cubic splines with natural boundary 2885 conditions. Problem is regularized by adding non-linearity penalty to the 2886 usual least squares penalty function: 2887 2888 S(x) = arg min { LS + P }, where 2889 LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty 2890 P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty 2891 rho - tunable constant given by user 2892 C - automatically determined scale parameter, 2893 makes penalty invariant with respect to scaling of X, Y, W. 2894 2895 ! COMMERCIAL EDITION OF ALGLIB: 2896 ! 2897 ! Commercial Edition of ALGLIB includes following important improvements 2898 ! of this function: 2899 ! * high-performance native backend with same C# interface (C# version) 2900 ! * multithreading support (C++ and C# versions) 2901 ! * hardware vendor (Intel) implementations of linear algebra primitives 2902 ! (C++ and C# versions, x86/x64 platform) 2903 ! 2904 ! We recommend you to read 'Working with commercial version' section of 2905 ! ALGLIB Reference Manual in order to find out how to use performance- 2906 ! related features provided by commercial edition of ALGLIB. 2907 2908 INPUT PARAMETERS: 2909 X - points, array[0..N-1]. 2910 Y - function values, array[0..N-1]. 2911 W - weights, array[0..N-1] 2912 Each summand in square sum of approximation deviations from 2913 given values is multiplied by the square of corresponding 2914 weight. Fill it by 1's if you don't want to solve weighted 2915 problem. 2916 N - number of points (optional): 2917 * N>0 2918 * if given, only first N elements of X/Y/W are processed 2919 * if not given, automatically determined from X/Y/W sizes 2920 M - number of basis functions ( = number_of_nodes), M>=4. 2921 Rho - regularization constant passed by user. It penalizes 2922 nonlinearity in the regression spline. It is logarithmically 2923 scaled, i.e. actual value of regularization constant is 2924 calculated as 10^Rho. It is automatically scaled so that: 2925 * Rho=2.0 corresponds to moderate amount of nonlinearity 2926 * generally, it should be somewhere in the [-8.0,+8.0] 2927 If you do not want to penalize nonlineary, 2928 pass small Rho. Values as low as -15 should work. 2929 2930 OUTPUT PARAMETERS: 2931 Info- same format as in LSFitLinearWC() subroutine. 2932 * Info>0 task is solved 2933 * Info<=0 an error occured: 2934 -4 means inconvergence of internal SVD or 2935 Cholesky decomposition; problem may be 2936 too ill-conditioned (very rare) 2937 S - spline interpolant. 2938 Rep - Following fields are set: 2939 * RMSError rms error on the (X,Y). 2940 * AvgError average error on the (X,Y). 2941 * AvgRelError average relative error on the non-zero Y 2942 * MaxError maximum error 2943 NON-WEIGHTED ERRORS ARE CALCULATED 2944 2945 IMPORTANT: 2946 this subroitine doesn't calculate task's condition number for K<>0. 2947 2948 NOTE 1: additional nodes are added to the spline outside of the fitting 2949 interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done 2950 for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so 2951 it is natural to force linearity outside of this interval. 2952 2953 NOTE 2: function automatically sorts points, so caller may pass unsorted 2954 array. 2955 2956 -- ALGLIB PROJECT -- 2957 Copyright 19.10.2010 by Bochkanov Sergey 2958 *************************************************************************/ 2959 void 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, const xparams _xparams = alglib::xdefault); 2960 void 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, const xparams _xparams = alglib::xdefault); 2961 2962 2963 /************************************************************************* 2964 This function builds monotone cubic Hermite interpolant. This interpolant 2965 is monotonic in [x(0),x(n-1)] and is constant outside of this interval. 2966 2967 In case y[] form non-monotonic sequence, interpolant is piecewise 2968 monotonic. Say, for x=(0,1,2,3,4) and y=(0,1,2,1,0) interpolant will 2969 monotonically grow at [0..2] and monotonically decrease at [2..4]. 2970 2971 INPUT PARAMETERS: 2972 X - spline nodes, array[0..N-1]. Subroutine automatically 2973 sorts points, so caller may pass unsorted array. 2974 Y - function values, array[0..N-1] 2975 N - the number of points(N>=2). 2976 2977 OUTPUT PARAMETERS: 2978 C - spline interpolant. 2979 2980 -- ALGLIB PROJECT -- 2981 Copyright 21.06.2012 by Bochkanov Sergey 2982 *************************************************************************/ 2983 void spline1dbuildmonotone(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2984 void spline1dbuildmonotone(const real_1d_array &x, const real_1d_array &y, spline1dinterpolant &c, const xparams _xparams = alglib::xdefault); 2985 #endif 2986 2987 #if defined(AE_COMPILE_PARAMETRIC) || !defined(AE_PARTIAL_BUILD) 2988 /************************************************************************* 2989 This function builds non-periodic 2-dimensional parametric spline which 2990 starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]). 2991 2992 INPUT PARAMETERS: 2993 XY - points, array[0..N-1,0..1]. 2994 XY[I,0:1] corresponds to the Ith point. 2995 Order of points is important! 2996 N - points count, N>=5 for Akima splines, N>=2 for other types of 2997 splines. 2998 ST - spline type: 2999 * 0 Akima spline 3000 * 1 parabolically terminated Catmull-Rom spline (Tension=0) 3001 * 2 parabolically terminated cubic spline 3002 PT - parameterization type: 3003 * 0 uniform 3004 * 1 chord length 3005 * 2 centripetal 3006 3007 OUTPUT PARAMETERS: 3008 P - parametric spline interpolant 3009 3010 3011 NOTES: 3012 * this function assumes that there all consequent points are distinct. 3013 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on. 3014 However, non-consequent points may coincide, i.e. we can have (x0,y0)= 3015 =(x2,y2). 3016 3017 -- ALGLIB PROJECT -- 3018 Copyright 28.05.2010 by Bochkanov Sergey 3019 *************************************************************************/ 3020 void pspline2build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p, const xparams _xparams = alglib::xdefault); 3021 3022 3023 /************************************************************************* 3024 This function builds non-periodic 3-dimensional parametric spline which 3025 starts at (X[0],Y[0],Z[0]) and ends at (X[N-1],Y[N-1],Z[N-1]). 3026 3027 Same as PSpline2Build() function, but for 3D, so we won't duplicate its 3028 description here. 3029 3030 -- ALGLIB PROJECT -- 3031 Copyright 28.05.2010 by Bochkanov Sergey 3032 *************************************************************************/ 3033 void pspline3build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p, const xparams _xparams = alglib::xdefault); 3034 3035 3036 /************************************************************************* 3037 This function builds periodic 2-dimensional parametric spline which 3038 starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then 3039 back to (X[0],Y[0]). 3040 3041 INPUT PARAMETERS: 3042 XY - points, array[0..N-1,0..1]. 3043 XY[I,0:1] corresponds to the Ith point. 3044 XY[N-1,0:1] must be different from XY[0,0:1]. 3045 Order of points is important! 3046 N - points count, N>=3 for other types of splines. 3047 ST - spline type: 3048 * 1 Catmull-Rom spline (Tension=0) with cyclic boundary conditions 3049 * 2 cubic spline with cyclic boundary conditions 3050 PT - parameterization type: 3051 * 0 uniform 3052 * 1 chord length 3053 * 2 centripetal 3054 3055 OUTPUT PARAMETERS: 3056 P - parametric spline interpolant 3057 3058 3059 NOTES: 3060 * this function assumes that there all consequent points are distinct. 3061 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on. 3062 However, non-consequent points may coincide, i.e. we can have (x0,y0)= 3063 =(x2,y2). 3064 * last point of sequence is NOT equal to the first point. You shouldn't 3065 make curve "explicitly periodic" by making them equal. 3066 3067 -- ALGLIB PROJECT -- 3068 Copyright 28.05.2010 by Bochkanov Sergey 3069 *************************************************************************/ 3070 void pspline2buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p, const xparams _xparams = alglib::xdefault); 3071 3072 3073 /************************************************************************* 3074 This function builds periodic 3-dimensional parametric spline which 3075 starts at (X[0],Y[0],Z[0]), goes through all points to (X[N-1],Y[N-1],Z[N-1]) 3076 and then back to (X[0],Y[0],Z[0]). 3077 3078 Same as PSpline2Build() function, but for 3D, so we won't duplicate its 3079 description here. 3080 3081 -- ALGLIB PROJECT -- 3082 Copyright 28.05.2010 by Bochkanov Sergey 3083 *************************************************************************/ 3084 void pspline3buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p, const xparams _xparams = alglib::xdefault); 3085 3086 3087 /************************************************************************* 3088 This function returns vector of parameter values correspoding to points. 3089 3090 I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P) we 3091 have 3092 (X[0],Y[0]) = PSpline2Calc(P,U[0]), 3093 (X[1],Y[1]) = PSpline2Calc(P,U[1]), 3094 (X[2],Y[2]) = PSpline2Calc(P,U[2]), 3095 ... 3096 3097 INPUT PARAMETERS: 3098 P - parametric spline interpolant 3099 3100 OUTPUT PARAMETERS: 3101 N - array size 3102 T - array[0..N-1] 3103 3104 3105 NOTES: 3106 * for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1 3107 * for periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1 3108 3109 -- ALGLIB PROJECT -- 3110 Copyright 28.05.2010 by Bochkanov Sergey 3111 *************************************************************************/ 3112 void pspline2parametervalues(const pspline2interpolant &p, ae_int_t &n, real_1d_array &t, const xparams _xparams = alglib::xdefault); 3113 3114 3115 /************************************************************************* 3116 This function returns vector of parameter values correspoding to points. 3117 3118 Same as PSpline2ParameterValues(), but for 3D. 3119 3120 -- ALGLIB PROJECT -- 3121 Copyright 28.05.2010 by Bochkanov Sergey 3122 *************************************************************************/ 3123 void pspline3parametervalues(const pspline3interpolant &p, ae_int_t &n, real_1d_array &t, const xparams _xparams = alglib::xdefault); 3124 3125 3126 /************************************************************************* 3127 This function calculates the value of the parametric spline for a given 3128 value of parameter T 3129 3130 INPUT PARAMETERS: 3131 P - parametric spline interpolant 3132 T - point: 3133 * T in [0,1] corresponds to interval spanned by points 3134 * for non-periodic splines T<0 (or T>1) correspond to parts of 3135 the curve before the first (after the last) point 3136 * for periodic splines T<0 (or T>1) are projected into [0,1] 3137 by making T=T-floor(T). 3138 3139 OUTPUT PARAMETERS: 3140 X - X-position 3141 Y - Y-position 3142 3143 3144 -- ALGLIB PROJECT -- 3145 Copyright 28.05.2010 by Bochkanov Sergey 3146 *************************************************************************/ 3147 void pspline2calc(const pspline2interpolant &p, const double t, double &x, double &y, const xparams _xparams = alglib::xdefault); 3148 3149 3150 /************************************************************************* 3151 This function calculates the value of the parametric spline for a given 3152 value of parameter T. 3153 3154 INPUT PARAMETERS: 3155 P - parametric spline interpolant 3156 T - point: 3157 * T in [0,1] corresponds to interval spanned by points 3158 * for non-periodic splines T<0 (or T>1) correspond to parts of 3159 the curve before the first (after the last) point 3160 * for periodic splines T<0 (or T>1) are projected into [0,1] 3161 by making T=T-floor(T). 3162 3163 OUTPUT PARAMETERS: 3164 X - X-position 3165 Y - Y-position 3166 Z - Z-position 3167 3168 3169 -- ALGLIB PROJECT -- 3170 Copyright 28.05.2010 by Bochkanov Sergey 3171 *************************************************************************/ 3172 void pspline3calc(const pspline3interpolant &p, const double t, double &x, double &y, double &z, const xparams _xparams = alglib::xdefault); 3173 3174 3175 /************************************************************************* 3176 This function calculates tangent vector for a given value of parameter T 3177 3178 INPUT PARAMETERS: 3179 P - parametric spline interpolant 3180 T - point: 3181 * T in [0,1] corresponds to interval spanned by points 3182 * for non-periodic splines T<0 (or T>1) correspond to parts of 3183 the curve before the first (after the last) point 3184 * for periodic splines T<0 (or T>1) are projected into [0,1] 3185 by making T=T-floor(T). 3186 3187 OUTPUT PARAMETERS: 3188 X - X-component of tangent vector (normalized) 3189 Y - Y-component of tangent vector (normalized) 3190 3191 NOTE: 3192 X^2+Y^2 is either 1 (for non-zero tangent vector) or 0. 3193 3194 3195 -- ALGLIB PROJECT -- 3196 Copyright 28.05.2010 by Bochkanov Sergey 3197 *************************************************************************/ 3198 void pspline2tangent(const pspline2interpolant &p, const double t, double &x, double &y, const xparams _xparams = alglib::xdefault); 3199 3200 3201 /************************************************************************* 3202 This function calculates tangent vector for a given value of parameter T 3203 3204 INPUT PARAMETERS: 3205 P - parametric spline interpolant 3206 T - point: 3207 * T in [0,1] corresponds to interval spanned by points 3208 * for non-periodic splines T<0 (or T>1) correspond to parts of 3209 the curve before the first (after the last) point 3210 * for periodic splines T<0 (or T>1) are projected into [0,1] 3211 by making T=T-floor(T). 3212 3213 OUTPUT PARAMETERS: 3214 X - X-component of tangent vector (normalized) 3215 Y - Y-component of tangent vector (normalized) 3216 Z - Z-component of tangent vector (normalized) 3217 3218 NOTE: 3219 X^2+Y^2+Z^2 is either 1 (for non-zero tangent vector) or 0. 3220 3221 3222 -- ALGLIB PROJECT -- 3223 Copyright 28.05.2010 by Bochkanov Sergey 3224 *************************************************************************/ 3225 void pspline3tangent(const pspline3interpolant &p, const double t, double &x, double &y, double &z, const xparams _xparams = alglib::xdefault); 3226 3227 3228 /************************************************************************* 3229 This function calculates derivative, i.e. it returns (dX/dT,dY/dT). 3230 3231 INPUT PARAMETERS: 3232 P - parametric spline interpolant 3233 T - point: 3234 * T in [0,1] corresponds to interval spanned by points 3235 * for non-periodic splines T<0 (or T>1) correspond to parts of 3236 the curve before the first (after the last) point 3237 * for periodic splines T<0 (or T>1) are projected into [0,1] 3238 by making T=T-floor(T). 3239 3240 OUTPUT PARAMETERS: 3241 X - X-value 3242 DX - X-derivative 3243 Y - Y-value 3244 DY - Y-derivative 3245 3246 3247 -- ALGLIB PROJECT -- 3248 Copyright 28.05.2010 by Bochkanov Sergey 3249 *************************************************************************/ 3250 void pspline2diff(const pspline2interpolant &p, const double t, double &x, double &dx, double &y, double &dy, const xparams _xparams = alglib::xdefault); 3251 3252 3253 /************************************************************************* 3254 This function calculates derivative, i.e. it returns (dX/dT,dY/dT,dZ/dT). 3255 3256 INPUT PARAMETERS: 3257 P - parametric spline interpolant 3258 T - point: 3259 * T in [0,1] corresponds to interval spanned by points 3260 * for non-periodic splines T<0 (or T>1) correspond to parts of 3261 the curve before the first (after the last) point 3262 * for periodic splines T<0 (or T>1) are projected into [0,1] 3263 by making T=T-floor(T). 3264 3265 OUTPUT PARAMETERS: 3266 X - X-value 3267 DX - X-derivative 3268 Y - Y-value 3269 DY - Y-derivative 3270 Z - Z-value 3271 DZ - Z-derivative 3272 3273 3274 -- ALGLIB PROJECT -- 3275 Copyright 28.05.2010 by Bochkanov Sergey 3276 *************************************************************************/ 3277 void pspline3diff(const pspline3interpolant &p, const double t, double &x, double &dx, double &y, double &dy, double &z, double &dz, const xparams _xparams = alglib::xdefault); 3278 3279 3280 /************************************************************************* 3281 This function calculates first and second derivative with respect to T. 3282 3283 INPUT PARAMETERS: 3284 P - parametric spline interpolant 3285 T - point: 3286 * T in [0,1] corresponds to interval spanned by points 3287 * for non-periodic splines T<0 (or T>1) correspond to parts of 3288 the curve before the first (after the last) point 3289 * for periodic splines T<0 (or T>1) are projected into [0,1] 3290 by making T=T-floor(T). 3291 3292 OUTPUT PARAMETERS: 3293 X - X-value 3294 DX - derivative 3295 D2X - second derivative 3296 Y - Y-value 3297 DY - derivative 3298 D2Y - second derivative 3299 3300 3301 -- ALGLIB PROJECT -- 3302 Copyright 28.05.2010 by Bochkanov Sergey 3303 *************************************************************************/ 3304 void pspline2diff2(const pspline2interpolant &p, const double t, double &x, double &dx, double &d2x, double &y, double &dy, double &d2y, const xparams _xparams = alglib::xdefault); 3305 3306 3307 /************************************************************************* 3308 This function calculates first and second derivative with respect to T. 3309 3310 INPUT PARAMETERS: 3311 P - parametric spline interpolant 3312 T - point: 3313 * T in [0,1] corresponds to interval spanned by points 3314 * for non-periodic splines T<0 (or T>1) correspond to parts of 3315 the curve before the first (after the last) point 3316 * for periodic splines T<0 (or T>1) are projected into [0,1] 3317 by making T=T-floor(T). 3318 3319 OUTPUT PARAMETERS: 3320 X - X-value 3321 DX - derivative 3322 D2X - second derivative 3323 Y - Y-value 3324 DY - derivative 3325 D2Y - second derivative 3326 Z - Z-value 3327 DZ - derivative 3328 D2Z - second derivative 3329 3330 3331 -- ALGLIB PROJECT -- 3332 Copyright 28.05.2010 by Bochkanov Sergey 3333 *************************************************************************/ 3334 void 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, const xparams _xparams = alglib::xdefault); 3335 3336 3337 /************************************************************************* 3338 This function calculates arc length, i.e. length of curve between t=a 3339 and t=b. 3340 3341 INPUT PARAMETERS: 3342 P - parametric spline interpolant 3343 A,B - parameter values corresponding to arc ends: 3344 * B>A will result in positive length returned 3345 * B<A will result in negative length returned 3346 3347 RESULT: 3348 length of arc starting at T=A and ending at T=B. 3349 3350 3351 -- ALGLIB PROJECT -- 3352 Copyright 30.05.2010 by Bochkanov Sergey 3353 *************************************************************************/ 3354 double pspline2arclength(const pspline2interpolant &p, const double a, const double b, const xparams _xparams = alglib::xdefault); 3355 3356 3357 /************************************************************************* 3358 This function calculates arc length, i.e. length of curve between t=a 3359 and t=b. 3360 3361 INPUT PARAMETERS: 3362 P - parametric spline interpolant 3363 A,B - parameter values corresponding to arc ends: 3364 * B>A will result in positive length returned 3365 * B<A will result in negative length returned 3366 3367 RESULT: 3368 length of arc starting at T=A and ending at T=B. 3369 3370 3371 -- ALGLIB PROJECT -- 3372 Copyright 30.05.2010 by Bochkanov Sergey 3373 *************************************************************************/ 3374 double pspline3arclength(const pspline3interpolant &p, const double a, const double b, const xparams _xparams = alglib::xdefault); 3375 3376 3377 /************************************************************************* 3378 This subroutine fits piecewise linear curve to points with Ramer-Douglas- 3379 Peucker algorithm. This function performs PARAMETRIC fit, i.e. it can be 3380 used to fit curves like circles. 3381 3382 On input it accepts dataset which describes parametric multidimensional 3383 curve X(t), with X being vector, and t taking values in [0,N), where N is 3384 a number of points in dataset. As result, it returns reduced dataset X2, 3385 which can be used to build parametric curve X2(t), which approximates 3386 X(t) with desired precision (or has specified number of sections). 3387 3388 3389 INPUT PARAMETERS: 3390 X - array of multidimensional points: 3391 * at least N elements, leading N elements are used if more 3392 than N elements were specified 3393 * order of points is IMPORTANT because it is parametric 3394 fit 3395 * each row of array is one point which has D coordinates 3396 N - number of elements in X 3397 D - number of dimensions (elements per row of X) 3398 StopM - stopping condition - desired number of sections: 3399 * at most M sections are generated by this function 3400 * less than M sections can be generated if we have N<M 3401 (or some X are non-distinct). 3402 * zero StopM means that algorithm does not stop after 3403 achieving some pre-specified section count 3404 StopEps - stopping condition - desired precision: 3405 * algorithm stops after error in each section is at most Eps 3406 * zero Eps means that algorithm does not stop after 3407 achieving some pre-specified precision 3408 3409 OUTPUT PARAMETERS: 3410 X2 - array of corner points for piecewise approximation, 3411 has length NSections+1 or zero (for NSections=0). 3412 Idx2 - array of indexes (parameter values): 3413 * has length NSections+1 or zero (for NSections=0). 3414 * each element of Idx2 corresponds to same-numbered 3415 element of X2 3416 * each element of Idx2 is index of corresponding element 3417 of X2 at original array X, i.e. I-th row of X2 is 3418 Idx2[I]-th row of X. 3419 * elements of Idx2 can be treated as parameter values 3420 which should be used when building new parametric curve 3421 * Idx2[0]=0, Idx2[NSections]=N-1 3422 NSections- number of sections found by algorithm, NSections<=M, 3423 NSections can be zero for degenerate datasets 3424 (N<=1 or all X[] are non-distinct). 3425 3426 NOTE: algorithm stops after: 3427 a) dividing curve into StopM sections 3428 b) achieving required precision StopEps 3429 c) dividing curve into N-1 sections 3430 If both StopM and StopEps are non-zero, algorithm is stopped by the 3431 FIRST criterion which is satisfied. In case both StopM and StopEps 3432 are zero, algorithm stops because of (c). 3433 3434 -- ALGLIB -- 3435 Copyright 02.10.2014 by Bochkanov Sergey 3436 *************************************************************************/ 3437 void 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, const xparams _xparams = alglib::xdefault); 3438 #endif 3439 3440 #if defined(AE_COMPILE_SPLINE3D) || !defined(AE_PARTIAL_BUILD) 3441 /************************************************************************* 3442 This subroutine calculates the value of the trilinear or tricubic spline at 3443 the given point (X,Y,Z). 3444 3445 INPUT PARAMETERS: 3446 C - coefficients table. 3447 Built by BuildBilinearSpline or BuildBicubicSpline. 3448 X, Y, 3449 Z - point 3450 3451 Result: 3452 S(x,y,z) 3453 3454 -- ALGLIB PROJECT -- 3455 Copyright 26.04.2012 by Bochkanov Sergey 3456 *************************************************************************/ 3457 double spline3dcalc(const spline3dinterpolant &c, const double x, const double y, const double z, const xparams _xparams = alglib::xdefault); 3458 3459 3460 /************************************************************************* 3461 This subroutine performs linear transformation of the spline argument. 3462 3463 INPUT PARAMETERS: 3464 C - spline interpolant 3465 AX, BX - transformation coefficients: x = A*u + B 3466 AY, BY - transformation coefficients: y = A*v + B 3467 AZ, BZ - transformation coefficients: z = A*w + B 3468 3469 OUTPUT PARAMETERS: 3470 C - transformed spline 3471 3472 -- ALGLIB PROJECT -- 3473 Copyright 26.04.2012 by Bochkanov Sergey 3474 *************************************************************************/ 3475 void spline3dlintransxyz(const spline3dinterpolant &c, const double ax, const double bx, const double ay, const double by, const double az, const double bz, const xparams _xparams = alglib::xdefault); 3476 3477 3478 /************************************************************************* 3479 This subroutine performs linear transformation of the spline. 3480 3481 INPUT PARAMETERS: 3482 C - spline interpolant. 3483 A, B- transformation coefficients: S2(x,y) = A*S(x,y,z) + B 3484 3485 OUTPUT PARAMETERS: 3486 C - transformed spline 3487 3488 -- ALGLIB PROJECT -- 3489 Copyright 26.04.2012 by Bochkanov Sergey 3490 *************************************************************************/ 3491 void spline3dlintransf(const spline3dinterpolant &c, const double a, const double b, const xparams _xparams = alglib::xdefault); 3492 3493 3494 /************************************************************************* 3495 Trilinear spline resampling 3496 3497 INPUT PARAMETERS: 3498 A - array[0..OldXCount*OldYCount*OldZCount-1], function 3499 values at the old grid, : 3500 A[0] x=0,y=0,z=0 3501 A[1] x=1,y=0,z=0 3502 A[..] ... 3503 A[..] x=oldxcount-1,y=0,z=0 3504 A[..] x=0,y=1,z=0 3505 A[..] ... 3506 ... 3507 OldZCount - old Z-count, OldZCount>1 3508 OldYCount - old Y-count, OldYCount>1 3509 OldXCount - old X-count, OldXCount>1 3510 NewZCount - new Z-count, NewZCount>1 3511 NewYCount - new Y-count, NewYCount>1 3512 NewXCount - new X-count, NewXCount>1 3513 3514 OUTPUT PARAMETERS: 3515 B - array[0..NewXCount*NewYCount*NewZCount-1], function 3516 values at the new grid: 3517 B[0] x=0,y=0,z=0 3518 B[1] x=1,y=0,z=0 3519 B[..] ... 3520 B[..] x=newxcount-1,y=0,z=0 3521 B[..] x=0,y=1,z=0 3522 B[..] ... 3523 ... 3524 3525 -- ALGLIB routine -- 3526 26.04.2012 3527 Copyright by Bochkanov Sergey 3528 *************************************************************************/ 3529 void 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, const xparams _xparams = alglib::xdefault); 3530 3531 3532 /************************************************************************* 3533 This subroutine builds trilinear vector-valued spline. 3534 3535 INPUT PARAMETERS: 3536 X - spline abscissas, array[0..N-1] 3537 Y - spline ordinates, array[0..M-1] 3538 Z - spline applicates, array[0..L-1] 3539 F - function values, array[0..M*N*L*D-1]: 3540 * first D elements store D values at (X[0],Y[0],Z[0]) 3541 * next D elements store D values at (X[1],Y[0],Z[0]) 3542 * next D elements store D values at (X[2],Y[0],Z[0]) 3543 * ... 3544 * next D elements store D values at (X[0],Y[1],Z[0]) 3545 * next D elements store D values at (X[1],Y[1],Z[0]) 3546 * next D elements store D values at (X[2],Y[1],Z[0]) 3547 * ... 3548 * next D elements store D values at (X[0],Y[0],Z[1]) 3549 * next D elements store D values at (X[1],Y[0],Z[1]) 3550 * next D elements store D values at (X[2],Y[0],Z[1]) 3551 * ... 3552 * general form - D function values at (X[i],Y[j]) are stored 3553 at F[D*(N*(M*K+J)+I)...D*(N*(M*K+J)+I)+D-1]. 3554 M,N, 3555 L - grid size, M>=2, N>=2, L>=2 3556 D - vector dimension, D>=1 3557 3558 OUTPUT PARAMETERS: 3559 C - spline interpolant 3560 3561 -- ALGLIB PROJECT -- 3562 Copyright 26.04.2012 by Bochkanov Sergey 3563 *************************************************************************/ 3564 void 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, const xparams _xparams = alglib::xdefault); 3565 3566 3567 /************************************************************************* 3568 This subroutine calculates bilinear or bicubic vector-valued spline at the 3569 given point (X,Y,Z). 3570 3571 INPUT PARAMETERS: 3572 C - spline interpolant. 3573 X, Y, 3574 Z - point 3575 F - output buffer, possibly preallocated array. In case array size 3576 is large enough to store result, it is not reallocated. Array 3577 which is too short will be reallocated 3578 3579 OUTPUT PARAMETERS: 3580 F - array[D] (or larger) which stores function values 3581 3582 -- ALGLIB PROJECT -- 3583 Copyright 26.04.2012 by Bochkanov Sergey 3584 *************************************************************************/ 3585 void spline3dcalcvbuf(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f, const xparams _xparams = alglib::xdefault); 3586 3587 3588 /************************************************************************* 3589 This subroutine calculates trilinear or tricubic vector-valued spline at the 3590 given point (X,Y,Z). 3591 3592 INPUT PARAMETERS: 3593 C - spline interpolant. 3594 X, Y, 3595 Z - point 3596 3597 OUTPUT PARAMETERS: 3598 F - array[D] which stores function values. F is out-parameter and 3599 it is reallocated after call to this function. In case you 3600 want to reuse previously allocated F, you may use 3601 Spline2DCalcVBuf(), which reallocates F only when it is too 3602 small. 3603 3604 -- ALGLIB PROJECT -- 3605 Copyright 26.04.2012 by Bochkanov Sergey 3606 *************************************************************************/ 3607 void spline3dcalcv(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f, const xparams _xparams = alglib::xdefault); 3608 3609 3610 /************************************************************************* 3611 This subroutine unpacks tri-dimensional spline into the coefficients table 3612 3613 INPUT PARAMETERS: 3614 C - spline interpolant. 3615 3616 Result: 3617 N - grid size (X) 3618 M - grid size (Y) 3619 L - grid size (Z) 3620 D - number of components 3621 SType- spline type. Currently, only one spline type is supported: 3622 trilinear spline, as indicated by SType=1. 3623 Tbl - spline coefficients: [0..(N-1)*(M-1)*(L-1)*D-1, 0..13]. 3624 For T=0..D-1 (component index), I = 0...N-2 (x index), 3625 J=0..M-2 (y index), K=0..L-2 (z index): 3626 Q := T + I*D + J*D*(N-1) + K*D*(N-1)*(M-1), 3627 3628 Q-th row stores decomposition for T-th component of the 3629 vector-valued function 3630 3631 Tbl[Q,0] = X[i] 3632 Tbl[Q,1] = X[i+1] 3633 Tbl[Q,2] = Y[j] 3634 Tbl[Q,3] = Y[j+1] 3635 Tbl[Q,4] = Z[k] 3636 Tbl[Q,5] = Z[k+1] 3637 3638 Tbl[Q,6] = C000 3639 Tbl[Q,7] = C100 3640 Tbl[Q,8] = C010 3641 Tbl[Q,9] = C110 3642 Tbl[Q,10]= C001 3643 Tbl[Q,11]= C101 3644 Tbl[Q,12]= C011 3645 Tbl[Q,13]= C111 3646 On each grid square spline is equals to: 3647 S(x) = SUM(c[i,j,k]*(x^i)*(y^j)*(z^k), i=0..1, j=0..1, k=0..1) 3648 t = x-x[j] 3649 u = y-y[i] 3650 v = z-z[k] 3651 3652 NOTE: format of Tbl is given for SType=1. Future versions of 3653 ALGLIB can use different formats for different values of 3654 SType. 3655 3656 -- ALGLIB PROJECT -- 3657 Copyright 26.04.2012 by Bochkanov Sergey 3658 *************************************************************************/ 3659 void 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, const xparams _xparams = alglib::xdefault); 3660 #endif 3661 3662 #if defined(AE_COMPILE_POLINT) || !defined(AE_PARTIAL_BUILD) 3663 /************************************************************************* 3664 Conversion from barycentric representation to Chebyshev basis. 3665 This function has O(N^2) complexity. 3666 3667 INPUT PARAMETERS: 3668 P - polynomial in barycentric form 3669 A,B - base interval for Chebyshev polynomials (see below) 3670 A<>B 3671 3672 OUTPUT PARAMETERS 3673 T - coefficients of Chebyshev representation; 3674 P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N-1 }, 3675 where Ti - I-th Chebyshev polynomial. 3676 3677 NOTES: 3678 barycentric interpolant passed as P may be either polynomial obtained 3679 from polynomial interpolation/ fitting or rational function which is 3680 NOT polynomial. We can't distinguish between these two cases, and this 3681 algorithm just tries to work assuming that P IS a polynomial. If not, 3682 algorithm will return results, but they won't have any meaning. 3683 3684 -- ALGLIB -- 3685 Copyright 30.09.2010 by Bochkanov Sergey 3686 *************************************************************************/ 3687 void polynomialbar2cheb(const barycentricinterpolant &p, const double a, const double b, real_1d_array &t, const xparams _xparams = alglib::xdefault); 3688 3689 3690 /************************************************************************* 3691 Conversion from Chebyshev basis to barycentric representation. 3692 This function has O(N^2) complexity. 3693 3694 INPUT PARAMETERS: 3695 T - coefficients of Chebyshev representation; 3696 P(x) = sum { T[i]*Ti(2*(x-A)/(B-A)-1), i=0..N }, 3697 where Ti - I-th Chebyshev polynomial. 3698 N - number of coefficients: 3699 * if given, only leading N elements of T are used 3700 * if not given, automatically determined from size of T 3701 A,B - base interval for Chebyshev polynomials (see above) 3702 A<B 3703 3704 OUTPUT PARAMETERS 3705 P - polynomial in barycentric form 3706 3707 -- ALGLIB -- 3708 Copyright 30.09.2010 by Bochkanov Sergey 3709 *************************************************************************/ 3710 void polynomialcheb2bar(const real_1d_array &t, const ae_int_t n, const double a, const double b, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3711 void polynomialcheb2bar(const real_1d_array &t, const double a, const double b, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3712 3713 3714 /************************************************************************* 3715 Conversion from barycentric representation to power basis. 3716 This function has O(N^2) complexity. 3717 3718 INPUT PARAMETERS: 3719 P - polynomial in barycentric form 3720 C - offset (see below); 0.0 is used as default value. 3721 S - scale (see below); 1.0 is used as default value. S<>0. 3722 3723 OUTPUT PARAMETERS 3724 A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 } 3725 N - number of coefficients (polynomial degree plus 1) 3726 3727 NOTES: 3728 1. this function accepts offset and scale, which can be set to improve 3729 numerical properties of polynomial. For example, if P was obtained as 3730 result of interpolation on [-1,+1], you can set C=0 and S=1 and 3731 represent P as sum of 1, x, x^2, x^3 and so on. In most cases you it 3732 is exactly what you need. 3733 3734 However, if your interpolation model was built on [999,1001], you will 3735 see significant growth of numerical errors when using {1, x, x^2, x^3} 3736 as basis. Representing P as sum of 1, (x-1000), (x-1000)^2, (x-1000)^3 3737 will be better option. Such representation can be obtained by using 3738 1000.0 as offset C and 1.0 as scale S. 3739 3740 2. power basis is ill-conditioned and tricks described above can't solve 3741 this problem completely. This function will return coefficients in 3742 any case, but for N>8 they will become unreliable. However, N's 3743 less than 5 are pretty safe. 3744 3745 3. barycentric interpolant passed as P may be either polynomial obtained 3746 from polynomial interpolation/ fitting or rational function which is 3747 NOT polynomial. We can't distinguish between these two cases, and this 3748 algorithm just tries to work assuming that P IS a polynomial. If not, 3749 algorithm will return results, but they won't have any meaning. 3750 3751 -- ALGLIB -- 3752 Copyright 30.09.2010 by Bochkanov Sergey 3753 *************************************************************************/ 3754 void polynomialbar2pow(const barycentricinterpolant &p, const double c, const double s, real_1d_array &a, const xparams _xparams = alglib::xdefault); 3755 void polynomialbar2pow(const barycentricinterpolant &p, real_1d_array &a, const xparams _xparams = alglib::xdefault); 3756 3757 3758 /************************************************************************* 3759 Conversion from power basis to barycentric representation. 3760 This function has O(N^2) complexity. 3761 3762 INPUT PARAMETERS: 3763 A - coefficients, P(x) = sum { A[i]*((X-C)/S)^i, i=0..N-1 } 3764 N - number of coefficients (polynomial degree plus 1) 3765 * if given, only leading N elements of A are used 3766 * if not given, automatically determined from size of A 3767 C - offset (see below); 0.0 is used as default value. 3768 S - scale (see below); 1.0 is used as default value. S<>0. 3769 3770 OUTPUT PARAMETERS 3771 P - polynomial in barycentric form 3772 3773 3774 NOTES: 3775 1. this function accepts offset and scale, which can be set to improve 3776 numerical properties of polynomial. For example, if you interpolate on 3777 [-1,+1], you can set C=0 and S=1 and convert from sum of 1, x, x^2, 3778 x^3 and so on. In most cases you it is exactly what you need. 3779 3780 However, if your interpolation model was built on [999,1001], you will 3781 see significant growth of numerical errors when using {1, x, x^2, x^3} 3782 as input basis. Converting from sum of 1, (x-1000), (x-1000)^2, 3783 (x-1000)^3 will be better option (you have to specify 1000.0 as offset 3784 C and 1.0 as scale S). 3785 3786 2. power basis is ill-conditioned and tricks described above can't solve 3787 this problem completely. This function will return barycentric model 3788 in any case, but for N>8 accuracy well degrade. However, N's less than 3789 5 are pretty safe. 3790 3791 -- ALGLIB -- 3792 Copyright 30.09.2010 by Bochkanov Sergey 3793 *************************************************************************/ 3794 void polynomialpow2bar(const real_1d_array &a, const ae_int_t n, const double c, const double s, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3795 void polynomialpow2bar(const real_1d_array &a, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3796 3797 3798 /************************************************************************* 3799 Lagrange intepolant: generation of the model on the general grid. 3800 This function has O(N^2) complexity. 3801 3802 INPUT PARAMETERS: 3803 X - abscissas, array[0..N-1] 3804 Y - function values, array[0..N-1] 3805 N - number of points, N>=1 3806 3807 OUTPUT PARAMETERS 3808 P - barycentric model which represents Lagrange interpolant 3809 (see ratint unit info and BarycentricCalc() description for 3810 more information). 3811 3812 -- ALGLIB -- 3813 Copyright 02.12.2009 by Bochkanov Sergey 3814 *************************************************************************/ 3815 void polynomialbuild(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3816 void polynomialbuild(const real_1d_array &x, const real_1d_array &y, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3817 3818 3819 /************************************************************************* 3820 Lagrange intepolant: generation of the model on equidistant grid. 3821 This function has O(N) complexity. 3822 3823 INPUT PARAMETERS: 3824 A - left boundary of [A,B] 3825 B - right boundary of [A,B] 3826 Y - function values at the nodes, array[0..N-1] 3827 N - number of points, N>=1 3828 for N=1 a constant model is constructed. 3829 3830 OUTPUT PARAMETERS 3831 P - barycentric model which represents Lagrange interpolant 3832 (see ratint unit info and BarycentricCalc() description for 3833 more information). 3834 3835 -- ALGLIB -- 3836 Copyright 03.12.2009 by Bochkanov Sergey 3837 *************************************************************************/ 3838 void polynomialbuildeqdist(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3839 void polynomialbuildeqdist(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3840 3841 3842 /************************************************************************* 3843 Lagrange intepolant on Chebyshev grid (first kind). 3844 This function has O(N) complexity. 3845 3846 INPUT PARAMETERS: 3847 A - left boundary of [A,B] 3848 B - right boundary of [A,B] 3849 Y - function values at the nodes, array[0..N-1], 3850 Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n))) 3851 N - number of points, N>=1 3852 for N=1 a constant model is constructed. 3853 3854 OUTPUT PARAMETERS 3855 P - barycentric model which represents Lagrange interpolant 3856 (see ratint unit info and BarycentricCalc() description for 3857 more information). 3858 3859 -- ALGLIB -- 3860 Copyright 03.12.2009 by Bochkanov Sergey 3861 *************************************************************************/ 3862 void polynomialbuildcheb1(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3863 void polynomialbuildcheb1(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3864 3865 3866 /************************************************************************* 3867 Lagrange intepolant on Chebyshev grid (second kind). 3868 This function has O(N) complexity. 3869 3870 INPUT PARAMETERS: 3871 A - left boundary of [A,B] 3872 B - right boundary of [A,B] 3873 Y - function values at the nodes, array[0..N-1], 3874 Y[I] = Y(0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1))) 3875 N - number of points, N>=1 3876 for N=1 a constant model is constructed. 3877 3878 OUTPUT PARAMETERS 3879 P - barycentric model which represents Lagrange interpolant 3880 (see ratint unit info and BarycentricCalc() description for 3881 more information). 3882 3883 -- ALGLIB -- 3884 Copyright 03.12.2009 by Bochkanov Sergey 3885 *************************************************************************/ 3886 void polynomialbuildcheb2(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3887 void polynomialbuildcheb2(const double a, const double b, const real_1d_array &y, barycentricinterpolant &p, const xparams _xparams = alglib::xdefault); 3888 3889 3890 /************************************************************************* 3891 Fast equidistant polynomial interpolation function with O(N) complexity 3892 3893 INPUT PARAMETERS: 3894 A - left boundary of [A,B] 3895 B - right boundary of [A,B] 3896 F - function values, array[0..N-1] 3897 N - number of points on equidistant grid, N>=1 3898 for N=1 a constant model is constructed. 3899 T - position where P(x) is calculated 3900 3901 RESULT 3902 value of the Lagrange interpolant at T 3903 3904 IMPORTANT 3905 this function provides fast interface which is not overflow-safe 3906 nor it is very precise. 3907 the best option is to use PolynomialBuildEqDist()/BarycentricCalc() 3908 subroutines unless you are pretty sure that your data will not result 3909 in overflow. 3910 3911 -- ALGLIB -- 3912 Copyright 02.12.2009 by Bochkanov Sergey 3913 *************************************************************************/ 3914 double polynomialcalceqdist(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t, const xparams _xparams = alglib::xdefault); 3915 double polynomialcalceqdist(const double a, const double b, const real_1d_array &f, const double t, const xparams _xparams = alglib::xdefault); 3916 3917 3918 /************************************************************************* 3919 Fast polynomial interpolation function on Chebyshev points (first kind) 3920 with O(N) complexity. 3921 3922 INPUT PARAMETERS: 3923 A - left boundary of [A,B] 3924 B - right boundary of [A,B] 3925 F - function values, array[0..N-1] 3926 N - number of points on Chebyshev grid (first kind), 3927 X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*(2*i+1)/(2*n)) 3928 for N=1 a constant model is constructed. 3929 T - position where P(x) is calculated 3930 3931 RESULT 3932 value of the Lagrange interpolant at T 3933 3934 IMPORTANT 3935 this function provides fast interface which is not overflow-safe 3936 nor it is very precise. 3937 the best option is to use PolIntBuildCheb1()/BarycentricCalc() 3938 subroutines unless you are pretty sure that your data will not result 3939 in overflow. 3940 3941 -- ALGLIB -- 3942 Copyright 02.12.2009 by Bochkanov Sergey 3943 *************************************************************************/ 3944 double polynomialcalccheb1(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t, const xparams _xparams = alglib::xdefault); 3945 double polynomialcalccheb1(const double a, const double b, const real_1d_array &f, const double t, const xparams _xparams = alglib::xdefault); 3946 3947 3948 /************************************************************************* 3949 Fast polynomial interpolation function on Chebyshev points (second kind) 3950 with O(N) complexity. 3951 3952 INPUT PARAMETERS: 3953 A - left boundary of [A,B] 3954 B - right boundary of [A,B] 3955 F - function values, array[0..N-1] 3956 N - number of points on Chebyshev grid (second kind), 3957 X[i] = 0.5*(B+A) + 0.5*(B-A)*Cos(PI*i/(n-1)) 3958 for N=1 a constant model is constructed. 3959 T - position where P(x) is calculated 3960 3961 RESULT 3962 value of the Lagrange interpolant at T 3963 3964 IMPORTANT 3965 this function provides fast interface which is not overflow-safe 3966 nor it is very precise. 3967 the best option is to use PolIntBuildCheb2()/BarycentricCalc() 3968 subroutines unless you are pretty sure that your data will not result 3969 in overflow. 3970 3971 -- ALGLIB -- 3972 Copyright 02.12.2009 by Bochkanov Sergey 3973 *************************************************************************/ 3974 double polynomialcalccheb2(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t, const xparams _xparams = alglib::xdefault); 3975 double polynomialcalccheb2(const double a, const double b, const real_1d_array &f, const double t, const xparams _xparams = alglib::xdefault); 3976 #endif 3977 3978 #if defined(AE_COMPILE_LSFIT) || !defined(AE_PARTIAL_BUILD) 3979 /************************************************************************* 3980 This subroutine fits piecewise linear curve to points with Ramer-Douglas- 3981 Peucker algorithm, which stops after generating specified number of linear 3982 sections. 3983 3984 IMPORTANT: 3985 * it does NOT perform least-squares fitting; it builds curve, but this 3986 curve does not minimize some least squares metric. See description of 3987 RDP algorithm (say, in Wikipedia) for more details on WHAT is performed. 3988 * this function does NOT work with parametric curves (i.e. curves which 3989 can be represented as {X(t),Y(t)}. It works with curves which can be 3990 represented as Y(X). Thus, it is impossible to model figures like 3991 circles with this functions. 3992 If you want to work with parametric curves, you should use 3993 ParametricRDPFixed() function provided by "Parametric" subpackage of 3994 "Interpolation" package. 3995 3996 INPUT PARAMETERS: 3997 X - array of X-coordinates: 3998 * at least N elements 3999 * can be unordered (points are automatically sorted) 4000 * this function may accept non-distinct X (see below for 4001 more information on handling of such inputs) 4002 Y - array of Y-coordinates: 4003 * at least N elements 4004 N - number of elements in X/Y 4005 M - desired number of sections: 4006 * at most M sections are generated by this function 4007 * less than M sections can be generated if we have N<M 4008 (or some X are non-distinct). 4009 4010 OUTPUT PARAMETERS: 4011 X2 - X-values of corner points for piecewise approximation, 4012 has length NSections+1 or zero (for NSections=0). 4013 Y2 - Y-values of corner points, 4014 has length NSections+1 or zero (for NSections=0). 4015 NSections- number of sections found by algorithm, NSections<=M, 4016 NSections can be zero for degenerate datasets 4017 (N<=1 or all X[] are non-distinct). 4018 4019 NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of 4020 curve, (X2[NSection-1],Y2[NSection-1]) is the last point. 4021 4022 -- ALGLIB -- 4023 Copyright 02.10.2014 by Bochkanov Sergey 4024 *************************************************************************/ 4025 void 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, const xparams _xparams = alglib::xdefault); 4026 4027 4028 /************************************************************************* 4029 This subroutine fits piecewise linear curve to points with Ramer-Douglas- 4030 Peucker algorithm, which stops after achieving desired precision. 4031 4032 IMPORTANT: 4033 * it performs non-least-squares fitting; it builds curve, but this curve 4034 does not minimize some least squares metric. See description of RDP 4035 algorithm (say, in Wikipedia) for more details on WHAT is performed. 4036 * this function does NOT work with parametric curves (i.e. curves which 4037 can be represented as {X(t),Y(t)}. It works with curves which can be 4038 represented as Y(X). Thus, it is impossible to model figures like circles 4039 with this functions. 4040 If you want to work with parametric curves, you should use 4041 ParametricRDPFixed() function provided by "Parametric" subpackage of 4042 "Interpolation" package. 4043 4044 INPUT PARAMETERS: 4045 X - array of X-coordinates: 4046 * at least N elements 4047 * can be unordered (points are automatically sorted) 4048 * this function may accept non-distinct X (see below for 4049 more information on handling of such inputs) 4050 Y - array of Y-coordinates: 4051 * at least N elements 4052 N - number of elements in X/Y 4053 Eps - positive number, desired precision. 4054 4055 4056 OUTPUT PARAMETERS: 4057 X2 - X-values of corner points for piecewise approximation, 4058 has length NSections+1 or zero (for NSections=0). 4059 Y2 - Y-values of corner points, 4060 has length NSections+1 or zero (for NSections=0). 4061 NSections- number of sections found by algorithm, 4062 NSections can be zero for degenerate datasets 4063 (N<=1 or all X[] are non-distinct). 4064 4065 NOTE: X2/Y2 are ordered arrays, i.e. (X2[0],Y2[0]) is a first point of 4066 curve, (X2[NSection-1],Y2[NSection-1]) is the last point. 4067 4068 -- ALGLIB -- 4069 Copyright 02.10.2014 by Bochkanov Sergey 4070 *************************************************************************/ 4071 void 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, const xparams _xparams = alglib::xdefault); 4072 4073 4074 /************************************************************************* 4075 Fitting by polynomials in barycentric form. This function provides simple 4076 unterface for unconstrained unweighted fitting. See PolynomialFitWC() if 4077 you need constrained fitting. 4078 4079 Task is linear, so linear least squares solver is used. Complexity of this 4080 computational scheme is O(N*M^2), mostly dominated by least squares solver 4081 4082 SEE ALSO: 4083 PolynomialFitWC() 4084 4085 NOTES: 4086 you can convert P from barycentric form to the power or Chebyshev 4087 basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from 4088 POLINT subpackage. 4089 4090 ! COMMERCIAL EDITION OF ALGLIB: 4091 ! 4092 ! Commercial Edition of ALGLIB includes following important improvements 4093 ! of this function: 4094 ! * high-performance native backend with same C# interface (C# version) 4095 ! * multithreading support (C++ and C# versions) 4096 ! * hardware vendor (Intel) implementations of linear algebra primitives 4097 ! (C++ and C# versions, x86/x64 platform) 4098 ! 4099 ! We recommend you to read 'Working with commercial version' section of 4100 ! ALGLIB Reference Manual in order to find out how to use performance- 4101 ! related features provided by commercial edition of ALGLIB. 4102 4103 INPUT PARAMETERS: 4104 X - points, array[0..N-1]. 4105 Y - function values, array[0..N-1]. 4106 N - number of points, N>0 4107 * if given, only leading N elements of X/Y are used 4108 * if not given, automatically determined from sizes of X/Y 4109 M - number of basis functions (= polynomial_degree + 1), M>=1 4110 4111 OUTPUT PARAMETERS: 4112 Info- same format as in LSFitLinearW() subroutine: 4113 * Info>0 task is solved 4114 * Info<=0 an error occured: 4115 -4 means inconvergence of internal SVD 4116 P - interpolant in barycentric form. 4117 Rep - report, same format as in LSFitLinearW() subroutine. 4118 Following fields are set: 4119 * RMSError rms error on the (X,Y). 4120 * AvgError average error on the (X,Y). 4121 * AvgRelError average relative error on the non-zero Y 4122 * MaxError maximum error 4123 NON-WEIGHTED ERRORS ARE CALCULATED 4124 4125 -- ALGLIB PROJECT -- 4126 Copyright 10.12.2009 by Bochkanov Sergey 4127 *************************************************************************/ 4128 void 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, const xparams _xparams = alglib::xdefault); 4129 void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep, const xparams _xparams = alglib::xdefault); 4130 4131 4132 /************************************************************************* 4133 Weighted fitting by polynomials in barycentric form, with constraints on 4134 function values or first derivatives. 4135 4136 Small regularizing term is used when solving constrained tasks (to improve 4137 stability). 4138 4139 Task is linear, so linear least squares solver is used. Complexity of this 4140 computational scheme is O(N*M^2), mostly dominated by least squares solver 4141 4142 SEE ALSO: 4143 PolynomialFit() 4144 4145 NOTES: 4146 you can convert P from barycentric form to the power or Chebyshev 4147 basis with PolynomialBar2Pow() or PolynomialBar2Cheb() functions from 4148 POLINT subpackage. 4149 4150 ! COMMERCIAL EDITION OF ALGLIB: 4151 ! 4152 ! Commercial Edition of ALGLIB includes following important improvements 4153 ! of this function: 4154 ! * high-performance native backend with same C# interface (C# version) 4155 ! * multithreading support (C++ and C# versions) 4156 ! * hardware vendor (Intel) implementations of linear algebra primitives 4157 ! (C++ and C# versions, x86/x64 platform) 4158 ! 4159 ! We recommend you to read 'Working with commercial version' section of 4160 ! ALGLIB Reference Manual in order to find out how to use performance- 4161 ! related features provided by commercial edition of ALGLIB. 4162 4163 INPUT PARAMETERS: 4164 X - points, array[0..N-1]. 4165 Y - function values, array[0..N-1]. 4166 W - weights, array[0..N-1] 4167 Each summand in square sum of approximation deviations from 4168 given values is multiplied by the square of corresponding 4169 weight. Fill it by 1's if you don't want to solve weighted 4170 task. 4171 N - number of points, N>0. 4172 * if given, only leading N elements of X/Y/W are used 4173 * if not given, automatically determined from sizes of X/Y/W 4174 XC - points where polynomial values/derivatives are constrained, 4175 array[0..K-1]. 4176 YC - values of constraints, array[0..K-1] 4177 DC - array[0..K-1], types of constraints: 4178 * DC[i]=0 means that P(XC[i])=YC[i] 4179 * DC[i]=1 means that P'(XC[i])=YC[i] 4180 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 4181 K - number of constraints, 0<=K<M. 4182 K=0 means no constraints (XC/YC/DC are not used in such cases) 4183 M - number of basis functions (= polynomial_degree + 1), M>=1 4184 4185 OUTPUT PARAMETERS: 4186 Info- same format as in LSFitLinearW() subroutine: 4187 * Info>0 task is solved 4188 * Info<=0 an error occured: 4189 -4 means inconvergence of internal SVD 4190 -3 means inconsistent constraints 4191 P - interpolant in barycentric form. 4192 Rep - report, same format as in LSFitLinearW() subroutine. 4193 Following fields are set: 4194 * RMSError rms error on the (X,Y). 4195 * AvgError average error on the (X,Y). 4196 * AvgRelError average relative error on the non-zero Y 4197 * MaxError maximum error 4198 NON-WEIGHTED ERRORS ARE CALCULATED 4199 4200 IMPORTANT: 4201 this subroitine doesn't calculate task's condition number for K<>0. 4202 4203 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 4204 4205 Setting constraints can lead to undesired results, like ill-conditioned 4206 behavior, or inconsistency being detected. From the other side, it allows 4207 us to improve quality of the fit. Here we summarize our experience with 4208 constrained regression splines: 4209 * even simple constraints can be inconsistent, see Wikipedia article on 4210 this subject: http://en.wikipedia.org/wiki/Birkhoff_interpolation 4211 * the greater is M (given fixed constraints), the more chances that 4212 constraints will be consistent 4213 * in the general case, consistency of constraints is NOT GUARANTEED. 4214 * in the one special cases, however, we can guarantee consistency. This 4215 case is: M>1 and constraints on the function values (NOT DERIVATIVES) 4216 4217 Our final recommendation is to use constraints WHEN AND ONLY when you 4218 can't solve your task without them. Anything beyond special cases given 4219 above is not guaranteed and may result in inconsistency. 4220 4221 -- ALGLIB PROJECT -- 4222 Copyright 10.12.2009 by Bochkanov Sergey 4223 *************************************************************************/ 4224 void 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, const xparams _xparams = alglib::xdefault); 4225 void 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, const xparams _xparams = alglib::xdefault); 4226 4227 4228 /************************************************************************* 4229 This function calculates value of four-parameter logistic (4PL) model at 4230 specified point X. 4PL model has following form: 4231 4232 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) 4233 4234 INPUT PARAMETERS: 4235 X - current point, X>=0: 4236 * zero X is correctly handled even for B<=0 4237 * negative X results in exception. 4238 A, B, C, D- parameters of 4PL model: 4239 * A is unconstrained 4240 * B is unconstrained; zero or negative values are handled 4241 correctly. 4242 * C>0, non-positive value results in exception 4243 * D is unconstrained 4244 4245 RESULT: 4246 model value at X 4247 4248 NOTE: if B=0, denominator is assumed to be equal to 2.0 even for zero X 4249 (strictly speaking, 0^0 is undefined). 4250 4251 NOTE: this function also throws exception if all input parameters are 4252 correct, but overflow was detected during calculations. 4253 4254 NOTE: this function performs a lot of checks; if you need really high 4255 performance, consider evaluating model yourself, without checking 4256 for degenerate cases. 4257 4258 4259 -- ALGLIB PROJECT -- 4260 Copyright 14.05.2014 by Bochkanov Sergey 4261 *************************************************************************/ 4262 double logisticcalc4(const double x, const double a, const double b, const double c, const double d, const xparams _xparams = alglib::xdefault); 4263 4264 4265 /************************************************************************* 4266 This function calculates value of five-parameter logistic (5PL) model at 4267 specified point X. 5PL model has following form: 4268 4269 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) 4270 4271 INPUT PARAMETERS: 4272 X - current point, X>=0: 4273 * zero X is correctly handled even for B<=0 4274 * negative X results in exception. 4275 A, B, C, D, G- parameters of 5PL model: 4276 * A is unconstrained 4277 * B is unconstrained; zero or negative values are handled 4278 correctly. 4279 * C>0, non-positive value results in exception 4280 * D is unconstrained 4281 * G>0, non-positive value results in exception 4282 4283 RESULT: 4284 model value at X 4285 4286 NOTE: if B=0, denominator is assumed to be equal to Power(2.0,G) even for 4287 zero X (strictly speaking, 0^0 is undefined). 4288 4289 NOTE: this function also throws exception if all input parameters are 4290 correct, but overflow was detected during calculations. 4291 4292 NOTE: this function performs a lot of checks; if you need really high 4293 performance, consider evaluating model yourself, without checking 4294 for degenerate cases. 4295 4296 4297 -- ALGLIB PROJECT -- 4298 Copyright 14.05.2014 by Bochkanov Sergey 4299 *************************************************************************/ 4300 double logisticcalc5(const double x, const double a, const double b, const double c, const double d, const double g, const xparams _xparams = alglib::xdefault); 4301 4302 4303 /************************************************************************* 4304 This function fits four-parameter logistic (4PL) model to data provided 4305 by user. 4PL model has following form: 4306 4307 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) 4308 4309 Here: 4310 * A, D - unconstrained (see LogisticFit4EC() for constrained 4PL) 4311 * B>=0 4312 * C>0 4313 4314 IMPORTANT: output of this function is constrained in such way that B>0. 4315 Because 4PL model is symmetric with respect to B, there is no 4316 need to explore B<0. Constraining B makes algorithm easier 4317 to stabilize and debug. 4318 Users who for some reason prefer to work with negative B's 4319 should transform output themselves (swap A and D, replace B by 4320 -B). 4321 4322 4PL fitting is implemented as follows: 4323 * we perform small number of restarts from random locations which helps to 4324 solve problem of bad local extrema. Locations are only partially random 4325 - we use input data to determine good initial guess, but we include 4326 controlled amount of randomness. 4327 * we perform Levenberg-Marquardt fitting with very tight constraints on 4328 parameters B and C - it allows us to find good initial guess for the 4329 second stage without risk of running into "flat spot". 4330 * second Levenberg-Marquardt round is performed without excessive 4331 constraints. Results from the previous round are used as initial guess. 4332 * after fitting is done, we compare results with best values found so far, 4333 rewrite "best solution" if needed, and move to next random location. 4334 4335 Overall algorithm is very stable and is not prone to bad local extrema. 4336 Furthermore, it automatically scales when input data have very large or 4337 very small range. 4338 4339 INPUT PARAMETERS: 4340 X - array[N], stores X-values. 4341 MUST include only non-negative numbers (but may include 4342 zero values). Can be unsorted. 4343 Y - array[N], values to fit. 4344 N - number of points. If N is less than length of X/Y, only 4345 leading N elements are used. 4346 4347 OUTPUT PARAMETERS: 4348 A, B, C, D- parameters of 4PL model 4349 Rep - fitting report. This structure has many fields, but ONLY 4350 ONES LISTED BELOW ARE SET: 4351 * Rep.IterationsCount - number of iterations performed 4352 * Rep.RMSError - root-mean-square error 4353 * Rep.AvgError - average absolute error 4354 * Rep.AvgRelError - average relative error (calculated for 4355 non-zero Y-values) 4356 * Rep.MaxError - maximum absolute error 4357 * Rep.R2 - coefficient of determination, R-squared. This 4358 coefficient is calculated as R2=1-RSS/TSS (in case 4359 of nonlinear regression there are multiple ways to 4360 define R2, each of them giving different results). 4361 4362 NOTE: for stability reasons the B parameter is restricted by [1/1000,1000] 4363 range. It prevents algorithm from making trial steps deep into the 4364 area of bad parameters. 4365 4366 NOTE: after you obtained coefficients, you can evaluate model with 4367 LogisticCalc4() function. 4368 4369 NOTE: if you need better control over fitting process than provided by this 4370 function, you may use LogisticFit45X(). 4371 4372 NOTE: step is automatically scaled according to scale of parameters being 4373 fitted before we compare its length with EpsX. Thus, this function 4374 can be used to fit data with very small or very large values without 4375 changing EpsX. 4376 4377 4378 -- ALGLIB PROJECT -- 4379 Copyright 14.02.2014 by Bochkanov Sergey 4380 *************************************************************************/ 4381 void 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, const xparams _xparams = alglib::xdefault); 4382 4383 4384 /************************************************************************* 4385 This function fits four-parameter logistic (4PL) model to data provided 4386 by user, with optional constraints on parameters A and D. 4PL model has 4387 following form: 4388 4389 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) 4390 4391 Here: 4392 * A, D - with optional equality constraints 4393 * B>=0 4394 * C>0 4395 4396 IMPORTANT: output of this function is constrained in such way that B>0. 4397 Because 4PL model is symmetric with respect to B, there is no 4398 need to explore B<0. Constraining B makes algorithm easier 4399 to stabilize and debug. 4400 Users who for some reason prefer to work with negative B's 4401 should transform output themselves (swap A and D, replace B by 4402 -B). 4403 4404 4PL fitting is implemented as follows: 4405 * we perform small number of restarts from random locations which helps to 4406 solve problem of bad local extrema. Locations are only partially random 4407 - we use input data to determine good initial guess, but we include 4408 controlled amount of randomness. 4409 * we perform Levenberg-Marquardt fitting with very tight constraints on 4410 parameters B and C - it allows us to find good initial guess for the 4411 second stage without risk of running into "flat spot". 4412 * second Levenberg-Marquardt round is performed without excessive 4413 constraints. Results from the previous round are used as initial guess. 4414 * after fitting is done, we compare results with best values found so far, 4415 rewrite "best solution" if needed, and move to next random location. 4416 4417 Overall algorithm is very stable and is not prone to bad local extrema. 4418 Furthermore, it automatically scales when input data have very large or 4419 very small range. 4420 4421 INPUT PARAMETERS: 4422 X - array[N], stores X-values. 4423 MUST include only non-negative numbers (but may include 4424 zero values). Can be unsorted. 4425 Y - array[N], values to fit. 4426 N - number of points. If N is less than length of X/Y, only 4427 leading N elements are used. 4428 CnstrLeft- optional equality constraint for model value at the left 4429 boundary (at X=0). Specify NAN (Not-a-Number) if you do 4430 not need constraint on the model value at X=0 (in C++ you 4431 can pass alglib::fp_nan as parameter, in C# it will be 4432 Double.NaN). 4433 See below, section "EQUALITY CONSTRAINTS" for more 4434 information about constraints. 4435 CnstrRight- optional equality constraint for model value at X=infinity. 4436 Specify NAN (Not-a-Number) if you do not need constraint 4437 on the model value (in C++ you can pass alglib::fp_nan as 4438 parameter, in C# it will be Double.NaN). 4439 See below, section "EQUALITY CONSTRAINTS" for more 4440 information about constraints. 4441 4442 OUTPUT PARAMETERS: 4443 A, B, C, D- parameters of 4PL model 4444 Rep - fitting report. This structure has many fields, but ONLY 4445 ONES LISTED BELOW ARE SET: 4446 * Rep.IterationsCount - number of iterations performed 4447 * Rep.RMSError - root-mean-square error 4448 * Rep.AvgError - average absolute error 4449 * Rep.AvgRelError - average relative error (calculated for 4450 non-zero Y-values) 4451 * Rep.MaxError - maximum absolute error 4452 * Rep.R2 - coefficient of determination, R-squared. This 4453 coefficient is calculated as R2=1-RSS/TSS (in case 4454 of nonlinear regression there are multiple ways to 4455 define R2, each of them giving different results). 4456 4457 NOTE: for stability reasons the B parameter is restricted by [1/1000,1000] 4458 range. It prevents algorithm from making trial steps deep into the 4459 area of bad parameters. 4460 4461 NOTE: after you obtained coefficients, you can evaluate model with 4462 LogisticCalc4() function. 4463 4464 NOTE: if you need better control over fitting process than provided by this 4465 function, you may use LogisticFit45X(). 4466 4467 NOTE: step is automatically scaled according to scale of parameters being 4468 fitted before we compare its length with EpsX. Thus, this function 4469 can be used to fit data with very small or very large values without 4470 changing EpsX. 4471 4472 EQUALITY CONSTRAINTS ON PARAMETERS 4473 4474 4PL/5PL solver supports equality constraints on model values at the left 4475 boundary (X=0) and right boundary (X=infinity). These constraints are 4476 completely optional and you can specify both of them, only one - or no 4477 constraints at all. 4478 4479 Parameter CnstrLeft contains left constraint (or NAN for unconstrained 4480 fitting), and CnstrRight contains right one. For 4PL, left constraint 4481 ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on 4482 D. That's because 4PL model is normalized in such way that B>=0. 4483 4484 4485 -- ALGLIB PROJECT -- 4486 Copyright 14.02.2014 by Bochkanov Sergey 4487 *************************************************************************/ 4488 void 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, const xparams _xparams = alglib::xdefault); 4489 4490 4491 /************************************************************************* 4492 This function fits five-parameter logistic (5PL) model to data provided 4493 by user. 5PL model has following form: 4494 4495 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) 4496 4497 Here: 4498 * A, D - unconstrained 4499 * B - unconstrained 4500 * C>0 4501 * G>0 4502 4503 IMPORTANT: unlike in 4PL fitting, output of this function is NOT 4504 constrained in such way that B is guaranteed to be positive. 4505 Furthermore, unlike 4PL, 5PL model is NOT symmetric with 4506 respect to B, so you can NOT transform model to equivalent one, 4507 with B having desired sign (>0 or <0). 4508 4509 5PL fitting is implemented as follows: 4510 * we perform small number of restarts from random locations which helps to 4511 solve problem of bad local extrema. Locations are only partially random 4512 - we use input data to determine good initial guess, but we include 4513 controlled amount of randomness. 4514 * we perform Levenberg-Marquardt fitting with very tight constraints on 4515 parameters B and C - it allows us to find good initial guess for the 4516 second stage without risk of running into "flat spot". Parameter G is 4517 fixed at G=1. 4518 * second Levenberg-Marquardt round is performed without excessive 4519 constraints on B and C, but with G still equal to 1. Results from the 4520 previous round are used as initial guess. 4521 * third Levenberg-Marquardt round relaxes constraints on G and tries two 4522 different models - one with B>0 and one with B<0. 4523 * after fitting is done, we compare results with best values found so far, 4524 rewrite "best solution" if needed, and move to next random location. 4525 4526 Overall algorithm is very stable and is not prone to bad local extrema. 4527 Furthermore, it automatically scales when input data have very large or 4528 very small range. 4529 4530 INPUT PARAMETERS: 4531 X - array[N], stores X-values. 4532 MUST include only non-negative numbers (but may include 4533 zero values). Can be unsorted. 4534 Y - array[N], values to fit. 4535 N - number of points. If N is less than length of X/Y, only 4536 leading N elements are used. 4537 4538 OUTPUT PARAMETERS: 4539 A,B,C,D,G- parameters of 5PL model 4540 Rep - fitting report. This structure has many fields, but ONLY 4541 ONES LISTED BELOW ARE SET: 4542 * Rep.IterationsCount - number of iterations performed 4543 * Rep.RMSError - root-mean-square error 4544 * Rep.AvgError - average absolute error 4545 * Rep.AvgRelError - average relative error (calculated for 4546 non-zero Y-values) 4547 * Rep.MaxError - maximum absolute error 4548 * Rep.R2 - coefficient of determination, R-squared. This 4549 coefficient is calculated as R2=1-RSS/TSS (in case 4550 of nonlinear regression there are multiple ways to 4551 define R2, each of them giving different results). 4552 4553 NOTE: for better stability B parameter is restricted by [+-1/1000,+-1000] 4554 range, and G is restricted by [1/10,10] range. It prevents algorithm 4555 from making trial steps deep into the area of bad parameters. 4556 4557 NOTE: after you obtained coefficients, you can evaluate model with 4558 LogisticCalc5() function. 4559 4560 NOTE: if you need better control over fitting process than provided by this 4561 function, you may use LogisticFit45X(). 4562 4563 NOTE: step is automatically scaled according to scale of parameters being 4564 fitted before we compare its length with EpsX. Thus, this function 4565 can be used to fit data with very small or very large values without 4566 changing EpsX. 4567 4568 4569 -- ALGLIB PROJECT -- 4570 Copyright 14.02.2014 by Bochkanov Sergey 4571 *************************************************************************/ 4572 void 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, const xparams _xparams = alglib::xdefault); 4573 4574 4575 /************************************************************************* 4576 This function fits five-parameter logistic (5PL) model to data provided 4577 by user, subject to optional equality constraints on parameters A and D. 4578 5PL model has following form: 4579 4580 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) 4581 4582 Here: 4583 * A, D - with optional equality constraints 4584 * B - unconstrained 4585 * C>0 4586 * G>0 4587 4588 IMPORTANT: unlike in 4PL fitting, output of this function is NOT 4589 constrained in such way that B is guaranteed to be positive. 4590 Furthermore, unlike 4PL, 5PL model is NOT symmetric with 4591 respect to B, so you can NOT transform model to equivalent one, 4592 with B having desired sign (>0 or <0). 4593 4594 5PL fitting is implemented as follows: 4595 * we perform small number of restarts from random locations which helps to 4596 solve problem of bad local extrema. Locations are only partially random 4597 - we use input data to determine good initial guess, but we include 4598 controlled amount of randomness. 4599 * we perform Levenberg-Marquardt fitting with very tight constraints on 4600 parameters B and C - it allows us to find good initial guess for the 4601 second stage without risk of running into "flat spot". Parameter G is 4602 fixed at G=1. 4603 * second Levenberg-Marquardt round is performed without excessive 4604 constraints on B and C, but with G still equal to 1. Results from the 4605 previous round are used as initial guess. 4606 * third Levenberg-Marquardt round relaxes constraints on G and tries two 4607 different models - one with B>0 and one with B<0. 4608 * after fitting is done, we compare results with best values found so far, 4609 rewrite "best solution" if needed, and move to next random location. 4610 4611 Overall algorithm is very stable and is not prone to bad local extrema. 4612 Furthermore, it automatically scales when input data have very large or 4613 very small range. 4614 4615 INPUT PARAMETERS: 4616 X - array[N], stores X-values. 4617 MUST include only non-negative numbers (but may include 4618 zero values). Can be unsorted. 4619 Y - array[N], values to fit. 4620 N - number of points. If N is less than length of X/Y, only 4621 leading N elements are used. 4622 CnstrLeft- optional equality constraint for model value at the left 4623 boundary (at X=0). Specify NAN (Not-a-Number) if you do 4624 not need constraint on the model value at X=0 (in C++ you 4625 can pass alglib::fp_nan as parameter, in C# it will be 4626 Double.NaN). 4627 See below, section "EQUALITY CONSTRAINTS" for more 4628 information about constraints. 4629 CnstrRight- optional equality constraint for model value at X=infinity. 4630 Specify NAN (Not-a-Number) if you do not need constraint 4631 on the model value (in C++ you can pass alglib::fp_nan as 4632 parameter, in C# it will be Double.NaN). 4633 See below, section "EQUALITY CONSTRAINTS" for more 4634 information about constraints. 4635 4636 OUTPUT PARAMETERS: 4637 A,B,C,D,G- parameters of 5PL model 4638 Rep - fitting report. This structure has many fields, but ONLY 4639 ONES LISTED BELOW ARE SET: 4640 * Rep.IterationsCount - number of iterations performed 4641 * Rep.RMSError - root-mean-square error 4642 * Rep.AvgError - average absolute error 4643 * Rep.AvgRelError - average relative error (calculated for 4644 non-zero Y-values) 4645 * Rep.MaxError - maximum absolute error 4646 * Rep.R2 - coefficient of determination, R-squared. This 4647 coefficient is calculated as R2=1-RSS/TSS (in case 4648 of nonlinear regression there are multiple ways to 4649 define R2, each of them giving different results). 4650 4651 NOTE: for better stability B parameter is restricted by [+-1/1000,+-1000] 4652 range, and G is restricted by [1/10,10] range. It prevents algorithm 4653 from making trial steps deep into the area of bad parameters. 4654 4655 NOTE: after you obtained coefficients, you can evaluate model with 4656 LogisticCalc5() function. 4657 4658 NOTE: if you need better control over fitting process than provided by this 4659 function, you may use LogisticFit45X(). 4660 4661 NOTE: step is automatically scaled according to scale of parameters being 4662 fitted before we compare its length with EpsX. Thus, this function 4663 can be used to fit data with very small or very large values without 4664 changing EpsX. 4665 4666 EQUALITY CONSTRAINTS ON PARAMETERS 4667 4668 5PL solver supports equality constraints on model values at the left 4669 boundary (X=0) and right boundary (X=infinity). These constraints are 4670 completely optional and you can specify both of them, only one - or no 4671 constraints at all. 4672 4673 Parameter CnstrLeft contains left constraint (or NAN for unconstrained 4674 fitting), and CnstrRight contains right one. 4675 4676 Unlike 4PL one, 5PL model is NOT symmetric with respect to change in sign 4677 of B. Thus, negative B's are possible, and left constraint may constrain 4678 parameter A (for positive B's) - or parameter D (for negative B's). 4679 Similarly changes meaning of right constraint. 4680 4681 You do not have to decide what parameter to constrain - algorithm will 4682 automatically determine correct parameters as fitting progresses. However, 4683 question highlighted above is important when you interpret fitting results. 4684 4685 4686 -- ALGLIB PROJECT -- 4687 Copyright 14.02.2014 by Bochkanov Sergey 4688 *************************************************************************/ 4689 void 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, const xparams _xparams = alglib::xdefault); 4690 4691 4692 /************************************************************************* 4693 This is "expert" 4PL/5PL fitting function, which can be used if you need 4694 better control over fitting process than provided by LogisticFit4() or 4695 LogisticFit5(). 4696 4697 This function fits model of the form 4698 4699 F(x|A,B,C,D) = D+(A-D)/(1+Power(x/C,B)) (4PL model) 4700 4701 or 4702 4703 F(x|A,B,C,D,G) = D+(A-D)/Power(1+Power(x/C,B),G) (5PL model) 4704 4705 Here: 4706 * A, D - unconstrained 4707 * B>=0 for 4PL, unconstrained for 5PL 4708 * C>0 4709 * G>0 (if present) 4710 4711 INPUT PARAMETERS: 4712 X - array[N], stores X-values. 4713 MUST include only non-negative numbers (but may include 4714 zero values). Can be unsorted. 4715 Y - array[N], values to fit. 4716 N - number of points. If N is less than length of X/Y, only 4717 leading N elements are used. 4718 CnstrLeft- optional equality constraint for model value at the left 4719 boundary (at X=0). Specify NAN (Not-a-Number) if you do 4720 not need constraint on the model value at X=0 (in C++ you 4721 can pass alglib::fp_nan as parameter, in C# it will be 4722 Double.NaN). 4723 See below, section "EQUALITY CONSTRAINTS" for more 4724 information about constraints. 4725 CnstrRight- optional equality constraint for model value at X=infinity. 4726 Specify NAN (Not-a-Number) if you do not need constraint 4727 on the model value (in C++ you can pass alglib::fp_nan as 4728 parameter, in C# it will be Double.NaN). 4729 See below, section "EQUALITY CONSTRAINTS" for more 4730 information about constraints. 4731 Is4PL - whether 4PL or 5PL models are fitted 4732 LambdaV - regularization coefficient, LambdaV>=0. 4733 Set it to zero unless you know what you are doing. 4734 EpsX - stopping condition (step size), EpsX>=0. 4735 Zero value means that small step is automatically chosen. 4736 See notes below for more information. 4737 RsCnt - number of repeated restarts from random points. 4PL/5PL 4738 models are prone to problem of bad local extrema. Utilizing 4739 multiple random restarts allows us to improve algorithm 4740 convergence. 4741 RsCnt>=0. 4742 Zero value means that function automatically choose small 4743 amount of restarts (recommended). 4744 4745 OUTPUT PARAMETERS: 4746 A, B, C, D- parameters of 4PL model 4747 G - parameter of 5PL model; for Is4PL=True, G=1 is returned. 4748 Rep - fitting report. This structure has many fields, but ONLY 4749 ONES LISTED BELOW ARE SET: 4750 * Rep.IterationsCount - number of iterations performed 4751 * Rep.RMSError - root-mean-square error 4752 * Rep.AvgError - average absolute error 4753 * Rep.AvgRelError - average relative error (calculated for 4754 non-zero Y-values) 4755 * Rep.MaxError - maximum absolute error 4756 * Rep.R2 - coefficient of determination, R-squared. This 4757 coefficient is calculated as R2=1-RSS/TSS (in case 4758 of nonlinear regression there are multiple ways to 4759 define R2, each of them giving different results). 4760 4761 NOTE: for better stability B parameter is restricted by [+-1/1000,+-1000] 4762 range, and G is restricted by [1/10,10] range. It prevents algorithm 4763 from making trial steps deep into the area of bad parameters. 4764 4765 NOTE: after you obtained coefficients, you can evaluate model with 4766 LogisticCalc5() function. 4767 4768 NOTE: step is automatically scaled according to scale of parameters being 4769 fitted before we compare its length with EpsX. Thus, this function 4770 can be used to fit data with very small or very large values without 4771 changing EpsX. 4772 4773 EQUALITY CONSTRAINTS ON PARAMETERS 4774 4775 4PL/5PL solver supports equality constraints on model values at the left 4776 boundary (X=0) and right boundary (X=infinity). These constraints are 4777 completely optional and you can specify both of them, only one - or no 4778 constraints at all. 4779 4780 Parameter CnstrLeft contains left constraint (or NAN for unconstrained 4781 fitting), and CnstrRight contains right one. For 4PL, left constraint 4782 ALWAYS corresponds to parameter A, and right one is ALWAYS constraint on 4783 D. That's because 4PL model is normalized in such way that B>=0. 4784 4785 For 5PL model things are different. Unlike 4PL one, 5PL model is NOT 4786 symmetric with respect to change in sign of B. Thus, negative B's are 4787 possible, and left constraint may constrain parameter A (for positive B's) 4788 - or parameter D (for negative B's). Similarly changes meaning of right 4789 constraint. 4790 4791 You do not have to decide what parameter to constrain - algorithm will 4792 automatically determine correct parameters as fitting progresses. However, 4793 question highlighted above is important when you interpret fitting results. 4794 4795 4796 -- ALGLIB PROJECT -- 4797 Copyright 14.02.2014 by Bochkanov Sergey 4798 *************************************************************************/ 4799 void 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, const xparams _xparams = alglib::xdefault); 4800 4801 4802 /************************************************************************* 4803 Weghted rational least squares fitting using Floater-Hormann rational 4804 functions with optimal D chosen from [0,9], with constraints and 4805 individual weights. 4806 4807 Equidistant grid with M node on [min(x),max(x)] is used to build basis 4808 functions. Different values of D are tried, optimal D (least WEIGHTED root 4809 mean square error) is chosen. Task is linear, so linear least squares 4810 solver is used. Complexity of this computational scheme is O(N*M^2) 4811 (mostly dominated by the least squares solver). 4812 4813 SEE ALSO 4814 * BarycentricFitFloaterHormann(), "lightweight" fitting without invididual 4815 weights and constraints. 4816 4817 ! COMMERCIAL EDITION OF ALGLIB: 4818 ! 4819 ! Commercial Edition of ALGLIB includes following important improvements 4820 ! of this function: 4821 ! * high-performance native backend with same C# interface (C# version) 4822 ! * multithreading support (C++ and C# versions) 4823 ! * hardware vendor (Intel) implementations of linear algebra primitives 4824 ! (C++ and C# versions, x86/x64 platform) 4825 ! 4826 ! We recommend you to read 'Working with commercial version' section of 4827 ! ALGLIB Reference Manual in order to find out how to use performance- 4828 ! related features provided by commercial edition of ALGLIB. 4829 4830 INPUT PARAMETERS: 4831 X - points, array[0..N-1]. 4832 Y - function values, array[0..N-1]. 4833 W - weights, array[0..N-1] 4834 Each summand in square sum of approximation deviations from 4835 given values is multiplied by the square of corresponding 4836 weight. Fill it by 1's if you don't want to solve weighted 4837 task. 4838 N - number of points, N>0. 4839 XC - points where function values/derivatives are constrained, 4840 array[0..K-1]. 4841 YC - values of constraints, array[0..K-1] 4842 DC - array[0..K-1], types of constraints: 4843 * DC[i]=0 means that S(XC[i])=YC[i] 4844 * DC[i]=1 means that S'(XC[i])=YC[i] 4845 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 4846 K - number of constraints, 0<=K<M. 4847 K=0 means no constraints (XC/YC/DC are not used in such cases) 4848 M - number of basis functions ( = number_of_nodes), M>=2. 4849 4850 OUTPUT PARAMETERS: 4851 Info- same format as in LSFitLinearWC() subroutine. 4852 * Info>0 task is solved 4853 * Info<=0 an error occured: 4854 -4 means inconvergence of internal SVD 4855 -3 means inconsistent constraints 4856 -1 means another errors in parameters passed 4857 (N<=0, for example) 4858 B - barycentric interpolant. 4859 Rep - report, same format as in LSFitLinearWC() subroutine. 4860 Following fields are set: 4861 * DBest best value of the D parameter 4862 * RMSError rms error on the (X,Y). 4863 * AvgError average error on the (X,Y). 4864 * AvgRelError average relative error on the non-zero Y 4865 * MaxError maximum error 4866 NON-WEIGHTED ERRORS ARE CALCULATED 4867 4868 IMPORTANT: 4869 this subroutine doesn't calculate task's condition number for K<>0. 4870 4871 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 4872 4873 Setting constraints can lead to undesired results, like ill-conditioned 4874 behavior, or inconsistency being detected. From the other side, it allows 4875 us to improve quality of the fit. Here we summarize our experience with 4876 constrained barycentric interpolants: 4877 * excessive constraints can be inconsistent. Floater-Hormann basis 4878 functions aren't as flexible as splines (although they are very smooth). 4879 * the more evenly constraints are spread across [min(x),max(x)], the more 4880 chances that they will be consistent 4881 * the greater is M (given fixed constraints), the more chances that 4882 constraints will be consistent 4883 * in the general case, consistency of constraints IS NOT GUARANTEED. 4884 * in the several special cases, however, we CAN guarantee consistency. 4885 * one of this cases is constraints on the function VALUES at the interval 4886 boundaries. Note that consustency of the constraints on the function 4887 DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines 4888 which are more flexible). 4889 * another special case is ONE constraint on the function value (OR, but 4890 not AND, derivative) anywhere in the interval 4891 4892 Our final recommendation is to use constraints WHEN AND ONLY WHEN you 4893 can't solve your task without them. Anything beyond special cases given 4894 above is not guaranteed and may result in inconsistency. 4895 4896 -- ALGLIB PROJECT -- 4897 Copyright 18.08.2009 by Bochkanov Sergey 4898 *************************************************************************/ 4899 void 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, const xparams _xparams = alglib::xdefault); 4900 4901 4902 /************************************************************************* 4903 Rational least squares fitting using Floater-Hormann rational functions 4904 with optimal D chosen from [0,9]. 4905 4906 Equidistant grid with M node on [min(x),max(x)] is used to build basis 4907 functions. Different values of D are tried, optimal D (least root mean 4908 square error) is chosen. Task is linear, so linear least squares solver 4909 is used. Complexity of this computational scheme is O(N*M^2) (mostly 4910 dominated by the least squares solver). 4911 4912 ! COMMERCIAL EDITION OF ALGLIB: 4913 ! 4914 ! Commercial Edition of ALGLIB includes following important improvements 4915 ! of this function: 4916 ! * high-performance native backend with same C# interface (C# version) 4917 ! * multithreading support (C++ and C# versions) 4918 ! * hardware vendor (Intel) implementations of linear algebra primitives 4919 ! (C++ and C# versions, x86/x64 platform) 4920 ! 4921 ! We recommend you to read 'Working with commercial version' section of 4922 ! ALGLIB Reference Manual in order to find out how to use performance- 4923 ! related features provided by commercial edition of ALGLIB. 4924 4925 INPUT PARAMETERS: 4926 X - points, array[0..N-1]. 4927 Y - function values, array[0..N-1]. 4928 N - number of points, N>0. 4929 M - number of basis functions ( = number_of_nodes), M>=2. 4930 4931 OUTPUT PARAMETERS: 4932 Info- same format as in LSFitLinearWC() subroutine. 4933 * Info>0 task is solved 4934 * Info<=0 an error occured: 4935 -4 means inconvergence of internal SVD 4936 -3 means inconsistent constraints 4937 B - barycentric interpolant. 4938 Rep - report, same format as in LSFitLinearWC() subroutine. 4939 Following fields are set: 4940 * DBest best value of the D parameter 4941 * RMSError rms error on the (X,Y). 4942 * AvgError average error on the (X,Y). 4943 * AvgRelError average relative error on the non-zero Y 4944 * MaxError maximum error 4945 NON-WEIGHTED ERRORS ARE CALCULATED 4946 4947 -- ALGLIB PROJECT -- 4948 Copyright 18.08.2009 by Bochkanov Sergey 4949 *************************************************************************/ 4950 void 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, const xparams _xparams = alglib::xdefault); 4951 4952 4953 /************************************************************************* 4954 Weighted fitting by cubic spline, with constraints on function values or 4955 derivatives. 4956 4957 Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build 4958 basis functions. Basis functions are cubic splines with continuous second 4959 derivatives and non-fixed first derivatives at interval ends. Small 4960 regularizing term is used when solving constrained tasks (to improve 4961 stability). 4962 4963 Task is linear, so linear least squares solver is used. Complexity of this 4964 computational scheme is O(N*M^2), mostly dominated by least squares solver 4965 4966 SEE ALSO 4967 Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible, 4968 less smooth) 4969 Spline1DFitCubic() - "lightweight" fitting by cubic splines, 4970 without invididual weights and constraints 4971 4972 ! COMMERCIAL EDITION OF ALGLIB: 4973 ! 4974 ! Commercial Edition of ALGLIB includes following important improvements 4975 ! of this function: 4976 ! * high-performance native backend with same C# interface (C# version) 4977 ! * multithreading support (C++ and C# versions) 4978 ! * hardware vendor (Intel) implementations of linear algebra primitives 4979 ! (C++ and C# versions, x86/x64 platform) 4980 ! 4981 ! We recommend you to read 'Working with commercial version' section of 4982 ! ALGLIB Reference Manual in order to find out how to use performance- 4983 ! related features provided by commercial edition of ALGLIB. 4984 4985 INPUT PARAMETERS: 4986 X - points, array[0..N-1]. 4987 Y - function values, array[0..N-1]. 4988 W - weights, array[0..N-1] 4989 Each summand in square sum of approximation deviations from 4990 given values is multiplied by the square of corresponding 4991 weight. Fill it by 1's if you don't want to solve weighted 4992 task. 4993 N - number of points (optional): 4994 * N>0 4995 * if given, only first N elements of X/Y/W are processed 4996 * if not given, automatically determined from X/Y/W sizes 4997 XC - points where spline values/derivatives are constrained, 4998 array[0..K-1]. 4999 YC - values of constraints, array[0..K-1] 5000 DC - array[0..K-1], types of constraints: 5001 * DC[i]=0 means that S(XC[i])=YC[i] 5002 * DC[i]=1 means that S'(XC[i])=YC[i] 5003 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 5004 K - number of constraints (optional): 5005 * 0<=K<M. 5006 * K=0 means no constraints (XC/YC/DC are not used) 5007 * if given, only first K elements of XC/YC/DC are used 5008 * if not given, automatically determined from XC/YC/DC 5009 M - number of basis functions ( = number_of_nodes+2), M>=4. 5010 5011 OUTPUT PARAMETERS: 5012 Info- same format as in LSFitLinearWC() subroutine. 5013 * Info>0 task is solved 5014 * Info<=0 an error occured: 5015 -4 means inconvergence of internal SVD 5016 -3 means inconsistent constraints 5017 S - spline interpolant. 5018 Rep - report, same format as in LSFitLinearWC() subroutine. 5019 Following fields are set: 5020 * RMSError rms error on the (X,Y). 5021 * AvgError average error on the (X,Y). 5022 * AvgRelError average relative error on the non-zero Y 5023 * MaxError maximum error 5024 NON-WEIGHTED ERRORS ARE CALCULATED 5025 5026 IMPORTANT: 5027 this subroitine doesn't calculate task's condition number for K<>0. 5028 5029 5030 ORDER OF POINTS 5031 5032 Subroutine automatically sorts points, so caller may pass unsorted array. 5033 5034 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 5035 5036 Setting constraints can lead to undesired results, like ill-conditioned 5037 behavior, or inconsistency being detected. From the other side, it allows 5038 us to improve quality of the fit. Here we summarize our experience with 5039 constrained regression splines: 5040 * excessive constraints can be inconsistent. Splines are piecewise cubic 5041 functions, and it is easy to create an example, where large number of 5042 constraints concentrated in small area will result in inconsistency. 5043 Just because spline is not flexible enough to satisfy all of them. And 5044 same constraints spread across the [min(x),max(x)] will be perfectly 5045 consistent. 5046 * the more evenly constraints are spread across [min(x),max(x)], the more 5047 chances that they will be consistent 5048 * the greater is M (given fixed constraints), the more chances that 5049 constraints will be consistent 5050 * in the general case, consistency of constraints IS NOT GUARANTEED. 5051 * in the several special cases, however, we CAN guarantee consistency. 5052 * one of this cases is constraints on the function values AND/OR its 5053 derivatives at the interval boundaries. 5054 * another special case is ONE constraint on the function value (OR, but 5055 not AND, derivative) anywhere in the interval 5056 5057 Our final recommendation is to use constraints WHEN AND ONLY WHEN you 5058 can't solve your task without them. Anything beyond special cases given 5059 above is not guaranteed and may result in inconsistency. 5060 5061 5062 -- ALGLIB PROJECT -- 5063 Copyright 18.08.2009 by Bochkanov Sergey 5064 *************************************************************************/ 5065 void 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, const xparams _xparams = alglib::xdefault); 5066 void 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, const xparams _xparams = alglib::xdefault); 5067 5068 5069 /************************************************************************* 5070 Weighted fitting by Hermite spline, with constraints on function values 5071 or first derivatives. 5072 5073 Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build 5074 basis functions. Basis functions are Hermite splines. Small regularizing 5075 term is used when solving constrained tasks (to improve stability). 5076 5077 Task is linear, so linear least squares solver is used. Complexity of this 5078 computational scheme is O(N*M^2), mostly dominated by least squares solver 5079 5080 SEE ALSO 5081 Spline1DFitCubicWC() - fitting by Cubic splines (less flexible, 5082 more smooth) 5083 Spline1DFitHermite() - "lightweight" Hermite fitting, without 5084 invididual weights and constraints 5085 5086 ! COMMERCIAL EDITION OF ALGLIB: 5087 ! 5088 ! Commercial Edition of ALGLIB includes following important improvements 5089 ! of this function: 5090 ! * high-performance native backend with same C# interface (C# version) 5091 ! * multithreading support (C++ and C# versions) 5092 ! * hardware vendor (Intel) implementations of linear algebra primitives 5093 ! (C++ and C# versions, x86/x64 platform) 5094 ! 5095 ! We recommend you to read 'Working with commercial version' section of 5096 ! ALGLIB Reference Manual in order to find out how to use performance- 5097 ! related features provided by commercial edition of ALGLIB. 5098 5099 INPUT PARAMETERS: 5100 X - points, array[0..N-1]. 5101 Y - function values, array[0..N-1]. 5102 W - weights, array[0..N-1] 5103 Each summand in square sum of approximation deviations from 5104 given values is multiplied by the square of corresponding 5105 weight. Fill it by 1's if you don't want to solve weighted 5106 task. 5107 N - number of points (optional): 5108 * N>0 5109 * if given, only first N elements of X/Y/W are processed 5110 * if not given, automatically determined from X/Y/W sizes 5111 XC - points where spline values/derivatives are constrained, 5112 array[0..K-1]. 5113 YC - values of constraints, array[0..K-1] 5114 DC - array[0..K-1], types of constraints: 5115 * DC[i]=0 means that S(XC[i])=YC[i] 5116 * DC[i]=1 means that S'(XC[i])=YC[i] 5117 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 5118 K - number of constraints (optional): 5119 * 0<=K<M. 5120 * K=0 means no constraints (XC/YC/DC are not used) 5121 * if given, only first K elements of XC/YC/DC are used 5122 * if not given, automatically determined from XC/YC/DC 5123 M - number of basis functions (= 2 * number of nodes), 5124 M>=4, 5125 M IS EVEN! 5126 5127 OUTPUT PARAMETERS: 5128 Info- same format as in LSFitLinearW() subroutine: 5129 * Info>0 task is solved 5130 * Info<=0 an error occured: 5131 -4 means inconvergence of internal SVD 5132 -3 means inconsistent constraints 5133 -2 means odd M was passed (which is not supported) 5134 -1 means another errors in parameters passed 5135 (N<=0, for example) 5136 S - spline interpolant. 5137 Rep - report, same format as in LSFitLinearW() subroutine. 5138 Following fields are set: 5139 * RMSError rms error on the (X,Y). 5140 * AvgError average error on the (X,Y). 5141 * AvgRelError average relative error on the non-zero Y 5142 * MaxError maximum error 5143 NON-WEIGHTED ERRORS ARE CALCULATED 5144 5145 IMPORTANT: 5146 this subroitine doesn't calculate task's condition number for K<>0. 5147 5148 IMPORTANT: 5149 this subroitine supports only even M's 5150 5151 5152 ORDER OF POINTS 5153 5154 Subroutine automatically sorts points, so caller may pass unsorted array. 5155 5156 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 5157 5158 Setting constraints can lead to undesired results, like ill-conditioned 5159 behavior, or inconsistency being detected. From the other side, it allows 5160 us to improve quality of the fit. Here we summarize our experience with 5161 constrained regression splines: 5162 * excessive constraints can be inconsistent. Splines are piecewise cubic 5163 functions, and it is easy to create an example, where large number of 5164 constraints concentrated in small area will result in inconsistency. 5165 Just because spline is not flexible enough to satisfy all of them. And 5166 same constraints spread across the [min(x),max(x)] will be perfectly 5167 consistent. 5168 * the more evenly constraints are spread across [min(x),max(x)], the more 5169 chances that they will be consistent 5170 * the greater is M (given fixed constraints), the more chances that 5171 constraints will be consistent 5172 * in the general case, consistency of constraints is NOT GUARANTEED. 5173 * in the several special cases, however, we can guarantee consistency. 5174 * one of this cases is M>=4 and constraints on the function value 5175 (AND/OR its derivative) at the interval boundaries. 5176 * another special case is M>=4 and ONE constraint on the function value 5177 (OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)] 5178 5179 Our final recommendation is to use constraints WHEN AND ONLY when you 5180 can't solve your task without them. Anything beyond special cases given 5181 above is not guaranteed and may result in inconsistency. 5182 5183 -- ALGLIB PROJECT -- 5184 Copyright 18.08.2009 by Bochkanov Sergey 5185 *************************************************************************/ 5186 void 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, const xparams _xparams = alglib::xdefault); 5187 void 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, const xparams _xparams = alglib::xdefault); 5188 5189 5190 /************************************************************************* 5191 Least squares fitting by cubic spline. 5192 5193 This subroutine is "lightweight" alternative for more complex and feature- 5194 rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information 5195 about subroutine parameters (we don't duplicate it here because of length) 5196 5197 ! COMMERCIAL EDITION OF ALGLIB: 5198 ! 5199 ! Commercial Edition of ALGLIB includes following important improvements 5200 ! of this function: 5201 ! * high-performance native backend with same C# interface (C# version) 5202 ! * multithreading support (C++ and C# versions) 5203 ! * hardware vendor (Intel) implementations of linear algebra primitives 5204 ! (C++ and C# versions, x86/x64 platform) 5205 ! 5206 ! We recommend you to read 'Working with commercial version' section of 5207 ! ALGLIB Reference Manual in order to find out how to use performance- 5208 ! related features provided by commercial edition of ALGLIB. 5209 5210 -- ALGLIB PROJECT -- 5211 Copyright 18.08.2009 by Bochkanov Sergey 5212 *************************************************************************/ 5213 void 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, const xparams _xparams = alglib::xdefault); 5214 void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep, const xparams _xparams = alglib::xdefault); 5215 5216 5217 /************************************************************************* 5218 Least squares fitting by Hermite spline. 5219 5220 This subroutine is "lightweight" alternative for more complex and feature- 5221 rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for 5222 more information about subroutine parameters (we don't duplicate it here 5223 because of length). 5224 5225 ! COMMERCIAL EDITION OF ALGLIB: 5226 ! 5227 ! Commercial Edition of ALGLIB includes following important improvements 5228 ! of this function: 5229 ! * high-performance native backend with same C# interface (C# version) 5230 ! * multithreading support (C++ and C# versions) 5231 ! * hardware vendor (Intel) implementations of linear algebra primitives 5232 ! (C++ and C# versions, x86/x64 platform) 5233 ! 5234 ! We recommend you to read 'Working with commercial version' section of 5235 ! ALGLIB Reference Manual in order to find out how to use performance- 5236 ! related features provided by commercial edition of ALGLIB. 5237 5238 -- ALGLIB PROJECT -- 5239 Copyright 18.08.2009 by Bochkanov Sergey 5240 *************************************************************************/ 5241 void 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, const xparams _xparams = alglib::xdefault); 5242 void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep, const xparams _xparams = alglib::xdefault); 5243 5244 5245 /************************************************************************* 5246 Weighted linear least squares fitting. 5247 5248 QR decomposition is used to reduce task to MxM, then triangular solver or 5249 SVD-based solver is used depending on condition number of the system. It 5250 allows to maximize speed and retain decent accuracy. 5251 5252 IMPORTANT: if you want to perform polynomial fitting, it may be more 5253 convenient to use PolynomialFit() function. This function gives 5254 best results on polynomial problems and solves numerical 5255 stability issues which arise when you fit high-degree 5256 polynomials to your data. 5257 5258 ! COMMERCIAL EDITION OF ALGLIB: 5259 ! 5260 ! Commercial Edition of ALGLIB includes following important improvements 5261 ! of this function: 5262 ! * high-performance native backend with same C# interface (C# version) 5263 ! * multithreading support (C++ and C# versions) 5264 ! * hardware vendor (Intel) implementations of linear algebra primitives 5265 ! (C++ and C# versions, x86/x64 platform) 5266 ! 5267 ! We recommend you to read 'Working with commercial version' section of 5268 ! ALGLIB Reference Manual in order to find out how to use performance- 5269 ! related features provided by commercial edition of ALGLIB. 5270 5271 INPUT PARAMETERS: 5272 Y - array[0..N-1] Function values in N points. 5273 W - array[0..N-1] Weights corresponding to function values. 5274 Each summand in square sum of approximation deviations 5275 from given values is multiplied by the square of 5276 corresponding weight. 5277 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 5278 FMatrix[I, J] - value of J-th basis function in I-th point. 5279 N - number of points used. N>=1. 5280 M - number of basis functions, M>=1. 5281 5282 OUTPUT PARAMETERS: 5283 Info - error code: 5284 * -4 internal SVD decomposition subroutine failed (very 5285 rare and for degenerate systems only) 5286 * -1 incorrect N/M were specified 5287 * 1 task is solved 5288 C - decomposition coefficients, array[0..M-1] 5289 Rep - fitting report. Following fields are set: 5290 * Rep.TaskRCond reciprocal of condition number 5291 * R2 non-adjusted coefficient of determination 5292 (non-weighted) 5293 * RMSError rms error on the (X,Y). 5294 * AvgError average error on the (X,Y). 5295 * AvgRelError average relative error on the non-zero Y 5296 * MaxError maximum error 5297 NON-WEIGHTED ERRORS ARE CALCULATED 5298 5299 ERRORS IN PARAMETERS 5300 5301 This solver also calculates different kinds of errors in parameters and 5302 fills corresponding fields of report: 5303 * Rep.CovPar covariance matrix for parameters, array[K,K]. 5304 * Rep.ErrPar errors in parameters, array[K], 5305 errpar = sqrt(diag(CovPar)) 5306 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 5307 best-fit curve from "ideal" best-fit curve built with 5308 infinite number of samples, array[N]. 5309 errcurve = sqrt(diag(F*CovPar*F')), 5310 where F is functions matrix. 5311 * Rep.Noise vector of per-point estimates of noise, array[N] 5312 5313 NOTE: noise in the data is estimated as follows: 5314 * for fitting without user-supplied weights all points are 5315 assumed to have same level of noise, which is estimated from 5316 the data 5317 * for fitting with user-supplied weights we assume that noise 5318 level in I-th point is inversely proportional to Ith weight. 5319 Coefficient of proportionality is estimated from the data. 5320 5321 NOTE: we apply small amount of regularization when we invert squared 5322 Jacobian and calculate covariance matrix. It guarantees that 5323 algorithm won't divide by zero during inversion, but skews 5324 error estimates a bit (fractional error is about 10^-9). 5325 5326 However, we believe that this difference is insignificant for 5327 all practical purposes except for the situation when you want 5328 to compare ALGLIB results with "reference" implementation up 5329 to the last significant digit. 5330 5331 NOTE: covariance matrix is estimated using correction for degrees 5332 of freedom (covariances are divided by N-M instead of dividing 5333 by N). 5334 5335 -- ALGLIB -- 5336 Copyright 17.08.2009 by Bochkanov Sergey 5337 *************************************************************************/ 5338 void 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, const xparams _xparams = alglib::xdefault); 5339 void 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, const xparams _xparams = alglib::xdefault); 5340 5341 5342 /************************************************************************* 5343 Weighted constained linear least squares fitting. 5344 5345 This is variation of LSFitLinearW(), which searchs for min|A*x=b| given 5346 that K additional constaints C*x=bc are satisfied. It reduces original 5347 task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW() 5348 is called. 5349 5350 IMPORTANT: if you want to perform polynomial fitting, it may be more 5351 convenient to use PolynomialFit() function. This function gives 5352 best results on polynomial problems and solves numerical 5353 stability issues which arise when you fit high-degree 5354 polynomials to your data. 5355 5356 ! COMMERCIAL EDITION OF ALGLIB: 5357 ! 5358 ! Commercial Edition of ALGLIB includes following important improvements 5359 ! of this function: 5360 ! * high-performance native backend with same C# interface (C# version) 5361 ! * multithreading support (C++ and C# versions) 5362 ! * hardware vendor (Intel) implementations of linear algebra primitives 5363 ! (C++ and C# versions, x86/x64 platform) 5364 ! 5365 ! We recommend you to read 'Working with commercial version' section of 5366 ! ALGLIB Reference Manual in order to find out how to use performance- 5367 ! related features provided by commercial edition of ALGLIB. 5368 5369 INPUT PARAMETERS: 5370 Y - array[0..N-1] Function values in N points. 5371 W - array[0..N-1] Weights corresponding to function values. 5372 Each summand in square sum of approximation deviations 5373 from given values is multiplied by the square of 5374 corresponding weight. 5375 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 5376 FMatrix[I,J] - value of J-th basis function in I-th point. 5377 CMatrix - a table of constaints, array[0..K-1,0..M]. 5378 I-th row of CMatrix corresponds to I-th linear constraint: 5379 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M] 5380 N - number of points used. N>=1. 5381 M - number of basis functions, M>=1. 5382 K - number of constraints, 0 <= K < M 5383 K=0 corresponds to absence of constraints. 5384 5385 OUTPUT PARAMETERS: 5386 Info - error code: 5387 * -4 internal SVD decomposition subroutine failed (very 5388 rare and for degenerate systems only) 5389 * -3 either too many constraints (M or more), 5390 degenerate constraints (some constraints are 5391 repetead twice) or inconsistent constraints were 5392 specified. 5393 * 1 task is solved 5394 C - decomposition coefficients, array[0..M-1] 5395 Rep - fitting report. Following fields are set: 5396 * R2 non-adjusted coefficient of determination 5397 (non-weighted) 5398 * RMSError rms error on the (X,Y). 5399 * AvgError average error on the (X,Y). 5400 * AvgRelError average relative error on the non-zero Y 5401 * MaxError maximum error 5402 NON-WEIGHTED ERRORS ARE CALCULATED 5403 5404 IMPORTANT: 5405 this subroitine doesn't calculate task's condition number for K<>0. 5406 5407 ERRORS IN PARAMETERS 5408 5409 This solver also calculates different kinds of errors in parameters and 5410 fills corresponding fields of report: 5411 * Rep.CovPar covariance matrix for parameters, array[K,K]. 5412 * Rep.ErrPar errors in parameters, array[K], 5413 errpar = sqrt(diag(CovPar)) 5414 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 5415 best-fit curve from "ideal" best-fit curve built with 5416 infinite number of samples, array[N]. 5417 errcurve = sqrt(diag(F*CovPar*F')), 5418 where F is functions matrix. 5419 * Rep.Noise vector of per-point estimates of noise, array[N] 5420 5421 IMPORTANT: errors in parameters are calculated without taking into 5422 account boundary/linear constraints! Presence of constraints 5423 changes distribution of errors, but there is no easy way to 5424 account for constraints when you calculate covariance matrix. 5425 5426 NOTE: noise in the data is estimated as follows: 5427 * for fitting without user-supplied weights all points are 5428 assumed to have same level of noise, which is estimated from 5429 the data 5430 * for fitting with user-supplied weights we assume that noise 5431 level in I-th point is inversely proportional to Ith weight. 5432 Coefficient of proportionality is estimated from the data. 5433 5434 NOTE: we apply small amount of regularization when we invert squared 5435 Jacobian and calculate covariance matrix. It guarantees that 5436 algorithm won't divide by zero during inversion, but skews 5437 error estimates a bit (fractional error is about 10^-9). 5438 5439 However, we believe that this difference is insignificant for 5440 all practical purposes except for the situation when you want 5441 to compare ALGLIB results with "reference" implementation up 5442 to the last significant digit. 5443 5444 NOTE: covariance matrix is estimated using correction for degrees 5445 of freedom (covariances are divided by N-M instead of dividing 5446 by N). 5447 5448 -- ALGLIB -- 5449 Copyright 07.09.2009 by Bochkanov Sergey 5450 *************************************************************************/ 5451 void 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, const xparams _xparams = alglib::xdefault); 5452 void 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, const xparams _xparams = alglib::xdefault); 5453 5454 5455 /************************************************************************* 5456 Linear least squares fitting. 5457 5458 QR decomposition is used to reduce task to MxM, then triangular solver or 5459 SVD-based solver is used depending on condition number of the system. It 5460 allows to maximize speed and retain decent accuracy. 5461 5462 IMPORTANT: if you want to perform polynomial fitting, it may be more 5463 convenient to use PolynomialFit() function. This function gives 5464 best results on polynomial problems and solves numerical 5465 stability issues which arise when you fit high-degree 5466 polynomials to your data. 5467 5468 ! COMMERCIAL EDITION OF ALGLIB: 5469 ! 5470 ! Commercial Edition of ALGLIB includes following important improvements 5471 ! of this function: 5472 ! * high-performance native backend with same C# interface (C# version) 5473 ! * multithreading support (C++ and C# versions) 5474 ! * hardware vendor (Intel) implementations of linear algebra primitives 5475 ! (C++ and C# versions, x86/x64 platform) 5476 ! 5477 ! We recommend you to read 'Working with commercial version' section of 5478 ! ALGLIB Reference Manual in order to find out how to use performance- 5479 ! related features provided by commercial edition of ALGLIB. 5480 5481 INPUT PARAMETERS: 5482 Y - array[0..N-1] Function values in N points. 5483 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 5484 FMatrix[I, J] - value of J-th basis function in I-th point. 5485 N - number of points used. N>=1. 5486 M - number of basis functions, M>=1. 5487 5488 OUTPUT PARAMETERS: 5489 Info - error code: 5490 * -4 internal SVD decomposition subroutine failed (very 5491 rare and for degenerate systems only) 5492 * 1 task is solved 5493 C - decomposition coefficients, array[0..M-1] 5494 Rep - fitting report. Following fields are set: 5495 * Rep.TaskRCond reciprocal of condition number 5496 * R2 non-adjusted coefficient of determination 5497 (non-weighted) 5498 * RMSError rms error on the (X,Y). 5499 * AvgError average error on the (X,Y). 5500 * AvgRelError average relative error on the non-zero Y 5501 * MaxError maximum error 5502 NON-WEIGHTED ERRORS ARE CALCULATED 5503 5504 ERRORS IN PARAMETERS 5505 5506 This solver also calculates different kinds of errors in parameters and 5507 fills corresponding fields of report: 5508 * Rep.CovPar covariance matrix for parameters, array[K,K]. 5509 * Rep.ErrPar errors in parameters, array[K], 5510 errpar = sqrt(diag(CovPar)) 5511 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 5512 best-fit curve from "ideal" best-fit curve built with 5513 infinite number of samples, array[N]. 5514 errcurve = sqrt(diag(F*CovPar*F')), 5515 where F is functions matrix. 5516 * Rep.Noise vector of per-point estimates of noise, array[N] 5517 5518 NOTE: noise in the data is estimated as follows: 5519 * for fitting without user-supplied weights all points are 5520 assumed to have same level of noise, which is estimated from 5521 the data 5522 * for fitting with user-supplied weights we assume that noise 5523 level in I-th point is inversely proportional to Ith weight. 5524 Coefficient of proportionality is estimated from the data. 5525 5526 NOTE: we apply small amount of regularization when we invert squared 5527 Jacobian and calculate covariance matrix. It guarantees that 5528 algorithm won't divide by zero during inversion, but skews 5529 error estimates a bit (fractional error is about 10^-9). 5530 5531 However, we believe that this difference is insignificant for 5532 all practical purposes except for the situation when you want 5533 to compare ALGLIB results with "reference" implementation up 5534 to the last significant digit. 5535 5536 NOTE: covariance matrix is estimated using correction for degrees 5537 of freedom (covariances are divided by N-M instead of dividing 5538 by N). 5539 5540 -- ALGLIB -- 5541 Copyright 17.08.2009 by Bochkanov Sergey 5542 *************************************************************************/ 5543 void 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, const xparams _xparams = alglib::xdefault); 5544 void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, ae_int_t &info, real_1d_array &c, lsfitreport &rep, const xparams _xparams = alglib::xdefault); 5545 5546 5547 /************************************************************************* 5548 Constained linear least squares fitting. 5549 5550 This is variation of LSFitLinear(), which searchs for min|A*x=b| given 5551 that K additional constaints C*x=bc are satisfied. It reduces original 5552 task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear() 5553 is called. 5554 5555 IMPORTANT: if you want to perform polynomial fitting, it may be more 5556 convenient to use PolynomialFit() function. This function gives 5557 best results on polynomial problems and solves numerical 5558 stability issues which arise when you fit high-degree 5559 polynomials to your data. 5560 5561 ! COMMERCIAL EDITION OF ALGLIB: 5562 ! 5563 ! Commercial Edition of ALGLIB includes following important improvements 5564 ! of this function: 5565 ! * high-performance native backend with same C# interface (C# version) 5566 ! * multithreading support (C++ and C# versions) 5567 ! * hardware vendor (Intel) implementations of linear algebra primitives 5568 ! (C++ and C# versions, x86/x64 platform) 5569 ! 5570 ! We recommend you to read 'Working with commercial version' section of 5571 ! ALGLIB Reference Manual in order to find out how to use performance- 5572 ! related features provided by commercial edition of ALGLIB. 5573 5574 INPUT PARAMETERS: 5575 Y - array[0..N-1] Function values in N points. 5576 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 5577 FMatrix[I,J] - value of J-th basis function in I-th point. 5578 CMatrix - a table of constaints, array[0..K-1,0..M]. 5579 I-th row of CMatrix corresponds to I-th linear constraint: 5580 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M] 5581 N - number of points used. N>=1. 5582 M - number of basis functions, M>=1. 5583 K - number of constraints, 0 <= K < M 5584 K=0 corresponds to absence of constraints. 5585 5586 OUTPUT PARAMETERS: 5587 Info - error code: 5588 * -4 internal SVD decomposition subroutine failed (very 5589 rare and for degenerate systems only) 5590 * -3 either too many constraints (M or more), 5591 degenerate constraints (some constraints are 5592 repetead twice) or inconsistent constraints were 5593 specified. 5594 * 1 task is solved 5595 C - decomposition coefficients, array[0..M-1] 5596 Rep - fitting report. Following fields are set: 5597 * R2 non-adjusted coefficient of determination 5598 (non-weighted) 5599 * RMSError rms error on the (X,Y). 5600 * AvgError average error on the (X,Y). 5601 * AvgRelError average relative error on the non-zero Y 5602 * MaxError maximum error 5603 NON-WEIGHTED ERRORS ARE CALCULATED 5604 5605 IMPORTANT: 5606 this subroitine doesn't calculate task's condition number for K<>0. 5607 5608 ERRORS IN PARAMETERS 5609 5610 This solver also calculates different kinds of errors in parameters and 5611 fills corresponding fields of report: 5612 * Rep.CovPar covariance matrix for parameters, array[K,K]. 5613 * Rep.ErrPar errors in parameters, array[K], 5614 errpar = sqrt(diag(CovPar)) 5615 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 5616 best-fit curve from "ideal" best-fit curve built with 5617 infinite number of samples, array[N]. 5618 errcurve = sqrt(diag(F*CovPar*F')), 5619 where F is functions matrix. 5620 * Rep.Noise vector of per-point estimates of noise, array[N] 5621 5622 IMPORTANT: errors in parameters are calculated without taking into 5623 account boundary/linear constraints! Presence of constraints 5624 changes distribution of errors, but there is no easy way to 5625 account for constraints when you calculate covariance matrix. 5626 5627 NOTE: noise in the data is estimated as follows: 5628 * for fitting without user-supplied weights all points are 5629 assumed to have same level of noise, which is estimated from 5630 the data 5631 * for fitting with user-supplied weights we assume that noise 5632 level in I-th point is inversely proportional to Ith weight. 5633 Coefficient of proportionality is estimated from the data. 5634 5635 NOTE: we apply small amount of regularization when we invert squared 5636 Jacobian and calculate covariance matrix. It guarantees that 5637 algorithm won't divide by zero during inversion, but skews 5638 error estimates a bit (fractional error is about 10^-9). 5639 5640 However, we believe that this difference is insignificant for 5641 all practical purposes except for the situation when you want 5642 to compare ALGLIB results with "reference" implementation up 5643 to the last significant digit. 5644 5645 NOTE: covariance matrix is estimated using correction for degrees 5646 of freedom (covariances are divided by N-M instead of dividing 5647 by N). 5648 5649 -- ALGLIB -- 5650 Copyright 07.09.2009 by Bochkanov Sergey 5651 *************************************************************************/ 5652 void 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, const xparams _xparams = alglib::xdefault); 5653 void 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, const xparams _xparams = alglib::xdefault); 5654 5655 5656 /************************************************************************* 5657 Weighted nonlinear least squares fitting using function values only. 5658 5659 Combination of numerical differentiation and secant updates is used to 5660 obtain function Jacobian. 5661 5662 Nonlinear task min(F(c)) is solved, where 5663 5664 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 5665 5666 * N is a number of points, 5667 * M is a dimension of a space points belong to, 5668 * K is a dimension of a space of parameters being fitted, 5669 * w is an N-dimensional vector of weight coefficients, 5670 * x is a set of N points, each of them is an M-dimensional vector, 5671 * c is a K-dimensional vector of parameters being fitted 5672 5673 This subroutine uses only f(c,x[i]). 5674 5675 INPUT PARAMETERS: 5676 X - array[0..N-1,0..M-1], points (one row = one point) 5677 Y - array[0..N-1], function values. 5678 W - weights, array[0..N-1] 5679 C - array[0..K-1], initial approximation to the solution, 5680 N - number of points, N>1 5681 M - dimension of space 5682 K - number of parameters being fitted 5683 DiffStep- numerical differentiation step; 5684 should not be very small or large; 5685 large = loss of accuracy 5686 small = growth of round-off errors 5687 5688 OUTPUT PARAMETERS: 5689 State - structure which stores algorithm state 5690 5691 -- ALGLIB -- 5692 Copyright 18.10.2008 by Bochkanov Sergey 5693 *************************************************************************/ 5694 void 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, const xparams _xparams = alglib::xdefault); 5695 void 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, const xparams _xparams = alglib::xdefault); 5696 5697 5698 /************************************************************************* 5699 Nonlinear least squares fitting using function values only. 5700 5701 Combination of numerical differentiation and secant updates is used to 5702 obtain function Jacobian. 5703 5704 Nonlinear task min(F(c)) is solved, where 5705 5706 F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2, 5707 5708 * N is a number of points, 5709 * M is a dimension of a space points belong to, 5710 * K is a dimension of a space of parameters being fitted, 5711 * w is an N-dimensional vector of weight coefficients, 5712 * x is a set of N points, each of them is an M-dimensional vector, 5713 * c is a K-dimensional vector of parameters being fitted 5714 5715 This subroutine uses only f(c,x[i]). 5716 5717 INPUT PARAMETERS: 5718 X - array[0..N-1,0..M-1], points (one row = one point) 5719 Y - array[0..N-1], function values. 5720 C - array[0..K-1], initial approximation to the solution, 5721 N - number of points, N>1 5722 M - dimension of space 5723 K - number of parameters being fitted 5724 DiffStep- numerical differentiation step; 5725 should not be very small or large; 5726 large = loss of accuracy 5727 small = growth of round-off errors 5728 5729 OUTPUT PARAMETERS: 5730 State - structure which stores algorithm state 5731 5732 -- ALGLIB -- 5733 Copyright 18.10.2008 by Bochkanov Sergey 5734 *************************************************************************/ 5735 void 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, const xparams _xparams = alglib::xdefault); 5736 void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const double diffstep, lsfitstate &state, const xparams _xparams = alglib::xdefault); 5737 5738 5739 /************************************************************************* 5740 Weighted nonlinear least squares fitting using gradient only. 5741 5742 Nonlinear task min(F(c)) is solved, where 5743 5744 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 5745 5746 * N is a number of points, 5747 * M is a dimension of a space points belong to, 5748 * K is a dimension of a space of parameters being fitted, 5749 * w is an N-dimensional vector of weight coefficients, 5750 * x is a set of N points, each of them is an M-dimensional vector, 5751 * c is a K-dimensional vector of parameters being fitted 5752 5753 This subroutine uses only f(c,x[i]) and its gradient. 5754 5755 INPUT PARAMETERS: 5756 X - array[0..N-1,0..M-1], points (one row = one point) 5757 Y - array[0..N-1], function values. 5758 W - weights, array[0..N-1] 5759 C - array[0..K-1], initial approximation to the solution, 5760 N - number of points, N>1 5761 M - dimension of space 5762 K - number of parameters being fitted 5763 CheapFG - boolean flag, which is: 5764 * True if both function and gradient calculation complexity 5765 are less than O(M^2). An improved algorithm can 5766 be used which corresponds to FGJ scheme from 5767 MINLM unit. 5768 * False otherwise. 5769 Standard Jacibian-bases Levenberg-Marquardt algo 5770 will be used (FJ scheme). 5771 5772 OUTPUT PARAMETERS: 5773 State - structure which stores algorithm state 5774 5775 See also: 5776 LSFitResults 5777 LSFitCreateFG (fitting without weights) 5778 LSFitCreateWFGH (fitting using Hessian) 5779 LSFitCreateFGH (fitting using Hessian, without weights) 5780 5781 -- ALGLIB -- 5782 Copyright 17.08.2009 by Bochkanov Sergey 5783 *************************************************************************/ 5784 void 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, const xparams _xparams = alglib::xdefault); 5785 void 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, const xparams _xparams = alglib::xdefault); 5786 5787 5788 /************************************************************************* 5789 Nonlinear least squares fitting using gradient only, without individual 5790 weights. 5791 5792 Nonlinear task min(F(c)) is solved, where 5793 5794 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2, 5795 5796 * N is a number of points, 5797 * M is a dimension of a space points belong to, 5798 * K is a dimension of a space of parameters being fitted, 5799 * x is a set of N points, each of them is an M-dimensional vector, 5800 * c is a K-dimensional vector of parameters being fitted 5801 5802 This subroutine uses only f(c,x[i]) and its gradient. 5803 5804 INPUT PARAMETERS: 5805 X - array[0..N-1,0..M-1], points (one row = one point) 5806 Y - array[0..N-1], function values. 5807 C - array[0..K-1], initial approximation to the solution, 5808 N - number of points, N>1 5809 M - dimension of space 5810 K - number of parameters being fitted 5811 CheapFG - boolean flag, which is: 5812 * True if both function and gradient calculation complexity 5813 are less than O(M^2). An improved algorithm can 5814 be used which corresponds to FGJ scheme from 5815 MINLM unit. 5816 * False otherwise. 5817 Standard Jacibian-bases Levenberg-Marquardt algo 5818 will be used (FJ scheme). 5819 5820 OUTPUT PARAMETERS: 5821 State - structure which stores algorithm state 5822 5823 -- ALGLIB -- 5824 Copyright 17.08.2009 by Bochkanov Sergey 5825 *************************************************************************/ 5826 void 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, const xparams _xparams = alglib::xdefault); 5827 void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const bool cheapfg, lsfitstate &state, const xparams _xparams = alglib::xdefault); 5828 5829 5830 /************************************************************************* 5831 Weighted nonlinear least squares fitting using gradient/Hessian. 5832 5833 Nonlinear task min(F(c)) is solved, where 5834 5835 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 5836 5837 * N is a number of points, 5838 * M is a dimension of a space points belong to, 5839 * K is a dimension of a space of parameters being fitted, 5840 * w is an N-dimensional vector of weight coefficients, 5841 * x is a set of N points, each of them is an M-dimensional vector, 5842 * c is a K-dimensional vector of parameters being fitted 5843 5844 This subroutine uses f(c,x[i]), its gradient and its Hessian. 5845 5846 INPUT PARAMETERS: 5847 X - array[0..N-1,0..M-1], points (one row = one point) 5848 Y - array[0..N-1], function values. 5849 W - weights, array[0..N-1] 5850 C - array[0..K-1], initial approximation to the solution, 5851 N - number of points, N>1 5852 M - dimension of space 5853 K - number of parameters being fitted 5854 5855 OUTPUT PARAMETERS: 5856 State - structure which stores algorithm state 5857 5858 -- ALGLIB -- 5859 Copyright 17.08.2009 by Bochkanov Sergey 5860 *************************************************************************/ 5861 void 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, const xparams _xparams = alglib::xdefault); 5862 void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, lsfitstate &state, const xparams _xparams = alglib::xdefault); 5863 5864 5865 /************************************************************************* 5866 Nonlinear least squares fitting using gradient/Hessian, without individial 5867 weights. 5868 5869 Nonlinear task min(F(c)) is solved, where 5870 5871 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2, 5872 5873 * N is a number of points, 5874 * M is a dimension of a space points belong to, 5875 * K is a dimension of a space of parameters being fitted, 5876 * x is a set of N points, each of them is an M-dimensional vector, 5877 * c is a K-dimensional vector of parameters being fitted 5878 5879 This subroutine uses f(c,x[i]), its gradient and its Hessian. 5880 5881 INPUT PARAMETERS: 5882 X - array[0..N-1,0..M-1], points (one row = one point) 5883 Y - array[0..N-1], function values. 5884 C - array[0..K-1], initial approximation to the solution, 5885 N - number of points, N>1 5886 M - dimension of space 5887 K - number of parameters being fitted 5888 5889 OUTPUT PARAMETERS: 5890 State - structure which stores algorithm state 5891 5892 5893 -- ALGLIB -- 5894 Copyright 17.08.2009 by Bochkanov Sergey 5895 *************************************************************************/ 5896 void 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, const xparams _xparams = alglib::xdefault); 5897 void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, lsfitstate &state, const xparams _xparams = alglib::xdefault); 5898 5899 5900 /************************************************************************* 5901 Stopping conditions for nonlinear least squares fitting. 5902 5903 INPUT PARAMETERS: 5904 State - structure which stores algorithm state 5905 EpsX - >=0 5906 The subroutine finishes its work if on k+1-th iteration 5907 the condition |v|<=EpsX is fulfilled, where: 5908 * |.| means Euclidian norm 5909 * v - scaled step vector, v[i]=dx[i]/s[i] 5910 * dx - ste pvector, dx=X(k+1)-X(k) 5911 * s - scaling coefficients set by LSFitSetScale() 5912 MaxIts - maximum number of iterations. If MaxIts=0, the number of 5913 iterations is unlimited. Only Levenberg-Marquardt 5914 iterations are counted (L-BFGS/CG iterations are NOT 5915 counted because their cost is very low compared to that of 5916 LM). 5917 5918 NOTE 5919 5920 Passing EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic 5921 stopping criterion selection (according to the scheme used by MINLM unit). 5922 5923 5924 -- ALGLIB -- 5925 Copyright 17.08.2009 by Bochkanov Sergey 5926 *************************************************************************/ 5927 void lsfitsetcond(const lsfitstate &state, const double epsx, const ae_int_t maxits, const xparams _xparams = alglib::xdefault); 5928 5929 5930 /************************************************************************* 5931 This function sets maximum step length 5932 5933 INPUT PARAMETERS: 5934 State - structure which stores algorithm state 5935 StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't 5936 want to limit step length. 5937 5938 Use this subroutine when you optimize target function which contains exp() 5939 or other fast growing functions, and optimization algorithm makes too 5940 large steps which leads to overflow. This function allows us to reject 5941 steps that are too large (and therefore expose us to the possible 5942 overflow) without actually calculating function value at the x+stp*d. 5943 5944 NOTE: non-zero StpMax leads to moderate performance degradation because 5945 intermediate step of preconditioned L-BFGS optimization is incompatible 5946 with limits on step size. 5947 5948 -- ALGLIB -- 5949 Copyright 02.04.2010 by Bochkanov Sergey 5950 *************************************************************************/ 5951 void lsfitsetstpmax(const lsfitstate &state, const double stpmax, const xparams _xparams = alglib::xdefault); 5952 5953 5954 /************************************************************************* 5955 This function turns on/off reporting. 5956 5957 INPUT PARAMETERS: 5958 State - structure which stores algorithm state 5959 NeedXRep- whether iteration reports are needed or not 5960 5961 When reports are needed, State.C (current parameters) and State.F (current 5962 value of fitting function) are reported. 5963 5964 5965 -- ALGLIB -- 5966 Copyright 15.08.2010 by Bochkanov Sergey 5967 *************************************************************************/ 5968 void lsfitsetxrep(const lsfitstate &state, const bool needxrep, const xparams _xparams = alglib::xdefault); 5969 5970 5971 /************************************************************************* 5972 This function sets scaling coefficients for underlying optimizer. 5973 5974 ALGLIB optimizers use scaling matrices to test stopping conditions (step 5975 size and gradient are scaled before comparison with tolerances). Scale of 5976 the I-th variable is a translation invariant measure of: 5977 a) "how large" the variable is 5978 b) how large the step should be to make significant changes in the function 5979 5980 Generally, scale is NOT considered to be a form of preconditioner. But LM 5981 optimizer is unique in that it uses scaling matrix both in the stopping 5982 condition tests and as Marquardt damping factor. 5983 5984 Proper scaling is very important for the algorithm performance. It is less 5985 important for the quality of results, but still has some influence (it is 5986 easier to converge when variables are properly scaled, so premature 5987 stopping is possible when very badly scalled variables are combined with 5988 relaxed stopping conditions). 5989 5990 INPUT PARAMETERS: 5991 State - structure stores algorithm state 5992 S - array[N], non-zero scaling coefficients 5993 S[i] may be negative, sign doesn't matter. 5994 5995 -- ALGLIB -- 5996 Copyright 14.01.2011 by Bochkanov Sergey 5997 *************************************************************************/ 5998 void lsfitsetscale(const lsfitstate &state, const real_1d_array &s, const xparams _xparams = alglib::xdefault); 5999 6000 6001 /************************************************************************* 6002 This function sets boundary constraints for underlying optimizer 6003 6004 Boundary constraints are inactive by default (after initial creation). 6005 They are preserved until explicitly turned off with another SetBC() call. 6006 6007 INPUT PARAMETERS: 6008 State - structure stores algorithm state 6009 BndL - lower bounds, array[K]. 6010 If some (all) variables are unbounded, you may specify 6011 very small number or -INF (latter is recommended because 6012 it will allow solver to use better algorithm). 6013 BndU - upper bounds, array[K]. 6014 If some (all) variables are unbounded, you may specify 6015 very large number or +INF (latter is recommended because 6016 it will allow solver to use better algorithm). 6017 6018 NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th 6019 variable will be "frozen" at X[i]=BndL[i]=BndU[i]. 6020 6021 NOTE 2: unlike other constrained optimization algorithms, this solver has 6022 following useful properties: 6023 * bound constraints are always satisfied exactly 6024 * function is evaluated only INSIDE area specified by bound constraints 6025 6026 -- ALGLIB -- 6027 Copyright 14.01.2011 by Bochkanov Sergey 6028 *************************************************************************/ 6029 void lsfitsetbc(const lsfitstate &state, const real_1d_array &bndl, const real_1d_array &bndu, const xparams _xparams = alglib::xdefault); 6030 6031 6032 /************************************************************************* 6033 This function sets linear constraints for underlying optimizer 6034 6035 Linear constraints are inactive by default (after initial creation). 6036 They are preserved until explicitly turned off with another SetLC() call. 6037 6038 INPUT PARAMETERS: 6039 State - structure stores algorithm state 6040 C - linear constraints, array[K,N+1]. 6041 Each row of C represents one constraint, either equality 6042 or inequality (see below): 6043 * first N elements correspond to coefficients, 6044 * last element corresponds to the right part. 6045 All elements of C (including right part) must be finite. 6046 CT - type of constraints, array[K]: 6047 * if CT[i]>0, then I-th constraint is C[i,*]*x >= C[i,n+1] 6048 * if CT[i]=0, then I-th constraint is C[i,*]*x = C[i,n+1] 6049 * if CT[i]<0, then I-th constraint is C[i,*]*x <= C[i,n+1] 6050 K - number of equality/inequality constraints, K>=0: 6051 * if given, only leading K elements of C/CT are used 6052 * if not given, automatically determined from sizes of C/CT 6053 6054 IMPORTANT: if you have linear constraints, it is strongly recommended to 6055 set scale of variables with lsfitsetscale(). QP solver which is 6056 used to calculate linearly constrained steps heavily relies on 6057 good scaling of input problems. 6058 6059 NOTE: linear (non-box) constraints are satisfied only approximately - 6060 there always exists some violation due to numerical errors and 6061 algorithmic limitations. 6062 6063 NOTE: general linear constraints add significant overhead to solution 6064 process. Although solver performs roughly same amount of iterations 6065 (when compared with similar box-only constrained problem), each 6066 iteration now involves solution of linearly constrained QP 6067 subproblem, which requires ~3-5 times more Cholesky decompositions. 6068 Thus, if you can reformulate your problem in such way this it has 6069 only box constraints, it may be beneficial to do so. 6070 6071 -- ALGLIB -- 6072 Copyright 29.04.2017 by Bochkanov Sergey 6073 *************************************************************************/ 6074 void lsfitsetlc(const lsfitstate &state, const real_2d_array &c, const integer_1d_array &ct, const ae_int_t k, const xparams _xparams = alglib::xdefault); 6075 void lsfitsetlc(const lsfitstate &state, const real_2d_array &c, const integer_1d_array &ct, const xparams _xparams = alglib::xdefault); 6076 6077 6078 /************************************************************************* 6079 This function provides reverse communication interface 6080 Reverse communication interface is not documented or recommended to use. 6081 See below for functions which provide better documented API 6082 *************************************************************************/ 6083 bool lsfititeration(const lsfitstate &state, const xparams _xparams = alglib::xdefault); 6084 6085 6086 /************************************************************************* 6087 This family of functions is used to launcn iterations of nonlinear fitter 6088 6089 These functions accept following parameters: 6090 state - algorithm state 6091 func - callback which calculates function (or merit function) 6092 value func at given point x 6093 grad - callback which calculates function (or merit function) 6094 value func and gradient grad at given point x 6095 hess - callback which calculates function (or merit function) 6096 value func, gradient grad and Hessian hess at given point x 6097 rep - optional callback which is called after each iteration 6098 can be NULL 6099 ptr - optional pointer which is passed to func/grad/hess/jac/rep 6100 can be NULL 6101 6102 NOTES: 6103 6104 1. this algorithm is somewhat unusual because it works with parameterized 6105 function f(C,X), where X is a function argument (we have many points 6106 which are characterized by different argument values), and C is a 6107 parameter to fit. 6108 6109 For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then 6110 x will be argument, and {c0,c1} will be parameters. 6111 6112 It is important to understand that this algorithm finds minimum in the 6113 space of function PARAMETERS (not arguments), so it needs derivatives 6114 of f() with respect to C, not X. 6115 6116 In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1} 6117 instead of {df/dx} = {c0}. 6118 6119 2. Callback functions accept C as the first parameter, and X as the second 6120 6121 3. If state was created with LSFitCreateFG(), algorithm needs just 6122 function and its gradient, but if state was created with 6123 LSFitCreateFGH(), algorithm will need function, gradient and Hessian. 6124 6125 According to the said above, there ase several versions of this 6126 function, which accept different sets of callbacks. 6127 6128 This flexibility opens way to subtle errors - you may create state with 6129 LSFitCreateFGH() (optimization using Hessian), but call function which 6130 does not accept Hessian. So when algorithm will request Hessian, there 6131 will be no callback to call. In this case exception will be thrown. 6132 6133 Be careful to avoid such errors because there is no way to find them at 6134 compile time - you can see them at runtime only. 6135 6136 -- ALGLIB -- 6137 Copyright 17.08.2009 by Bochkanov Sergey 6138 6139 *************************************************************************/ 6140 void lsfitfit(lsfitstate &state, 6141 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr), 6142 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL, 6143 void *ptr = NULL, 6144 const xparams _xparams = alglib::xdefault); 6145 void lsfitfit(lsfitstate &state, 6146 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr), 6147 void (*grad)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, void *ptr), 6148 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL, 6149 void *ptr = NULL, 6150 const xparams _xparams = alglib::xdefault); 6151 void lsfitfit(lsfitstate &state, 6152 void (*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr), 6153 void (*grad)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, void *ptr), 6154 void (*hess)(const real_1d_array &c, const real_1d_array &x, double &func, real_1d_array &grad, real_2d_array &hess, void *ptr), 6155 void (*rep)(const real_1d_array &c, double func, void *ptr) = NULL, 6156 void *ptr = NULL, 6157 const xparams _xparams = alglib::xdefault); 6158 6159 6160 /************************************************************************* 6161 Nonlinear least squares fitting results. 6162 6163 Called after return from LSFitFit(). 6164 6165 INPUT PARAMETERS: 6166 State - algorithm state 6167 6168 OUTPUT PARAMETERS: 6169 Info - completion code: 6170 * -8 optimizer detected NAN/INF in the target 6171 function and/or gradient 6172 * -7 gradient verification failed. 6173 See LSFitSetGradientCheck() for more information. 6174 * -3 inconsistent constraints 6175 * 2 relative step is no more than EpsX. 6176 * 5 MaxIts steps was taken 6177 * 7 stopping conditions are too stringent, 6178 further improvement is impossible 6179 C - array[0..K-1], solution 6180 Rep - optimization report. On success following fields are set: 6181 * R2 non-adjusted coefficient of determination 6182 (non-weighted) 6183 * RMSError rms error on the (X,Y). 6184 * AvgError average error on the (X,Y). 6185 * AvgRelError average relative error on the non-zero Y 6186 * MaxError maximum error 6187 NON-WEIGHTED ERRORS ARE CALCULATED 6188 * WRMSError weighted rms error on the (X,Y). 6189 6190 ERRORS IN PARAMETERS 6191 6192 This solver also calculates different kinds of errors in parameters and 6193 fills corresponding fields of report: 6194 * Rep.CovPar covariance matrix for parameters, array[K,K]. 6195 * Rep.ErrPar errors in parameters, array[K], 6196 errpar = sqrt(diag(CovPar)) 6197 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 6198 best-fit curve from "ideal" best-fit curve built with 6199 infinite number of samples, array[N]. 6200 errcurve = sqrt(diag(J*CovPar*J')), 6201 where J is Jacobian matrix. 6202 * Rep.Noise vector of per-point estimates of noise, array[N] 6203 6204 IMPORTANT: errors in parameters are calculated without taking into 6205 account boundary/linear constraints! Presence of constraints 6206 changes distribution of errors, but there is no easy way to 6207 account for constraints when you calculate covariance matrix. 6208 6209 NOTE: noise in the data is estimated as follows: 6210 * for fitting without user-supplied weights all points are 6211 assumed to have same level of noise, which is estimated from 6212 the data 6213 * for fitting with user-supplied weights we assume that noise 6214 level in I-th point is inversely proportional to Ith weight. 6215 Coefficient of proportionality is estimated from the data. 6216 6217 NOTE: we apply small amount of regularization when we invert squared 6218 Jacobian and calculate covariance matrix. It guarantees that 6219 algorithm won't divide by zero during inversion, but skews 6220 error estimates a bit (fractional error is about 10^-9). 6221 6222 However, we believe that this difference is insignificant for 6223 all practical purposes except for the situation when you want 6224 to compare ALGLIB results with "reference" implementation up 6225 to the last significant digit. 6226 6227 NOTE: covariance matrix is estimated using correction for degrees 6228 of freedom (covariances are divided by N-M instead of dividing 6229 by N). 6230 6231 -- ALGLIB -- 6232 Copyright 17.08.2009 by Bochkanov Sergey 6233 *************************************************************************/ 6234 void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c, lsfitreport &rep, const xparams _xparams = alglib::xdefault); 6235 6236 6237 /************************************************************************* 6238 This subroutine turns on verification of the user-supplied analytic 6239 gradient: 6240 * user calls this subroutine before fitting begins 6241 * LSFitFit() is called 6242 * prior to actual fitting, for each point in data set X_i and each 6243 component of parameters being fited C_j algorithm performs following 6244 steps: 6245 * two trial steps are made to C_j-TestStep*S[j] and C_j+TestStep*S[j], 6246 where C_j is j-th parameter and S[j] is a scale of j-th parameter 6247 * if needed, steps are bounded with respect to constraints on C[] 6248 * F(X_i|C) is evaluated at these trial points 6249 * we perform one more evaluation in the middle point of the interval 6250 * we build cubic model using function values and derivatives at trial 6251 points and we compare its prediction with actual value in the middle 6252 point 6253 * in case difference between prediction and actual value is higher than 6254 some predetermined threshold, algorithm stops with completion code -7; 6255 Rep.VarIdx is set to index of the parameter with incorrect derivative. 6256 * after verification is over, algorithm proceeds to the actual optimization. 6257 6258 NOTE 1: verification needs N*K (points count * parameters count) gradient 6259 evaluations. It is very costly and you should use it only for low 6260 dimensional problems, when you want to be sure that you've 6261 correctly calculated analytic derivatives. You should not use it 6262 in the production code (unless you want to check derivatives 6263 provided by some third party). 6264 6265 NOTE 2: you should carefully choose TestStep. Value which is too large 6266 (so large that function behaviour is significantly non-cubic) will 6267 lead to false alarms. You may use different step for different 6268 parameters by means of setting scale with LSFitSetScale(). 6269 6270 NOTE 3: this function may lead to false positives. In case it reports that 6271 I-th derivative was calculated incorrectly, you may decrease test 6272 step and try one more time - maybe your function changes too 6273 sharply and your step is too large for such rapidly chanding 6274 function. 6275 6276 NOTE 4: this function works only for optimizers created with LSFitCreateWFG() 6277 or LSFitCreateFG() constructors. 6278 6279 INPUT PARAMETERS: 6280 State - structure used to store algorithm state 6281 TestStep - verification step: 6282 * TestStep=0 turns verification off 6283 * TestStep>0 activates verification 6284 6285 -- ALGLIB -- 6286 Copyright 15.06.2012 by Bochkanov Sergey 6287 *************************************************************************/ 6288 void lsfitsetgradientcheck(const lsfitstate &state, const double teststep, const xparams _xparams = alglib::xdefault); 6289 #endif 6290 6291 #if defined(AE_COMPILE_RBFV2) || !defined(AE_PARTIAL_BUILD) 6292 6293 #endif 6294 6295 #if defined(AE_COMPILE_SPLINE2D) || !defined(AE_PARTIAL_BUILD) 6296 /************************************************************************* 6297 This function serializes data structure to string. 6298 6299 Important properties of s_out: 6300 * it contains alphanumeric characters, dots, underscores, minus signs 6301 * these symbols are grouped into words, which are separated by spaces 6302 and Windows-style (CR+LF) newlines 6303 * although serializer uses spaces and CR+LF as separators, you can 6304 replace any separator character by arbitrary combination of spaces, 6305 tabs, Windows or Unix newlines. It allows flexible reformatting of 6306 the string in case you want to include it into text or XML file. 6307 But you should not insert separators into the middle of the "words" 6308 nor you should change case of letters. 6309 * s_out can be freely moved between 32-bit and 64-bit systems, little 6310 and big endian machines, and so on. You can serialize structure on 6311 32-bit machine and unserialize it on 64-bit one (or vice versa), or 6312 serialize it on SPARC and unserialize on x86. You can also 6313 serialize it in C++ version of ALGLIB and unserialize in C# one, 6314 and vice versa. 6315 *************************************************************************/ 6316 void spline2dserialize(spline2dinterpolant &obj, std::string &s_out); 6317 6318 6319 /************************************************************************* 6320 This function unserializes data structure from string. 6321 *************************************************************************/ 6322 void spline2dunserialize(const std::string &s_in, spline2dinterpolant &obj); 6323 6324 6325 6326 6327 /************************************************************************* 6328 This function serializes data structure to C++ stream. 6329 6330 Data stream generated by this function is same as string representation 6331 generated by string version of serializer - alphanumeric characters, 6332 dots, underscores, minus signs, which are grouped into words separated by 6333 spaces and CR+LF. 6334 6335 We recommend you to read comments on string version of serializer to find 6336 out more about serialization of AlGLIB objects. 6337 *************************************************************************/ 6338 void spline2dserialize(spline2dinterpolant &obj, std::ostream &s_out); 6339 6340 6341 /************************************************************************* 6342 This function unserializes data structure from stream. 6343 *************************************************************************/ 6344 void spline2dunserialize(const std::istream &s_in, spline2dinterpolant &obj); 6345 6346 6347 /************************************************************************* 6348 This subroutine calculates the value of the bilinear or bicubic spline at 6349 the given point X. 6350 6351 Input parameters: 6352 C - 2D spline object. 6353 Built by spline2dbuildbilinearv or spline2dbuildbicubicv. 6354 X, Y- point 6355 6356 Result: 6357 S(x,y) 6358 6359 -- ALGLIB PROJECT -- 6360 Copyright 05.07.2007 by Bochkanov Sergey 6361 *************************************************************************/ 6362 double spline2dcalc(const spline2dinterpolant &c, const double x, const double y, const xparams _xparams = alglib::xdefault); 6363 6364 6365 /************************************************************************* 6366 This subroutine calculates the value of the bilinear or bicubic spline at 6367 the given point X and its derivatives. 6368 6369 Input parameters: 6370 C - spline interpolant. 6371 X, Y- point 6372 6373 Output parameters: 6374 F - S(x,y) 6375 FX - dS(x,y)/dX 6376 FY - dS(x,y)/dY 6377 FXY - d2S(x,y)/dXdY 6378 6379 -- ALGLIB PROJECT -- 6380 Copyright 05.07.2007 by Bochkanov Sergey 6381 *************************************************************************/ 6382 void spline2ddiff(const spline2dinterpolant &c, const double x, const double y, double &f, double &fx, double &fy, double &fxy, const xparams _xparams = alglib::xdefault); 6383 6384 6385 /************************************************************************* 6386 This subroutine calculates bilinear or bicubic vector-valued spline at the 6387 given point (X,Y). 6388 6389 If you need just some specific component of vector-valued spline, you can 6390 use spline2dcalcvi() function. 6391 6392 INPUT PARAMETERS: 6393 C - spline interpolant. 6394 X, Y- point 6395 F - output buffer, possibly preallocated array. In case array size 6396 is large enough to store result, it is not reallocated. Array 6397 which is too short will be reallocated 6398 6399 OUTPUT PARAMETERS: 6400 F - array[D] (or larger) which stores function values 6401 6402 -- ALGLIB PROJECT -- 6403 Copyright 01.02.2018 by Bochkanov Sergey 6404 *************************************************************************/ 6405 void spline2dcalcvbuf(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f, const xparams _xparams = alglib::xdefault); 6406 6407 6408 /************************************************************************* 6409 This subroutine calculates specific component of vector-valued bilinear or 6410 bicubic spline at the given point (X,Y). 6411 6412 INPUT PARAMETERS: 6413 C - spline interpolant. 6414 X, Y- point 6415 I - component index, in [0,D). An exception is generated for out 6416 of range values. 6417 6418 RESULT: 6419 value of I-th component 6420 6421 -- ALGLIB PROJECT -- 6422 Copyright 01.02.2018 by Bochkanov Sergey 6423 *************************************************************************/ 6424 double spline2dcalcvi(const spline2dinterpolant &c, const double x, const double y, const ae_int_t i, const xparams _xparams = alglib::xdefault); 6425 6426 6427 /************************************************************************* 6428 This subroutine calculates bilinear or bicubic vector-valued spline at the 6429 given point (X,Y). 6430 6431 INPUT PARAMETERS: 6432 C - spline interpolant. 6433 X, Y- point 6434 6435 OUTPUT PARAMETERS: 6436 F - array[D] which stores function values. F is out-parameter and 6437 it is reallocated after call to this function. In case you 6438 want to reuse previously allocated F, you may use 6439 Spline2DCalcVBuf(), which reallocates F only when it is too 6440 small. 6441 6442 -- ALGLIB PROJECT -- 6443 Copyright 16.04.2012 by Bochkanov Sergey 6444 *************************************************************************/ 6445 void spline2dcalcv(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f, const xparams _xparams = alglib::xdefault); 6446 6447 6448 /************************************************************************* 6449 This subroutine calculates value of specific component of bilinear or 6450 bicubic vector-valued spline and its derivatives. 6451 6452 Input parameters: 6453 C - spline interpolant. 6454 X, Y- point 6455 I - component index, in [0,D) 6456 6457 Output parameters: 6458 F - S(x,y) 6459 FX - dS(x,y)/dX 6460 FY - dS(x,y)/dY 6461 FXY - d2S(x,y)/dXdY 6462 6463 -- ALGLIB PROJECT -- 6464 Copyright 05.07.2007 by Bochkanov Sergey 6465 *************************************************************************/ 6466 void spline2ddiffvi(const spline2dinterpolant &c, const double x, const double y, const ae_int_t i, double &f, double &fx, double &fy, double &fxy, const xparams _xparams = alglib::xdefault); 6467 6468 6469 /************************************************************************* 6470 This subroutine performs linear transformation of the spline argument. 6471 6472 Input parameters: 6473 C - spline interpolant 6474 AX, BX - transformation coefficients: x = A*t + B 6475 AY, BY - transformation coefficients: y = A*u + B 6476 Result: 6477 C - transformed spline 6478 6479 -- ALGLIB PROJECT -- 6480 Copyright 30.06.2007 by Bochkanov Sergey 6481 *************************************************************************/ 6482 void spline2dlintransxy(const spline2dinterpolant &c, const double ax, const double bx, const double ay, const double by, const xparams _xparams = alglib::xdefault); 6483 6484 6485 /************************************************************************* 6486 This subroutine performs linear transformation of the spline. 6487 6488 Input parameters: 6489 C - spline interpolant. 6490 A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B 6491 6492 Output parameters: 6493 C - transformed spline 6494 6495 -- ALGLIB PROJECT -- 6496 Copyright 30.06.2007 by Bochkanov Sergey 6497 *************************************************************************/ 6498 void spline2dlintransf(const spline2dinterpolant &c, const double a, const double b, const xparams _xparams = alglib::xdefault); 6499 6500 6501 /************************************************************************* 6502 This subroutine makes the copy of the spline model. 6503 6504 Input parameters: 6505 C - spline interpolant 6506 6507 Output parameters: 6508 CC - spline copy 6509 6510 -- ALGLIB PROJECT -- 6511 Copyright 29.06.2007 by Bochkanov Sergey 6512 *************************************************************************/ 6513 void spline2dcopy(const spline2dinterpolant &c, spline2dinterpolant &cc, const xparams _xparams = alglib::xdefault); 6514 6515 6516 /************************************************************************* 6517 Bicubic spline resampling 6518 6519 Input parameters: 6520 A - function values at the old grid, 6521 array[0..OldHeight-1, 0..OldWidth-1] 6522 OldHeight - old grid height, OldHeight>1 6523 OldWidth - old grid width, OldWidth>1 6524 NewHeight - new grid height, NewHeight>1 6525 NewWidth - new grid width, NewWidth>1 6526 6527 Output parameters: 6528 B - function values at the new grid, 6529 array[0..NewHeight-1, 0..NewWidth-1] 6530 6531 -- ALGLIB routine -- 6532 15 May, 2007 6533 Copyright by Bochkanov Sergey 6534 *************************************************************************/ 6535 void 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, const xparams _xparams = alglib::xdefault); 6536 6537 6538 /************************************************************************* 6539 Bilinear spline resampling 6540 6541 Input parameters: 6542 A - function values at the old grid, 6543 array[0..OldHeight-1, 0..OldWidth-1] 6544 OldHeight - old grid height, OldHeight>1 6545 OldWidth - old grid width, OldWidth>1 6546 NewHeight - new grid height, NewHeight>1 6547 NewWidth - new grid width, NewWidth>1 6548 6549 Output parameters: 6550 B - function values at the new grid, 6551 array[0..NewHeight-1, 0..NewWidth-1] 6552 6553 -- ALGLIB routine -- 6554 09.07.2007 6555 Copyright by Bochkanov Sergey 6556 *************************************************************************/ 6557 void 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, const xparams _xparams = alglib::xdefault); 6558 6559 6560 /************************************************************************* 6561 This subroutine builds bilinear vector-valued spline. 6562 6563 Input parameters: 6564 X - spline abscissas, array[0..N-1] 6565 Y - spline ordinates, array[0..M-1] 6566 F - function values, array[0..M*N*D-1]: 6567 * first D elements store D values at (X[0],Y[0]) 6568 * next D elements store D values at (X[1],Y[0]) 6569 * general form - D function values at (X[i],Y[j]) are stored 6570 at F[D*(J*N+I)...D*(J*N+I)+D-1]. 6571 M,N - grid size, M>=2, N>=2 6572 D - vector dimension, D>=1 6573 6574 Output parameters: 6575 C - spline interpolant 6576 6577 -- ALGLIB PROJECT -- 6578 Copyright 16.04.2012 by Bochkanov Sergey 6579 *************************************************************************/ 6580 void 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, const xparams _xparams = alglib::xdefault); 6581 6582 6583 /************************************************************************* 6584 This subroutine builds bicubic vector-valued spline. 6585 6586 Input parameters: 6587 X - spline abscissas, array[0..N-1] 6588 Y - spline ordinates, array[0..M-1] 6589 F - function values, array[0..M*N*D-1]: 6590 * first D elements store D values at (X[0],Y[0]) 6591 * next D elements store D values at (X[1],Y[0]) 6592 * general form - D function values at (X[i],Y[j]) are stored 6593 at F[D*(J*N+I)...D*(J*N+I)+D-1]. 6594 M,N - grid size, M>=2, N>=2 6595 D - vector dimension, D>=1 6596 6597 Output parameters: 6598 C - spline interpolant 6599 6600 -- ALGLIB PROJECT -- 6601 Copyright 16.04.2012 by Bochkanov Sergey 6602 *************************************************************************/ 6603 void 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, const xparams _xparams = alglib::xdefault); 6604 6605 6606 /************************************************************************* 6607 This subroutine unpacks two-dimensional spline into the coefficients table 6608 6609 Input parameters: 6610 C - spline interpolant. 6611 6612 Result: 6613 M, N- grid size (x-axis and y-axis) 6614 D - number of components 6615 Tbl - coefficients table, unpacked format, 6616 D - components: [0..(N-1)*(M-1)*D-1, 0..19]. 6617 For T=0..D-1 (component index), I = 0...N-2 (x index), 6618 J=0..M-2 (y index): 6619 K := T + I*D + J*D*(N-1) 6620 6621 K-th row stores decomposition for T-th component of the 6622 vector-valued function 6623 6624 Tbl[K,0] = X[i] 6625 Tbl[K,1] = X[i+1] 6626 Tbl[K,2] = Y[j] 6627 Tbl[K,3] = Y[j+1] 6628 Tbl[K,4] = C00 6629 Tbl[K,5] = C01 6630 Tbl[K,6] = C02 6631 Tbl[K,7] = C03 6632 Tbl[K,8] = C10 6633 Tbl[K,9] = C11 6634 ... 6635 Tbl[K,19] = C33 6636 On each grid square spline is equals to: 6637 S(x) = SUM(c[i,j]*(t^i)*(u^j), i=0..3, j=0..3) 6638 t = x-x[j] 6639 u = y-y[i] 6640 6641 -- ALGLIB PROJECT -- 6642 Copyright 16.04.2012 by Bochkanov Sergey 6643 *************************************************************************/ 6644 void spline2dunpackv(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, ae_int_t &d, real_2d_array &tbl, const xparams _xparams = alglib::xdefault); 6645 6646 6647 /************************************************************************* 6648 This subroutine was deprecated in ALGLIB 3.6.0 6649 6650 We recommend you to switch to Spline2DBuildBilinearV(), which is more 6651 flexible and accepts its arguments in more convenient order. 6652 6653 -- ALGLIB PROJECT -- 6654 Copyright 05.07.2007 by Bochkanov Sergey 6655 *************************************************************************/ 6656 void 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, const xparams _xparams = alglib::xdefault); 6657 6658 6659 /************************************************************************* 6660 This subroutine was deprecated in ALGLIB 3.6.0 6661 6662 We recommend you to switch to Spline2DBuildBicubicV(), which is more 6663 flexible and accepts its arguments in more convenient order. 6664 6665 -- ALGLIB PROJECT -- 6666 Copyright 05.07.2007 by Bochkanov Sergey 6667 *************************************************************************/ 6668 void 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, const xparams _xparams = alglib::xdefault); 6669 6670 6671 /************************************************************************* 6672 This subroutine was deprecated in ALGLIB 3.6.0 6673 6674 We recommend you to switch to Spline2DUnpackV(), which is more flexible 6675 and accepts its arguments in more convenient order. 6676 6677 -- ALGLIB PROJECT -- 6678 Copyright 29.06.2007 by Bochkanov Sergey 6679 *************************************************************************/ 6680 void spline2dunpack(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, real_2d_array &tbl, const xparams _xparams = alglib::xdefault); 6681 6682 6683 /************************************************************************* 6684 This subroutine creates least squares solver used to fit 2D splines to 6685 irregularly sampled (scattered) data. 6686 6687 Solver object is used to perform spline fits as follows: 6688 * solver object is created with spline2dbuildercreate() function 6689 * dataset is added with spline2dbuildersetpoints() function 6690 * fit area is chosen: 6691 * spline2dbuildersetarea() - for user-defined area 6692 * spline2dbuildersetareaauto() - for automatically chosen area 6693 * number of grid nodes is chosen with spline2dbuildersetgrid() 6694 * prior term is chosen with one of the following functions: 6695 * spline2dbuildersetlinterm() to set linear prior 6696 * spline2dbuildersetconstterm() to set constant prior 6697 * spline2dbuildersetzeroterm() to set zero prior 6698 * spline2dbuildersetuserterm() to set user-defined constant prior 6699 * solver algorithm is chosen with either: 6700 * spline2dbuildersetalgoblocklls() - BlockLLS algorithm, medium-scale problems 6701 * spline2dbuildersetalgofastddm() - FastDDM algorithm, large-scale problems 6702 * finally, fitting itself is performed with spline2dfit() function. 6703 6704 Most of the steps above can be omitted, solver is configured with good 6705 defaults. The minimum is to call: 6706 * spline2dbuildercreate() to create solver object 6707 * spline2dbuildersetpoints() to specify dataset 6708 * spline2dbuildersetgrid() to tell how many nodes you need 6709 * spline2dfit() to perform fit 6710 6711 ! COMMERCIAL EDITION OF ALGLIB: 6712 ! 6713 ! Commercial Edition of ALGLIB includes following important improvements 6714 ! of this function: 6715 ! * high-performance native backend with same C# interface (C# version) 6716 ! * multithreading support (C++ and C# versions) 6717 ! * hardware vendor (Intel) implementations of linear algebra primitives 6718 ! (C++ and C# versions, x86/x64 platform) 6719 ! 6720 ! We recommend you to read 'Working with commercial version' section of 6721 ! ALGLIB Reference Manual in order to find out how to use performance- 6722 ! related features provided by commercial edition of ALGLIB. 6723 6724 INPUT PARAMETERS: 6725 D - positive number, number of Y-components: D=1 for simple scalar 6726 fit, D>1 for vector-valued spline fitting. 6727 6728 OUTPUT PARAMETERS: 6729 S - solver object 6730 6731 -- ALGLIB PROJECT -- 6732 Copyright 29.01.2018 by Bochkanov Sergey 6733 *************************************************************************/ 6734 void spline2dbuildercreate(const ae_int_t d, spline2dbuilder &state, const xparams _xparams = alglib::xdefault); 6735 6736 6737 /************************************************************************* 6738 This function sets constant prior term (model is a sum of bicubic spline 6739 and global prior, which can be linear, constant, user-defined constant or 6740 zero). 6741 6742 Constant prior term is determined by least squares fitting. 6743 6744 INPUT PARAMETERS: 6745 S - spline builder 6746 V - value for user-defined prior 6747 6748 -- ALGLIB -- 6749 Copyright 01.02.2018 by Bochkanov Sergey 6750 *************************************************************************/ 6751 void spline2dbuildersetuserterm(const spline2dbuilder &state, const double v, const xparams _xparams = alglib::xdefault); 6752 6753 6754 /************************************************************************* 6755 This function sets linear prior term (model is a sum of bicubic spline and 6756 global prior, which can be linear, constant, user-defined constant or 6757 zero). 6758 6759 Linear prior term is determined by least squares fitting. 6760 6761 INPUT PARAMETERS: 6762 S - spline builder 6763 6764 -- ALGLIB -- 6765 Copyright 01.02.2018 by Bochkanov Sergey 6766 *************************************************************************/ 6767 void spline2dbuildersetlinterm(const spline2dbuilder &state, const xparams _xparams = alglib::xdefault); 6768 6769 6770 /************************************************************************* 6771 This function sets constant prior term (model is a sum of bicubic spline 6772 and global prior, which can be linear, constant, user-defined constant or 6773 zero). 6774 6775 Constant prior term is determined by least squares fitting. 6776 6777 INPUT PARAMETERS: 6778 S - spline builder 6779 6780 -- ALGLIB -- 6781 Copyright 01.02.2018 by Bochkanov Sergey 6782 *************************************************************************/ 6783 void spline2dbuildersetconstterm(const spline2dbuilder &state, const xparams _xparams = alglib::xdefault); 6784 6785 6786 /************************************************************************* 6787 This function sets zero prior term (model is a sum of bicubic spline and 6788 global prior, which can be linear, constant, user-defined constant or 6789 zero). 6790 6791 INPUT PARAMETERS: 6792 S - spline builder 6793 6794 -- ALGLIB -- 6795 Copyright 01.02.2018 by Bochkanov Sergey 6796 *************************************************************************/ 6797 void spline2dbuildersetzeroterm(const spline2dbuilder &state, const xparams _xparams = alglib::xdefault); 6798 6799 6800 /************************************************************************* 6801 This function adds dataset to the builder object. 6802 6803 This function overrides results of the previous calls, i.e. multiple calls 6804 of this function will result in only the last set being added. 6805 6806 INPUT PARAMETERS: 6807 S - spline 2D builder object 6808 XY - points, array[N,2+D]. One row corresponds to one point 6809 in the dataset. First 2 elements are coordinates, next 6810 D elements are function values. Array may be larger than 6811 specified, in this case only leading [N,NX+NY] elements 6812 will be used. 6813 N - number of points in the dataset 6814 6815 -- ALGLIB -- 6816 Copyright 05.02.2018 by Bochkanov Sergey 6817 *************************************************************************/ 6818 void spline2dbuildersetpoints(const spline2dbuilder &state, const real_2d_array &xy, const ae_int_t n, const xparams _xparams = alglib::xdefault); 6819 6820 6821 /************************************************************************* 6822 This function sets area where 2D spline interpolant is built. "Auto" means 6823 that area extent is determined automatically from dataset extent. 6824 6825 INPUT PARAMETERS: 6826 S - spline 2D builder object 6827 6828 -- ALGLIB -- 6829 Copyright 05.02.2018 by Bochkanov Sergey 6830 *************************************************************************/ 6831 void spline2dbuildersetareaauto(const spline2dbuilder &state, const xparams _xparams = alglib::xdefault); 6832 6833 6834 /************************************************************************* 6835 This function sets area where 2D spline interpolant is built to 6836 user-defined one: [XA,XB]*[YA,YB] 6837 6838 INPUT PARAMETERS: 6839 S - spline 2D builder object 6840 XA,XB - spatial extent in the first (X) dimension, XA<XB 6841 YA,YB - spatial extent in the second (Y) dimension, YA<YB 6842 6843 -- ALGLIB -- 6844 Copyright 05.02.2018 by Bochkanov Sergey 6845 *************************************************************************/ 6846 void spline2dbuildersetarea(const spline2dbuilder &state, const double xa, const double xb, const double ya, const double yb, const xparams _xparams = alglib::xdefault); 6847 6848 6849 /************************************************************************* 6850 This function sets nodes count for 2D spline interpolant. Fitting is 6851 performed on area defined with one of the "setarea" functions; this one 6852 sets number of nodes placed upon the fitting area. 6853 6854 INPUT PARAMETERS: 6855 S - spline 2D builder object 6856 KX - nodes count for the first (X) dimension; fitting interval 6857 [XA,XB] is separated into KX-1 subintervals, with KX nodes 6858 created at the boundaries. 6859 KY - nodes count for the first (Y) dimension; fitting interval 6860 [YA,YB] is separated into KY-1 subintervals, with KY nodes 6861 created at the boundaries. 6862 6863 NOTE: at least 4 nodes is created in each dimension, so KX and KY are 6864 silently increased if needed. 6865 6866 -- ALGLIB -- 6867 Copyright 05.02.2018 by Bochkanov Sergey 6868 *************************************************************************/ 6869 void spline2dbuildersetgrid(const spline2dbuilder &state, const ae_int_t kx, const ae_int_t ky, const xparams _xparams = alglib::xdefault); 6870 6871 6872 /************************************************************************* 6873 This function allows you to choose least squares solver used to perform 6874 fitting. This function sets solver algorithm to "FastDDM", which performs 6875 fast parallel fitting by splitting problem into smaller chunks and merging 6876 results together. 6877 6878 This solver is optimized for large-scale problems, starting from 256x256 6879 grids, and up to 10000x10000 grids. Of course, it will work for smaller 6880 grids too. 6881 6882 More detailed description of the algorithm is given below: 6883 * algorithm generates hierarchy of nested grids, ranging from ~16x16 6884 (topmost "layer" of the model) to ~KX*KY one (final layer). Upper layers 6885 model global behavior of the function, lower layers are used to model 6886 fine details. Moving from layer to layer doubles grid density. 6887 * fitting is started from topmost layer, subsequent layers are fitted 6888 using residuals from previous ones. 6889 * user may choose to skip generation of upper layers and generate only a 6890 few bottom ones, which will result in much better performance and 6891 parallelization efficiency, at the cost of algorithm inability to "patch" 6892 large holes in the dataset. 6893 * every layer is regularized using progressively increasing regularization 6894 coefficient; thus, increasing LambdaV penalizes fine details first, 6895 leaving lower frequencies almost intact for a while. 6896 * after fitting is done, all layers are merged together into one bicubic 6897 spline 6898 6899 IMPORTANT: regularization coefficient used by this solver is different 6900 from the one used by BlockLLS. Latter utilizes nonlinearity 6901 penalty, which is global in nature (large regularization 6902 results in global linear trend being extracted); this solver 6903 uses another, localized form of penalty, which is suitable for 6904 parallel processing. 6905 6906 Notes on memory and performance: 6907 * memory requirements: most memory is consumed during modeling of the 6908 higher layers; ~[512*NPoints] bytes is required for a model with full 6909 hierarchy of grids being generated. However, if you skip a few topmost 6910 layers, you will get nearly constant (wrt. points count and grid size) 6911 memory consumption. 6912 * serial running time: O(K*K)+O(NPoints) for a KxK grid 6913 * parallelism potential: good. You may get nearly linear speed-up when 6914 performing fitting with just a few layers. Adding more layers results in 6915 model becoming more global, which somewhat reduces efficiency of the 6916 parallel code. 6917 6918 ! COMMERCIAL EDITION OF ALGLIB: 6919 ! 6920 ! Commercial Edition of ALGLIB includes following important improvements 6921 ! of this function: 6922 ! * high-performance native backend with same C# interface (C# version) 6923 ! * multithreading support (C++ and C# versions) 6924 ! * hardware vendor (Intel) implementations of linear algebra primitives 6925 ! (C++ and C# versions, x86/x64 platform) 6926 ! 6927 ! We recommend you to read 'Working with commercial version' section of 6928 ! ALGLIB Reference Manual in order to find out how to use performance- 6929 ! related features provided by commercial edition of ALGLIB. 6930 6931 INPUT PARAMETERS: 6932 S - spline 2D builder object 6933 NLayers - number of layers in the model: 6934 * NLayers>=1 means that up to chosen number of bottom 6935 layers is fitted 6936 * NLayers=0 means that maximum number of layers is chosen 6937 (according to current grid size) 6938 * NLayers<=-1 means that up to |NLayers| topmost layers is 6939 skipped 6940 Recommendations: 6941 * good "default" value is 2 layers 6942 * you may need more layers, if your dataset is very 6943 irregular and you want to "patch" large holes. For a 6944 grid step H (equal to AreaWidth/GridSize) you may expect 6945 that last layer reproduces variations at distance H (and 6946 can patch holes that wide); that higher layers operate 6947 at distances 2*H, 4*H, 8*H and so on. 6948 * good value for "bullletproof" mode is NLayers=0, which 6949 results in complete hierarchy of layers being generated. 6950 LambdaV - regularization coefficient, chosen in such a way that it 6951 penalizes bottom layers (fine details) first. 6952 LambdaV>=0, zero value means that no penalty is applied. 6953 6954 -- ALGLIB -- 6955 Copyright 05.02.2018 by Bochkanov Sergey 6956 *************************************************************************/ 6957 void spline2dbuildersetalgofastddm(const spline2dbuilder &state, const ae_int_t nlayers, const double lambdav, const xparams _xparams = alglib::xdefault); 6958 6959 6960 /************************************************************************* 6961 This function allows you to choose least squares solver used to perform 6962 fitting. This function sets solver algorithm to "BlockLLS", which performs 6963 least squares fitting with fast sparse direct solver, with optional 6964 nonsmoothness penalty being applied. 6965 6966 Nonlinearity penalty has the following form: 6967 6968 [ ] 6969 P() ~ Lambda* integral[ (d2S/dx2)^2 + 2*(d2S/dxdy)^2 + (d2S/dy2)^2 ]dxdy 6970 [ ] 6971 6972 here integral is calculated over entire grid, and "~" means "proportional" 6973 because integral is normalized after calcilation. Extremely large values 6974 of Lambda result in linear fit being performed. 6975 6976 NOTE: this algorithm is the most robust and controllable one, but it is 6977 limited by 512x512 grids and (say) up to 1.000.000 points. However, 6978 ALGLIB has one more spline solver: FastDDM algorithm, which is 6979 intended for really large-scale problems (in 10M-100M range). FastDDM 6980 algorithm also has better parallelism properties. 6981 6982 More information on BlockLLS solver: 6983 * memory requirements: ~[32*K^3+256*NPoints] bytes for KxK grid with 6984 NPoints-sized dataset 6985 * serial running time: O(K^4+NPoints) 6986 * parallelism potential: limited. You may get some sublinear gain when 6987 working with large grids (K's in 256..512 range) 6988 6989 ! COMMERCIAL EDITION OF ALGLIB: 6990 ! 6991 ! Commercial Edition of ALGLIB includes following important improvements 6992 ! of this function: 6993 ! * high-performance native backend with same C# interface (C# version) 6994 ! * multithreading support (C++ and C# versions) 6995 ! * hardware vendor (Intel) implementations of linear algebra primitives 6996 ! (C++ and C# versions, x86/x64 platform) 6997 ! 6998 ! We recommend you to read 'Working with commercial version' section of 6999 ! ALGLIB Reference Manual in order to find out how to use performance- 7000 ! related features provided by commercial edition of ALGLIB. 7001 7002 INPUT PARAMETERS: 7003 S - spline 2D builder object 7004 LambdaNS- non-negative value: 7005 * positive value means that some smoothing is applied 7006 * zero value means that no smoothing is applied, and 7007 corresponding entries of design matrix are numerically 7008 zero and dropped from consideration. 7009 7010 -- ALGLIB -- 7011 Copyright 05.02.2018 by Bochkanov Sergey 7012 *************************************************************************/ 7013 void spline2dbuildersetalgoblocklls(const spline2dbuilder &state, const double lambdans, const xparams _xparams = alglib::xdefault); 7014 7015 7016 /************************************************************************* 7017 This function allows you to choose least squares solver used to perform 7018 fitting. This function sets solver algorithm to "NaiveLLS". 7019 7020 IMPORTANT: NaiveLLS is NOT intended to be used in real life code! This 7021 algorithm solves problem by generated dense (K^2)x(K^2+NPoints) 7022 matrix and solves linear least squares problem with dense 7023 solver. 7024 7025 It is here just to test BlockLLS against reference solver 7026 (and maybe for someone trying to compare well optimized solver 7027 against straightforward approach to the LLS problem). 7028 7029 More information on naive LLS solver: 7030 * memory requirements: ~[8*K^4+256*NPoints] bytes for KxK grid. 7031 * serial running time: O(K^6+NPoints) for KxK grid 7032 * when compared with BlockLLS, NaiveLLS has ~K larger memory demand and 7033 ~K^2 larger running time. 7034 7035 INPUT PARAMETERS: 7036 S - spline 2D builder object 7037 LambdaNS- nonsmoothness penalty 7038 7039 -- ALGLIB -- 7040 Copyright 05.02.2018 by Bochkanov Sergey 7041 *************************************************************************/ 7042 void spline2dbuildersetalgonaivells(const spline2dbuilder &state, const double lambdans, const xparams _xparams = alglib::xdefault); 7043 7044 7045 /************************************************************************* 7046 This function fits bicubic spline to current dataset, using current area/ 7047 grid and current LLS solver. 7048 7049 ! COMMERCIAL EDITION OF ALGLIB: 7050 ! 7051 ! Commercial Edition of ALGLIB includes following important improvements 7052 ! of this function: 7053 ! * high-performance native backend with same C# interface (C# version) 7054 ! * multithreading support (C++ and C# versions) 7055 ! * hardware vendor (Intel) implementations of linear algebra primitives 7056 ! (C++ and C# versions, x86/x64 platform) 7057 ! 7058 ! We recommend you to read 'Working with commercial version' section of 7059 ! ALGLIB Reference Manual in order to find out how to use performance- 7060 ! related features provided by commercial edition of ALGLIB. 7061 7062 INPUT PARAMETERS: 7063 State - spline 2D builder object 7064 7065 OUTPUT PARAMETERS: 7066 S - 2D spline, fit result 7067 Rep - fitting report, which provides some additional info about 7068 errors, R2 coefficient and so on. 7069 7070 -- ALGLIB -- 7071 Copyright 05.02.2018 by Bochkanov Sergey 7072 *************************************************************************/ 7073 void spline2dfit(const spline2dbuilder &state, spline2dinterpolant &s, spline2dfitreport &rep, const xparams _xparams = alglib::xdefault); 7074 #endif 7075 7076 #if defined(AE_COMPILE_RBFV1) || !defined(AE_PARTIAL_BUILD) 7077 7078 #endif 7079 7080 #if defined(AE_COMPILE_RBF) || !defined(AE_PARTIAL_BUILD) 7081 /************************************************************************* 7082 This function serializes data structure to string. 7083 7084 Important properties of s_out: 7085 * it contains alphanumeric characters, dots, underscores, minus signs 7086 * these symbols are grouped into words, which are separated by spaces 7087 and Windows-style (CR+LF) newlines 7088 * although serializer uses spaces and CR+LF as separators, you can 7089 replace any separator character by arbitrary combination of spaces, 7090 tabs, Windows or Unix newlines. It allows flexible reformatting of 7091 the string in case you want to include it into text or XML file. 7092 But you should not insert separators into the middle of the "words" 7093 nor you should change case of letters. 7094 * s_out can be freely moved between 32-bit and 64-bit systems, little 7095 and big endian machines, and so on. You can serialize structure on 7096 32-bit machine and unserialize it on 64-bit one (or vice versa), or 7097 serialize it on SPARC and unserialize on x86. You can also 7098 serialize it in C++ version of ALGLIB and unserialize in C# one, 7099 and vice versa. 7100 *************************************************************************/ 7101 void rbfserialize(rbfmodel &obj, std::string &s_out); 7102 7103 7104 /************************************************************************* 7105 This function unserializes data structure from string. 7106 *************************************************************************/ 7107 void rbfunserialize(const std::string &s_in, rbfmodel &obj); 7108 7109 7110 7111 7112 /************************************************************************* 7113 This function serializes data structure to C++ stream. 7114 7115 Data stream generated by this function is same as string representation 7116 generated by string version of serializer - alphanumeric characters, 7117 dots, underscores, minus signs, which are grouped into words separated by 7118 spaces and CR+LF. 7119 7120 We recommend you to read comments on string version of serializer to find 7121 out more about serialization of AlGLIB objects. 7122 *************************************************************************/ 7123 void rbfserialize(rbfmodel &obj, std::ostream &s_out); 7124 7125 7126 /************************************************************************* 7127 This function unserializes data structure from stream. 7128 *************************************************************************/ 7129 void rbfunserialize(const std::istream &s_in, rbfmodel &obj); 7130 7131 7132 /************************************************************************* 7133 This function creates RBF model for a scalar (NY=1) or vector (NY>1) 7134 function in a NX-dimensional space (NX>=1). 7135 7136 Newly created model is empty. It can be used for interpolation right after 7137 creation, but it just returns zeros. You have to add points to the model, 7138 tune interpolation settings, and then call model construction function 7139 rbfbuildmodel() which will update model according to your specification. 7140 7141 USAGE: 7142 1. User creates model with rbfcreate() 7143 2. User adds dataset with rbfsetpoints() (points do NOT have to be on a 7144 regular grid) or rbfsetpointsandscales(). 7145 3. (OPTIONAL) User chooses polynomial term by calling: 7146 * rbflinterm() to set linear term 7147 * rbfconstterm() to set constant term 7148 * rbfzeroterm() to set zero term 7149 By default, linear term is used. 7150 4. User tweaks algorithm properties with rbfsetalgohierarchical() method 7151 (or chooses one of the legacy algorithms - QNN (rbfsetalgoqnn) or ML 7152 (rbfsetalgomultilayer)). 7153 5. User calls rbfbuildmodel() function which rebuilds model according to 7154 the specification 7155 6. User may call rbfcalc() to calculate model value at the specified point, 7156 rbfgridcalc() to calculate model values at the points of the regular 7157 grid. User may extract model coefficients with rbfunpack() call. 7158 7159 IMPORTANT: we recommend you to use latest model construction algorithm - 7160 hierarchical RBFs, which is activated by rbfsetalgohierarchical() 7161 function. This algorithm is the fastest one, and most memory- 7162 efficient. 7163 However, it is incompatible with older versions of ALGLIB 7164 (pre-3.11). So, if you serialize hierarchical model, you will 7165 be unable to load it in pre-3.11 ALGLIB. Other model types (QNN 7166 and RBF-ML) are still backward-compatible. 7167 7168 INPUT PARAMETERS: 7169 NX - dimension of the space, NX>=1 7170 NY - function dimension, NY>=1 7171 7172 OUTPUT PARAMETERS: 7173 S - RBF model (initially equals to zero) 7174 7175 NOTE 1: memory requirements. RBF models require amount of memory which is 7176 proportional to the number of data points. Some additional memory 7177 is allocated during model construction, but most of this memory is 7178 freed after model coefficients are calculated. Amount of this 7179 additional memory depends on model construction algorithm being 7180 used. 7181 7182 NOTE 2: prior to ALGLIB version 3.11, RBF models supported only NX=2 or 7183 NX=3. Any attempt to create single-dimensional or more than 7184 3-dimensional RBF model resulted in exception. 7185 7186 ALGLIB 3.11 supports any NX>0, but models created with NX!=2 and 7187 NX!=3 are incompatible with (a) older versions of ALGLIB, (b) old 7188 model construction algorithms (QNN or RBF-ML). 7189 7190 So, if you create a model with NX=2 or NX=3, then, depending on 7191 specific model construction algorithm being chosen, you will (QNN 7192 and RBF-ML) or will not (HierarchicalRBF) get backward compatibility 7193 with older versions of ALGLIB. You have a choice here. 7194 7195 However, if you create a model with NX neither 2 nor 3, you have 7196 no backward compatibility from the start, and you are forced to 7197 use hierarchical RBFs and ALGLIB 3.11 or later. 7198 7199 -- ALGLIB -- 7200 Copyright 13.12.2011, 20.06.2016 by Bochkanov Sergey 7201 *************************************************************************/ 7202 void rbfcreate(const ae_int_t nx, const ae_int_t ny, rbfmodel &s, const xparams _xparams = alglib::xdefault); 7203 7204 7205 /************************************************************************* 7206 This function creates buffer structure which can be used to perform 7207 parallel RBF model evaluations (with one RBF model instance being 7208 used from multiple threads, as long as different threads use different 7209 instances of buffer). 7210 7211 This buffer object can be used with rbftscalcbuf() function (here "ts" 7212 stands for "thread-safe", "buf" is a suffix which denotes function which 7213 reuses previously allocated output space). 7214 7215 How to use it: 7216 * create RBF model structure with rbfcreate() 7217 * load data, tune parameters 7218 * call rbfbuildmodel() 7219 * call rbfcreatecalcbuffer(), once per thread working with RBF model (you 7220 should call this function only AFTER call to rbfbuildmodel(), see below 7221 for more information) 7222 * call rbftscalcbuf() from different threads, with each thread working 7223 with its own copy of buffer object. 7224 7225 INPUT PARAMETERS 7226 S - RBF model 7227 7228 OUTPUT PARAMETERS 7229 Buf - external buffer. 7230 7231 7232 IMPORTANT: buffer object should be used only with RBF model object which 7233 was used to initialize buffer. Any attempt to use buffer with 7234 different object is dangerous - you may get memory violation 7235 error because sizes of internal arrays do not fit to dimensions 7236 of RBF structure. 7237 7238 IMPORTANT: you should call this function only for model which was built 7239 with rbfbuildmodel() function, after successful invocation of 7240 rbfbuildmodel(). Sizes of some internal structures are 7241 determined only after model is built, so buffer object created 7242 before model construction stage will be useless (and any 7243 attempt to use it will result in exception). 7244 7245 -- ALGLIB -- 7246 Copyright 02.04.2016 by Sergey Bochkanov 7247 *************************************************************************/ 7248 void rbfcreatecalcbuffer(const rbfmodel &s, rbfcalcbuffer &buf, const xparams _xparams = alglib::xdefault); 7249 7250 7251 /************************************************************************* 7252 This function adds dataset. 7253 7254 This function overrides results of the previous calls, i.e. multiple calls 7255 of this function will result in only the last set being added. 7256 7257 IMPORTANT: ALGLIB version 3.11 and later allows you to specify a set of 7258 per-dimension scales. Interpolation radii are multiplied by the 7259 scale vector. It may be useful if you have mixed spatio-temporal 7260 data (say, a set of 3D slices recorded at different times). 7261 You should call rbfsetpointsandscales() function to use this 7262 feature. 7263 7264 INPUT PARAMETERS: 7265 S - RBF model, initialized by rbfcreate() call. 7266 XY - points, array[N,NX+NY]. One row corresponds to one point 7267 in the dataset. First NX elements are coordinates, next 7268 NY elements are function values. Array may be larger than 7269 specified, in this case only leading [N,NX+NY] elements 7270 will be used. 7271 N - number of points in the dataset 7272 7273 After you've added dataset and (optionally) tuned algorithm settings you 7274 should call rbfbuildmodel() in order to build a model for you. 7275 7276 NOTE: dataset added by this function is not saved during model serialization. 7277 MODEL ITSELF is serialized, but data used to build it are not. 7278 7279 So, if you 1) add dataset to empty RBF model, 2) serialize and 7280 unserialize it, then you will get an empty RBF model with no dataset 7281 being attached. 7282 7283 From the other side, if you call rbfbuildmodel() between (1) and (2), 7284 then after (2) you will get your fully constructed RBF model - but 7285 again with no dataset attached, so subsequent calls to rbfbuildmodel() 7286 will produce empty model. 7287 7288 7289 -- ALGLIB -- 7290 Copyright 13.12.2011 by Bochkanov Sergey 7291 *************************************************************************/ 7292 void rbfsetpoints(const rbfmodel &s, const real_2d_array &xy, const ae_int_t n, const xparams _xparams = alglib::xdefault); 7293 void rbfsetpoints(const rbfmodel &s, const real_2d_array &xy, const xparams _xparams = alglib::xdefault); 7294 7295 7296 /************************************************************************* 7297 This function adds dataset and a vector of per-dimension scales. 7298 7299 It may be useful if you have mixed spatio-temporal data - say, a set of 3D 7300 slices recorded at different times. Such data typically require different 7301 RBF radii for spatial and temporal dimensions. ALGLIB solves this problem 7302 by specifying single RBF radius, which is (optionally) multiplied by the 7303 scale vector. 7304 7305 This function overrides results of the previous calls, i.e. multiple calls 7306 of this function will result in only the last set being added. 7307 7308 IMPORTANT: only HierarchicalRBF algorithm can work with scaled points. So, 7309 using this function results in RBF models which can be used in 7310 ALGLIB 3.11 or later. Previous versions of the library will be 7311 unable to unserialize models produced by HierarchicalRBF algo. 7312 7313 Any attempt to use this function with RBF-ML or QNN algorithms 7314 will result in -3 error code being returned (incorrect 7315 algorithm). 7316 7317 INPUT PARAMETERS: 7318 R - RBF model, initialized by rbfcreate() call. 7319 XY - points, array[N,NX+NY]. One row corresponds to one point 7320 in the dataset. First NX elements are coordinates, next 7321 NY elements are function values. Array may be larger than 7322 specified, in this case only leading [N,NX+NY] elements 7323 will be used. 7324 N - number of points in the dataset 7325 S - array[NX], scale vector, S[i]>0. 7326 7327 After you've added dataset and (optionally) tuned algorithm settings you 7328 should call rbfbuildmodel() in order to build a model for you. 7329 7330 NOTE: dataset added by this function is not saved during model serialization. 7331 MODEL ITSELF is serialized, but data used to build it are not. 7332 7333 So, if you 1) add dataset to empty RBF model, 2) serialize and 7334 unserialize it, then you will get an empty RBF model with no dataset 7335 being attached. 7336 7337 From the other side, if you call rbfbuildmodel() between (1) and (2), 7338 then after (2) you will get your fully constructed RBF model - but 7339 again with no dataset attached, so subsequent calls to rbfbuildmodel() 7340 will produce empty model. 7341 7342 7343 -- ALGLIB -- 7344 Copyright 20.06.2016 by Bochkanov Sergey 7345 *************************************************************************/ 7346 void rbfsetpointsandscales(const rbfmodel &r, const real_2d_array &xy, const ae_int_t n, const real_1d_array &s, const xparams _xparams = alglib::xdefault); 7347 void rbfsetpointsandscales(const rbfmodel &r, const real_2d_array &xy, const real_1d_array &s, const xparams _xparams = alglib::xdefault); 7348 7349 7350 /************************************************************************* 7351 DEPRECATED:since version 3.11 ALGLIB includes new RBF model construction 7352 algorithm, Hierarchical RBF. This algorithm is faster and 7353 requires less memory than QNN and RBF-ML. It is especially good 7354 for large-scale interpolation problems. So, we recommend you to 7355 consider Hierarchical RBF as default option. 7356 7357 ========================================================================== 7358 7359 This function sets RBF interpolation algorithm. ALGLIB supports several 7360 RBF algorithms with different properties. 7361 7362 This algorithm is called RBF-QNN and it is good for point sets with 7363 following properties: 7364 a) all points are distinct 7365 b) all points are well separated. 7366 c) points distribution is approximately uniform. There is no "contour 7367 lines", clusters of points, or other small-scale structures. 7368 7369 Algorithm description: 7370 1) interpolation centers are allocated to data points 7371 2) interpolation radii are calculated as distances to the nearest centers 7372 times Q coefficient (where Q is a value from [0.75,1.50]). 7373 3) after performing (2) radii are transformed in order to avoid situation 7374 when single outlier has very large radius and influences many points 7375 across all dataset. Transformation has following form: 7376 new_r[i] = min(r[i],Z*median(r[])) 7377 where r[i] is I-th radius, median() is a median radius across entire 7378 dataset, Z is user-specified value which controls amount of deviation 7379 from median radius. 7380 7381 When (a) is violated, we will be unable to build RBF model. When (b) or 7382 (c) are violated, model will be built, but interpolation quality will be 7383 low. See http://www.alglib.net/interpolation/ for more information on this 7384 subject. 7385 7386 This algorithm is used by default. 7387 7388 Additional Q parameter controls smoothness properties of the RBF basis: 7389 * Q<0.75 will give perfectly conditioned basis, but terrible smoothness 7390 properties (RBF interpolant will have sharp peaks around function values) 7391 * Q around 1.0 gives good balance between smoothness and condition number 7392 * Q>1.5 will lead to badly conditioned systems and slow convergence of the 7393 underlying linear solver (although smoothness will be very good) 7394 * Q>2.0 will effectively make optimizer useless because it won't converge 7395 within reasonable amount of iterations. It is possible to set such large 7396 Q, but it is advised not to do so. 7397 7398 INPUT PARAMETERS: 7399 S - RBF model, initialized by RBFCreate() call 7400 Q - Q parameter, Q>0, recommended value - 1.0 7401 Z - Z parameter, Z>0, recommended value - 5.0 7402 7403 NOTE: this function has some serialization-related subtleties. We 7404 recommend you to study serialization examples from ALGLIB Reference 7405 Manual if you want to perform serialization of your models. 7406 7407 7408 -- ALGLIB -- 7409 Copyright 13.12.2011 by Bochkanov Sergey 7410 *************************************************************************/ 7411 void rbfsetalgoqnn(const rbfmodel &s, const double q, const double z, const xparams _xparams = alglib::xdefault); 7412 void rbfsetalgoqnn(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 7413 7414 7415 /************************************************************************* 7416 DEPRECATED:since version 3.11 ALGLIB includes new RBF model construction 7417 algorithm, Hierarchical RBF. This algorithm is faster and 7418 requires less memory than QNN and RBF-ML. It is especially good 7419 for large-scale interpolation problems. So, we recommend you to 7420 consider Hierarchical RBF as default option. 7421 7422 ========================================================================== 7423 7424 This function sets RBF interpolation algorithm. ALGLIB supports several 7425 RBF algorithms with different properties. 7426 7427 This algorithm is called RBF-ML. It builds multilayer RBF model, i.e. 7428 model with subsequently decreasing radii, which allows us to combine 7429 smoothness (due to large radii of the first layers) with exactness (due 7430 to small radii of the last layers) and fast convergence. 7431 7432 Internally RBF-ML uses many different means of acceleration, from sparse 7433 matrices to KD-trees, which results in algorithm whose working time is 7434 roughly proportional to N*log(N)*Density*RBase^2*NLayers, where N is a 7435 number of points, Density is an average density if points per unit of the 7436 interpolation space, RBase is an initial radius, NLayers is a number of 7437 layers. 7438 7439 RBF-ML is good for following kinds of interpolation problems: 7440 1. "exact" problems (perfect fit) with well separated points 7441 2. least squares problems with arbitrary distribution of points (algorithm 7442 gives perfect fit where it is possible, and resorts to least squares 7443 fit in the hard areas). 7444 3. noisy problems where we want to apply some controlled amount of 7445 smoothing. 7446 7447 INPUT PARAMETERS: 7448 S - RBF model, initialized by RBFCreate() call 7449 RBase - RBase parameter, RBase>0 7450 NLayers - NLayers parameter, NLayers>0, recommended value to start 7451 with - about 5. 7452 LambdaV - regularization value, can be useful when solving problem 7453 in the least squares sense. Optimal lambda is problem- 7454 dependent and require trial and error. In our experience, 7455 good lambda can be as large as 0.1, and you can use 0.001 7456 as initial guess. 7457 Default value - 0.01, which is used when LambdaV is not 7458 given. You can specify zero value, but it is not 7459 recommended to do so. 7460 7461 TUNING ALGORITHM 7462 7463 In order to use this algorithm you have to choose three parameters: 7464 * initial radius RBase 7465 * number of layers in the model NLayers 7466 * regularization coefficient LambdaV 7467 7468 Initial radius is easy to choose - you can pick any number several times 7469 larger than the average distance between points. Algorithm won't break 7470 down if you choose radius which is too large (model construction time will 7471 increase, but model will be built correctly). 7472 7473 Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used 7474 by the last layer) will be smaller than the typical distance between 7475 points. In case model error is too large, you can increase number of 7476 layers. Having more layers will make model construction and evaluation 7477 proportionally slower, but it will allow you to have model which precisely 7478 fits your data. From the other side, if you want to suppress noise, you 7479 can DECREASE number of layers to make your model less flexible. 7480 7481 Regularization coefficient LambdaV controls smoothness of the individual 7482 models built for each layer. We recommend you to use default value in case 7483 you don't want to tune this parameter, because having non-zero LambdaV 7484 accelerates and stabilizes internal iterative algorithm. In case you want 7485 to suppress noise you can use LambdaV as additional parameter (larger 7486 value = more smoothness) to tune. 7487 7488 TYPICAL ERRORS 7489 7490 1. Using initial radius which is too large. Memory requirements of the 7491 RBF-ML are roughly proportional to N*Density*RBase^2 (where Density is 7492 an average density of points per unit of the interpolation space). In 7493 the extreme case of the very large RBase we will need O(N^2) units of 7494 memory - and many layers in order to decrease radius to some reasonably 7495 small value. 7496 7497 2. Using too small number of layers - RBF models with large radius are not 7498 flexible enough to reproduce small variations in the target function. 7499 You need many layers with different radii, from large to small, in 7500 order to have good model. 7501 7502 3. Using initial radius which is too small. You will get model with 7503 "holes" in the areas which are too far away from interpolation centers. 7504 However, algorithm will work correctly (and quickly) in this case. 7505 7506 4. Using too many layers - you will get too large and too slow model. This 7507 model will perfectly reproduce your function, but maybe you will be 7508 able to achieve similar results with less layers (and less memory). 7509 7510 -- ALGLIB -- 7511 Copyright 02.03.2012 by Bochkanov Sergey 7512 *************************************************************************/ 7513 void rbfsetalgomultilayer(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const double lambdav, const xparams _xparams = alglib::xdefault); 7514 void rbfsetalgomultilayer(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const xparams _xparams = alglib::xdefault); 7515 7516 7517 /************************************************************************* 7518 This function sets RBF interpolation algorithm. ALGLIB supports several 7519 RBF algorithms with different properties. 7520 7521 This algorithm is called Hierarchical RBF. It similar to its previous 7522 incarnation, RBF-ML, i.e. it also builds a sequence of models with 7523 decreasing radii. However, it uses more economical way of building upper 7524 layers (ones with large radii), which results in faster model construction 7525 and evaluation, as well as smaller memory footprint during construction. 7526 7527 This algorithm has following important features: 7528 * ability to handle millions of points 7529 * controllable smoothing via nonlinearity penalization 7530 * support for NX-dimensional models with NX=1 or NX>3 (unlike QNN or RBF-ML) 7531 * support for specification of per-dimensional radii via scale vector, 7532 which is set by means of rbfsetpointsandscales() function. This feature 7533 is useful if you solve spatio-temporal interpolation problems, where 7534 different radii are required for spatial and temporal dimensions. 7535 7536 Running times are roughly proportional to: 7537 * N*log(N)*NLayers - for model construction 7538 * N*NLayers - for model evaluation 7539 You may see that running time does not depend on search radius or points 7540 density, just on number of layers in the hierarchy. 7541 7542 IMPORTANT: this model construction algorithm was introduced in ALGLIB 3.11 7543 and produces models which are INCOMPATIBLE with previous 7544 versions of ALGLIB. You can not unserialize models produced 7545 with this function in ALGLIB 3.10 or earlier. 7546 7547 INPUT PARAMETERS: 7548 S - RBF model, initialized by rbfcreate() call 7549 RBase - RBase parameter, RBase>0 7550 NLayers - NLayers parameter, NLayers>0, recommended value to start 7551 with - about 5. 7552 LambdaNS- >=0, nonlinearity penalty coefficient, negative values are 7553 not allowed. This parameter adds controllable smoothing to 7554 the problem, which may reduce noise. Specification of non- 7555 zero lambda means that in addition to fitting error solver 7556 will also minimize LambdaNS*|S''(x)|^2 (appropriately 7557 generalized to multiple dimensions. 7558 7559 Specification of exactly zero value means that no penalty 7560 is added (we do not even evaluate matrix of second 7561 derivatives which is necessary for smoothing). 7562 7563 Calculation of nonlinearity penalty is costly - it results 7564 in several-fold increase of model construction time. 7565 Evaluation time remains the same. 7566 7567 Optimal lambda is problem-dependent and requires trial 7568 and error. Good value to start from is 1e-5...1e-6, 7569 which corresponds to slightly noticeable smoothing of the 7570 function. Value 1e-2 usually means that quite heavy 7571 smoothing is applied. 7572 7573 TUNING ALGORITHM 7574 7575 In order to use this algorithm you have to choose three parameters: 7576 * initial radius RBase 7577 * number of layers in the model NLayers 7578 * penalty coefficient LambdaNS 7579 7580 Initial radius is easy to choose - you can pick any number several times 7581 larger than the average distance between points. Algorithm won't break 7582 down if you choose radius which is too large (model construction time will 7583 increase, but model will be built correctly). 7584 7585 Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used 7586 by the last layer) will be smaller than the typical distance between 7587 points. In case model error is too large, you can increase number of 7588 layers. Having more layers will make model construction and evaluation 7589 proportionally slower, but it will allow you to have model which precisely 7590 fits your data. From the other side, if you want to suppress noise, you 7591 can DECREASE number of layers to make your model less flexible (or specify 7592 non-zero LambdaNS). 7593 7594 TYPICAL ERRORS 7595 7596 1. Using too small number of layers - RBF models with large radius are not 7597 flexible enough to reproduce small variations in the target function. 7598 You need many layers with different radii, from large to small, in 7599 order to have good model. 7600 7601 2. Using initial radius which is too small. You will get model with 7602 "holes" in the areas which are too far away from interpolation centers. 7603 However, algorithm will work correctly (and quickly) in this case. 7604 7605 -- ALGLIB -- 7606 Copyright 20.06.2016 by Bochkanov Sergey 7607 *************************************************************************/ 7608 void rbfsetalgohierarchical(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const double lambdans, const xparams _xparams = alglib::xdefault); 7609 7610 7611 /************************************************************************* 7612 This function sets linear term (model is a sum of radial basis functions 7613 plus linear polynomial). This function won't have effect until next call 7614 to RBFBuildModel(). 7615 7616 INPUT PARAMETERS: 7617 S - RBF model, initialized by RBFCreate() call 7618 7619 NOTE: this function has some serialization-related subtleties. We 7620 recommend you to study serialization examples from ALGLIB Reference 7621 Manual if you want to perform serialization of your models. 7622 7623 -- ALGLIB -- 7624 Copyright 13.12.2011 by Bochkanov Sergey 7625 *************************************************************************/ 7626 void rbfsetlinterm(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 7627 7628 7629 /************************************************************************* 7630 This function sets constant term (model is a sum of radial basis functions 7631 plus constant). This function won't have effect until next call to 7632 RBFBuildModel(). 7633 7634 INPUT PARAMETERS: 7635 S - RBF model, initialized by RBFCreate() call 7636 7637 NOTE: this function has some serialization-related subtleties. We 7638 recommend you to study serialization examples from ALGLIB Reference 7639 Manual if you want to perform serialization of your models. 7640 7641 -- ALGLIB -- 7642 Copyright 13.12.2011 by Bochkanov Sergey 7643 *************************************************************************/ 7644 void rbfsetconstterm(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 7645 7646 7647 /************************************************************************* 7648 This function sets zero term (model is a sum of radial basis functions 7649 without polynomial term). This function won't have effect until next call 7650 to RBFBuildModel(). 7651 7652 INPUT PARAMETERS: 7653 S - RBF model, initialized by RBFCreate() call 7654 7655 NOTE: this function has some serialization-related subtleties. We 7656 recommend you to study serialization examples from ALGLIB Reference 7657 Manual if you want to perform serialization of your models. 7658 7659 -- ALGLIB -- 7660 Copyright 13.12.2011 by Bochkanov Sergey 7661 *************************************************************************/ 7662 void rbfsetzeroterm(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 7663 7664 7665 /************************************************************************* 7666 This function sets basis function type, which can be: 7667 * 0 for classic Gaussian 7668 * 1 for fast and compact bell-like basis function, which becomes exactly 7669 zero at distance equal to 3*R (default option). 7670 7671 INPUT PARAMETERS: 7672 S - RBF model, initialized by RBFCreate() call 7673 BF - basis function type: 7674 * 0 - classic Gaussian 7675 * 1 - fast and compact one 7676 7677 -- ALGLIB -- 7678 Copyright 01.02.2017 by Bochkanov Sergey 7679 *************************************************************************/ 7680 void rbfsetv2bf(const rbfmodel &s, const ae_int_t bf, const xparams _xparams = alglib::xdefault); 7681 7682 7683 /************************************************************************* 7684 This function sets stopping criteria of the underlying linear solver for 7685 hierarchical (version 2) RBF constructor. 7686 7687 INPUT PARAMETERS: 7688 S - RBF model, initialized by RBFCreate() call 7689 MaxIts - this criterion will stop algorithm after MaxIts iterations. 7690 Typically a few hundreds iterations is required, with 400 7691 being a good default value to start experimentation. 7692 Zero value means that default value will be selected. 7693 7694 -- ALGLIB -- 7695 Copyright 01.02.2017 by Bochkanov Sergey 7696 *************************************************************************/ 7697 void rbfsetv2its(const rbfmodel &s, const ae_int_t maxits, const xparams _xparams = alglib::xdefault); 7698 7699 7700 /************************************************************************* 7701 This function sets support radius parameter of hierarchical (version 2) 7702 RBF constructor. 7703 7704 Hierarchical RBF model achieves great speed-up by removing from the model 7705 excessive (too dense) nodes. Say, if you have RBF radius equal to 1 meter, 7706 and two nodes are just 1 millimeter apart, you may remove one of them 7707 without reducing model quality. 7708 7709 Support radius parameter is used to justify which points need removal, and 7710 which do not. If two points are less than SUPPORT_R*CUR_RADIUS units of 7711 distance apart, one of them is removed from the model. The larger support 7712 radius is, the faster model construction AND evaluation are. However, 7713 too large values result in "bumpy" models. 7714 7715 INPUT PARAMETERS: 7716 S - RBF model, initialized by RBFCreate() call 7717 R - support radius coefficient, >=0. 7718 Recommended values are [0.1,0.4] range, with 0.1 being 7719 default value. 7720 7721 -- ALGLIB -- 7722 Copyright 01.02.2017 by Bochkanov Sergey 7723 *************************************************************************/ 7724 void rbfsetv2supportr(const rbfmodel &s, const double r, const xparams _xparams = alglib::xdefault); 7725 7726 7727 /************************************************************************* 7728 This function builds RBF model and returns report (contains some 7729 information which can be used for evaluation of the algorithm properties). 7730 7731 Call to this function modifies RBF model by calculating its centers/radii/ 7732 weights and saving them into RBFModel structure. Initially RBFModel 7733 contain zero coefficients, but after call to this function we will have 7734 coefficients which were calculated in order to fit our dataset. 7735 7736 After you called this function you can call RBFCalc(), RBFGridCalc() and 7737 other model calculation functions. 7738 7739 INPUT PARAMETERS: 7740 S - RBF model, initialized by RBFCreate() call 7741 Rep - report: 7742 * Rep.TerminationType: 7743 * -5 - non-distinct basis function centers were detected, 7744 interpolation aborted; only QNN returns this 7745 error code, other algorithms can handle non- 7746 distinct nodes. 7747 * -4 - nonconvergence of the internal SVD solver 7748 * -3 incorrect model construction algorithm was chosen: 7749 QNN or RBF-ML, combined with one of the incompatible 7750 features - NX=1 or NX>3; points with per-dimension 7751 scales. 7752 * 1 - successful termination 7753 * 8 - a termination request was submitted via 7754 rbfrequesttermination() function. 7755 7756 Fields which are set only by modern RBF solvers (hierarchical 7757 or nonnegative; older solvers like QNN and ML initialize these 7758 fields by NANs): 7759 * rep.rmserror - root-mean-square error at nodes 7760 * rep.maxerror - maximum error at nodes 7761 7762 Fields are used for debugging purposes: 7763 * Rep.IterationsCount - iterations count of the LSQR solver 7764 * Rep.NMV - number of matrix-vector products 7765 * Rep.ARows - rows count for the system matrix 7766 * Rep.ACols - columns count for the system matrix 7767 * Rep.ANNZ - number of significantly non-zero elements 7768 (elements above some algorithm-determined threshold) 7769 7770 NOTE: failure to build model will leave current state of the structure 7771 unchanged. 7772 7773 -- ALGLIB -- 7774 Copyright 13.12.2011 by Bochkanov Sergey 7775 *************************************************************************/ 7776 void rbfbuildmodel(const rbfmodel &s, rbfreport &rep, const xparams _xparams = alglib::xdefault); 7777 7778 7779 /************************************************************************* 7780 This function calculates values of the RBF model in the given point. 7781 7782 IMPORTANT: this function works only with modern (hierarchical) RBFs. It 7783 can not be used with legacy (version 1) RBFs because older RBF 7784 code does not support 1-dimensional models. 7785 7786 This function should be used when we have NY=1 (scalar function) and NX=1 7787 (1-dimensional space). If you have 3-dimensional space, use rbfcalc3(). If 7788 you have 2-dimensional space, use rbfcalc3(). If you have general 7789 situation (NX-dimensional space, NY-dimensional function) you should use 7790 generic rbfcalc(). 7791 7792 If you want to perform parallel model evaluation from multiple threads, 7793 use rbftscalcbuf() with per-thread buffer object. 7794 7795 This function returns 0.0 when: 7796 * model is not initialized 7797 * NX<>1 7798 * NY<>1 7799 7800 INPUT PARAMETERS: 7801 S - RBF model 7802 X0 - X-coordinate, finite number 7803 7804 RESULT: 7805 value of the model or 0.0 (as defined above) 7806 7807 -- ALGLIB -- 7808 Copyright 13.12.2011 by Bochkanov Sergey 7809 *************************************************************************/ 7810 double rbfcalc1(const rbfmodel &s, const double x0, const xparams _xparams = alglib::xdefault); 7811 7812 7813 /************************************************************************* 7814 This function calculates values of the RBF model in the given point. 7815 7816 This function should be used when we have NY=1 (scalar function) and NX=2 7817 (2-dimensional space). If you have 3-dimensional space, use rbfcalc3(). If 7818 you have general situation (NX-dimensional space, NY-dimensional function) 7819 you should use generic rbfcalc(). 7820 7821 If you want to calculate function values many times, consider using 7822 rbfgridcalc2v(), which is far more efficient than many subsequent calls to 7823 rbfcalc2(). 7824 7825 If you want to perform parallel model evaluation from multiple threads, 7826 use rbftscalcbuf() with per-thread buffer object. 7827 7828 This function returns 0.0 when: 7829 * model is not initialized 7830 * NX<>2 7831 *NY<>1 7832 7833 INPUT PARAMETERS: 7834 S - RBF model 7835 X0 - first coordinate, finite number 7836 X1 - second coordinate, finite number 7837 7838 RESULT: 7839 value of the model or 0.0 (as defined above) 7840 7841 -- ALGLIB -- 7842 Copyright 13.12.2011 by Bochkanov Sergey 7843 *************************************************************************/ 7844 double rbfcalc2(const rbfmodel &s, const double x0, const double x1, const xparams _xparams = alglib::xdefault); 7845 7846 7847 /************************************************************************* 7848 This function calculates value of the RBF model in the given point. 7849 7850 This function should be used when we have NY=1 (scalar function) and NX=3 7851 (3-dimensional space). If you have 2-dimensional space, use rbfcalc2(). If 7852 you have general situation (NX-dimensional space, NY-dimensional function) 7853 you should use generic rbfcalc(). 7854 7855 If you want to calculate function values many times, consider using 7856 rbfgridcalc3v(), which is far more efficient than many subsequent calls to 7857 rbfcalc3(). 7858 7859 If you want to perform parallel model evaluation from multiple threads, 7860 use rbftscalcbuf() with per-thread buffer object. 7861 7862 This function returns 0.0 when: 7863 * model is not initialized 7864 * NX<>3 7865 *NY<>1 7866 7867 INPUT PARAMETERS: 7868 S - RBF model 7869 X0 - first coordinate, finite number 7870 X1 - second coordinate, finite number 7871 X2 - third coordinate, finite number 7872 7873 RESULT: 7874 value of the model or 0.0 (as defined above) 7875 7876 -- ALGLIB -- 7877 Copyright 13.12.2011 by Bochkanov Sergey 7878 *************************************************************************/ 7879 double rbfcalc3(const rbfmodel &s, const double x0, const double x1, const double x2, const xparams _xparams = alglib::xdefault); 7880 7881 7882 /************************************************************************* 7883 This function calculates values of the RBF model at the given point. 7884 7885 This is general function which can be used for arbitrary NX (dimension of 7886 the space of arguments) and NY (dimension of the function itself). However 7887 when you have NY=1 you may find more convenient to use rbfcalc2() or 7888 rbfcalc3(). 7889 7890 If you want to perform parallel model evaluation from multiple threads, 7891 use rbftscalcbuf() with per-thread buffer object. 7892 7893 This function returns 0.0 when model is not initialized. 7894 7895 INPUT PARAMETERS: 7896 S - RBF model 7897 X - coordinates, array[NX]. 7898 X may have more than NX elements, in this case only 7899 leading NX will be used. 7900 7901 OUTPUT PARAMETERS: 7902 Y - function value, array[NY]. Y is out-parameter and 7903 reallocated after call to this function. In case you want 7904 to reuse previously allocated Y, you may use RBFCalcBuf(), 7905 which reallocates Y only when it is too small. 7906 7907 -- ALGLIB -- 7908 Copyright 13.12.2011 by Bochkanov Sergey 7909 *************************************************************************/ 7910 void rbfcalc(const rbfmodel &s, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 7911 7912 7913 /************************************************************************* 7914 This function calculates values of the RBF model at the given point. 7915 7916 Same as rbfcalc(), but does not reallocate Y when in is large enough to 7917 store function values. 7918 7919 If you want to perform parallel model evaluation from multiple threads, 7920 use rbftscalcbuf() with per-thread buffer object. 7921 7922 INPUT PARAMETERS: 7923 S - RBF model 7924 X - coordinates, array[NX]. 7925 X may have more than NX elements, in this case only 7926 leading NX will be used. 7927 Y - possibly preallocated array 7928 7929 OUTPUT PARAMETERS: 7930 Y - function value, array[NY]. Y is not reallocated when it 7931 is larger than NY. 7932 7933 -- ALGLIB -- 7934 Copyright 13.12.2011 by Bochkanov Sergey 7935 *************************************************************************/ 7936 void rbfcalcbuf(const rbfmodel &s, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 7937 7938 7939 /************************************************************************* 7940 This function calculates values of the RBF model at the given point, using 7941 external buffer object (internal temporaries of RBF model are not 7942 modified). 7943 7944 This function allows to use same RBF model object in different threads, 7945 assuming that different threads use different instances of buffer 7946 structure. 7947 7948 INPUT PARAMETERS: 7949 S - RBF model, may be shared between different threads 7950 Buf - buffer object created for this particular instance of RBF 7951 model with rbfcreatecalcbuffer(). 7952 X - coordinates, array[NX]. 7953 X may have more than NX elements, in this case only 7954 leading NX will be used. 7955 Y - possibly preallocated array 7956 7957 OUTPUT PARAMETERS: 7958 Y - function value, array[NY]. Y is not reallocated when it 7959 is larger than NY. 7960 7961 -- ALGLIB -- 7962 Copyright 13.12.2011 by Bochkanov Sergey 7963 *************************************************************************/ 7964 void rbftscalcbuf(const rbfmodel &s, const rbfcalcbuffer &buf, const real_1d_array &x, real_1d_array &y, const xparams _xparams = alglib::xdefault); 7965 7966 7967 /************************************************************************* 7968 This is legacy function for gridded calculation of RBF model. 7969 7970 It is superseded by rbfgridcalc2v() and rbfgridcalc2vsubset() functions. 7971 7972 -- ALGLIB -- 7973 Copyright 13.12.2011 by Bochkanov Sergey 7974 *************************************************************************/ 7975 void 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, const xparams _xparams = alglib::xdefault); 7976 7977 7978 /************************************************************************* 7979 This function calculates values of the RBF model at the regular grid, 7980 which has N0*N1 points, with Point[I,J] = (X0[I], X1[J]). Vector-valued 7981 RBF models are supported. 7982 7983 This function returns 0.0 when: 7984 * model is not initialized 7985 * NX<>2 7986 7987 ! COMMERCIAL EDITION OF ALGLIB: 7988 ! 7989 ! Commercial Edition of ALGLIB includes following important improvements 7990 ! of this function: 7991 ! * high-performance native backend with same C# interface (C# version) 7992 ! * multithreading support (C++ and C# versions) 7993 ! 7994 ! We recommend you to read 'Working with commercial version' section of 7995 ! ALGLIB Reference Manual in order to find out how to use performance- 7996 ! related features provided by commercial edition of ALGLIB. 7997 7998 NOTE: Parallel processing is implemented only for modern (hierarchical) 7999 RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still 8000 processed serially. 8001 8002 INPUT PARAMETERS: 8003 S - RBF model, used in read-only mode, can be shared between 8004 multiple invocations of this function from multiple 8005 threads. 8006 8007 X0 - array of grid nodes, first coordinates, array[N0]. 8008 Must be ordered by ascending. Exception is generated 8009 if the array is not correctly ordered. 8010 N0 - grid size (number of nodes) in the first dimension 8011 8012 X1 - array of grid nodes, second coordinates, array[N1] 8013 Must be ordered by ascending. Exception is generated 8014 if the array is not correctly ordered. 8015 N1 - grid size (number of nodes) in the second dimension 8016 8017 OUTPUT PARAMETERS: 8018 Y - function values, array[NY*N0*N1], where NY is a number of 8019 "output" vector values (this function supports vector- 8020 valued RBF models). Y is out-variable and is reallocated 8021 by this function. 8022 Y[K+NY*(I0+I1*N0)]=F_k(X0[I0],X1[I1]), for: 8023 * K=0...NY-1 8024 * I0=0...N0-1 8025 * I1=0...N1-1 8026 8027 NOTE: this function supports weakly ordered grid nodes, i.e. you may have 8028 X[i]=X[i+1] for some i. It does not provide you any performance 8029 benefits due to duplication of points, just convenience and 8030 flexibility. 8031 8032 NOTE: this function is re-entrant, i.e. you may use same rbfmodel 8033 structure in multiple threads calling this function for different 8034 grids. 8035 8036 NOTE: if you need function values on some subset of regular grid, which 8037 may be described as "several compact and dense islands", you may 8038 use rbfgridcalc2vsubset(). 8039 8040 -- ALGLIB -- 8041 Copyright 27.01.2017 by Bochkanov Sergey 8042 *************************************************************************/ 8043 void 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, const xparams _xparams = alglib::xdefault); 8044 8045 8046 /************************************************************************* 8047 This function calculates values of the RBF model at some subset of regular 8048 grid: 8049 * grid has N0*N1 points, with Point[I,J] = (X0[I], X1[J]) 8050 * only values at some subset of this grid are required 8051 Vector-valued RBF models are supported. 8052 8053 This function returns 0.0 when: 8054 * model is not initialized 8055 * NX<>2 8056 8057 ! COMMERCIAL EDITION OF ALGLIB: 8058 ! 8059 ! Commercial Edition of ALGLIB includes following important improvements 8060 ! of this function: 8061 ! * high-performance native backend with same C# interface (C# version) 8062 ! * multithreading support (C++ and C# versions) 8063 ! 8064 ! We recommend you to read 'Working with commercial version' section of 8065 ! ALGLIB Reference Manual in order to find out how to use performance- 8066 ! related features provided by commercial edition of ALGLIB. 8067 8068 NOTE: Parallel processing is implemented only for modern (hierarchical) 8069 RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still 8070 processed serially. 8071 8072 INPUT PARAMETERS: 8073 S - RBF model, used in read-only mode, can be shared between 8074 multiple invocations of this function from multiple 8075 threads. 8076 8077 X0 - array of grid nodes, first coordinates, array[N0]. 8078 Must be ordered by ascending. Exception is generated 8079 if the array is not correctly ordered. 8080 N0 - grid size (number of nodes) in the first dimension 8081 8082 X1 - array of grid nodes, second coordinates, array[N1] 8083 Must be ordered by ascending. Exception is generated 8084 if the array is not correctly ordered. 8085 N1 - grid size (number of nodes) in the second dimension 8086 8087 FlagY - array[N0*N1]: 8088 * Y[I0+I1*N0] corresponds to node (X0[I0],X1[I1]) 8089 * it is a "bitmap" array which contains False for nodes 8090 which are NOT calculated, and True for nodes which are 8091 required. 8092 8093 OUTPUT PARAMETERS: 8094 Y - function values, array[NY*N0*N1*N2], where NY is a number 8095 of "output" vector values (this function supports vector- 8096 valued RBF models): 8097 * Y[K+NY*(I0+I1*N0)]=F_k(X0[I0],X1[I1]), 8098 for K=0...NY-1, I0=0...N0-1, I1=0...N1-1. 8099 * elements of Y[] which correspond to FlagY[]=True are 8100 loaded by model values (which may be exactly zero for 8101 some nodes). 8102 * elements of Y[] which correspond to FlagY[]=False MAY be 8103 initialized by zeros OR may be calculated. This function 8104 processes grid as a hierarchy of nested blocks and 8105 micro-rows. If just one element of micro-row is required, 8106 entire micro-row (up to 8 nodes in the current version, 8107 but no promises) is calculated. 8108 8109 NOTE: this function supports weakly ordered grid nodes, i.e. you may have 8110 X[i]=X[i+1] for some i. It does not provide you any performance 8111 benefits due to duplication of points, just convenience and 8112 flexibility. 8113 8114 NOTE: this function is re-entrant, i.e. you may use same rbfmodel 8115 structure in multiple threads calling this function for different 8116 grids. 8117 8118 -- ALGLIB -- 8119 Copyright 04.03.2016 by Bochkanov Sergey 8120 *************************************************************************/ 8121 void 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, const xparams _xparams = alglib::xdefault); 8122 8123 8124 /************************************************************************* 8125 This function calculates values of the RBF model at the regular grid, 8126 which has N0*N1*N2 points, with Point[I,J,K] = (X0[I], X1[J], X2[K]). 8127 Vector-valued RBF models are supported. 8128 8129 This function returns 0.0 when: 8130 * model is not initialized 8131 * NX<>3 8132 8133 ! COMMERCIAL EDITION OF ALGLIB: 8134 ! 8135 ! Commercial Edition of ALGLIB includes following important improvements 8136 ! of this function: 8137 ! * high-performance native backend with same C# interface (C# version) 8138 ! * multithreading support (C++ and C# versions) 8139 ! 8140 ! We recommend you to read 'Working with commercial version' section of 8141 ! ALGLIB Reference Manual in order to find out how to use performance- 8142 ! related features provided by commercial edition of ALGLIB. 8143 8144 NOTE: Parallel processing is implemented only for modern (hierarchical) 8145 RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still 8146 processed serially. 8147 8148 INPUT PARAMETERS: 8149 S - RBF model, used in read-only mode, can be shared between 8150 multiple invocations of this function from multiple 8151 threads. 8152 8153 X0 - array of grid nodes, first coordinates, array[N0]. 8154 Must be ordered by ascending. Exception is generated 8155 if the array is not correctly ordered. 8156 N0 - grid size (number of nodes) in the first dimension 8157 8158 X1 - array of grid nodes, second coordinates, array[N1] 8159 Must be ordered by ascending. Exception is generated 8160 if the array is not correctly ordered. 8161 N1 - grid size (number of nodes) in the second dimension 8162 8163 X2 - array of grid nodes, third coordinates, array[N2] 8164 Must be ordered by ascending. Exception is generated 8165 if the array is not correctly ordered. 8166 N2 - grid size (number of nodes) in the third dimension 8167 8168 OUTPUT PARAMETERS: 8169 Y - function values, array[NY*N0*N1*N2], where NY is a number 8170 of "output" vector values (this function supports vector- 8171 valued RBF models). Y is out-variable and is reallocated 8172 by this function. 8173 Y[K+NY*(I0+I1*N0+I2*N0*N1)]=F_k(X0[I0],X1[I1],X2[I2]), for: 8174 * K=0...NY-1 8175 * I0=0...N0-1 8176 * I1=0...N1-1 8177 * I2=0...N2-1 8178 8179 NOTE: this function supports weakly ordered grid nodes, i.e. you may have 8180 X[i]=X[i+1] for some i. It does not provide you any performance 8181 benefits due to duplication of points, just convenience and 8182 flexibility. 8183 8184 NOTE: this function is re-entrant, i.e. you may use same rbfmodel 8185 structure in multiple threads calling this function for different 8186 grids. 8187 8188 NOTE: if you need function values on some subset of regular grid, which 8189 may be described as "several compact and dense islands", you may 8190 use rbfgridcalc3vsubset(). 8191 8192 -- ALGLIB -- 8193 Copyright 04.03.2016 by Bochkanov Sergey 8194 *************************************************************************/ 8195 void 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, const xparams _xparams = alglib::xdefault); 8196 8197 8198 /************************************************************************* 8199 This function calculates values of the RBF model at some subset of regular 8200 grid: 8201 * grid has N0*N1*N2 points, with Point[I,J,K] = (X0[I], X1[J], X2[K]) 8202 * only values at some subset of this grid are required 8203 Vector-valued RBF models are supported. 8204 8205 This function returns 0.0 when: 8206 * model is not initialized 8207 * NX<>3 8208 8209 ! COMMERCIAL EDITION OF ALGLIB: 8210 ! 8211 ! Commercial Edition of ALGLIB includes following important improvements 8212 ! of this function: 8213 ! * high-performance native backend with same C# interface (C# version) 8214 ! * multithreading support (C++ and C# versions) 8215 ! 8216 ! We recommend you to read 'Working with commercial version' section of 8217 ! ALGLIB Reference Manual in order to find out how to use performance- 8218 ! related features provided by commercial edition of ALGLIB. 8219 8220 NOTE: Parallel processing is implemented only for modern (hierarchical) 8221 RBFs. Legacy version 1 RBFs (created by QNN or RBF-ML) are still 8222 processed serially. 8223 8224 INPUT PARAMETERS: 8225 S - RBF model, used in read-only mode, can be shared between 8226 multiple invocations of this function from multiple 8227 threads. 8228 8229 X0 - array of grid nodes, first coordinates, array[N0]. 8230 Must be ordered by ascending. Exception is generated 8231 if the array is not correctly ordered. 8232 N0 - grid size (number of nodes) in the first dimension 8233 8234 X1 - array of grid nodes, second coordinates, array[N1] 8235 Must be ordered by ascending. Exception is generated 8236 if the array is not correctly ordered. 8237 N1 - grid size (number of nodes) in the second dimension 8238 8239 X2 - array of grid nodes, third coordinates, array[N2] 8240 Must be ordered by ascending. Exception is generated 8241 if the array is not correctly ordered. 8242 N2 - grid size (number of nodes) in the third dimension 8243 8244 FlagY - array[N0*N1*N2]: 8245 * Y[I0+I1*N0+I2*N0*N1] corresponds to node (X0[I0],X1[I1],X2[I2]) 8246 * it is a "bitmap" array which contains False for nodes 8247 which are NOT calculated, and True for nodes which are 8248 required. 8249 8250 OUTPUT PARAMETERS: 8251 Y - function values, array[NY*N0*N1*N2], where NY is a number 8252 of "output" vector values (this function supports vector- 8253 valued RBF models): 8254 * Y[K+NY*(I0+I1*N0+I2*N0*N1)]=F_k(X0[I0],X1[I1],X2[I2]), 8255 for K=0...NY-1, I0=0...N0-1, I1=0...N1-1, I2=0...N2-1. 8256 * elements of Y[] which correspond to FlagY[]=True are 8257 loaded by model values (which may be exactly zero for 8258 some nodes). 8259 * elements of Y[] which correspond to FlagY[]=False MAY be 8260 initialized by zeros OR may be calculated. This function 8261 processes grid as a hierarchy of nested blocks and 8262 micro-rows. If just one element of micro-row is required, 8263 entire micro-row (up to 8 nodes in the current version, 8264 but no promises) is calculated. 8265 8266 NOTE: this function supports weakly ordered grid nodes, i.e. you may have 8267 X[i]=X[i+1] for some i. It does not provide you any performance 8268 benefits due to duplication of points, just convenience and 8269 flexibility. 8270 8271 NOTE: this function is re-entrant, i.e. you may use same rbfmodel 8272 structure in multiple threads calling this function for different 8273 grids. 8274 8275 -- ALGLIB -- 8276 Copyright 04.03.2016 by Bochkanov Sergey 8277 *************************************************************************/ 8278 void 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, const xparams _xparams = alglib::xdefault); 8279 8280 8281 /************************************************************************* 8282 This function "unpacks" RBF model by extracting its coefficients. 8283 8284 INPUT PARAMETERS: 8285 S - RBF model 8286 8287 OUTPUT PARAMETERS: 8288 NX - dimensionality of argument 8289 NY - dimensionality of the target function 8290 XWR - model information, array[NC,NX+NY+1]. 8291 One row of the array corresponds to one basis function: 8292 * first NX columns - coordinates of the center 8293 * next NY columns - weights, one per dimension of the 8294 function being modelled 8295 For ModelVersion=1: 8296 * last column - radius, same for all dimensions of 8297 the function being modelled 8298 For ModelVersion=2: 8299 * last NX columns - radii, one per dimension 8300 NC - number of the centers 8301 V - polynomial term , array[NY,NX+1]. One row per one 8302 dimension of the function being modelled. First NX 8303 elements are linear coefficients, V[NX] is equal to the 8304 constant part. 8305 ModelVersion-version of the RBF model: 8306 * 1 - for models created by QNN and RBF-ML algorithms, 8307 compatible with ALGLIB 3.10 or earlier. 8308 * 2 - for models created by HierarchicalRBF, requires 8309 ALGLIB 3.11 or later 8310 8311 -- ALGLIB -- 8312 Copyright 13.12.2011 by Bochkanov Sergey 8313 *************************************************************************/ 8314 void 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, const xparams _xparams = alglib::xdefault); 8315 8316 8317 /************************************************************************* 8318 This function returns model version. 8319 8320 INPUT PARAMETERS: 8321 S - RBF model 8322 8323 RESULT: 8324 * 1 - for models created by QNN and RBF-ML algorithms, 8325 compatible with ALGLIB 3.10 or earlier. 8326 * 2 - for models created by HierarchicalRBF, requires 8327 ALGLIB 3.11 or later 8328 8329 -- ALGLIB -- 8330 Copyright 06.07.2016 by Bochkanov Sergey 8331 *************************************************************************/ 8332 ae_int_t rbfgetmodelversion(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 8333 8334 8335 /************************************************************************* 8336 This function is used to peek into hierarchical RBF construction process 8337 from some other thread and get current progress indicator. It returns 8338 value in [0,1]. 8339 8340 IMPORTANT: only HRBFs (hierarchical RBFs) support peeking into progress 8341 indicator. Legacy RBF-ML and RBF-QNN do not support it. You 8342 will always get 0 value. 8343 8344 INPUT PARAMETERS: 8345 S - RBF model object 8346 8347 RESULT: 8348 progress value, in [0,1] 8349 8350 -- ALGLIB -- 8351 Copyright 17.11.2018 by Bochkanov Sergey 8352 *************************************************************************/ 8353 double rbfpeekprogress(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 8354 8355 8356 /************************************************************************* 8357 This function is used to submit a request for termination of the 8358 hierarchical RBF construction process from some other thread. As result, 8359 RBF construction is terminated smoothly (with proper deallocation of all 8360 necessary resources) and resultant model is filled by zeros. 8361 8362 A rep.terminationtype=8 will be returned upon receiving such request. 8363 8364 IMPORTANT: only HRBFs (hierarchical RBFs) support termination requests. 8365 Legacy RBF-ML and RBF-QNN do not support it. An attempt to 8366 terminate their construction will be ignored. 8367 8368 IMPORTANT: termination request flag is cleared when the model construction 8369 starts. Thus, any pre-construction termination requests will be 8370 silently ignored - only ones submitted AFTER construction has 8371 actually began will be handled. 8372 8373 INPUT PARAMETERS: 8374 S - RBF model object 8375 8376 -- ALGLIB -- 8377 Copyright 17.11.2018 by Bochkanov Sergey 8378 *************************************************************************/ 8379 void rbfrequesttermination(const rbfmodel &s, const xparams _xparams = alglib::xdefault); 8380 #endif 8381 8382 #if defined(AE_COMPILE_INTCOMP) || !defined(AE_PARTIAL_BUILD) 8383 /************************************************************************* 8384 This function is left for backward compatibility. 8385 Use fitspheremc() instead. 8386 8387 8388 -- ALGLIB -- 8389 Copyright 14.04.2017 by Bochkanov Sergey 8390 *************************************************************************/ 8391 void nsfitspheremcc(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rhi, const xparams _xparams = alglib::xdefault); 8392 8393 8394 /************************************************************************* 8395 This function is left for backward compatibility. 8396 Use fitspheremi() instead. 8397 8398 -- ALGLIB -- 8399 Copyright 14.04.2017 by Bochkanov Sergey 8400 *************************************************************************/ 8401 void nsfitspheremic(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo, const xparams _xparams = alglib::xdefault); 8402 8403 8404 /************************************************************************* 8405 This function is left for backward compatibility. 8406 Use fitspheremz() instead. 8407 8408 -- ALGLIB -- 8409 Copyright 14.04.2017 by Bochkanov Sergey 8410 *************************************************************************/ 8411 void nsfitspheremzc(const real_2d_array &xy, const ae_int_t npoints, const ae_int_t nx, real_1d_array &cx, double &rlo, double &rhi, const xparams _xparams = alglib::xdefault); 8412 8413 8414 /************************************************************************* 8415 This function is left for backward compatibility. 8416 Use fitspherex() instead. 8417 8418 -- ALGLIB -- 8419 Copyright 14.04.2017 by Bochkanov Sergey 8420 *************************************************************************/ 8421 void 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, const xparams _xparams = alglib::xdefault); 8422 #endif 8423 } 8424 8425 ///////////////////////////////////////////////////////////////////////// 8426 // 8427 // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) 8428 // 8429 ///////////////////////////////////////////////////////////////////////// 8430 namespace alglib_impl 8431 { 8432 #if defined(AE_COMPILE_IDW) || !defined(AE_PARTIAL_BUILD) 8433 void idwcreatecalcbuffer(idwmodel* s, 8434 idwcalcbuffer* buf, 8435 ae_state *_state); 8436 void idwbuildercreate(ae_int_t nx, 8437 ae_int_t ny, 8438 idwbuilder* state, 8439 ae_state *_state); 8440 void idwbuildersetnlayers(idwbuilder* state, 8441 ae_int_t nlayers, 8442 ae_state *_state); 8443 void idwbuildersetpoints(idwbuilder* state, 8444 /* Real */ ae_matrix* xy, 8445 ae_int_t n, 8446 ae_state *_state); 8447 void idwbuildersetalgomstab(idwbuilder* state, 8448 double srad, 8449 ae_state *_state); 8450 void idwbuildersetalgotextbookshepard(idwbuilder* state, 8451 double p, 8452 ae_state *_state); 8453 void idwbuildersetalgotextbookmodshepard(idwbuilder* state, 8454 double r, 8455 ae_state *_state); 8456 void idwbuildersetuserterm(idwbuilder* state, double v, ae_state *_state); 8457 void idwbuildersetconstterm(idwbuilder* state, ae_state *_state); 8458 void idwbuildersetzeroterm(idwbuilder* state, ae_state *_state); 8459 double idwcalc1(idwmodel* s, double x0, ae_state *_state); 8460 double idwcalc2(idwmodel* s, double x0, double x1, ae_state *_state); 8461 double idwcalc3(idwmodel* s, 8462 double x0, 8463 double x1, 8464 double x2, 8465 ae_state *_state); 8466 void idwcalc(idwmodel* s, 8467 /* Real */ ae_vector* x, 8468 /* Real */ ae_vector* y, 8469 ae_state *_state); 8470 void idwcalcbuf(idwmodel* s, 8471 /* Real */ ae_vector* x, 8472 /* Real */ ae_vector* y, 8473 ae_state *_state); 8474 void idwtscalcbuf(idwmodel* s, 8475 idwcalcbuffer* buf, 8476 /* Real */ ae_vector* x, 8477 /* Real */ ae_vector* y, 8478 ae_state *_state); 8479 void idwfit(idwbuilder* state, 8480 idwmodel* model, 8481 idwreport* rep, 8482 ae_state *_state); 8483 void idwalloc(ae_serializer* s, idwmodel* model, ae_state *_state); 8484 void idwserialize(ae_serializer* s, idwmodel* model, ae_state *_state); 8485 void idwunserialize(ae_serializer* s, idwmodel* model, ae_state *_state); 8486 void _idwcalcbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic); 8487 void _idwcalcbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8488 void _idwcalcbuffer_clear(void* _p); 8489 void _idwcalcbuffer_destroy(void* _p); 8490 void _idwmodel_init(void* _p, ae_state *_state, ae_bool make_automatic); 8491 void _idwmodel_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8492 void _idwmodel_clear(void* _p); 8493 void _idwmodel_destroy(void* _p); 8494 void _idwbuilder_init(void* _p, ae_state *_state, ae_bool make_automatic); 8495 void _idwbuilder_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8496 void _idwbuilder_clear(void* _p); 8497 void _idwbuilder_destroy(void* _p); 8498 void _idwreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 8499 void _idwreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8500 void _idwreport_clear(void* _p); 8501 void _idwreport_destroy(void* _p); 8502 #endif 8503 #if defined(AE_COMPILE_RATINT) || !defined(AE_PARTIAL_BUILD) 8504 double barycentriccalc(barycentricinterpolant* b, 8505 double t, 8506 ae_state *_state); 8507 void barycentricdiff1(barycentricinterpolant* b, 8508 double t, 8509 double* f, 8510 double* df, 8511 ae_state *_state); 8512 void barycentricdiff2(barycentricinterpolant* b, 8513 double t, 8514 double* f, 8515 double* df, 8516 double* d2f, 8517 ae_state *_state); 8518 void barycentriclintransx(barycentricinterpolant* b, 8519 double ca, 8520 double cb, 8521 ae_state *_state); 8522 void barycentriclintransy(barycentricinterpolant* b, 8523 double ca, 8524 double cb, 8525 ae_state *_state); 8526 void barycentricunpack(barycentricinterpolant* b, 8527 ae_int_t* n, 8528 /* Real */ ae_vector* x, 8529 /* Real */ ae_vector* y, 8530 /* Real */ ae_vector* w, 8531 ae_state *_state); 8532 void barycentricbuildxyw(/* Real */ ae_vector* x, 8533 /* Real */ ae_vector* y, 8534 /* Real */ ae_vector* w, 8535 ae_int_t n, 8536 barycentricinterpolant* b, 8537 ae_state *_state); 8538 void barycentricbuildfloaterhormann(/* Real */ ae_vector* x, 8539 /* Real */ ae_vector* y, 8540 ae_int_t n, 8541 ae_int_t d, 8542 barycentricinterpolant* b, 8543 ae_state *_state); 8544 void barycentriccopy(barycentricinterpolant* b, 8545 barycentricinterpolant* b2, 8546 ae_state *_state); 8547 void _barycentricinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 8548 void _barycentricinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8549 void _barycentricinterpolant_clear(void* _p); 8550 void _barycentricinterpolant_destroy(void* _p); 8551 #endif 8552 #if defined(AE_COMPILE_FITSPHERE) || !defined(AE_PARTIAL_BUILD) 8553 void fitspherels(/* Real */ ae_matrix* xy, 8554 ae_int_t npoints, 8555 ae_int_t nx, 8556 /* Real */ ae_vector* cx, 8557 double* r, 8558 ae_state *_state); 8559 void fitspheremc(/* Real */ ae_matrix* xy, 8560 ae_int_t npoints, 8561 ae_int_t nx, 8562 /* Real */ ae_vector* cx, 8563 double* rhi, 8564 ae_state *_state); 8565 void fitspheremi(/* Real */ ae_matrix* xy, 8566 ae_int_t npoints, 8567 ae_int_t nx, 8568 /* Real */ ae_vector* cx, 8569 double* rlo, 8570 ae_state *_state); 8571 void fitspheremz(/* Real */ ae_matrix* xy, 8572 ae_int_t npoints, 8573 ae_int_t nx, 8574 /* Real */ ae_vector* cx, 8575 double* rlo, 8576 double* rhi, 8577 ae_state *_state); 8578 void fitspherex(/* Real */ ae_matrix* xy, 8579 ae_int_t npoints, 8580 ae_int_t nx, 8581 ae_int_t problemtype, 8582 double epsx, 8583 ae_int_t aulits, 8584 double penalty, 8585 /* Real */ ae_vector* cx, 8586 double* rlo, 8587 double* rhi, 8588 ae_state *_state); 8589 void fitsphereinternal(/* Real */ ae_matrix* xy, 8590 ae_int_t npoints, 8591 ae_int_t nx, 8592 ae_int_t problemtype, 8593 ae_int_t solvertype, 8594 double epsx, 8595 ae_int_t aulits, 8596 double penalty, 8597 /* Real */ ae_vector* cx, 8598 double* rlo, 8599 double* rhi, 8600 fitsphereinternalreport* rep, 8601 ae_state *_state); 8602 void _fitsphereinternalreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 8603 void _fitsphereinternalreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8604 void _fitsphereinternalreport_clear(void* _p); 8605 void _fitsphereinternalreport_destroy(void* _p); 8606 #endif 8607 #if defined(AE_COMPILE_INTFITSERV) || !defined(AE_PARTIAL_BUILD) 8608 void lsfitscalexy(/* Real */ ae_vector* x, 8609 /* Real */ ae_vector* y, 8610 /* Real */ ae_vector* w, 8611 ae_int_t n, 8612 /* Real */ ae_vector* xc, 8613 /* Real */ ae_vector* yc, 8614 /* Integer */ ae_vector* dc, 8615 ae_int_t k, 8616 double* xa, 8617 double* xb, 8618 double* sa, 8619 double* sb, 8620 /* Real */ ae_vector* xoriginal, 8621 /* Real */ ae_vector* yoriginal, 8622 ae_state *_state); 8623 void buildpriorterm(/* Real */ ae_matrix* xy, 8624 ae_int_t n, 8625 ae_int_t nx, 8626 ae_int_t ny, 8627 ae_int_t modeltype, 8628 double priorval, 8629 /* Real */ ae_matrix* v, 8630 ae_state *_state); 8631 void buildpriorterm1(/* Real */ ae_vector* xy1, 8632 ae_int_t n, 8633 ae_int_t nx, 8634 ae_int_t ny, 8635 ae_int_t modeltype, 8636 double priorval, 8637 /* Real */ ae_matrix* v, 8638 ae_state *_state); 8639 #endif 8640 #if defined(AE_COMPILE_SPLINE1D) || !defined(AE_PARTIAL_BUILD) 8641 void spline1dbuildlinear(/* Real */ ae_vector* x, 8642 /* Real */ ae_vector* y, 8643 ae_int_t n, 8644 spline1dinterpolant* c, 8645 ae_state *_state); 8646 void spline1dbuildcubic(/* Real */ ae_vector* x, 8647 /* Real */ ae_vector* y, 8648 ae_int_t n, 8649 ae_int_t boundltype, 8650 double boundl, 8651 ae_int_t boundrtype, 8652 double boundr, 8653 spline1dinterpolant* c, 8654 ae_state *_state); 8655 void spline1dgriddiffcubic(/* Real */ ae_vector* x, 8656 /* Real */ ae_vector* y, 8657 ae_int_t n, 8658 ae_int_t boundltype, 8659 double boundl, 8660 ae_int_t boundrtype, 8661 double boundr, 8662 /* Real */ ae_vector* d, 8663 ae_state *_state); 8664 void spline1dgriddiff2cubic(/* Real */ ae_vector* x, 8665 /* Real */ ae_vector* y, 8666 ae_int_t n, 8667 ae_int_t boundltype, 8668 double boundl, 8669 ae_int_t boundrtype, 8670 double boundr, 8671 /* Real */ ae_vector* d1, 8672 /* Real */ ae_vector* d2, 8673 ae_state *_state); 8674 void spline1dconvcubic(/* Real */ ae_vector* x, 8675 /* Real */ ae_vector* y, 8676 ae_int_t n, 8677 ae_int_t boundltype, 8678 double boundl, 8679 ae_int_t boundrtype, 8680 double boundr, 8681 /* Real */ ae_vector* x2, 8682 ae_int_t n2, 8683 /* Real */ ae_vector* y2, 8684 ae_state *_state); 8685 void spline1dconvdiffcubic(/* Real */ ae_vector* x, 8686 /* Real */ ae_vector* y, 8687 ae_int_t n, 8688 ae_int_t boundltype, 8689 double boundl, 8690 ae_int_t boundrtype, 8691 double boundr, 8692 /* Real */ ae_vector* x2, 8693 ae_int_t n2, 8694 /* Real */ ae_vector* y2, 8695 /* Real */ ae_vector* d2, 8696 ae_state *_state); 8697 void spline1dconvdiff2cubic(/* Real */ ae_vector* x, 8698 /* Real */ ae_vector* y, 8699 ae_int_t n, 8700 ae_int_t boundltype, 8701 double boundl, 8702 ae_int_t boundrtype, 8703 double boundr, 8704 /* Real */ ae_vector* x2, 8705 ae_int_t n2, 8706 /* Real */ ae_vector* y2, 8707 /* Real */ ae_vector* d2, 8708 /* Real */ ae_vector* dd2, 8709 ae_state *_state); 8710 void spline1dbuildcatmullrom(/* Real */ ae_vector* x, 8711 /* Real */ ae_vector* y, 8712 ae_int_t n, 8713 ae_int_t boundtype, 8714 double tension, 8715 spline1dinterpolant* c, 8716 ae_state *_state); 8717 void spline1dbuildhermite(/* Real */ ae_vector* x, 8718 /* Real */ ae_vector* y, 8719 /* Real */ ae_vector* d, 8720 ae_int_t n, 8721 spline1dinterpolant* c, 8722 ae_state *_state); 8723 void spline1dbuildakima(/* Real */ ae_vector* x, 8724 /* Real */ ae_vector* y, 8725 ae_int_t n, 8726 spline1dinterpolant* c, 8727 ae_state *_state); 8728 double spline1dcalc(spline1dinterpolant* c, double x, ae_state *_state); 8729 void spline1ddiff(spline1dinterpolant* c, 8730 double x, 8731 double* s, 8732 double* ds, 8733 double* d2s, 8734 ae_state *_state); 8735 void spline1dcopy(spline1dinterpolant* c, 8736 spline1dinterpolant* cc, 8737 ae_state *_state); 8738 void spline1dunpack(spline1dinterpolant* c, 8739 ae_int_t* n, 8740 /* Real */ ae_matrix* tbl, 8741 ae_state *_state); 8742 void spline1dlintransx(spline1dinterpolant* c, 8743 double a, 8744 double b, 8745 ae_state *_state); 8746 void spline1dlintransy(spline1dinterpolant* c, 8747 double a, 8748 double b, 8749 ae_state *_state); 8750 double spline1dintegrate(spline1dinterpolant* c, 8751 double x, 8752 ae_state *_state); 8753 void spline1dfitpenalized(/* Real */ ae_vector* x, 8754 /* Real */ ae_vector* y, 8755 ae_int_t n, 8756 ae_int_t m, 8757 double rho, 8758 ae_int_t* info, 8759 spline1dinterpolant* s, 8760 spline1dfitreport* rep, 8761 ae_state *_state); 8762 void spline1dfitpenalizedw(/* Real */ ae_vector* x, 8763 /* Real */ ae_vector* y, 8764 /* Real */ ae_vector* w, 8765 ae_int_t n, 8766 ae_int_t m, 8767 double rho, 8768 ae_int_t* info, 8769 spline1dinterpolant* s, 8770 spline1dfitreport* rep, 8771 ae_state *_state); 8772 void spline1dconvdiffinternal(/* Real */ ae_vector* xold, 8773 /* Real */ ae_vector* yold, 8774 /* Real */ ae_vector* dold, 8775 ae_int_t n, 8776 /* Real */ ae_vector* x2, 8777 ae_int_t n2, 8778 /* Real */ ae_vector* y, 8779 ae_bool needy, 8780 /* Real */ ae_vector* d1, 8781 ae_bool needd1, 8782 /* Real */ ae_vector* d2, 8783 ae_bool needd2, 8784 ae_state *_state); 8785 void spline1drootsandextrema(spline1dinterpolant* c, 8786 /* Real */ ae_vector* r, 8787 ae_int_t* nr, 8788 ae_bool* dr, 8789 /* Real */ ae_vector* e, 8790 /* Integer */ ae_vector* et, 8791 ae_int_t* ne, 8792 ae_bool* de, 8793 ae_state *_state); 8794 void heapsortdpoints(/* Real */ ae_vector* x, 8795 /* Real */ ae_vector* y, 8796 /* Real */ ae_vector* d, 8797 ae_int_t n, 8798 ae_state *_state); 8799 void solvepolinom2(double p0, 8800 double m0, 8801 double p1, 8802 double m1, 8803 double* x0, 8804 double* x1, 8805 ae_int_t* nr, 8806 ae_state *_state); 8807 void solvecubicpolinom(double pa, 8808 double ma, 8809 double pb, 8810 double mb, 8811 double a, 8812 double b, 8813 double* x0, 8814 double* x1, 8815 double* x2, 8816 double* ex0, 8817 double* ex1, 8818 ae_int_t* nr, 8819 ae_int_t* ne, 8820 /* Real */ ae_vector* tempdata, 8821 ae_state *_state); 8822 ae_int_t bisectmethod(double pa, 8823 double ma, 8824 double pb, 8825 double mb, 8826 double a, 8827 double b, 8828 double* x, 8829 ae_state *_state); 8830 void spline1dbuildmonotone(/* Real */ ae_vector* x, 8831 /* Real */ ae_vector* y, 8832 ae_int_t n, 8833 spline1dinterpolant* c, 8834 ae_state *_state); 8835 void _spline1dinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 8836 void _spline1dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8837 void _spline1dinterpolant_clear(void* _p); 8838 void _spline1dinterpolant_destroy(void* _p); 8839 void _spline1dfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 8840 void _spline1dfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8841 void _spline1dfitreport_clear(void* _p); 8842 void _spline1dfitreport_destroy(void* _p); 8843 #endif 8844 #if defined(AE_COMPILE_PARAMETRIC) || !defined(AE_PARTIAL_BUILD) 8845 void pspline2build(/* Real */ ae_matrix* xy, 8846 ae_int_t n, 8847 ae_int_t st, 8848 ae_int_t pt, 8849 pspline2interpolant* p, 8850 ae_state *_state); 8851 void pspline3build(/* Real */ ae_matrix* xy, 8852 ae_int_t n, 8853 ae_int_t st, 8854 ae_int_t pt, 8855 pspline3interpolant* p, 8856 ae_state *_state); 8857 void pspline2buildperiodic(/* Real */ ae_matrix* xy, 8858 ae_int_t n, 8859 ae_int_t st, 8860 ae_int_t pt, 8861 pspline2interpolant* p, 8862 ae_state *_state); 8863 void pspline3buildperiodic(/* Real */ ae_matrix* xy, 8864 ae_int_t n, 8865 ae_int_t st, 8866 ae_int_t pt, 8867 pspline3interpolant* p, 8868 ae_state *_state); 8869 void pspline2parametervalues(pspline2interpolant* p, 8870 ae_int_t* n, 8871 /* Real */ ae_vector* t, 8872 ae_state *_state); 8873 void pspline3parametervalues(pspline3interpolant* p, 8874 ae_int_t* n, 8875 /* Real */ ae_vector* t, 8876 ae_state *_state); 8877 void pspline2calc(pspline2interpolant* p, 8878 double t, 8879 double* x, 8880 double* y, 8881 ae_state *_state); 8882 void pspline3calc(pspline3interpolant* p, 8883 double t, 8884 double* x, 8885 double* y, 8886 double* z, 8887 ae_state *_state); 8888 void pspline2tangent(pspline2interpolant* p, 8889 double t, 8890 double* x, 8891 double* y, 8892 ae_state *_state); 8893 void pspline3tangent(pspline3interpolant* p, 8894 double t, 8895 double* x, 8896 double* y, 8897 double* z, 8898 ae_state *_state); 8899 void pspline2diff(pspline2interpolant* p, 8900 double t, 8901 double* x, 8902 double* dx, 8903 double* y, 8904 double* dy, 8905 ae_state *_state); 8906 void pspline3diff(pspline3interpolant* p, 8907 double t, 8908 double* x, 8909 double* dx, 8910 double* y, 8911 double* dy, 8912 double* z, 8913 double* dz, 8914 ae_state *_state); 8915 void pspline2diff2(pspline2interpolant* p, 8916 double t, 8917 double* x, 8918 double* dx, 8919 double* d2x, 8920 double* y, 8921 double* dy, 8922 double* d2y, 8923 ae_state *_state); 8924 void pspline3diff2(pspline3interpolant* p, 8925 double t, 8926 double* x, 8927 double* dx, 8928 double* d2x, 8929 double* y, 8930 double* dy, 8931 double* d2y, 8932 double* z, 8933 double* dz, 8934 double* d2z, 8935 ae_state *_state); 8936 double pspline2arclength(pspline2interpolant* p, 8937 double a, 8938 double b, 8939 ae_state *_state); 8940 double pspline3arclength(pspline3interpolant* p, 8941 double a, 8942 double b, 8943 ae_state *_state); 8944 void parametricrdpfixed(/* Real */ ae_matrix* x, 8945 ae_int_t n, 8946 ae_int_t d, 8947 ae_int_t stopm, 8948 double stopeps, 8949 /* Real */ ae_matrix* x2, 8950 /* Integer */ ae_vector* idx2, 8951 ae_int_t* nsections, 8952 ae_state *_state); 8953 void _pspline2interpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 8954 void _pspline2interpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8955 void _pspline2interpolant_clear(void* _p); 8956 void _pspline2interpolant_destroy(void* _p); 8957 void _pspline3interpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 8958 void _pspline3interpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 8959 void _pspline3interpolant_clear(void* _p); 8960 void _pspline3interpolant_destroy(void* _p); 8961 #endif 8962 #if defined(AE_COMPILE_SPLINE3D) || !defined(AE_PARTIAL_BUILD) 8963 double spline3dcalc(spline3dinterpolant* c, 8964 double x, 8965 double y, 8966 double z, 8967 ae_state *_state); 8968 void spline3dlintransxyz(spline3dinterpolant* c, 8969 double ax, 8970 double bx, 8971 double ay, 8972 double by, 8973 double az, 8974 double bz, 8975 ae_state *_state); 8976 void spline3dlintransf(spline3dinterpolant* c, 8977 double a, 8978 double b, 8979 ae_state *_state); 8980 void spline3dcopy(spline3dinterpolant* c, 8981 spline3dinterpolant* cc, 8982 ae_state *_state); 8983 void spline3dresampletrilinear(/* Real */ ae_vector* a, 8984 ae_int_t oldzcount, 8985 ae_int_t oldycount, 8986 ae_int_t oldxcount, 8987 ae_int_t newzcount, 8988 ae_int_t newycount, 8989 ae_int_t newxcount, 8990 /* Real */ ae_vector* b, 8991 ae_state *_state); 8992 void spline3dbuildtrilinearv(/* Real */ ae_vector* x, 8993 ae_int_t n, 8994 /* Real */ ae_vector* y, 8995 ae_int_t m, 8996 /* Real */ ae_vector* z, 8997 ae_int_t l, 8998 /* Real */ ae_vector* f, 8999 ae_int_t d, 9000 spline3dinterpolant* c, 9001 ae_state *_state); 9002 void spline3dcalcvbuf(spline3dinterpolant* c, 9003 double x, 9004 double y, 9005 double z, 9006 /* Real */ ae_vector* f, 9007 ae_state *_state); 9008 void spline3dcalcv(spline3dinterpolant* c, 9009 double x, 9010 double y, 9011 double z, 9012 /* Real */ ae_vector* f, 9013 ae_state *_state); 9014 void spline3dunpackv(spline3dinterpolant* c, 9015 ae_int_t* n, 9016 ae_int_t* m, 9017 ae_int_t* l, 9018 ae_int_t* d, 9019 ae_int_t* stype, 9020 /* Real */ ae_matrix* tbl, 9021 ae_state *_state); 9022 void _spline3dinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 9023 void _spline3dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9024 void _spline3dinterpolant_clear(void* _p); 9025 void _spline3dinterpolant_destroy(void* _p); 9026 #endif 9027 #if defined(AE_COMPILE_POLINT) || !defined(AE_PARTIAL_BUILD) 9028 void polynomialbar2cheb(barycentricinterpolant* p, 9029 double a, 9030 double b, 9031 /* Real */ ae_vector* t, 9032 ae_state *_state); 9033 void polynomialcheb2bar(/* Real */ ae_vector* t, 9034 ae_int_t n, 9035 double a, 9036 double b, 9037 barycentricinterpolant* p, 9038 ae_state *_state); 9039 void polynomialbar2pow(barycentricinterpolant* p, 9040 double c, 9041 double s, 9042 /* Real */ ae_vector* a, 9043 ae_state *_state); 9044 void polynomialpow2bar(/* Real */ ae_vector* a, 9045 ae_int_t n, 9046 double c, 9047 double s, 9048 barycentricinterpolant* p, 9049 ae_state *_state); 9050 void polynomialbuild(/* Real */ ae_vector* x, 9051 /* Real */ ae_vector* y, 9052 ae_int_t n, 9053 barycentricinterpolant* p, 9054 ae_state *_state); 9055 void polynomialbuildeqdist(double a, 9056 double b, 9057 /* Real */ ae_vector* y, 9058 ae_int_t n, 9059 barycentricinterpolant* p, 9060 ae_state *_state); 9061 void polynomialbuildcheb1(double a, 9062 double b, 9063 /* Real */ ae_vector* y, 9064 ae_int_t n, 9065 barycentricinterpolant* p, 9066 ae_state *_state); 9067 void polynomialbuildcheb2(double a, 9068 double b, 9069 /* Real */ ae_vector* y, 9070 ae_int_t n, 9071 barycentricinterpolant* p, 9072 ae_state *_state); 9073 double polynomialcalceqdist(double a, 9074 double b, 9075 /* Real */ ae_vector* f, 9076 ae_int_t n, 9077 double t, 9078 ae_state *_state); 9079 double polynomialcalccheb1(double a, 9080 double b, 9081 /* Real */ ae_vector* f, 9082 ae_int_t n, 9083 double t, 9084 ae_state *_state); 9085 double polynomialcalccheb2(double a, 9086 double b, 9087 /* Real */ ae_vector* f, 9088 ae_int_t n, 9089 double t, 9090 ae_state *_state); 9091 #endif 9092 #if defined(AE_COMPILE_LSFIT) || !defined(AE_PARTIAL_BUILD) 9093 void lstfitpiecewiselinearrdpfixed(/* Real */ ae_vector* x, 9094 /* Real */ ae_vector* y, 9095 ae_int_t n, 9096 ae_int_t m, 9097 /* Real */ ae_vector* x2, 9098 /* Real */ ae_vector* y2, 9099 ae_int_t* nsections, 9100 ae_state *_state); 9101 void lstfitpiecewiselinearrdp(/* Real */ ae_vector* x, 9102 /* Real */ ae_vector* y, 9103 ae_int_t n, 9104 double eps, 9105 /* Real */ ae_vector* x2, 9106 /* Real */ ae_vector* y2, 9107 ae_int_t* nsections, 9108 ae_state *_state); 9109 void polynomialfit(/* Real */ ae_vector* x, 9110 /* Real */ ae_vector* y, 9111 ae_int_t n, 9112 ae_int_t m, 9113 ae_int_t* info, 9114 barycentricinterpolant* p, 9115 polynomialfitreport* rep, 9116 ae_state *_state); 9117 void polynomialfitwc(/* Real */ ae_vector* x, 9118 /* Real */ ae_vector* y, 9119 /* Real */ ae_vector* w, 9120 ae_int_t n, 9121 /* Real */ ae_vector* xc, 9122 /* Real */ ae_vector* yc, 9123 /* Integer */ ae_vector* dc, 9124 ae_int_t k, 9125 ae_int_t m, 9126 ae_int_t* info, 9127 barycentricinterpolant* p, 9128 polynomialfitreport* rep, 9129 ae_state *_state); 9130 double logisticcalc4(double x, 9131 double a, 9132 double b, 9133 double c, 9134 double d, 9135 ae_state *_state); 9136 double logisticcalc5(double x, 9137 double a, 9138 double b, 9139 double c, 9140 double d, 9141 double g, 9142 ae_state *_state); 9143 void logisticfit4(/* Real */ ae_vector* x, 9144 /* Real */ ae_vector* y, 9145 ae_int_t n, 9146 double* a, 9147 double* b, 9148 double* c, 9149 double* d, 9150 lsfitreport* rep, 9151 ae_state *_state); 9152 void logisticfit4ec(/* Real */ ae_vector* x, 9153 /* Real */ ae_vector* y, 9154 ae_int_t n, 9155 double cnstrleft, 9156 double cnstrright, 9157 double* a, 9158 double* b, 9159 double* c, 9160 double* d, 9161 lsfitreport* rep, 9162 ae_state *_state); 9163 void logisticfit5(/* Real */ ae_vector* x, 9164 /* Real */ ae_vector* y, 9165 ae_int_t n, 9166 double* a, 9167 double* b, 9168 double* c, 9169 double* d, 9170 double* g, 9171 lsfitreport* rep, 9172 ae_state *_state); 9173 void logisticfit5ec(/* Real */ ae_vector* x, 9174 /* Real */ ae_vector* y, 9175 ae_int_t n, 9176 double cnstrleft, 9177 double cnstrright, 9178 double* a, 9179 double* b, 9180 double* c, 9181 double* d, 9182 double* g, 9183 lsfitreport* rep, 9184 ae_state *_state); 9185 void logisticfit45x(/* Real */ ae_vector* x, 9186 /* Real */ ae_vector* y, 9187 ae_int_t n, 9188 double cnstrleft, 9189 double cnstrright, 9190 ae_bool is4pl, 9191 double lambdav, 9192 double epsx, 9193 ae_int_t rscnt, 9194 double* a, 9195 double* b, 9196 double* c, 9197 double* d, 9198 double* g, 9199 lsfitreport* rep, 9200 ae_state *_state); 9201 void barycentricfitfloaterhormannwc(/* Real */ ae_vector* x, 9202 /* Real */ ae_vector* y, 9203 /* Real */ ae_vector* w, 9204 ae_int_t n, 9205 /* Real */ ae_vector* xc, 9206 /* Real */ ae_vector* yc, 9207 /* Integer */ ae_vector* dc, 9208 ae_int_t k, 9209 ae_int_t m, 9210 ae_int_t* info, 9211 barycentricinterpolant* b, 9212 barycentricfitreport* rep, 9213 ae_state *_state); 9214 void barycentricfitfloaterhormann(/* Real */ ae_vector* x, 9215 /* Real */ ae_vector* y, 9216 ae_int_t n, 9217 ae_int_t m, 9218 ae_int_t* info, 9219 barycentricinterpolant* b, 9220 barycentricfitreport* rep, 9221 ae_state *_state); 9222 void spline1dfitcubicwc(/* Real */ ae_vector* x, 9223 /* Real */ ae_vector* y, 9224 /* Real */ ae_vector* w, 9225 ae_int_t n, 9226 /* Real */ ae_vector* xc, 9227 /* Real */ ae_vector* yc, 9228 /* Integer */ ae_vector* dc, 9229 ae_int_t k, 9230 ae_int_t m, 9231 ae_int_t* info, 9232 spline1dinterpolant* s, 9233 spline1dfitreport* rep, 9234 ae_state *_state); 9235 void spline1dfithermitewc(/* Real */ ae_vector* x, 9236 /* Real */ ae_vector* y, 9237 /* Real */ ae_vector* w, 9238 ae_int_t n, 9239 /* Real */ ae_vector* xc, 9240 /* Real */ ae_vector* yc, 9241 /* Integer */ ae_vector* dc, 9242 ae_int_t k, 9243 ae_int_t m, 9244 ae_int_t* info, 9245 spline1dinterpolant* s, 9246 spline1dfitreport* rep, 9247 ae_state *_state); 9248 void spline1dfitcubic(/* Real */ ae_vector* x, 9249 /* Real */ ae_vector* y, 9250 ae_int_t n, 9251 ae_int_t m, 9252 ae_int_t* info, 9253 spline1dinterpolant* s, 9254 spline1dfitreport* rep, 9255 ae_state *_state); 9256 void spline1dfithermite(/* Real */ ae_vector* x, 9257 /* Real */ ae_vector* y, 9258 ae_int_t n, 9259 ae_int_t m, 9260 ae_int_t* info, 9261 spline1dinterpolant* s, 9262 spline1dfitreport* rep, 9263 ae_state *_state); 9264 void lsfitlinearw(/* Real */ ae_vector* y, 9265 /* Real */ ae_vector* w, 9266 /* Real */ ae_matrix* fmatrix, 9267 ae_int_t n, 9268 ae_int_t m, 9269 ae_int_t* info, 9270 /* Real */ ae_vector* c, 9271 lsfitreport* rep, 9272 ae_state *_state); 9273 void lsfitlinearwc(/* Real */ ae_vector* y, 9274 /* Real */ ae_vector* w, 9275 /* Real */ ae_matrix* fmatrix, 9276 /* Real */ ae_matrix* cmatrix, 9277 ae_int_t n, 9278 ae_int_t m, 9279 ae_int_t k, 9280 ae_int_t* info, 9281 /* Real */ ae_vector* c, 9282 lsfitreport* rep, 9283 ae_state *_state); 9284 void lsfitlinear(/* Real */ ae_vector* y, 9285 /* Real */ ae_matrix* fmatrix, 9286 ae_int_t n, 9287 ae_int_t m, 9288 ae_int_t* info, 9289 /* Real */ ae_vector* c, 9290 lsfitreport* rep, 9291 ae_state *_state); 9292 void lsfitlinearc(/* Real */ ae_vector* y, 9293 /* Real */ ae_matrix* fmatrix, 9294 /* Real */ ae_matrix* cmatrix, 9295 ae_int_t n, 9296 ae_int_t m, 9297 ae_int_t k, 9298 ae_int_t* info, 9299 /* Real */ ae_vector* c, 9300 lsfitreport* rep, 9301 ae_state *_state); 9302 void lsfitcreatewf(/* Real */ ae_matrix* x, 9303 /* Real */ ae_vector* y, 9304 /* Real */ ae_vector* w, 9305 /* Real */ ae_vector* c, 9306 ae_int_t n, 9307 ae_int_t m, 9308 ae_int_t k, 9309 double diffstep, 9310 lsfitstate* state, 9311 ae_state *_state); 9312 void lsfitcreatef(/* Real */ ae_matrix* x, 9313 /* Real */ ae_vector* y, 9314 /* Real */ ae_vector* c, 9315 ae_int_t n, 9316 ae_int_t m, 9317 ae_int_t k, 9318 double diffstep, 9319 lsfitstate* state, 9320 ae_state *_state); 9321 void lsfitcreatewfg(/* Real */ ae_matrix* x, 9322 /* Real */ ae_vector* y, 9323 /* Real */ ae_vector* w, 9324 /* Real */ ae_vector* c, 9325 ae_int_t n, 9326 ae_int_t m, 9327 ae_int_t k, 9328 ae_bool cheapfg, 9329 lsfitstate* state, 9330 ae_state *_state); 9331 void lsfitcreatefg(/* Real */ ae_matrix* x, 9332 /* Real */ ae_vector* y, 9333 /* Real */ ae_vector* c, 9334 ae_int_t n, 9335 ae_int_t m, 9336 ae_int_t k, 9337 ae_bool cheapfg, 9338 lsfitstate* state, 9339 ae_state *_state); 9340 void lsfitcreatewfgh(/* Real */ ae_matrix* x, 9341 /* Real */ ae_vector* y, 9342 /* Real */ ae_vector* w, 9343 /* Real */ ae_vector* c, 9344 ae_int_t n, 9345 ae_int_t m, 9346 ae_int_t k, 9347 lsfitstate* state, 9348 ae_state *_state); 9349 void lsfitcreatefgh(/* Real */ ae_matrix* x, 9350 /* Real */ ae_vector* y, 9351 /* Real */ ae_vector* c, 9352 ae_int_t n, 9353 ae_int_t m, 9354 ae_int_t k, 9355 lsfitstate* state, 9356 ae_state *_state); 9357 void lsfitsetcond(lsfitstate* state, 9358 double epsx, 9359 ae_int_t maxits, 9360 ae_state *_state); 9361 void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state); 9362 void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state); 9363 void lsfitsetscale(lsfitstate* state, 9364 /* Real */ ae_vector* s, 9365 ae_state *_state); 9366 void lsfitsetbc(lsfitstate* state, 9367 /* Real */ ae_vector* bndl, 9368 /* Real */ ae_vector* bndu, 9369 ae_state *_state); 9370 void lsfitsetlc(lsfitstate* state, 9371 /* Real */ ae_matrix* c, 9372 /* Integer */ ae_vector* ct, 9373 ae_int_t k, 9374 ae_state *_state); 9375 ae_bool lsfititeration(lsfitstate* state, ae_state *_state); 9376 void lsfitresults(lsfitstate* state, 9377 ae_int_t* info, 9378 /* Real */ ae_vector* c, 9379 lsfitreport* rep, 9380 ae_state *_state); 9381 void lsfitsetgradientcheck(lsfitstate* state, 9382 double teststep, 9383 ae_state *_state); 9384 void _polynomialfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 9385 void _polynomialfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9386 void _polynomialfitreport_clear(void* _p); 9387 void _polynomialfitreport_destroy(void* _p); 9388 void _barycentricfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 9389 void _barycentricfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9390 void _barycentricfitreport_clear(void* _p); 9391 void _barycentricfitreport_destroy(void* _p); 9392 void _lsfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 9393 void _lsfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9394 void _lsfitreport_clear(void* _p); 9395 void _lsfitreport_destroy(void* _p); 9396 void _lsfitstate_init(void* _p, ae_state *_state, ae_bool make_automatic); 9397 void _lsfitstate_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9398 void _lsfitstate_clear(void* _p); 9399 void _lsfitstate_destroy(void* _p); 9400 #endif 9401 #if defined(AE_COMPILE_RBFV2) || !defined(AE_PARTIAL_BUILD) 9402 void rbfv2create(ae_int_t nx, 9403 ae_int_t ny, 9404 rbfv2model* s, 9405 ae_state *_state); 9406 void rbfv2createcalcbuffer(rbfv2model* s, 9407 rbfv2calcbuffer* buf, 9408 ae_state *_state); 9409 void rbfv2buildhierarchical(/* Real */ ae_matrix* x, 9410 /* Real */ ae_matrix* y, 9411 ae_int_t n, 9412 /* Real */ ae_vector* scalevec, 9413 ae_int_t aterm, 9414 ae_int_t nh, 9415 double rbase, 9416 double lambdans, 9417 rbfv2model* s, 9418 ae_int_t* progress10000, 9419 ae_bool* terminationrequest, 9420 rbfv2report* rep, 9421 ae_state *_state); 9422 void rbfv2alloc(ae_serializer* s, rbfv2model* model, ae_state *_state); 9423 void rbfv2serialize(ae_serializer* s, rbfv2model* model, ae_state *_state); 9424 void rbfv2unserialize(ae_serializer* s, 9425 rbfv2model* model, 9426 ae_state *_state); 9427 double rbfv2farradius(ae_int_t bf, ae_state *_state); 9428 double rbfv2nearradius(ae_int_t bf, ae_state *_state); 9429 double rbfv2basisfunc(ae_int_t bf, double d2, ae_state *_state); 9430 void rbfv2basisfuncdiff2(ae_int_t bf, 9431 double d2, 9432 double* f, 9433 double* df, 9434 double* d2f, 9435 ae_state *_state); 9436 double rbfv2calc1(rbfv2model* s, double x0, ae_state *_state); 9437 double rbfv2calc2(rbfv2model* s, double x0, double x1, ae_state *_state); 9438 double rbfv2calc3(rbfv2model* s, 9439 double x0, 9440 double x1, 9441 double x2, 9442 ae_state *_state); 9443 void rbfv2calcbuf(rbfv2model* s, 9444 /* Real */ ae_vector* x, 9445 /* Real */ ae_vector* y, 9446 ae_state *_state); 9447 void rbfv2tscalcbuf(rbfv2model* s, 9448 rbfv2calcbuffer* buf, 9449 /* Real */ ae_vector* x, 9450 /* Real */ ae_vector* y, 9451 ae_state *_state); 9452 void rbfv2gridcalc2(rbfv2model* s, 9453 /* Real */ ae_vector* x0, 9454 ae_int_t n0, 9455 /* Real */ ae_vector* x1, 9456 ae_int_t n1, 9457 /* Real */ ae_matrix* y, 9458 ae_state *_state); 9459 void rbfv2gridcalcvx(rbfv2model* s, 9460 /* Real */ ae_vector* x0, 9461 ae_int_t n0, 9462 /* Real */ ae_vector* x1, 9463 ae_int_t n1, 9464 /* Real */ ae_vector* x2, 9465 ae_int_t n2, 9466 /* Real */ ae_vector* x3, 9467 ae_int_t n3, 9468 /* Boolean */ ae_vector* flagy, 9469 ae_bool sparsey, 9470 /* Real */ ae_vector* y, 9471 ae_state *_state); 9472 void rbfv2partialgridcalcrec(rbfv2model* s, 9473 /* Real */ ae_vector* x0, 9474 ae_int_t n0, 9475 /* Real */ ae_vector* x1, 9476 ae_int_t n1, 9477 /* Real */ ae_vector* x2, 9478 ae_int_t n2, 9479 /* Real */ ae_vector* x3, 9480 ae_int_t n3, 9481 /* Integer */ ae_vector* blocks0, 9482 ae_int_t block0a, 9483 ae_int_t block0b, 9484 /* Integer */ ae_vector* blocks1, 9485 ae_int_t block1a, 9486 ae_int_t block1b, 9487 /* Integer */ ae_vector* blocks2, 9488 ae_int_t block2a, 9489 ae_int_t block2b, 9490 /* Integer */ ae_vector* blocks3, 9491 ae_int_t block3a, 9492 ae_int_t block3b, 9493 /* Boolean */ ae_vector* flagy, 9494 ae_bool sparsey, 9495 ae_int_t levelidx, 9496 double avgfuncpernode, 9497 ae_shared_pool* bufpool, 9498 /* Real */ ae_vector* y, 9499 ae_state *_state); 9500 ae_bool _trypexec_rbfv2partialgridcalcrec(rbfv2model* s, 9501 /* Real */ ae_vector* x0, 9502 ae_int_t n0, 9503 /* Real */ ae_vector* x1, 9504 ae_int_t n1, 9505 /* Real */ ae_vector* x2, 9506 ae_int_t n2, 9507 /* Real */ ae_vector* x3, 9508 ae_int_t n3, 9509 /* Integer */ ae_vector* blocks0, 9510 ae_int_t block0a, 9511 ae_int_t block0b, 9512 /* Integer */ ae_vector* blocks1, 9513 ae_int_t block1a, 9514 ae_int_t block1b, 9515 /* Integer */ ae_vector* blocks2, 9516 ae_int_t block2a, 9517 ae_int_t block2b, 9518 /* Integer */ ae_vector* blocks3, 9519 ae_int_t block3a, 9520 ae_int_t block3b, 9521 /* Boolean */ ae_vector* flagy, 9522 ae_bool sparsey, 9523 ae_int_t levelidx, 9524 double avgfuncpernode, 9525 ae_shared_pool* bufpool, 9526 /* Real */ ae_vector* y, ae_state *_state); 9527 void rbfv2unpack(rbfv2model* s, 9528 ae_int_t* nx, 9529 ae_int_t* ny, 9530 /* Real */ ae_matrix* xwr, 9531 ae_int_t* nc, 9532 /* Real */ ae_matrix* v, 9533 ae_state *_state); 9534 void _rbfv2calcbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic); 9535 void _rbfv2calcbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9536 void _rbfv2calcbuffer_clear(void* _p); 9537 void _rbfv2calcbuffer_destroy(void* _p); 9538 void _rbfv2model_init(void* _p, ae_state *_state, ae_bool make_automatic); 9539 void _rbfv2model_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9540 void _rbfv2model_clear(void* _p); 9541 void _rbfv2model_destroy(void* _p); 9542 void _rbfv2gridcalcbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic); 9543 void _rbfv2gridcalcbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9544 void _rbfv2gridcalcbuffer_clear(void* _p); 9545 void _rbfv2gridcalcbuffer_destroy(void* _p); 9546 void _rbfv2report_init(void* _p, ae_state *_state, ae_bool make_automatic); 9547 void _rbfv2report_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9548 void _rbfv2report_clear(void* _p); 9549 void _rbfv2report_destroy(void* _p); 9550 #endif 9551 #if defined(AE_COMPILE_SPLINE2D) || !defined(AE_PARTIAL_BUILD) 9552 double spline2dcalc(spline2dinterpolant* c, 9553 double x, 9554 double y, 9555 ae_state *_state); 9556 void spline2ddiff(spline2dinterpolant* c, 9557 double x, 9558 double y, 9559 double* f, 9560 double* fx, 9561 double* fy, 9562 double* fxy, 9563 ae_state *_state); 9564 void spline2dcalcvbuf(spline2dinterpolant* c, 9565 double x, 9566 double y, 9567 /* Real */ ae_vector* f, 9568 ae_state *_state); 9569 double spline2dcalcvi(spline2dinterpolant* c, 9570 double x, 9571 double y, 9572 ae_int_t i, 9573 ae_state *_state); 9574 void spline2dcalcv(spline2dinterpolant* c, 9575 double x, 9576 double y, 9577 /* Real */ ae_vector* f, 9578 ae_state *_state); 9579 void spline2ddiffvi(spline2dinterpolant* c, 9580 double x, 9581 double y, 9582 ae_int_t i, 9583 double* f, 9584 double* fx, 9585 double* fy, 9586 double* fxy, 9587 ae_state *_state); 9588 void spline2dlintransxy(spline2dinterpolant* c, 9589 double ax, 9590 double bx, 9591 double ay, 9592 double by, 9593 ae_state *_state); 9594 void spline2dlintransf(spline2dinterpolant* c, 9595 double a, 9596 double b, 9597 ae_state *_state); 9598 void spline2dcopy(spline2dinterpolant* c, 9599 spline2dinterpolant* cc, 9600 ae_state *_state); 9601 void spline2dresamplebicubic(/* Real */ ae_matrix* a, 9602 ae_int_t oldheight, 9603 ae_int_t oldwidth, 9604 /* Real */ ae_matrix* b, 9605 ae_int_t newheight, 9606 ae_int_t newwidth, 9607 ae_state *_state); 9608 void spline2dresamplebilinear(/* Real */ ae_matrix* a, 9609 ae_int_t oldheight, 9610 ae_int_t oldwidth, 9611 /* Real */ ae_matrix* b, 9612 ae_int_t newheight, 9613 ae_int_t newwidth, 9614 ae_state *_state); 9615 void spline2dbuildbilinearv(/* Real */ ae_vector* x, 9616 ae_int_t n, 9617 /* Real */ ae_vector* y, 9618 ae_int_t m, 9619 /* Real */ ae_vector* f, 9620 ae_int_t d, 9621 spline2dinterpolant* c, 9622 ae_state *_state); 9623 void spline2dbuildbicubicv(/* Real */ ae_vector* x, 9624 ae_int_t n, 9625 /* Real */ ae_vector* y, 9626 ae_int_t m, 9627 /* Real */ ae_vector* f, 9628 ae_int_t d, 9629 spline2dinterpolant* c, 9630 ae_state *_state); 9631 void spline2dunpackv(spline2dinterpolant* c, 9632 ae_int_t* m, 9633 ae_int_t* n, 9634 ae_int_t* d, 9635 /* Real */ ae_matrix* tbl, 9636 ae_state *_state); 9637 void spline2dbuildbilinear(/* Real */ ae_vector* x, 9638 /* Real */ ae_vector* y, 9639 /* Real */ ae_matrix* f, 9640 ae_int_t m, 9641 ae_int_t n, 9642 spline2dinterpolant* c, 9643 ae_state *_state); 9644 void spline2dbuildbicubic(/* Real */ ae_vector* x, 9645 /* Real */ ae_vector* y, 9646 /* Real */ ae_matrix* f, 9647 ae_int_t m, 9648 ae_int_t n, 9649 spline2dinterpolant* c, 9650 ae_state *_state); 9651 void spline2dunpack(spline2dinterpolant* c, 9652 ae_int_t* m, 9653 ae_int_t* n, 9654 /* Real */ ae_matrix* tbl, 9655 ae_state *_state); 9656 void spline2dbuildercreate(ae_int_t d, 9657 spline2dbuilder* state, 9658 ae_state *_state); 9659 void spline2dbuildersetuserterm(spline2dbuilder* state, 9660 double v, 9661 ae_state *_state); 9662 void spline2dbuildersetlinterm(spline2dbuilder* state, ae_state *_state); 9663 void spline2dbuildersetconstterm(spline2dbuilder* state, ae_state *_state); 9664 void spline2dbuildersetzeroterm(spline2dbuilder* state, ae_state *_state); 9665 void spline2dbuildersetpoints(spline2dbuilder* state, 9666 /* Real */ ae_matrix* xy, 9667 ae_int_t n, 9668 ae_state *_state); 9669 void spline2dbuildersetareaauto(spline2dbuilder* state, ae_state *_state); 9670 void spline2dbuildersetarea(spline2dbuilder* state, 9671 double xa, 9672 double xb, 9673 double ya, 9674 double yb, 9675 ae_state *_state); 9676 void spline2dbuildersetgrid(spline2dbuilder* state, 9677 ae_int_t kx, 9678 ae_int_t ky, 9679 ae_state *_state); 9680 void spline2dbuildersetalgofastddm(spline2dbuilder* state, 9681 ae_int_t nlayers, 9682 double lambdav, 9683 ae_state *_state); 9684 void spline2dbuildersetalgoblocklls(spline2dbuilder* state, 9685 double lambdans, 9686 ae_state *_state); 9687 void spline2dbuildersetalgonaivells(spline2dbuilder* state, 9688 double lambdans, 9689 ae_state *_state); 9690 void spline2dfit(spline2dbuilder* state, 9691 spline2dinterpolant* s, 9692 spline2dfitreport* rep, 9693 ae_state *_state); 9694 void spline2dalloc(ae_serializer* s, 9695 spline2dinterpolant* spline, 9696 ae_state *_state); 9697 void spline2dserialize(ae_serializer* s, 9698 spline2dinterpolant* spline, 9699 ae_state *_state); 9700 void spline2dunserialize(ae_serializer* s, 9701 spline2dinterpolant* spline, 9702 ae_state *_state); 9703 void _spline2dinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic); 9704 void _spline2dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9705 void _spline2dinterpolant_clear(void* _p); 9706 void _spline2dinterpolant_destroy(void* _p); 9707 void _spline2dbuilder_init(void* _p, ae_state *_state, ae_bool make_automatic); 9708 void _spline2dbuilder_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9709 void _spline2dbuilder_clear(void* _p); 9710 void _spline2dbuilder_destroy(void* _p); 9711 void _spline2dfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 9712 void _spline2dfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9713 void _spline2dfitreport_clear(void* _p); 9714 void _spline2dfitreport_destroy(void* _p); 9715 void _spline2dxdesignmatrix_init(void* _p, ae_state *_state, ae_bool make_automatic); 9716 void _spline2dxdesignmatrix_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9717 void _spline2dxdesignmatrix_clear(void* _p); 9718 void _spline2dxdesignmatrix_destroy(void* _p); 9719 void _spline2dblockllsbuf_init(void* _p, ae_state *_state, ae_bool make_automatic); 9720 void _spline2dblockllsbuf_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9721 void _spline2dblockllsbuf_clear(void* _p); 9722 void _spline2dblockllsbuf_destroy(void* _p); 9723 void _spline2dfastddmbuf_init(void* _p, ae_state *_state, ae_bool make_automatic); 9724 void _spline2dfastddmbuf_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9725 void _spline2dfastddmbuf_clear(void* _p); 9726 void _spline2dfastddmbuf_destroy(void* _p); 9727 #endif 9728 #if defined(AE_COMPILE_RBFV1) || !defined(AE_PARTIAL_BUILD) 9729 void rbfv1create(ae_int_t nx, 9730 ae_int_t ny, 9731 rbfv1model* s, 9732 ae_state *_state); 9733 void rbfv1createcalcbuffer(rbfv1model* s, 9734 rbfv1calcbuffer* buf, 9735 ae_state *_state); 9736 void rbfv1buildmodel(/* Real */ ae_matrix* x, 9737 /* Real */ ae_matrix* y, 9738 ae_int_t n, 9739 ae_int_t aterm, 9740 ae_int_t algorithmtype, 9741 ae_int_t nlayers, 9742 double radvalue, 9743 double radzvalue, 9744 double lambdav, 9745 double epsort, 9746 double epserr, 9747 ae_int_t maxits, 9748 rbfv1model* s, 9749 rbfv1report* rep, 9750 ae_state *_state); 9751 void rbfv1alloc(ae_serializer* s, rbfv1model* model, ae_state *_state); 9752 void rbfv1serialize(ae_serializer* s, rbfv1model* model, ae_state *_state); 9753 void rbfv1unserialize(ae_serializer* s, 9754 rbfv1model* model, 9755 ae_state *_state); 9756 double rbfv1calc2(rbfv1model* s, double x0, double x1, ae_state *_state); 9757 double rbfv1calc3(rbfv1model* s, 9758 double x0, 9759 double x1, 9760 double x2, 9761 ae_state *_state); 9762 void rbfv1calcbuf(rbfv1model* s, 9763 /* Real */ ae_vector* x, 9764 /* Real */ ae_vector* y, 9765 ae_state *_state); 9766 void rbfv1tscalcbuf(rbfv1model* s, 9767 rbfv1calcbuffer* buf, 9768 /* Real */ ae_vector* x, 9769 /* Real */ ae_vector* y, 9770 ae_state *_state); 9771 void rbfv1gridcalc2(rbfv1model* s, 9772 /* Real */ ae_vector* x0, 9773 ae_int_t n0, 9774 /* Real */ ae_vector* x1, 9775 ae_int_t n1, 9776 /* Real */ ae_matrix* y, 9777 ae_state *_state); 9778 void rbfv1gridcalc3vrec(rbfv1model* s, 9779 /* Real */ ae_vector* x0, 9780 ae_int_t n0, 9781 /* Real */ ae_vector* x1, 9782 ae_int_t n1, 9783 /* Real */ ae_vector* x2, 9784 ae_int_t n2, 9785 /* Integer */ ae_vector* blocks0, 9786 ae_int_t block0a, 9787 ae_int_t block0b, 9788 /* Integer */ ae_vector* blocks1, 9789 ae_int_t block1a, 9790 ae_int_t block1b, 9791 /* Integer */ ae_vector* blocks2, 9792 ae_int_t block2a, 9793 ae_int_t block2b, 9794 /* Boolean */ ae_vector* flagy, 9795 ae_bool sparsey, 9796 double searchradius, 9797 double avgfuncpernode, 9798 ae_shared_pool* bufpool, 9799 /* Real */ ae_vector* y, 9800 ae_state *_state); 9801 ae_bool _trypexec_rbfv1gridcalc3vrec(rbfv1model* s, 9802 /* Real */ ae_vector* x0, 9803 ae_int_t n0, 9804 /* Real */ ae_vector* x1, 9805 ae_int_t n1, 9806 /* Real */ ae_vector* x2, 9807 ae_int_t n2, 9808 /* Integer */ ae_vector* blocks0, 9809 ae_int_t block0a, 9810 ae_int_t block0b, 9811 /* Integer */ ae_vector* blocks1, 9812 ae_int_t block1a, 9813 ae_int_t block1b, 9814 /* Integer */ ae_vector* blocks2, 9815 ae_int_t block2a, 9816 ae_int_t block2b, 9817 /* Boolean */ ae_vector* flagy, 9818 ae_bool sparsey, 9819 double searchradius, 9820 double avgfuncpernode, 9821 ae_shared_pool* bufpool, 9822 /* Real */ ae_vector* y, ae_state *_state); 9823 void rbfv1unpack(rbfv1model* s, 9824 ae_int_t* nx, 9825 ae_int_t* ny, 9826 /* Real */ ae_matrix* xwr, 9827 ae_int_t* nc, 9828 /* Real */ ae_matrix* v, 9829 ae_state *_state); 9830 void _rbfv1calcbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic); 9831 void _rbfv1calcbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9832 void _rbfv1calcbuffer_clear(void* _p); 9833 void _rbfv1calcbuffer_destroy(void* _p); 9834 void _rbfv1model_init(void* _p, ae_state *_state, ae_bool make_automatic); 9835 void _rbfv1model_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9836 void _rbfv1model_clear(void* _p); 9837 void _rbfv1model_destroy(void* _p); 9838 void _gridcalc3v1buf_init(void* _p, ae_state *_state, ae_bool make_automatic); 9839 void _gridcalc3v1buf_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9840 void _gridcalc3v1buf_clear(void* _p); 9841 void _gridcalc3v1buf_destroy(void* _p); 9842 void _rbfv1report_init(void* _p, ae_state *_state, ae_bool make_automatic); 9843 void _rbfv1report_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9844 void _rbfv1report_clear(void* _p); 9845 void _rbfv1report_destroy(void* _p); 9846 #endif 9847 #if defined(AE_COMPILE_RBF) || !defined(AE_PARTIAL_BUILD) 9848 void rbfcreate(ae_int_t nx, ae_int_t ny, rbfmodel* s, ae_state *_state); 9849 void rbfcreatecalcbuffer(rbfmodel* s, 9850 rbfcalcbuffer* buf, 9851 ae_state *_state); 9852 void rbfsetpoints(rbfmodel* s, 9853 /* Real */ ae_matrix* xy, 9854 ae_int_t n, 9855 ae_state *_state); 9856 void rbfsetpointsandscales(rbfmodel* r, 9857 /* Real */ ae_matrix* xy, 9858 ae_int_t n, 9859 /* Real */ ae_vector* s, 9860 ae_state *_state); 9861 void rbfsetalgoqnn(rbfmodel* s, double q, double z, ae_state *_state); 9862 void rbfsetalgomultilayer(rbfmodel* s, 9863 double rbase, 9864 ae_int_t nlayers, 9865 double lambdav, 9866 ae_state *_state); 9867 void rbfsetalgohierarchical(rbfmodel* s, 9868 double rbase, 9869 ae_int_t nlayers, 9870 double lambdans, 9871 ae_state *_state); 9872 void rbfsetlinterm(rbfmodel* s, ae_state *_state); 9873 void rbfsetconstterm(rbfmodel* s, ae_state *_state); 9874 void rbfsetzeroterm(rbfmodel* s, ae_state *_state); 9875 void rbfsetv2bf(rbfmodel* s, ae_int_t bf, ae_state *_state); 9876 void rbfsetv2its(rbfmodel* s, ae_int_t maxits, ae_state *_state); 9877 void rbfsetv2supportr(rbfmodel* s, double r, ae_state *_state); 9878 void rbfsetcond(rbfmodel* s, 9879 double epsort, 9880 double epserr, 9881 ae_int_t maxits, 9882 ae_state *_state); 9883 void rbfbuildmodel(rbfmodel* s, rbfreport* rep, ae_state *_state); 9884 double rbfcalc1(rbfmodel* s, double x0, ae_state *_state); 9885 double rbfcalc2(rbfmodel* s, double x0, double x1, ae_state *_state); 9886 double rbfcalc3(rbfmodel* s, 9887 double x0, 9888 double x1, 9889 double x2, 9890 ae_state *_state); 9891 void rbfcalc(rbfmodel* s, 9892 /* Real */ ae_vector* x, 9893 /* Real */ ae_vector* y, 9894 ae_state *_state); 9895 void rbfcalcbuf(rbfmodel* s, 9896 /* Real */ ae_vector* x, 9897 /* Real */ ae_vector* y, 9898 ae_state *_state); 9899 void rbftscalcbuf(rbfmodel* s, 9900 rbfcalcbuffer* buf, 9901 /* Real */ ae_vector* x, 9902 /* Real */ ae_vector* y, 9903 ae_state *_state); 9904 void rbfgridcalc2(rbfmodel* s, 9905 /* Real */ ae_vector* x0, 9906 ae_int_t n0, 9907 /* Real */ ae_vector* x1, 9908 ae_int_t n1, 9909 /* Real */ ae_matrix* y, 9910 ae_state *_state); 9911 void rbfgridcalc2v(rbfmodel* s, 9912 /* Real */ ae_vector* x0, 9913 ae_int_t n0, 9914 /* Real */ ae_vector* x1, 9915 ae_int_t n1, 9916 /* Real */ ae_vector* y, 9917 ae_state *_state); 9918 void rbfgridcalc2vsubset(rbfmodel* s, 9919 /* Real */ ae_vector* x0, 9920 ae_int_t n0, 9921 /* Real */ ae_vector* x1, 9922 ae_int_t n1, 9923 /* Boolean */ ae_vector* flagy, 9924 /* Real */ ae_vector* y, 9925 ae_state *_state); 9926 void rbfgridcalc3v(rbfmodel* s, 9927 /* Real */ ae_vector* x0, 9928 ae_int_t n0, 9929 /* Real */ ae_vector* x1, 9930 ae_int_t n1, 9931 /* Real */ ae_vector* x2, 9932 ae_int_t n2, 9933 /* Real */ ae_vector* y, 9934 ae_state *_state); 9935 void rbfgridcalc3vsubset(rbfmodel* s, 9936 /* Real */ ae_vector* x0, 9937 ae_int_t n0, 9938 /* Real */ ae_vector* x1, 9939 ae_int_t n1, 9940 /* Real */ ae_vector* x2, 9941 ae_int_t n2, 9942 /* Boolean */ ae_vector* flagy, 9943 /* Real */ ae_vector* y, 9944 ae_state *_state); 9945 void rbfgridcalc2vx(rbfmodel* s, 9946 /* Real */ ae_vector* x0, 9947 ae_int_t n0, 9948 /* Real */ ae_vector* x1, 9949 ae_int_t n1, 9950 /* Boolean */ ae_vector* flagy, 9951 ae_bool sparsey, 9952 /* Real */ ae_vector* y, 9953 ae_state *_state); 9954 void rbfgridcalc3vx(rbfmodel* s, 9955 /* Real */ ae_vector* x0, 9956 ae_int_t n0, 9957 /* Real */ ae_vector* x1, 9958 ae_int_t n1, 9959 /* Real */ ae_vector* x2, 9960 ae_int_t n2, 9961 /* Boolean */ ae_vector* flagy, 9962 ae_bool sparsey, 9963 /* Real */ ae_vector* y, 9964 ae_state *_state); 9965 void rbfunpack(rbfmodel* s, 9966 ae_int_t* nx, 9967 ae_int_t* ny, 9968 /* Real */ ae_matrix* xwr, 9969 ae_int_t* nc, 9970 /* Real */ ae_matrix* v, 9971 ae_int_t* modelversion, 9972 ae_state *_state); 9973 ae_int_t rbfgetmodelversion(rbfmodel* s, ae_state *_state); 9974 double rbfpeekprogress(rbfmodel* s, ae_state *_state); 9975 void rbfrequesttermination(rbfmodel* s, ae_state *_state); 9976 void rbfalloc(ae_serializer* s, rbfmodel* model, ae_state *_state); 9977 void rbfserialize(ae_serializer* s, rbfmodel* model, ae_state *_state); 9978 void rbfunserialize(ae_serializer* s, rbfmodel* model, ae_state *_state); 9979 void _rbfcalcbuffer_init(void* _p, ae_state *_state, ae_bool make_automatic); 9980 void _rbfcalcbuffer_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9981 void _rbfcalcbuffer_clear(void* _p); 9982 void _rbfcalcbuffer_destroy(void* _p); 9983 void _rbfmodel_init(void* _p, ae_state *_state, ae_bool make_automatic); 9984 void _rbfmodel_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9985 void _rbfmodel_clear(void* _p); 9986 void _rbfmodel_destroy(void* _p); 9987 void _rbfreport_init(void* _p, ae_state *_state, ae_bool make_automatic); 9988 void _rbfreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic); 9989 void _rbfreport_clear(void* _p); 9990 void _rbfreport_destroy(void* _p); 9991 #endif 9992 #if defined(AE_COMPILE_INTCOMP) || !defined(AE_PARTIAL_BUILD) 9993 void nsfitspheremcc(/* Real */ ae_matrix* xy, 9994 ae_int_t npoints, 9995 ae_int_t nx, 9996 /* Real */ ae_vector* cx, 9997 double* rhi, 9998 ae_state *_state); 9999 void nsfitspheremic(/* Real */ ae_matrix* xy, 10000 ae_int_t npoints, 10001 ae_int_t nx, 10002 /* Real */ ae_vector* cx, 10003 double* rlo, 10004 ae_state *_state); 10005 void nsfitspheremzc(/* Real */ ae_matrix* xy, 10006 ae_int_t npoints, 10007 ae_int_t nx, 10008 /* Real */ ae_vector* cx, 10009 double* rlo, 10010 double* rhi, 10011 ae_state *_state); 10012 void nsfitspherex(/* Real */ ae_matrix* xy, 10013 ae_int_t npoints, 10014 ae_int_t nx, 10015 ae_int_t problemtype, 10016 double epsx, 10017 ae_int_t aulits, 10018 double penalty, 10019 /* Real */ ae_vector* cx, 10020 double* rlo, 10021 double* rhi, 10022 ae_state *_state); 10023 #endif 10024 10025 } 10026 #endif 10027 10028