API Reference
Public functions and types
These are the functions and types exported by BigRiverEssence.jl.
BigRiverEssence.cca — Method
cca(X::Matrix{Float64}, Y::Matrix{Float64}; method::Symbol = :svd,
outdim::Int = min(size(X,1), size(Y,1)))Fit a canonical correlation analysis (CCA) between two sets of variables, after Weenink (2003)
Arguments
X::Matrix{Float64}: 2d array of floats; the first variable set, with variables in ROWS and observations in COLUMNS (dx×n)Y::Matrix{Float64}: 2d array of floats; the second variable set (dy×n), with the same number of observations (columns) as Xmethod::Symbol: The solver,:svd(works directly from the centered data, more stable) or:cov(works from covariance matrices). Both give the same result. Defaults to:svdoutdim::Int: The number of canonical components to return; must be in 1:min(dx, dy). Defaults to min(dx, dy)
Value
A Cca holding the X and Y means, the canonical directions for each side, and the canonical correlations (descending). CCA finds pairs of directions, one in X-space and one in Y-space, whose projected variates are maximally correlated; the k-th pair is the most correlated subject to being uncorrelated with the previous k−1. The default solver follows the SVD-based approach of Weenink (2003), which avoids forming covariance matrices for numerical stability. Warns when n is not comfortably larger than dx and dy, where CCA becomes unstable
BigRiverEssence.cca_transform — Method
cca_transform(M::Cca, Z::AbstractMatrix, c::Symbol)Project data onto the canonical directions of a fitted CCA model
Arguments
M::Cca: A fitted CCA model, as returned byccaZ::AbstractMatrix: 2d array of floats; the data to project, with variables in rows and observations in columns, matching the side selected bycc::Symbol: Which side to project,:x(using the X directions and X mean) or:y(using the Y directions and Y mean)
Value
2d array of floats; the p×n matrix of canonical variates (each observation's coordinates along the canonical directions). Throws an ArgumentError if c is neither :x nor :y
BigRiverEssence.jive — Method
jive(Xs::Vector{Matrix{Float64}}, r::Int, ri::Vector{Int}; kwargs...)Positional-argument form of jive for supplying the joint rank r and individual ranks ri directly
Arguments
Xs::Vector{Matrix{Float64}}: The data blocks, each pᵢ×nr::Int: The joint rankri::Vector{Int}: The individual ranks, one per blockkwargs...: Any keyword arguments accepted by the keyword form ofjive
Value
A Jive; identical to calling jive(Xs; r = r, ri = ri, kwargs...)
BigRiverEssence.jive — Method
jive(Xs::Vector{Matrix{Float64}}; r = nothing, ri = nothing, scale = true,
center = true, tol = nothing, maxiter = 1000, nperm = 100, alpha = 0.05)Fit a JIVE (Joint and Individual Variation Explained) decomposition of several data blocks sharing a common set of observations
Arguments
Xs::Vector{Matrix{Float64}}: The data blocks, each pᵢ×n with the SAME number of columns n (observations); rows (features) may differ per blockr: The joint rank; if nothing, estimated by permutation test. Defaults to nothingri: The vector of individual ranks; if nothing, estimated by permutation test. Defaults to nothingscale::Bool: Whether to scale each block by its Frobenius norm (and √(total elements)) so blocks contribute comparably. Defaults to truecenter::Bool: Whether to row-center each block. Defaults to truetol: The convergence threshold; if nothing, set to 1e-6·‖stacked data‖. Defaults to nothingmaxiter::Int: The maximum core-fit iterations. Defaults to 1000nperm::Int: The permutations per rank test (when ranks are estimated). Defaults to 100alpha::Float64: The significance level for the rank test. Defaults to 0.05
Value
A Jive with the joint and individual decompositions. Each block is first row-centered and Frobenius-scaled so no block dominates by sheer magnitude. If the joint and individual ranks are not supplied, they are estimated by a permutation test; the decomposition is then computed by alternating between estimating the shared joint structure and each block's individual structure until they converge. The result splits each block into joint structure (a common row space across all blocks) and block-specific individual structure orthogonal to it, after Lock et al. (2013)
BigRiverEssence.nmf — Method
nmf(X::Matrix{Float64}; k::Int = minimum(size(X)), init::Symbol = :auto,
tol::Real = 1e-4, maxiter::Int = 200, alpha_w::Real = 0.0,
alpha_h::Union{Nothing,Real} = nothing, l1_ratio::Real = 0.0,
shuffle::Bool = false, rng::AbstractRNG = Random.GLOBAL_RNG,
w_init = nothing, h_init = nothing)Fit a nonnegative matrix factorization using Fast HALS coordinate descent
Arguments
X::Matrix{Float64}: 2d array of nonnegative finite floats; observations in rows and features in columnsk::Int: The factorization rank. Defaults to min(n,p)init::Symbol: Initialization method::auto,:random,:nndsvd,:nndsvda,:nndsvdar, or:custom.:autouses:nndsvdawhen possible and:randomotherwise. Defaults to:autotol::Real: Stopping tolerance for the normalized projected-gradient violation. Defaults to 1e-4maxiter::Int: Maximum number of alternating coordinate-descent iterations. Defaults to 200alpha_w::Real: Elastic-net strength for W, scaled internally by the number of features. Defaults to 0alpha_h::Union{Nothing,Real}: Elastic-net strength for H, scaled internally by the number of observations.nothingusesalpha_w. Defaults to nothingl1_ratio::Real: Fraction of regularization assigned to L1, in [0,1]; the remainder is squared Frobenius regularization. Defaults to 0shuffle::Bool: Whether to randomize the component-coordinate order at every W and H update. Defaults to falserng::AbstractRNG: Random-number generator used by randomized initialization and coordinate shuffling. Defaults to Julia's global RNGw_init: Custom n×k nonnegative initial W, required only withinit=:customh_init: Custom k×p nonnegative initial H, required only withinit=:custom
Value
An Nmf holding nonnegative factors W and H, their Frobenius reconstruction error, convergence information, and regularization settings. It minimizes the scikit-learn NMF objective: one-half squared reconstruction error plus size-scaled elastic-net penalties on W and H, using alternating Fast HALS coordinate descent. Warns if maxiter is reached before convergence
BigRiverEssence.nmf_invtransform — Method
nmf_invtransform(M::Nmf, W::Matrix{Float64})Reconstruct observations in the original feature space from nonnegative NMF scores
Arguments
M::Nmf: A fitted NMF model, as returned bynmfW::Matrix{Float64}: 2d array of floats; the n×k score matrix to reconstruct, with k matching the number of fitted components
Value
2d array of floats; the n×p reconstruction W*M.h
BigRiverEssence.nmf_transform — Method
nmf_transform(M::Nmf, X::Matrix{Float64}; tol::Real = 1e-4,
maxiter::Int = 200, shuffle::Bool = false,
rng::AbstractRNG = Random.GLOBAL_RNG)Represent new nonnegative observations using the fixed components of a fitted NMF
Arguments
M::Nmf: A fitted NMF model, as returned bynmfX::Matrix{Float64}: 2d array of nonnegative finite floats; new observations in rows and the same p features used to fitMin columnstol::Real: The stopping tolerance for the normalized projected-gradient violation. Defaults to 1e-4maxiter::Int: The maximum number of coordinate-descent sweeps. Defaults to 200shuffle::Bool: Whether to randomize the component-update order in each sweep. Defaults to falserng::AbstractRNG: Random-number generator used only whenshuffle=true. Defaults to Julia's global RNG
Value
2d array of floats; the n×k nonnegative score matrix W minimizing ‖X − W*M.h‖² with the fitted components held fixed and the model's W regularization applied
BigRiverEssence.pca — Method
pca(X::Matrix{Float64}; k::Int = minimum(size(X)),
standardize::Bool = false, method::Symbol = :auto)Fit a principal component analysis (PCA) model
Arguments
X::Matrix{Float64}: 2d array of floats; observations (rows) by features (columns)k::Int: The number of components to retain; 1 ≤ k ≤ min(n,p). Defaults to min(n,p)standardize::Bool: Whether to scale columns to unit variance in addition to centering. Defaults to false (center only)method::Symbol::auto(pick by shape —:covwhen n ≥ p,:svdwhen p > n),:cov(eigendecomposition of the p×p covariance), or:svd(SVD of the centered data). Defaults to:auto
Value
A Pca holding the column means, scales, k loadings, component variances, and proportion of variance explained
BigRiverEssence.pca_invtransform — Method
pca_invtransform(m::Pca, scores::Matrix{Float64})Reconstruct data in the original feature space from principal-component scores
Arguments
m::Pca: A fitted PCA model, as returned bypcascores::Matrix{Float64}: 2d array of floats; the n×k matrix of principal-component scores to invert, with k matching the number of components retained inm
Value
2d array of floats; the n×p reconstruction in the original units. Exact only when all components are retained (k = p); otherwise a low-rank approximation
BigRiverEssence.pca_transform — Method
pca_transform(m::Pca, X::Matrix{Float64})Project data onto the principal directions of a fitted PCA model
Arguments
m::Pca: A fitted PCA model, as returned bypcaX::Matrix{Float64}: 2d array of floats; the observations (rows) by features (columns) to project, with the same features as the training data
Value
2d array of floats; the n×k matrix of principal-component scores
BigRiverEssence.plsda — Method
plsda(X::Matrix{Float64}, y::Vector, ncomp::Int;
scale = true, tol = 1e-6, max_iter = 100, levels = nothing)Fit a PLS discriminant analysis (PLS-DA) for multiclass problems — the non-sparse counterpart of splsda. The class labels are dummy-encoded and the problem solved as a PLS regression of X onto the indicator matrix: each component is the rank-1 approximation of the cross-product Mₕ = XₕᵀYₕ by alternating power iteration, after which both X and Y are deflated by regression on the X-variate (mixOmics' regression mode). Unlike splsda, no L1 penalty is applied, so every variable contributes to each loading.
BigRiverEssence.plskern — Method
plskern(X::Matrix{Float64}, Y::Matrix{Float64}; nlv::Int = 2,
standardize::Bool = false, method::Symbol = :algo1)Fit a kernel partial least squares (PLS) regression using the improved algorithms of Dayal & MacGregor (1997). The caller's X and Y are left untouched; centering and scaling are done on internal copies
Arguments
X::Matrix{Float64}: 2d array of floats; the n×p predictor matrixY::Matrix{Float64}: 2d array of floats; the n×q response matrixnlv::Int: The number of latent variables; clamped to min(nlv, n, p). Defaults to 2standardize::Bool: Whether to scale each column to unit standard deviation in addition to centering. Defaults to false (center only)method::Symbol::algo1(kernel via XᵀY) or:algo2(kernel via XᵀX, faster when p ≪ n). Both give identical results. Defaults to:algo1
Value
A Plskern holding the weight (W, R), loading (P, Q), and score (T) matrices together with the centering means and scales
BigRiverEssence.plskern_coef — Method
plskern_coef(m::Plskern; nlv::Int = size(m.R, 2))Assemble the regression coefficient matrix and intercept from a fitted PLS model
Arguments
m::Plskern: A fitted PLS model, as returned byplskernnlv::Int: The number of latent variables to include; clamped to the number fitted. Defaults to all fitted components
Value
A tuple (B, intercept) where B is the p×q coefficient matrix and intercept is the 1×q intercept, such that a prediction is intercept .+ Xnew * B. The scales are folded in so B maps raw (uncentered, unscaled) X to Y
BigRiverEssence.plskern_predict — Method
plskern_predict(m::Plskern, Xnew::Matrix{Float64}; nlv::Int = size(m.R, 2))Predict responses for new observations from a fitted PLS model
Arguments
m::Plskern: A fitted PLS model, as returned byplskernXnew::Matrix{Float64}: 2d array of floats; the new observations (rows) by predictors (columns), with the same p predictors as the training datanlv::Int: The number of latent variables to use; clamped to the number fitted. Defaults to all fitted components
Value
2d array of floats; the predicted n×q responses, intercept .+ Xnew * B
BigRiverEssence.plskern_transform — Method
plskern_transform(m::Plskern, Xnew::Matrix{Float64}; nlv::Int = size(m.R, 2))Project new observations onto the PLS latent space (compute their X-scores)
Arguments
m::Plskern: A fitted PLS model, as returned byplskernXnew::Matrix{Float64}: 2d array of floats; the new observations (rows) by predictors (columns), with the same p predictors as the training datanlv::Int: The number of latent variables to project onto; clamped to the number fitted. Defaults to all fitted components
Value
2d array of floats; the n×nlv matrix of X-scores. For the training data this reproduces the stored scores m.T, since scores are linear: T = Xc·R
BigRiverEssence.pmd — Method
pmd(X::Matrix{Float64}; sumabs::Real = 0.4,
sumabsu::Union{Nothing,Real} = nothing,
sumabsv::Union{Nothing,Real} = nothing,
K::Int = 1, niter::Int = 20, center::Bool = true)Fit a penalized matrix decomposition with L1 penalties on both factors, PMD(L1,L1)
Arguments
X::Matrix{Float64}: 2d array of floats; the n×p data matrixsumabs::Real: The shared sparsity budget in (0,1], scaled internally to give the per-column L1 budgets su = √n·sumabs on u and sv = √p·sumabs on v. Smaller values give sparser factors. Ignored when bothsumabsuandsumabsvare supplied. Defaults to 0.4sumabsu::Union{Nothing,Real}: An explicit L1 budget on each u column, in [1, √n]; overridessumabswhen given together withsumabsv. Defaults to nothingsumabsv::Union{Nothing,Real}: An explicit L1 budget on each v column, in [1, √p]; overridessumabswhen given together withsumabsu. Defaults to nothingK::Int: The number of components to extract; must be in 1:min(n,p). Defaults to 1niter::Int: The maximum number of power-iteration steps per component. Defaults to 20center::Bool: Whether to subtract the grand mean ofXbefore decomposing. Defaults to true
Value
A Pmd holding the n×K left factors u, the p×K right factors v, the K weights d, the resolved budgets su and sv, the number of components K, and the grand mean removed (or NaN when center=false)
BigRiverEssence.scca — Method
scca(X::Matrix{Float64}, Y::Matrix{Float64}; penaltyx::Real = 0.3,
penaltyz::Real = 0.3, K::Int = 1, niter::Int = 15, standardize::Bool = true)Fit a sparse canonical correlation analysis (sparse CCA) between two sets of variables, after Witten, Tibshirani & Hastie (2009)
Arguments
X::Matrix{Float64}: 2d array of floats; the first variable set, with variables in ROWS and observations in COLUMNS (dx×n)Y::Matrix{Float64}: 2d array of floats; the second variable set (dy×n), same number of observations (columns) as Xpenaltyx::Real: The L1 penalty on the X canonical vectors, in (0,1]; smaller values give sparser vectors. Defaults to 0.3penaltyz::Real: The L1 penalty on the Y canonical vectors, in (0,1]. Defaults to 0.3K::Int: The number of canonical components to extract; must be in 1:min(dx,dy). Defaults to 1niter::Int: The maximum power-iteration steps per component. Defaults to 15standardize::Bool: Whether to center and scale each variable to unit variance before fitting. Defaults to true
Value
An Scca holding the sparse X and Y canonical vectors (u, v), the component weights d, the sample correlations of the paired variates, the penalties, and K. Sparse CCA finds pairs of sparse vectors, one in X-space and one in Y-space, whose projected variates are maximally correlated under an L1 penalty (so each vector selects only a few variables). It uses the diagonal-covariance penalized formulation of Witten, Tibshirani & Hastie (2009): each component is a rank-1 penalized approximation of XᵀY solved by alternating soft-thresholded power iteration, after which the data are deflated before the next component
BigRiverEssence.spc — Method
spc(X::Matrix{Float64}; k::Int = 2, c::Real = sqrt(size(X,2))/2,
standardize::Bool = false, tol::Real = 1e-7, niter::Int = 20)Fit a sparse principal component analysis using the SPC criterion (deflation variant)
Arguments
X::Matrix{Float64}: 2d array of floats; the n×p data matrixk::Int: The number of sparse components to extract. Defaults to 2c::Real: The L1 budget on each loading, in [1, √p]; smaller values give sparser loadings, c = √p gives ordinary (dense) PCA. Defaults to √p / 2standardize::Bool: Whether to scale each column to unit standard deviation in addition to centering. Defaults to false (center only)tol::Real: The ℓ₁ convergence tolerance per component. Defaults to 1e-7niter::Int: The maximum number of power-iteration steps per component. Defaults to 20
Value
An Spc holding the column means, scales, k sparse loadings, component variances, and cumulative proportion of variance explained. Components are found sequentially: each loading is fit on the residual, then removed by rank-1 deflation before the next is extracted
BigRiverEssence.spc_orth — Method
spc_orth(X::Matrix{Float64}; k::Int = 2, c::Real = sqrt(size(X,2))/2,
standardize::Bool = false, tol::Real = 1e-6, niter::Int = 20)Fit a sparse principal component analysis with orthogonal scores (orthogonal variant of the SPC criterion)
Arguments
X::Matrix{Float64}: 2d array of floats; the n×p data matrixk::Int: The number of sparse components to extract. Defaults to 2c::Real: The L1 budget on each loading, in [1, √p]; smaller values give sparser loadings. Defaults to √p / 2standardize::Bool: Whether to scale each column to unit standard deviation in addition to centering. Defaults to false (center only)tol::Real: The ℓ₁ convergence tolerance per component. Defaults to 1e-6niter::Int: The maximum number of power-iteration steps per component. Defaults to 20
Value
An Spc holding the column means, scales, k sparse loadings, component variances, and cumulative proportion of variance explained. Unlike spc, each component's scores are constrained to be orthogonal to all previous components' scores (via projection rather than deflation), so the score directions form an orthonormal set
BigRiverEssence.splsda — Method
splsda(X::Matrix{Float64}, y::Vector, ncomp::Int, keepX::Vector{Int};
scale = true, tol = 1e-6, max_iter = 100, levels = nothing)Fit a sparse PLS discriminant analysis (sPLS-DA) for multiclass problems, after Lê Cao, Boitard & Besse (2011)
Arguments
X::Matrix{Float64}: 2d array of floats; the n×p predictor matrixy::Vector: The class labels, one per observation (n total)ncomp::Int: The number of components to extractkeepX::Vector{Int}: The number of variables to keep per component; must have length ncomp (one sparsity budget per component)scale::Bool: Whether to scale columns to unit variance in addition to centering. Defaults to truetol::Real: The convergence tolerance on the loading iterates. Defaults to 1e-6max_iter::Int: The maximum number of inner iterations per component. Defaults to 100levels: An optional class ordering passed to the dummy encoding; fixes the column order of the classes. Defaults to nothing (sorted unique labels)
Value
An Splsda holding the X and Y variates (scores), the sparse X and dense Y loadings, the number of components, the per-component keepX, the one-hot class encoding, and the class labels. The class labels are dummy-encoded into an indicator matrix and the problem solved as a sparse PLS regression of X onto that matrix: each component is the penalized rank-1 approximation of the cross-product Mₕ = XₕᵀYₕ, solved by alternating soft-thresholded power iteration, after which X (only) is deflated by regression on its variate (Y is not deflated — the discriminant regression mode)
BigRiverEssence.vip — Method
vip(m)Compute Variable Importance in Projection (VIP) scores for a fitted PLS discriminant model
Arguments
m: a fitted model (PlsdaorSplsda) exposing the X-loadings (loadings_X), the X-variates (variates_X), the dummy-encoded response (Y_dummy), and the number of components (ncomp)
Value
A p×ncomp matrix of VIP scores, where p is the number of variables (rows of the X-loadings). Entry [j, h] is the importance of variable j using the first h components; the last column is the cross-component VIP that summarizes each variable's contribution over all components. The scores are normalized so that the mean squared VIP equals 1, so a value above 1 marks an above-average-importance variable — the conventional selection threshold. This follows the VIP definition of Wold et al. as implemented in mixOmics::vip: each component's contribution is weighted by the redundancy (the squared correlation between the dummy response and that component's variate) it explains, so components that better separate the classes count more toward the score
BigRiverEssence.Cca — Type
Cca{T}Container for a fitted canonical correlation analysis, as returned by cca
Fields
xmean::Vector{T}: The mean of each X variable (length dx), removed during centeringymean::Vector{T}: The mean of each Y variable (length dy), removed during centeringxproj::Matrix{T}: The dx×p X canonical directions (columns), one per componentyproj::Matrix{T}: The dy×p Y canonical directions (columns), one per componentcorrs::Vector{T}: The p canonical correlations, in [0,1] and descendingnobs::Int: The number of observations used (or −1 when fit via the covariance path, which doesn't carry n through)
BigRiverEssence.Jive — Type
Jive{T}Container for a fitted JIVE (Joint and Individual Variation Explained) decomposition, as returned by jive
Fields
J::Vector{Matrix{T}}: The joint structure, one pᵢ×n matrix per data block; all blocks share the same n-dimensional joint row spaceA::Vector{Matrix{T}}: The individual structure, one pᵢ×n matrix per block, orthogonal to the joint structureS::Matrix{T}: The r×n joint scores (orthonormal rows), the basis of the shared joint row spaceU::Vector{Matrix{T}}: The joint loadings, one pᵢ×r block, so that J[i] = U[i]·SSi::Vector{Matrix{T}}: The individual scores, one rᵢ×n matrix per blockWi::Vector{Matrix{T}}: The individual loadings, one pᵢ×rᵢ matrix per block, so that A[i] = Wi[i]·Si[i]r::Int: The joint rank (dimension of the shared structure)ri::Vector{Int}: The individual ranks, one per block
BigRiverEssence.Nmf — Type
Nmf{T}Container for a fitted nonnegative matrix factorization, as returned by nmf
Fields
w::Matrix{T}: The n×k nonnegative sample scores, one row per observationh::Matrix{T}: The k×p nonnegative components, one column per input featurereconstruction_error::T: The Frobenius norm ‖X − w*h‖_F of the final reconstruction residualniter::Int: The number of alternating coordinate-descent iterations performedconverged::Bool: Whether the normalized projected-gradient violation reached the requested tolerance beforemaxiteralpha_w::T: The elastic-net regularization strength used forwalpha_h::T: The elastic-net regularization strength used forhl1_ratio::T: The fraction of regularization assigned to the L1 penalty, in [0,1]; the remainder is assigned to the squared Frobenius penalty
BigRiverEssence.Pca — Type
Pca{T}Container for a fitted PCA model, as returned by pca
Fields
mean::Vector{T}: The column means of the training data (length p), removed during centeringscale::Vector{T}: The column scales (length p) — the column standard deviations whenstandardize=true, otherwise onesloadings::Matrix{T}: The p×k principal directions (right singular vectors of the centered data / leading eigenvectors of the covariance matrix), unit-norm columns ordered by decreasing explained variancevariances::Vector{T}: The variance explained by each of the k components (the eigenvalues, σᵢ² / (n-1))propOFvar::Vector{T}: The proportion of total variance explained by each component (variances ./ total variance)
BigRiverEssence.Plsda — Type
Plsda{T}Container for a fitted PLS discriminant analysis, as returned by plsda.
Fields
variates_X::Matrix{T}: n×ncomp X-scores (sample coordinates)variates_Y::Matrix{T}: n×ncomp Y-scoresloadings_X::Matrix{T}: p×ncomp dense X-loadingsloadings_Y::Matrix{T}: K×ncomp Y-loadings (K = number of classes)ncomp::Int: number of componentsY_dummy::Matrix{T}: n×K one-hot encoding of the labelsclasses::Vector: class labels, in Y_dummy column order
BigRiverEssence.Plskern — Type
Plskern{T}Container for a fitted kernel PLS regression model, as returned by plskern. Holds the standard PLS factor matrices and the centering/scaling statistics
Fields
W::Matrix{T}: The p×nlv weight matrix (unit-norm columns)P::Matrix{T}: The p×nlv X-loadingsQ::Matrix{T}: The q×nlv Y-loadingsR::Matrix{T}: The p×nlv weight matrix in the deflated basis, so that scores satisfy T = Xc·R (the SIMPLS-style weights)T::Matrix{T}: The n×nlv X-scores (orthogonal columns)xmeans::Vector{T}: The column means of X removed during centeringxscales::Vector{T}: The column scales of X (standard deviations ifstandardize=true, otherwise ones)ymeans::Vector{T}: The column means of Y removed during centeringyscales::Vector{T}: The column scales of Y
BigRiverEssence.Pmd — Type
Pmd{T}Container for a fitted penalized matrix decomposition, as returned by pmd
Fields
u::Matrix{T}: The n×K left factors (one unit-ℓ₂, L1-penalized column per component)v::Matrix{T}: The p×K right factors (one unit-ℓ₂, L1-penalized column per component)d::Vector{T}: The K nonnegative singular-value-like weights, dₖ = uₖᵀ X vₖsumabsu::Float64: The resolved L1 budget on each u column (in [1, √n])sumabsv::Float64: The resolved L1 budget on each v column (in [1, √p])K::Int: The number of componentsmeanx::Float64: The grand mean removed during centering, or NaN if center=false
BigRiverEssence.Scca — Type
Scca{T}Container for a fitted sparse canonical correlation analysis, as returned by scca
Fields
u::Matrix{T}: The dx×K sparse X canonical vectors (one unit-ℓ₂, L1-penalized column per component); nonzero entries are the selected X featuresv::Matrix{T}: The dy×K sparse Y canonical vectors; nonzero entries are the selected Y featuresd::Vector{T}: The K weights dₖ = uₖᵀ Xᵀ Z vₖ (the penalized-covariance objective values)cors::Vector{T}: The K sample correlations between the paired canonical variatespenaltyx::Float64: The L1 penalty applied to the X vectors, in (0,1]penaltyz::Float64: The L1 penalty applied to the Y vectors, in (0,1]K::Int: The number of components
BigRiverEssence.Spc — Type
Spc{T}Container for a fitted sparse principal component analysis, as returned by spc or spc_orth
Fields
mean::Vector{T}: The column means of the training data (length p), removed during centeringscale::Vector{T}: The column scales (length p) — the column standard deviations whenstandardize=true, otherwise onesloadings::Matrix{T}: The p×k sparse loadings (one unit-ℓ₂, L1-penalized column per component), signs fixed by_sign_consistency_opt!variances::Vector{T}: The variance associated with each of the k components (dₖ² / (n-1), where dₖ is the component weight)propOFvar::Vector{T}: The cumulative proportion of variance explained by the first k components (see_prop_var_explained)
BigRiverEssence.Splsda — Type
Splsda{T}Container for a fitted sparse PLS discriminant analysis, as returned by splsda
Fields
variates_X::Matrix{T}: The n×ncomp X-scores (sample coordinates for plotting/classification)variates_Y::Matrix{T}: The n×ncomp Y-scores (the class-side variates)loadings_X::Matrix{T}: The p×ncomp sparse X-loadings; the nonzero entries per column are the variables selected for that componentloadings_Y::Matrix{T}: The K×ncomp Y-loadings (K = number of classes)ncomp::Int: The number of components fittedkeepX::Vector{Int}: The number of variables kept per component (the sparsity budget)Y_dummy::Matrix{T}: The n×K one-hot encoding of the class labelsclasses::Vector: The class labels, in the column order of Y_dummy
Internal functions
Internal helpers, documented for reference. These are not part of the public API and may change.
BigRiverEssence._binary_search_opt — Method
_binary_search_opt(argu, sumabs)Find the soft-threshold that makes a soft-thresholded vector meet a target L1 budget
Arguments
argu: 1d array of floats; the vector to be thresholdedsumabs: Float; the target ℓ₁/ℓ₂ ratio (the L1 budget)
Value
Float; the threshold d ≥ 0 such that ‖S(argu,d)‖₁/‖S(argu,d)‖₂ ≈ sumabs. Returns 0 when the vector already satisfies the budget. Implements the bisection step bracketing d in [0, max|argu|] and halving for up to 150 iterations or until the bracket is below 1e-6
BigRiverEssence._cca_cov_opt — Method
_cca_cov_opt(Cxx, Cyy, Cxy, xmean, ymean, p::Int)Solve CCA from the covariance matrices via a generalized eigenproblem
Arguments
Cxx: 2d array of floats; the dx×dx X covarianceCyy: 2d array of floats; the dy×dy Y covarianceCxy: 2d array of floats; the dx×dy cross-covariancexmean: 1d array of floats; the X means, stored in the resultymean: 1d array of floats; the Y means, stored in the resultp::Int: The number of canonical components to return
Value
A Cca with the top-p canonical directions and correlations (its nobs is −1, since this path works from covariances and doesn't carry n). Solves the classical canonical-correlation generalized eigenproblem (Weenink 2003), reducing through whichever side is smaller (dx ≤ dy or dx > dy) for efficiency: the squared canonical correlations are the eigenvalues, one side's directions are the eigenvectors, and the other side's are recovered and normalized to unit variance by _qnormalize!
BigRiverEssence._cca_svd_opt — Method
_cca_svd_opt(Zx, Zy, xmean, ymean, p::Int)Solve CCA directly from the centered data via SVD (no covariance matrices formed)
Arguments
Zx: 2d array of floats; the centered X data (dx×n), OVERWRITTEN by svd!Zy: 2d array of floats; the centered Y data (dy×n), OVERWRITTEN by svd!xmean: 1d array of floats; the X means, stored in the resultymean: 1d array of floats; the Y means, stored in the resultp::Int: The number of canonical components to return
Value
A Cca with the top-p canonical directions and correlations. Works from the SVDs of Zx and Zy directly rather than forming covariance matrices, which is the numerically stable route advocated by Weenink (2003): the canonical correlations are the singular values of the overlap between the two right-singular-vector bases, and the canonical directions are recovered by rescaling the left singular vectors so the variates have unit variance
BigRiverEssence._center_scale — Method
_center_scale(M::AbstractMatrix; scale = true)Center, and optionally scale, the columns of a matrix
Arguments
M::AbstractMatrix: 2d array of floats; the matrix to center/scalescale::Bool: Whether to divide each column by its (n−1) standard deviation after centering. Defaults to true
Value
2d array of floats; the column-centered (and, if scale=true, unit-variance) matrix. Constant columns (zero standard deviation) are guarded: their scale is treated as 1 and the column is set to all zeros rather than producing NaN. The n−1 (corrected) standard deviation matches mixOmics' colSds
BigRiverEssence._fast_init_v — Method
_fast_init_v(x, z, K)Initialize the Y canonical vectors for wide data via an SVD construction
Arguments
x: 2d array of floats; the (observations × features) X blockz: 2d array of floats; the (observations × features) Z blockK: Int; the number of components to initialize
Value
2d array of floats; the K leading left singular vectors of zᵀ·(xxᵀ)^½, used as the starting v for the sparse iteration when both blocks are wider than they are tall. Building the init from xxᵀ (observations × observations) keeps the SVD small in the high-dimensional case
BigRiverEssence._finding_v! — Method
_finding_v!(v, s, z, c)Project a vector onto the intersection of the unit ℓ₂ ball and the L1 budget, writing the result in place
Arguments
v: 1d array of floats; the destination buffer for the result, overwritten in places: 1d array of floats; preallocated scratch for the soft-thresholded vectorz: 1d array of floats; the raw direction to project (e.g. Xᵀu)c: Float; the L1 budget (in [1, √p]); the returned v satisfies ‖v‖₂ = 1 and ‖v‖₁ ≤ c
Value
The buffer v, holding the unit-ℓ₂ vector closest to z whose ℓ₁ norm meets the budget. If the plain unit-normalized z already satisfies the budget it is returned unchanged; otherwise a soft-threshold δ is found by bisection (up to 150 steps) so that the normalized, thresholded vector has ‖v‖₁ ≈ c. This is the penalized update of the SPC criterion in Witten, Tibshirani & Hastie (2009)
BigRiverEssence._init_rsv — Method
_init_rsv(Xc, k::Int)Compute the top-k right singular vectors of a centered data matrix, used to initialize the sparse power iteration
Arguments
Xc: 2d array of floats; the centered (and optionally scaled) data matrixk::Int: The number of leading right singular vectors to return
Value
2d array of floats; the p×k matrix of leading right singular vectors of Xc. Two branches keep the eigenproblem small: for tall data (p ≤ n) it eigendecomposes the p×p Gram matrix XcᵀXc directly, otherwise it eigendecomposes the n×n Gram matrix XcXcᵀ and back-projects. Both use a partial eigendecomposition (only the top k eigenpairs) and return columns in descending eigenvalue order
BigRiverEssence._jive_perm_ranks_opt — Method
_jive_perm_ranks_opt(Xc::Vector{Matrix{Float64}}, n::Int; nperm::Int,
alpha::Float64, conv::Float64, maxiter::Int,
maxrounds::Int = 10)Estimate the joint and individual ranks by a permutation test
Arguments
Xc::Vector{Matrix{Float64}}: The preprocessed data blocks, each pᵢ×nn::Int: The shared number of columns (observations)nperm::Int: The number of permutations used to build each null distributionalpha::Float64: The significance level; a singular value counts as signal if it exceeds the (1−alpha) quantile of the permuted nullconv::Float64: The convergence threshold passed to the core fitmaxiter::Int: The maximum core-fit iterationsmaxrounds::Int: The maximum number of estimate-then-refit rounds. Defaults to 10
Value
A tuple (rJ, rA) of the estimated joint rank and the vector of individual ranks. The joint rank is the number of leading singular values of the stacked (data − individual) residual that exceed the column-permuted null; each individual rank is found the same way on each block's (data − joint) residual. Ranks and the fit are alternated until the rank estimates stabilize, following the r.jive permutation procedure of Lock et al. (2013)
BigRiverEssence._jive_rjive_core_opt2 — Method
_jive_rjive_core_opt2(Xc::Vector{Matrix{Float64}}, n::Int, r::Int,
ri::Vector{Int}; conv::Float64, maxiter::Int)Compute the JIVE decomposition for GIVEN joint and individual ranks, by alternating between estimating the joint and individual structure
Arguments
Xc::Vector{Matrix{Float64}}: The preprocessed (centered/scaled) data blocks, each pᵢ×n with a shared column dimension nn::Int: The number of columns (observations) shared across blocksr::Int: The joint rankri::Vector{Int}: The individual ranks, one per blockconv::Float64: The convergence threshold on the change in J and A between iterationsmaxiter::Int: The maximum number of outer iterations
Value
A Jive with the joint (J, S, U) and individual (A, Si, Wi) parts. Implements the r.jive "orthIndiv" algorithm of Lock et al. (2013): wide blocks are first compressed to their score space (via SVD) for efficiency, then the joint structure is the rank-r SVD of the stacked residual (data minus individual), and each block's individual structure is the rank-rᵢ SVD of its residual projected off the joint row space and off the other blocks' individual spaces. The two estimates are alternated to convergence, then mapped back to the original row space
BigRiverEssence._l1_diff — Method
_l1_diff(a, b)Compute the ℓ₁ distance between two vectors
Arguments
a: 1d array of floatsb: 1d array of floats
Value
Float; ‖a − b‖₁. Used as the convergence criterion between successive iterates
BigRiverEssence._l1_of_norm — Method
_l1_of_norm(a)Compute the ℓ₁/ℓ₂ ratio of a vector
Arguments
a: 1d array of floats
Value
Float; ‖a‖₁ / ‖a‖₂. This ratio is the quantity the L1 budget constrains; it ranges from 1 (maximally sparse) to √length(a) (fully dense)
BigRiverEssence._l1_of_norm_soft — Method
_l1_of_norm_soft(a, d)Compute the ℓ₁/ℓ₂ ratio of a vector AFTER soft-thresholding it by d, without materializing the thresholded vector
Arguments
a: 1d array of floats; the unthresholded vectord: Float; the soft-threshold to apply
Value
Float; ‖S(a,d)‖₁ / ‖S(a,d)‖₂ where S is the soft-threshold operator. Used inside the binary search to test whether a candidate threshold meets the L1 budget
BigRiverEssence._l1diff — Method
_l1diff(a, b)Compute the ℓ₁ distance between two vectors
Arguments
a: 1d array of floatsb: 1d array of floats
Value
Float; ‖a − b‖₁. Used as the convergence criterion between successive iterates
BigRiverEssence._l2n_val — Method
_l2n_val(a)Compute the ℓ₂ norm of a vector with a zero-guard
Arguments
a: 1d array of floats
Value
Float; the Euclidean norm ‖a‖₂, or 0.05 when a is all zeros. The guard mirrors PMA's convention and prevents division by zero in the normalization steps
BigRiverEssence._matsqrt — Method
_matsqrt(A)Compute the symmetric square root of a symmetric positive-semidefinite matrix
Arguments
A: 2d array of floats; a symmetric (positive-semidefinite) matrix
Value
2d array of floats; the symmetric matrix R such that R·R = A, formed from the eigendecomposition with eigenvalues floored at zero (so tiny negative roundoff eigenvalues don't produce complex results)
BigRiverEssence._nmf_cd_sweep! — Method
_nmf_cd_sweep!(A, F, G, gram, cross, gradient, order,
l1_regularization::Float64, l2_regularization::Float64)Perform one Fast HALS coordinate-descent sweep over a nonnegative factor
Arguments
A: 2d array of floats; the m×q target matrixF: 2d array of floats; the mutable m×k factor updated in placeG: 2d array of floats; the fixed q×k factor for this half-stepgram: Preallocated k×k buffer for GᵀGcross: Preallocated m×k buffer for A*Ggradient: Preallocated length-m gradient bufferorder: Length-k integer vector giving the coordinate-update orderl1_regularization::Float64: L1 term added to every coordinate gradientl2_regularization::Float64: L2 term added to the Gram-matrix diagonal
Value
Float; the sum of absolute projected-gradient violations before each coordinate update. The sweep updates every column of F in place using max(F[:,t] - gradient/GᵀG[t,t], 0). All matrix products and work vectors are reused, so the iterative hot path does not allocate an m×q reconstruction
BigRiverEssence._nmf_fit_cd! — Method
_nmf_fit_cd!(X, w, ht, l1_w::Float64, l1_h::Float64,
l2_w::Float64, l2_h::Float64; tol::Float64, maxiter::Int,
shuffle::Bool, rng::AbstractRNG, update_h::Bool = true)Fit mutable NMF factors with alternating Fast HALS coordinate descent
Arguments
X: 2d array of floats; the n×p nonnegative target matrixw: Mutable n×k score matrixht: Mutable p×k transposed-component matrix; held fixed whenupdate_h=falsel1_w::Float64: Scaled L1 regularization applied to Wl1_h::Float64: Scaled L1 regularization applied to Hl2_w::Float64: Scaled L2 regularization applied to Wl2_h::Float64: Scaled L2 regularization applied to Htol::Float64: Stopping tolerance for violation/initial_violationmaxiter::Int: Maximum number of alternating sweepsshuffle::Bool: Whether to shuffle component coordinates before each half-steprng::AbstractRNG: Random-number generator used when shufflingupdate_h::Bool: Whether to update H as well as W. Defaults to true
Value
A tuple (niter, converged). The convergence rule matches scikit-learn's coordinate-descent NMF: stop when the projected-gradient violation relative to the first iteration is no greater than tol
BigRiverEssence._nmf_initialize — Method
_nmf_initialize(X::Matrix{Float64}, k::Int, init::Symbol,
rng::AbstractRNG, w_init, h_init)Resolve and construct the requested NMF initialization
Arguments
X::Matrix{Float64}: 2d array of nonnegative floats; the n×p matrix to factorizek::Int: The requested factorization rankinit::Symbol::auto,:random,:nndsvd,:nndsvda,:nndsvdar, or:customrng::AbstractRNG: Random-number generator for randomized initializationsw_init: Optional n×k custom initial score matrixh_init: Optional k×p custom initial component matrix
Value
A tuple (w, ht) containing mutable Float64 factors. :auto selects :nndsvda when k <= min(n,p), otherwise :random. Throws an ArgumentError or DimensionMismatch for an invalid initialization request
BigRiverEssence._nmf_nndsvd_init — Method
_nmf_nndsvd_init(X::Matrix{Float64}, k::Int, variant::Symbol,
rng::AbstractRNG; eps::Float64 = 1e-6)Initialize NMF factors with Nonnegative Double Singular Value Decomposition
Arguments
X::Matrix{Float64}: 2d array of nonnegative floats; the n×p matrix to factorizek::Int: The requested rank, no larger than min(n,p)variant::Symbol::nndsvdto retain zeros,:nndsvdato replace zeros bymean(X), or:nndsvdarto replace zeros by small random valuesrng::AbstractRNG: Random-number generator used only by:nndsvdareps::Float64: Values below this threshold are set to zero before applying the selected zero-filling rule. Defaults to 1e-6
Value
A tuple (w, ht) containing the n×k scores and p×k transposed components. Positive and negative singular-vector parts are compared without materializing four temporary vectors, and only the selected pair is written into the factors
BigRiverEssence._nmf_random_init — Method
_nmf_random_init(X::Matrix{Float64}, k::Int, rng::AbstractRNG)Initialize both NMF factors with scaled absolute Gaussian values
Arguments
X::Matrix{Float64}: 2d array of nonnegative floats; the n×p matrix to factorizek::Int: The requested factorization rankrng::AbstractRNG: Random-number generator used for every draw
Value
A tuple (w, ht) containing an n×k score matrix and a p×k transposed-component matrix. Entries are abs(randn()) * sqrt(mean(X)/k), matching scikit-learn's random NMF initialization while storing Hᵀ for column-major coordinate updates
BigRiverEssence._nmf_reconstruction_error — Method
_nmf_reconstruction_error(X, w, h)Compute the NMF Frobenius reconstruction error without forming W*H
Arguments
X: 2d array of floats; the n×p target matrixw: 2d array of floats; the n×k score matrixh: 2d array of floats; the k×p component matrix
Value
Float; ‖X − W*H‖_F. Accumulates each reconstructed entry directly so it avoids an n×p residual allocation without suffering the cancellation error of the expanded Gram-matrix identity when the reconstruction is nearly exact
BigRiverEssence._pmd_binary_search — Method
_pmd_binary_search(argu, sumabs::Float64)Find the soft-threshold λ that makes a soft-thresholded vector meet a target L1 budget
Arguments
argu: 1d array of floats; the vector to be thresholdedsumabs::Float64: The target ℓ₁/ℓ₂ ratio (the L1 budget)
Value
Float; the threshold λ ≥ 0 such that ‖S(argu,λ)‖₁/‖S(argu,λ)‖₂ ≈ sumabs. Returns 0 when the vector already satisfies the budget. Implements the bisection step of Witten, Tibshirani & Hastie (2009), bracketing λ in [0, max|argu|] and halving for up to 150 iterations or until the bracket is below 1e-6
BigRiverEssence._pmd_check_v — Method
_pmd_check_v(x::Matrix{Float64}, K::Int)Initialize the right factors from the leading right singular vectors of the data
Arguments
x::Matrix{Float64}: 2d array of floats; the (already preprocessed) data matrixK::Int: The number of components to initialize
Value
2d array of floats; the p×K matrix of leading right singular vectors of x. Two branches keep the eigenproblem small: for wide data (p > n) it decomposes the n×n Gram matrix x·xᵀ and back-projects, otherwise it decomposes the p×p Gram matrix xᵀ·x directly. SVD initialization is the deterministic starting point recommended in Witten, Tibshirani & Hastie (2009)
BigRiverEssence._pmd_l1_norm — Method
_pmd_l1_norm(a)Compute the ℓ₁/ℓ₂ ratio of a vector
Arguments
a: 1d array of floats
Value
Float; ‖a‖₁ / ‖a‖₂. This ratio is the quantity the L1 budget constrains; it ranges from 1 (maximally sparse) to √length(a) (fully dense)
BigRiverEssence._pmd_l1_norm_soft — Method
_pmd_l1_norm_soft(a, λ::Float64)Compute the ℓ₁/ℓ₂ ratio of a vector AFTER soft-thresholding it by λ, without materializing the thresholded vector
Arguments
a: 1d array of floats; the unthresholded vectorλ::Float64: The soft-threshold to apply
Value
Float; ‖S(a,λ)‖₁ / ‖S(a,λ)‖₂ where S is the soft-threshold operator. Used inside the binary search to test whether a candidate λ meets the L1 budget
BigRiverEssence._pmd_l1diff — Method
_pmd_l1diff(a, b)Compute the ℓ₁ distance between two vectors
Arguments
a: 1d array of floatsb: 1d array of floats
Value
Float; ‖a − b‖₁. Used as the convergence criterion between successive v iterates
BigRiverEssence._pmd_l2n — Method
_pmd_l2n(a)Compute the ℓ₂ norm of a vector with a zero-guard
Arguments
a: 1d array of floats
Value
Float; the Euclidean norm ‖a‖₂, or 0.05 when a is all zeros. The guard mirrors the R package PMA's convention and prevents division by zero in the normalization steps
BigRiverEssence._pmd_smd! — Method
_pmd_smd!(x, v0, sumabsu::Float64, sumabsv::Float64, niter::Int,
u, v, vold, argu, argv)Compute one rank-1 sparse factor pair by alternating, soft-thresholded power iteration
Arguments
x: 2d array of floats; the (deflated) data matrix for this componentv0: 1d array of floats; the initial right factor (from_pmd_check_v)sumabsu::Float64: The L1 budget on u (in [1, √n])sumabsv::Float64: The L1 budget on v (in [1, √p])niter::Int: The maximum number of power-iteration stepsu: 1d array of floats; preallocated buffer for the left factor, written in placev: 1d array of floats; preallocated buffer for the right factor, written in placevold: 1d array of floats; preallocated scratch holding the previous v iterateargu: 1d array of floats; preallocated scratch of length nargv: 1d array of floats; preallocated scratch of length p
Value
Float; the weight d = uᵀ x v for the fitted component. On return u and v hold the unit-ℓ₂, L1-penalized factors. Each step alternates u ← normalize(S(x v, λᵤ)) and v ← normalize(S(xᵀ u, λᵥ)), with λ chosen by _pmd_binary_search to meet the budgets; this is the single-factor PMD(L1,L1) update of Witten, Tibshirani & Hastie (2009). The randn primer on vold only forces the first iteration to run and does not affect the converged fixed point
BigRiverEssence._pmd_soft — Method
_pmd_soft(a::Float64, λ::Float64)Soft-threshold a scalar: shrink toward zero by λ, clamping at zero
Arguments
a::Float64: The value to thresholdλ::Float64: The nonnegative threshold
Value
Float; sign(a)·max(|a| − λ, 0). The elementwise solution to the L1-penalized update in Witten, Tibshirani & Hastie (2009)
BigRiverEssence._pmd_soft_normalize! — Method
_pmd_soft_normalize!(out, arg, λ::Float64)Soft-threshold a vector by λ and rescale it to unit ℓ₂ norm, writing into a preallocated buffer
Arguments
out: 1d array of floats; the destination buffer, overwritten in placearg: 1d array of floats; the vector to thresholdλ::Float64: The soft-threshold
Value
The buffer out, holding S(arg,λ) normalized to unit ℓ₂ norm (or all zeros, guarded against division by zero). This is the factor update of the PMD power iteration
BigRiverEssence._prop_var_explained — Method
_prop_var_explained(Xc, V)Compute the cumulative proportion of variance explained by sparse components
Arguments
Xc: 2d array of floats; the centered data matrixV: 2d array of floats; the p×K matrix of (possibly non-orthonormal) sparse loadings
Value
1d array of floats of length K; entry k is the proportion of total variance explained by the first k loadings jointly. Because sparse loadings need not be orthonormal, the adjusted variance uses the projection ‖Xc·Vₖ(VₖᵀVₖ)⁻¹Vₖᵀ‖²F / ‖Xc‖²F, evaluated here in the equivalent trace form tr((VₖᵀVₖ)⁻¹ VₖᵀXcᵀXcVₖ) / ‖Xc‖²_F. This is the adjusted-variance measure of Shen & Huang / Witten et al. for non-orthogonal sparse PCs
BigRiverEssence._qnormalize! — Method
_qnormalize!(P, C)Normalize the columns of a direction matrix to unit variance under a covariance metric, in place
Arguments
P: 2d array of floats; the directions (columns), overwritten in placeC: 2d array of floats; the covariance defining the metric
Value
The matrix P, with each column pⱼ rescaled so that pⱼᵀ C pⱼ = 1 (unit variance of the corresponding canonical variate). Used to normalize the recovered side's directions in the covariance-based CCA solver
BigRiverEssence._safe_svd! — Method
_safe_svd!(A)In-place variant of _safe_svd: compute an SVD, overwriting A, with a robust fallback on convergence failure
Arguments
A: 2d array of floats; the matrix to decompose, OVERWRITTEN in place by the default path
Value
An SVD factorization object. Tries the in-place svd! first; on a LAPACKException retries with the (non-mutating) QR-iteration SVD. Used in the inner JIVE iterations where the input is scratch that can be destroyed
BigRiverEssence._safe_svd — Method
_safe_svd(A)Compute an SVD, falling back to a slower but more robust algorithm if the default one fails to converge
Arguments
A: 2d array of floats; the matrix to decompose
Value
An SVD factorization object. Tries the default divide-and-conquer SVD first; if it raises a LAPACKException (a convergence failure on certain ill-conditioned inputs), retries with the QR-iteration algorithm, which is slower but more stable. Any other error is rethrown
BigRiverEssence._safe_svdvals — Method
_safe_svdvals(A)Compute singular values, falling back to a more robust algorithm if the default one fails to converge
Arguments
A: 2d array of floats; the matrix whose singular values are wanted
Value
A vector of singular values. Like _safe_svd, retries with QR iteration on a LAPACKException and rethrows anything else
BigRiverEssence._sign_consistency_opt! — Method
_sign_consistency_opt!(V)Fix the sign of each column of a loading matrix so the largest-magnitude entry is positive, in place
Arguments
V: 2d array of floats; the loading/direction matrix whose columns are sign-fixed in place
Value
The matrix V, with each column multiplied by ±1 so that its entry of largest absolute value is positive. SVD- and eigen-derived directions are only determined up to a sign, so this canonicalizes the choice to make results reproducible across runs and comparable across implementations. An all-zero column (whose largest entry has sign 0) is left untouched
BigRiverEssence._soft_threshold_L1! — Method
_soft_threshold_L1!(out, x, nx::Int, absx, ord, ranks)Soft-threshold a loading vector to keep only its largest-magnitude entries, writing the result into a preallocated buffer
Arguments
out: 1d array of floats; the destination buffer, overwritten in placex: 1d array of floats; the loading vector to thresholdnx::Int: The number of SMALLEST-magnitude entries to drop (= p − keepX). If nx ≤ 0 the vector is copied through unchangedabsx: 1d array of floats; preallocated scratch for the entry magnitudesord: 1d array of ints; preallocated scratch for the sort permutationranks: 1d array of ints; preallocated scratch for the magnitude ranks
Value
The buffer out, holding the thresholded vector: the keepX = p − nx largest entries survive (shrunk by λ = the largest dropped magnitude), the rest are zeroed. Implements the L1 penalty Pλ(u) = sign(u)(|u| − λ)₊ of Lê Cao et al. (2011), reparameterized as a keep-count rather than a λ (mixOmics `softthresholding_L1`). The rank computation handles magnitude ties so that tied entries are dropped or kept together
BigRiverEssence._softcca! — Method
_softcca!(out, a, d)Soft-threshold a vector into a preallocated buffer
Arguments
out: 1d array of floats; the destination buffer, overwritten in placea: 1d array of floats; the vector to thresholdd: Float; the nonnegative threshold
Value
The buffer out, holding sign(aᵢ)·max(|aᵢ| − d, 0). The elementwise L1-penalized update of Witten, Tibshirani & Hastie (2009)
BigRiverEssence._sparse_cca_single_opt! — Method
_sparse_cca_single_opt!(u, v, x, z, v0, penaltyx, penaltyz, niter,
vold, zv_buf, xu_buf, argu, argv, su, sv)Compute one rank-1 sparse canonical vector pair by alternating, soft-thresholded power iteration
Arguments
u: 1d array of floats; the X canonical vector, written in placev: 1d array of floats; the Z canonical vector, written in placex: 2d array of floats; the (observations × features) X block for this componentz: 2d array of floats; the (observations × features) Z block for this componentv0: 1d array of floats; the initial v (from_fast_init_vor an SVD)penaltyx: Float; the X penalty in (0,1], scaled internally to the budget penaltyx·√(#X features)penaltyz: Float; the Z penalty in (0,1], scaled to penaltyz·√(#Z features)niter: Int; the maximum number of power-iteration stepsvold: 1d array of floats; scratch holding the previous v iteratezv_buf,xu_buf: 1d arrays of floats; scratch for z·v and x·u (sized for the deflated block height)argu,argv: 1d arrays of floats; scratch for the raw (pre-threshold) canonical vectorssu,sv: 1d arrays of floats; scratch for the soft-thresholded vectors
Value
Float; the weight d = uᵀ xᵀ z v = ⟨x u, z v⟩. On return u and v hold the unit-ℓ₂, L1-penalized canonical vectors. Each step alternates u ← normalize(S(xᵀz v, λᵤ)) and v ← normalize(S(zᵀx u, λᵥ)), with the thresholds chosen by _binary_search_opt to meet the penalty budgets — the penalized-CCA update of Witten, Tibshirani & Hastie (2009). The randn primer on vold only forces the first iteration to run and does not affect the converged fixed point
BigRiverEssence._spca_component! — Method
_spca_component!(v, X, c, u, Xv, Xtu, s, vold; tol = 1e-7, niter = 20)Compute one sparse principal component by soft-thresholded power iteration (deflation variant)
Arguments
v: 1d array of floats; the right factor, initialized by the caller and overwritten in place with the converged loadingX: 2d array of floats; the (deflated) data matrix for this componentc: Float; the L1 budget on v (in [1, √p])u: 1d array of floats; preallocated buffer for the left factor (scores direction)Xv: 1d array of floats; preallocated scratch of length nXtu: 1d array of floats; preallocated scratch of length ps: 1d array of floats; preallocated scratch for_finding_v!vold: 1d array of floats; preallocated scratch holding the previous v iteratetol: Float; the ℓ₁ convergence tolerance on v. Defaults to 1e-7niter::Int: The maximum number of power-iteration steps. Defaults to 20
Value
Float; the component weight d = uᵀ X v. On return v holds the unit-ℓ₂, L1-penalized loading and u the corresponding unit-ℓ₂ scores direction. Each step sets u ← normalize(X v) then v ← project(Xᵀ u) onto the unit ball and L1 budget via _finding_v!, the SPC update of Witten, Tibshirani & Hastie (2009)
BigRiverEssence._spca_component_orth! — Method
_spca_component_orth!(v, X, c, U_prev, u, uold, Xv, Xtu, s, vold, proj;
tol = 1e-6, niter = 20)Compute one sparse principal component whose scores are orthogonal to all previously extracted components
Arguments
v: 1d array of floats; the right factor, initialized by the caller and overwritten in place with the converged loadingX: 2d array of floats; the (uncentered-residual) data matrix — note the orthogonal variant decomposes the original Xc, not a deflated residualc: Float; the L1 budget on v (in [1, √p])U_prev: 2d array of floats; the n×(j-1) matrix of previously extracted scores directions that the new u must be orthogonal to (empty for the first component)u: 1d array of floats; preallocated buffer for the left factor, written in placeuold: 1d array of floats; preallocated scratch holding the previous u iterateXv: 1d array of floats; preallocated scratch of length nXtu: 1d array of floats; preallocated scratch of length ps: 1d array of floats; preallocated scratch for_finding_v!vold: 1d array of floats; preallocated scratch holding the previous v iterateproj: 1d array of floats; preallocated scratch for the orthogonal projection coefficientstol: Float; the ℓ₁ convergence tolerance on u and v. Defaults to 1e-6niter::Int: The maximum number of power-iteration steps. Defaults to 20
Value
Float; the component weight d = uᵀ X v. Differs from _spca_component! by projecting u onto the orthogonal complement of U_prev each iteration (u ← u − Uprev Uprevᵀ u before normalizing), which enforces orthogonal scores across components instead of relying on deflation — the orthogonal SPC variant of Witten, Tibshirani & Hastie (2009)
BigRiverEssence._sqdiff — Method
_sqdiff(a, b)Compute the squared ℓ₂ distance between two vectors
Arguments
a: 1d array of floatsb: 1d array of floats
Value
Float; Σ(aᵢ − bᵢ)². Used as the convergence criterion between successive loading iterates
BigRiverEssence._unmap — Method
_unmap(y::AbstractVector; levels = nothing)One-hot encode a vector of class labels into a dummy indicator matrix
Arguments
y::AbstractVector: The class labels, one per observationlevels: An optional ordering of the classes; when given, it fixes the column order of the output and must list each class exactly once. Defaults to nothing (classes sorted bysort(unique(y)))
Value
A tuple (Yd, classes) where Yd is the n×K one-hot matrix (Yd[i,k] = 1 when observation i is in class k, else 0) and classes is the class labels in column order. This is mixOmics' unmap, the dummy encoding that turns classification into a PLS regression onto the indicator matrix
BigRiverEssence._validate_nmf_data — Method
_validate_nmf_data(X::Matrix{Float64})Validate a data matrix for nonnegative matrix factorization
Arguments
X::Matrix{Float64}: 2d array of floats; observations in rows and features in columns
Value
The input matrix X. Throws an ArgumentError if it is empty, contains a non-finite value, or contains a negative value