R/RcppExports.R

Defines functions space_shooting

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Active-set coordinate-descent shooting algorithm for matSPACE
#'
#' Compiled engine behind [space()]: fits the symmetric off-diagonal
#' partial-correlation coefficients via lasso-penalized coordinate
#' descent, restricting most sweeps to the current active set (nonzero
#' coefficients) for speed and falling back to a full global sweep to
#' detect newly active pairs. Called internally by [space()]; end users
#' should call [space()] instead.
#'
#' @param Y_data numeric vector of length `NN * PP * QQ`: the `NN`
#'   replicate `PP x QQ` matrices (weighted data), each flattened in
#'   row-major order and concatenated, as produced by R's
#'   `tensor_to_vec()`.
#' @param sigma_sr numeric vector of length `QQ`, the square root of
#'   `SIG / WEIGHT` per column; used to build the `B[i, j] = sigma_sr[i]
#'   / sigma_sr[j]` rescaling applied to each coefficient.
#' @param NN number of replicate matrices (`n`).
#' @param PP number of rows per matrix (`p`).
#' @param QQ number of columns/variables per matrix (`q`).
#' @param L1 lasso penalty (`lam`) applied to the off-diagonal
#'   coefficients via soft-thresholding.
#' @param n_iter maximum number of outer sweep iterations before giving
#'   up on convergence (each iteration is an active-set pass followed,
#'   when converged or empty, by a global sweep).
#' @param beta_init optional warm start: a length `QQ * QQ` numeric
#'   vector (row-major, `i * QQ + j` layout) used as the initial
#'   coefficient matrix instead of the default univariate
#'   soft-threshold initialization. Pass `R_NilValue` (the default) for
#'   a cold start.
#' @return A list with components:
#'   \item{beta}{length `QQ * QQ` numeric vector (row-major), the fitted
#'     symmetric coefficient matrix with a zero diagonal; in R this is
#'     reshaped and its diagonal set to 1 to form `ParCor`.}
#'   \item{Y_m}{length `NN * PP * QQ` numeric vector (row-major), `Y_data`
#'     after column-wise mean centering.}
#'   \item{E_m}{length `NN * PP * QQ` numeric vector (row-major), the
#'     residuals of `Y_m` after the fitted coefficients.}
#'   \item{iter_count}{total number of coordinate-descent coefficient
#'     updates performed across all active-set and global sweeps.}
#' @noRd
space_shooting <- function(Y_data, sigma_sr, NN, PP, QQ, L1, n_iter = 500L, beta_init = NULL) {
    .Call(`_matSPACE_space_shooting`, Y_data, sigma_sr, NN, PP, QQ, L1, n_iter, beta_init)
}

Try the matSPACE package in your browser

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

matSPACE documentation built on Sept. 12, 2026, 5:10 p.m.