Creates a non-negative matrix factorization layer that decomposes its input into W * diag(d) * H with non-negativity constraints.
Usage
nmf_layer(
input,
k,
L1 = 0,
L2 = 0,
L21 = 0,
angular = 0,
upper_bound = 0,
mask = NULL,
zi = c("none", "row", "col"),
projective = FALSE,
symmetric = FALSE,
robust = FALSE,
W = NULL,
H = NULL,
name = NULL,
...
)Arguments
- input
An
fn_node(input, shared, condition, or another layer).- k
Factorization rank.
- L1
L1 penalty (shared by W and H unless overridden). Default 0.
- L2
L2 penalty. Default 0.
- L21
Group sparsity penalty. Default 0.
- angular
Orthogonality penalty. Default 0.
- upper_bound
Box constraint. Default 0.
- mask
Masking mode: NULL (none),
"zeros","NA", or a sparse mask matrix. Seenmffor details.- zi
Zero-inflation mode:
"none","row", or"col". Requiresloss = "gp"or"nb"infactor_config(). Default"none".- projective
Use projective NMF (W is reused as H). Default FALSE.
- symmetric
Use symmetric NMF (W == H). Default FALSE.
- robust
Robustness control:
FALSE(default, no robustness),TRUE(Huber delta=1.345),"mae"(near-MAE, delta=1e-4), or a positive numeric Huber delta. Seenmffor details.- W
Optional
W()config to override W-specific settings.- H
Optional
H()config to override H-specific settings.- name
Optional layer name (for results access).
- ...
Additional arguments forwarded to
nmfat fit time. Supports all advanced parameters: distribution tuning (dispersion,theta_init, etc.), IRLS control (irls_max_iter,irls_tol), solver tuning (cd_tol,cd_maxit), streaming (streaming,panel_cols), callbacks (on_iteration), and more. See?nmffor the complete list.
Details
When used with |>, the input node is the first argument:
x |> nmf_layer(k = 64).
Layer-level regularization parameters (L1, L2, etc.) apply to both
W and H unless overridden by W() or H().
Examples
data(aml)
inp <- factor_input(aml)
layer <- nmf_layer(inp, k = 5)
# With zero-inflation and distribution-specific tuning
layer_gp <- nmf_layer(inp, k = 5, zi = "row",
dispersion = "per_col", theta_init = 0.5)