R/startUV.R

Defines functions startUV

Documented in startUV

#' Starting values of U and V
#'
#' Initialize starting values of U and V
#'
#' @param Z Degree-corrected network array data.
#' @param R The dimensionality of latent space.
#' @param K The dimensionality of Z.
#'
#' @return A list of U and V
#'
#' @export
#'
startUV <- function(Z, R, K){
    eig.temp <- eigen(apply(Z,c(1,2),mean))
    d2m <- abs(eig.temp$val)
    U0 <- eig.temp$vec[, order(d2m,decreasing=TRUE) ]
    U <- matrix(U0[, 1:R], nrow=nrow(U0), ncol=R)
    V0 <- rep(1,K[3])%*%t(eig.temp$val)
    V1 <- V0[, order(d2m,decreasing=TRUE) ]
    if(K[3] == 1){
        V <- matrix(V1[1:R], K[3], R)
    }else{
        V <- matrix(V1[, 1:R], K[3], R)
    }
    if(is.complex(V)){
        stop("Principal eigenvalues have a complex number. Computation is halted.")
    }
    out <- list(U, V)
}

Try the NetworkChange package in your browser

Any scripts or data that you put into this service are public.

NetworkChange documentation built on March 18, 2022, 7:52 p.m.