# Polynomial Baselines

## Introduction

In 2D, a polynomial can be expressed as

where \(\beta\) is the matrix of coefficients for the polynomial and \(d_r\) and \(d_c\) are the polynomial degrees for the rows (\(x\)) and columns (\(z\)), respectively.

For regular polynomial fitting, the polynomial coefficients that best fit data are gotten from minimizing the least-squares:

where \(y_{ij}\), \(x_i\), and \(z_j\) are the measured data, \(p(x_i, z_j)\) is the polynomial estimate at \(x_i\), and \(z_j\) and \(w_{ij}\) is the weighting.

However, since only the baseline of the data is desired, the least-squares approach must be modified. For polynomial-based algorithms, this is done by 1) only fitting the data in regions where there is only baseline, 2) modifying the y-values being fit each iteration, or 3) penalyzing outliers.

Note

For two dimensional data, polynomial algorithms take a single `poly_order`

parameter that can either be a single number, in which case both the rows and columns
will use the same polynomial degree, ie. \(d_r = d_c\), or a sequence
of two numbers (\(d_r\), \(d_c\)) to use different polynomials along
the rows and columns. Further, `max_cross`

can be set to limit the polynomial
coefficients for the cross terms.

## Algorithms

### poly (Regular Polynomial)

`poly()`

:
explanation for the algorithm. No plot
will be shown since it is just a simple least-squares polynomial fitting.