R/RcppExports.R

Defines functions get_B

Documented in get_B

# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @title Given Y, H, and W, optimize B coordinate descent
#' @description This is minimizing ||Y - HBW^{T}||_{2}^{2} over B, with all
#' other matrices assumed known.
#' @param Y An N x J real matrix, with censored values set to NA. The standard
#' application we have in mind is the sample x OTU count matrix.
#' @param H The spline basis matrix, from which the latent sources arise (as
#' the linear mixture HB.)
#' @param W The samples-to-latent-source coefficients matrix, assumed known.
#' @param nu The learning rate for the coordinate descent. Arbitrarily
#' defaults to 1e-3.
#' @param n_iter The number of sweeps over all entries of B via coordinate
#' descent.
#' @return A list with the following elements, \cr
#'   $obj The RSS after each update to an entry of B. \cr
#'   $B The optimized value of B.
#' @export
#' @examples
#' # generate data
#' N <- 150
#' P <- 20
#' K <- 5
#' L <- 6
#'
#' library("splines")
#' H <- bs(1:N, df = L, degree = 1)
#' W <- matrix(rnorm(P * K), P, K)
#' B <- matrix(rnorm(L * K), L, K)
#' E <- matrix(.5 * rnorm(N * P), N, P)
#'
#' Y <- H %*% B %*% t(W) + E
#' Y[sample(N * P, N * P * .4)] <- NA # 40% missing at random
#'
#' # fit the model
#' B0 <- matrix(rnorm(L * K), L, K)
#' B_res <- get_B(Y, H, W, B0)
#' @importFrom Rcpp evalCpp
#' @useDynLib LFExpers
get_B <- function(Y, H, W, B0, nu = 1e-5, n_iter = 100L) {
    .Call('LFExpers_get_B', PACKAGE = 'LFExpers', Y, H, W, B0, nu, n_iter)
}
krisrs1128/LFExpers documentation built on May 20, 2019, 1:25 p.m.