#' objective function: loss function + penalty terms
#' @param x.lr low-rank coefficient matrix
#' @param x.sparse sparse coefficient matrix
#' @param A design matrix
#' @param b target vector
#' @param lambda tuning parameter for sparse
#' @param mu tuning parameter for low-rank
#' @return value of objective function
#' @details This is the full objective function: loss function + penalties
#' @examples
#' x.lr <- stats::rnorm(10)
#' x.sparse <- vector('list', 2)
#' x.sparse[[1]] <- c(0.1, 0.5, 0, 0, 0, -0.25, 0.55, 0, 0, 1.25)
#' x.sparse[[2]] <- c(0, -0.5, 1.0, -0.1, 0, 0.5, 0, 0, 0, -1)
#' A <- matrix(stats::rnorm(200), 20, 10)
#' b <- stats::rnorm(20)
#' lambda <- 0.1
#' mu <- 0.5
#' obj_func(x.lr, x.sparse, A, b, lambda, mu)
#'
#' @export
obj_func <- function(x.lr, x.sparse, A, b, lambda, mu){
### x.sparse is a list
m <- length(x.sparse)
loss <- 0
for(i in 1:m){
loss <- loss + f_func((x.lr[[i]] + x.sparse[[i]]), A, b) + sparse_pen(x.sparse[[i]], lambda) + nuclear_pen(x.lr[[i]], mu)
}
return(loss)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.