mlr.orthogonalize: Orthogonalization of vectors with repsect to a matrix

View source: R/mlr_core.R

mlr.orthogonalizeR Documentation

Orthogonalization of vectors with repsect to a matrix

Description

Decomposing a collection of vectors into parallel and orthogonal components with respect to the subspace spanned by columns of a reference matrix.

Usage

mlr.orthogonalize(X, Z, normalize = FALSE, tolerance = .Machine$double.eps^0.5)

Arguments

X

Matrix whose columns form the subspace, with respect to which we want to orthogonalize columns of Z.

Z

Matrix whose columns we want to orthogonalize with respect to the subpsace spanned by columns of X. We must have nrow(Z) == nrow(X).

normalize

Boolean flag, indicating whether the orthogonal component of Z columns must be normalized so that their L2 norms equal nrow(Z) (mean squared is 1).

tolerance

If unnormalized projection of a column of Z has an L2 norm below tolerance, it will not be normalized (even if requested via normalize) and instead a zero vector will be returned.

Details

Current implementation uses Singular Value Decomposition (svd) of X to form an orthonormal basis from columns of X to facilitate the projection process.

Value

A matrix of same dimensions as Z is returned, with each column containing the orthogonal component of the corresponding column of Z. Parallel components are attached as parallel attribute.

Author(s)

Alireza S. Mahani, Mansour T.A. Sharabiani

References

Link to a draft paper, documenting the supporting mathematical framework, will be provided in the next release.

Examples


K <- 10
N <- 100
Ko <- 5

X <- matrix(runif(N*K), ncol = K)
Z <- matrix(runif(N*Ko), ncol = Ko)

ret <- mlr.orthogonalize(X = X, Z = Z, normalize = FALSE)

orthogonal <- ret
parallel <- attr(ret, "parallel")
Z.rec <- parallel + orthogonal

# check that parallel and orthogonal components add up to Z
cat("check 1:", all.equal(as.numeric(Z.rec), as.numeric(Z)), "\n")
# check that inner product of orthogonal columns and X columns are zero
cat("check 2:", all.equal(t(orthogonal) %*% X, matrix(0, nrow = Ko, ncol = K)), "\n")


MatchLinReg documentation built on Aug. 30, 2022, 5:05 p.m.