dosma.polyfit

dosma.polyfit(x, y, deg: int, rcond=None, full=False, w=None, cov=False, eps=1e-08, y_bounds=None, show_pbar=False, num_workers=None, chunksize: Optional[int] = None)[source]

Use linear least squares to fit a polynomial of degree deg to data.

This function is a wrapper around the numpy.polyfit() and cupy.polyfit() functions.

In addition to standard polyfit functionality, this function also supports multiprocessing of the data using multiple workers. When multiprocessing is enabled, each data sequence is fit using a separate worker.

In most cases, multiprocessing is not needed for linear least squares as most computations can be done quickly via matrix decomposition. However, there are cases where y values can cause low condition numbers and/or invalid outputs. In these cases, solving for each data sequence separately can be beneficial.

Solving each data sequence separately without multiprocessing can also be done by setting num_workers=0. This can be useful when certain data sequences are ill conditioned.

Parameters
  • x (ndarray) – The independent variable(s) where the data is measured. Should usually be an M-length sequence or an (k,M)-shaped array for functions with k predictors, but can actually be any object.

  • y (ndarray) – The dependent data, a length M array - nominally func(xdata, …) - or an (M,N)-shaped array for N different sequences.

  • deg (int) – Degree of the fitting polynomial. Same as numpy.polyfit().

  • rcond (float, optional) – Same as numpy.polyfit().

  • full (bool, optional) – Same as numpy.polyfit().

  • w (array-like, optional) – Same as numpy.polyfit().

  • cov (bool, optional) – Same as numpy.polyfit().

  • eps (float, optional) – Epsilon for computing r-squared.

  • y_bounds (tuple, optional) – Same as curve_fit().

  • show_pbar (bool, optional) – Same as curve_fit().

  • num_workers (int, optional) – Maximum number of workers to use for fitting. If None, all data sequences should be solved as a single least squares problem. If 0, each data sequence will be fit separately from one another. Defaults to None.

  • chunksize (int, optional) – Same as curve_fit(). Only used when num_workers is not None.