
Fast ICA via Rust from processed data
fast_ica_rust_helper.RdThis functions is a wrapper over the Rust implementation of fastICA expected
already the pre-processed matrix and the pre-whitening matrix. It has
the same two options c("logcosh", "exp") to run ICA in parallel modus. You
can control the parameters of ICA via ica_params.
Usage
fast_ica_rust_helper(
X,
K,
n_icas,
ica_fun = c("logcosh", "exp"),
seed = NULL,
ica_params = params_ica_general()
)Arguments
- X
Numeric matrix. Processed data. Output of
rs_prepare_whitening().- K
The K matrix. Pre-whitening matrix. Output of
rs_prepare_whitening().- n_icas
Integer. Number of independent components to recover.
- ica_fun
String, element of
c("logcosh", "exp").- seed
Integer. Seed to ensure reproducible results.
- ica_params
List. The ICA parameters, see
params_ica_general()wrapper function. This function generates a list containing:maxit - Integer. Maximum number of iterations for ICA.
alpha - Float. The alpha parameter for the logcosh version of ICA. Should be between 1 to 2.
max_tol - Maximum tolerance of the algorithm.
verbose - Controls verbosity of the function.
Value
A list containing:
w The mixing matrix w.
A ICA results matrix A.
S ICA results matrix S.
converged Boolean indicating if algorithm converged.
Examples
# same run, but with the whitening done up front
sources <- cbind(sin((1:1000) / 20), rep(((1:200) - 100) / 100, 5))
mixed <- sources %*% matrix(c(0.291, 0.6557, -0.5439, 0.5572), 2, 2)
whitened <- rs_prepare_whitening(
x = mixed,
fast_svd = TRUE,
seed = 42L,
rank = NULL,
oversampling = NULL,
n_power_iter = NULL
)
ica_res <- fast_ica_rust_helper(
X = whitened$x,
K = whitened$k,
n_icas = 2L,
ica_fun = "logcosh",
seed = 42L
)
dim(ica_res$S)
#> [1] 2 1000