You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Baseline correction using asymmetric least squares, accelerated with C++.
Asymmetric least squares method is a technique that can correct the baseline while adjusting the balance between the fit of the baseline to the spectrum and the smoothness of the baseline curve.
pybind11 (Seamless operability between C++11 and Python)
NumPy (Fundamental package for scientific computing with Python)
Principle
In ALS, the baseline
$\mathbf{Z}=\lbrace z_1, z_2, \cdots, z_n \rbrace$
for the spectrum
$\mathbf{Y}=\lbrace y_1, y_2, \cdots, y_n \rbrace$
is determined to minimize the function:
This prioritizes points where the spectrum falls below the baseline $(y_i < z_i)$ in fitting, causing the baseline to fall below the spectrum. $\Delta^2$ represents the second derivative (numerical derivative) of the spectrum and is calculated as:
The first term of $F(\mathbf{Z})$ represents the difference between the spectrum and the baseline, while the second term serves as a penalty term representing the complexity of the baseline curve, with the constant $\lambda$ determining its scale. Setting $\lambda$ to a small value yields a complex baseline curve, while a large value yields a smooth baseline curve.
The algorithm for baseline calculation using ALS is as follows. First, initialize all the weights $\mathbf{w}=\lbrace w_1, w_2, \cdots, w_n \rbrace$ to 1. Then update the baseline $\mathbf{Z}$ and weights $\mathbf{w}$ iteratively:
where $\mathbf{W}$ is a diagonal matrix with the weights $\mathbf{w}$ as its diagonal elements, and $\mathbf{D}$ is an $(n-2)×n$ matrix such that $\mathbf{DZ} = \Delta^2\mathbf{Z}$, defined as: