normalize_rows: Normalize Rows or Columns of Matrix to Unit Length...

normalize.rowsR Documentation

Normalize Rows or Columns of Matrix to Unit Length (wordspace)

Description

Efficiently normalize the row or column vectors of a dense or sparse matrix to unit length.

Usage


normalize.rows(M, method = "euclidean", p = 2, ..., 
               tol = 1e-6, inplace = FALSE)

normalize.cols(M, method = "euclidean", p = 2, ...,
               tol = 1e-6, inplace = FALSE)

Arguments

M

a dense or sparse numeric matrix

method

norm to be computed, see rowNorms

p

exponent of Minkowski p-norm in the range 0 < p ≤ ∞. Note that normalization is not possible for very small values of p.

...

any further arguments are passed to rowNorms (or colNorms)

tol

row/column vectors with norm below tol are assumed to be all zeroes and cannot be normalized (see “Details” below)

inplace

if TRUE, modify the matrix M in place. Don't ever set this argument to TRUE.

Details

These functions return a matrix with row (or column) vectors rescaled to a length of 1 according to the selected norm.

All-zero vectors (with |0| = 0) cannot be normalized. In order to avoid scaling up rounding errors, rows (or columns) with |x| < tol are explicitly set to 0 (and thus not normalized). Since a suitable threshold for rounding errors depends on the scaling behaviour of the selected norm and the provenance of M, it is advisable to set tol explicitly to an appropriate value. Pass tol = 0 to normalize all nonzero vectors.

The generalized Minkowski norm with p < 1 is not homogeneous but can still be normalized. This is numerically unstable for very small values of p, which will be rejected with an error message. The Hamming length (p = 0) cannot be normalized at all. See rowNorms for more information.

Value

A row-normalized (or column-normalized) matrix with the same dimensions as M.

Author(s)

Stephanie Evert (https://purl.org/stephanie.evert)

See Also

See rowNorms for details on available norms and their parameters.


wordspace documentation built on Aug. 23, 2022, 1:06 a.m.