R/L2HalfThr.R

Defines functions L2HalfThr

Documented in L2HalfThr

#' @title L2HalfThr - Iterative Half Thresholding Algorithm based on \eqn{l_{2,1/2}} norm
#' @description The function aims to solve \eqn{l_{2,1/2}} regularized least squares.
#' @param A Gene expression data of transcriptome factors (i.e. feature matrix in machine learning).
#' The dimension of A is m * n.
#' @param B Gene expression data of target genes (i.e. observation matrix in machine learning).
#' The dimension of B is m * t.
#' @param X Gene expression data of Chromatin immunoprecipitation or other matrix
#' (i.e. initial iterative point in machine learning). The dimension of X is n * t.
#' @param s joint sparsity level
#' @param maxIter maximum iteration
#' @return The solution of proximal gradient method with \eqn{l_{2,1/2}} regularizer.
#' @author Xinlin Hu <thompson-xinlin.hu@connect.polyu.hk>
#'
#' Yaohua Hu <mayhhu@szu.edu.cn>
#' @details The L2HalfThr function aims to solve the problem:
#' \deqn{\min \|AX-B\|_F^2 + \lambda \|X\|_{2,1/2}}
#' to obtain s-joint sparse solution.
#' @export L2HalfThr
#' @examples
#' m <- 256; n <- 1024; t <- 5; maxIter0 <- 50
#' A0 <- matrix(rnorm(m * n), nrow = m, ncol = n)
#' B0 <- matrix(rnorm(m * t), nrow = m, ncol = t)
#' X0 <- matrix(0, nrow = n, ncol = t)
#' NoA <- norm(A0, '2'); A0 <- A0/NoA; B0 <- B0/NoA
#' res_L2half <- L2HalfThr(A0, B0, X0, s = 10, maxIter = maxIter0)
#'
L2HalfThr <- function(A, B, X, s, maxIter = 200){
  # Initialization
  v <- 0.5 # stepsize
  Va1 <- (2/3)^(1.5) / v
  Bu1 <- 2 * v * t(A) %*% B
  Bu2 <- 2 * v * t(A) %*% A

  for(k in 1:maxIter){
    # Gradient descent
    Bu <- X + Bu1 - Bu2 %*% X

    # L2-1/2 threhsolding operator
    normBu <- apply(Bu, 1, norm, '2') # L2 norm of each row
    criterion <- sort(normBu, decreasing = T)[s+1]
    lambda <- Va1 * criterion^(1.5)
    q <- lambda * v / 4

    # Consider what if s-th largest group is not the only one
    if(criterion == sort(normBu, decreasing = T)[s]){
      ind <- which(normBu >= criterion)
    }else{
      ind <- which(normBu > criterion)
    }

    Xnew <- matrix(0, nrow = nrow(Bu), ncol = ncol(Bu))
    for(i in ind){
      rowDa <- Bu[i, ]
      normRow <- norm(rowDa, '2')
      phi <- acos(q * (3/normRow)^(1.5))
      eta <- 16 * normRow^(3/2) * cos((pi - phi)/3)^3

      # Update matrix
      Xnew[i, ] <- (eta/(3 * sqrt(3) * lambda * v + eta)) * rowDa
    }

    if(norm(Xnew - X, 'f') <= 1e-6){ break }
    # Update and report
    X <- Xnew
    # message(paste('The', k, '-th iteration completes.'))
  }

  return(Xnew)
}

Try the JSparO package in your browser

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

JSparO documentation built on Aug. 18, 2022, 9:06 a.m.