Helper function used to implement the `` fit`` functions. Parameters ---------- vander_f : function(array_like, int) -> ndarray The 1d vander function, such as ``polyvander`` c1, c2 See the `` fit`` functions for more detail
(vander_f, x, y, deg, rcond=None, full=False, w=None)
| 597 | |
| 598 | |
| 599 | def _fit(vander_f, x, y, deg, rcond=None, full=False, w=None): |
| 600 | """ |
| 601 | Helper function used to implement the ``<type>fit`` functions. |
| 602 | |
| 603 | Parameters |
| 604 | ---------- |
| 605 | vander_f : function(array_like, int) -> ndarray |
| 606 | The 1d vander function, such as ``polyvander`` |
| 607 | c1, c2 |
| 608 | See the ``<type>fit`` functions for more detail |
| 609 | """ |
| 610 | x = np.asarray(x) + 0.0 |
| 611 | y = np.asarray(y) + 0.0 |
| 612 | deg = np.asarray(deg) |
| 613 | |
| 614 | # check arguments. |
| 615 | if deg.ndim > 1 or deg.dtype.kind not in 'iu' or deg.size == 0: |
| 616 | raise TypeError("deg must be an int or non-empty 1-D array of int") |
| 617 | if deg.min() < 0: |
| 618 | raise ValueError("expected deg >= 0") |
| 619 | if x.ndim != 1: |
| 620 | raise TypeError("expected 1D vector for x") |
| 621 | if x.size == 0: |
| 622 | raise TypeError("expected non-empty vector for x") |
| 623 | if y.ndim < 1 or y.ndim > 2: |
| 624 | raise TypeError("expected 1D or 2D array for y") |
| 625 | if len(x) != len(y): |
| 626 | raise TypeError("expected x and y to have same length") |
| 627 | |
| 628 | if deg.ndim == 0: |
| 629 | lmax = deg |
| 630 | order = lmax + 1 |
| 631 | van = vander_f(x, lmax) |
| 632 | else: |
| 633 | deg = np.sort(deg) |
| 634 | lmax = deg[-1] |
| 635 | order = len(deg) |
| 636 | van = vander_f(x, lmax)[:, deg] |
| 637 | |
| 638 | # set up the least squares matrices in transposed form |
| 639 | lhs = van.T |
| 640 | rhs = y.T |
| 641 | if w is not None: |
| 642 | w = np.asarray(w) + 0.0 |
| 643 | if w.ndim != 1: |
| 644 | raise TypeError("expected 1D vector for w") |
| 645 | if len(x) != len(w): |
| 646 | raise TypeError("expected x and w to have same length") |
| 647 | # apply weights. Don't use inplace operations as they |
| 648 | # can cause problems with NA. |
| 649 | lhs = lhs * w |
| 650 | rhs = rhs * w |
| 651 | |
| 652 | # set rcond |
| 653 | if rcond is None: |
| 654 | rcond = len(x)*np.finfo(x.dtype).eps |
| 655 | |
| 656 | # Determine the norms of the design matrix columns. |