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*}\]The centers \(c\) and scales \(s\) are either user-provided or deduced from \(Z\) via
mean()
andvar()
, respectively, with equal sample weights \(1/n\). The degrees of freedom \(\mathrm{df}\) can be specified for \(s\) so that the sample weights are \(1 / (n-\mathrm{df})\) instead. Therefore, \(c\) will usually coincide with\[\begin{align*} \overline{Z} = \frac{1}{n} Z^\top \mathbf{1} \end{align*}\]and \(s\) with
\[\begin{align*} \hat{\sigma}_j = \frac{1}{\sqrt{n - \mathrm{df}}} \|Z_{\cdot j} - c_j \mathbf{1} \|_2 \end{align*}\]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 implied column means are used viamean()
. Default isNone
.- scalesndarray, optional
The scale values \(s\) for each column of
mat
. IfNone
, the implied column standard deviations are used viavar()
. 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.