svd_align: Align singular vectors with majority of data vectors

View source: R/svd_align.R

svd_alignR Documentation

Align singular vectors with majority of data vectors

Description

Singular value decomposition is specified up to the sign (+/-) of the singular vectors. This algorithm attempts to align the singular vectors with the majority of vectors of the input matrix.

Usage

svd_align(x, r = NA)

Arguments

x

A data matrix.

r

An integer; number of columns to include as a reduced rank SVD solution. Defaults to full rank.

Value

svd_flip Aligned svd

References

Bro, R., Acar, E., & Kolda, T. G. (2008). Resolving the sign ambiguity in the singular value decomposition. Journal of Chemometrics: A Journal of the Chemometrics Society, 22(2), 135-140.

Examples

# Generate data
x <- cbind(runif(10, -0.5, 2), runif(10, -0.5, 2))


svd_flip <- svd_align(x)

# Extract components of svd and plot
U <- svd_flip$u
Sigma <- svd_flip$d
VT <- t(svd_flip$v)

# Plot data
plot(0, 0, xlim=c(-2,2), ylim=c(-2,2), type="n")

for (i in 1:dim(x)[1]){
  arrows(0, 0, x[i,1], x[i,2], lwd=2)
}

arrows(0, 0, VT[1, 1], VT[1, 2], col='red')


RobertGM111/havok documentation built on July 8, 2023, 8:23 p.m.