Skip to content

Commit

Permalink
add extracting U function
Browse files Browse the repository at this point in the history
  • Loading branch information
yunqiyang0215 committed Apr 19, 2024
1 parent 5da1a2e commit 5b352a4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ makeposdef <- function (X, minval = 1e-8) {
return(tcrossprod(out$vectors %*% diag(sqrt(d))))
}
}

# For symmetric semi-definite matrix X, return u such that
# tcrossprod(u) is the nearest rank-1 matrix.
getrank1 <- function (X) {
out <- eigen(X)
return(with(out,sqrt(values[1]) * vectors[,1]))
}
# Function to calculate matrix Q where U=QQ^T when U is rank-deficient.

# Function to calculate matrix Q where U=QQ^T when U is rank-deficient.
# @param U is the rank-deficient matrix to decompose
# @param r is the rank of U.
get_mat_Q <- function (U, minval = 1e-8) {
Expand Down Expand Up @@ -144,3 +144,11 @@ ldet <- function (A)
# Compute trace of matrix A.
tr <- function (A)
sum(diag(A))

#' Extract the list of fitted U from udr fit object
#' @param fit udr object
#' @export
get_Ulist <- function(fit){
U <- lapply(fit$U,function (e) "[["(e,"mat"))
return(U)
}

0 comments on commit 5b352a4

Please sign in to comment.