adelie.matrix.standardize#
- adelie.matrix.standardize(mat: ndarray | MatrixNaiveBase32 | MatrixNaiveBase64, centers: ndarray | None = None, scales: ndarray | None = None, ddof: int = 0, *, n_threads: int = 1)[source]#
Creates a standardized matrix.
Given a matrix \(Z \in \mathbb{R}^{n \times p}\), the standardized matrix \(X \in \mathbb{R}^{n \times p}\) of \(Z\) centered by \(c \in \mathbb{R}^{p}\) and scaled by \(s \in \mathbb{R}^p\) is defined by
\[\begin{align*} X = (Z - \mathbf{1} c^\top) \mathrm{diag}(s)^{-1} \end{align*}\]We define the column means \(\overline{Z} \in \mathbb{R}^p\) to be
\[\begin{align*} \overline{Z} = \frac{1}{n} Z^\top \mathbf{1} \end{align*}\]Lastly, we define the column standard deviations \(\hat{\sigma} \in \mathbb{R}^p\) to be
\[\begin{align*} \hat{\sigma}_j = \frac{1}{\sqrt{n - \mathrm{df}}} \|Z_{\cdot j} - c_j \mathbf{1} \|_2 \end{align*}\]where \(\mathrm{df}\) is the degrees of freedom given by
ddof
.Note
This matrix only works for naive method!
- Parameters:
- matUnion[ndarray, MatrixNaiveBase32, MatrixNaiveBase64]
The underlying matrix \(Z\) to standardize.
- centersndarray, optional
The center values \(c\) for each column of
mat
. IfNone
, the column means \(\overline{Z}\) are used as centers. Default isNone
.- scalesndarray, optional
The scale values \(s\) for each column of
mat
. IfNone
, the column standard deviations \(\hat{\sigma}\) are used as scales. Default isNone
.- ddofint, optional
The degrees of freedom used to compute
scales
. This is only used ifscales
isNone
. Default is0
.- n_threadsint, optional
Number of threads. Default is
1
.
- Returns:
- wrap
Wrapper matrix object.