Skip to content

Commit 463dc7d

Browse files
committed
ENH: fa pca evaluation
1 parent 7b5b83e commit 463dc7d

File tree

2 files changed

+19
-724
lines changed

2 files changed

+19
-724
lines changed

R/multiscaleSVDxpts.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11731,7 +11731,7 @@ nsa_flow_pca_fa <- function(
1173111731
alpha = 0.0001,
1173211732
max_iter = 100,
1173311733
proximal_type = c("basic", "nsa_flow"),
11734-
w_pca = 1.0, nsa_w = 0.5,
11734+
w_pca = 1.0,
1173511735
apply_soft_thresh_in_nns = FALSE,
1173611736
tol = 1e-6, retraction = NULL,
1173711737
grad_tol = 1e-4, nsa_flow_fn = NULL, verbose = FALSE,
@@ -11749,15 +11749,14 @@ nsa_flow_pca_fa <- function(
1174911749
if (lambda < 0) stop("lambda must be non-negative")
1175011750
if (alpha <= 0) stop("alpha must be positive")
1175111751
if (w_pca <= 0) stop("w_pca must be positive")
11752-
if (nsa_w < 0 || nsa_w > 1) stop("nsa_w must be in [0,1]")
1175311752
if (is.null(nsa_flow_fn) && proximal_type == "nsa_flow") {
1175411753
# lazy require: user must have provided nsa_flow_fn (e.g., nsa_flow_autograd)
1175511754
stop("nsa_flow_fn must be provided when proximal_type == 'nsa_flow'")
1175611755
}
1175711756
# If NSA proximal used, we follow previous convention: disable L1 lambda to avoid double regularization
11758-
if (nsa_w > 0 && proximal_type == "nsa_flow") {
11757+
if (proximal_type == "nsa_flow") {
1175911758
lambda <- 0.0
11760-
if (verbose) message("nsa_w > 0 and proximal_type == 'nsa_flow' -> lambda set to 0")
11759+
if (verbose) message("proximal_type == 'nsa_flow' -> lambda set to 0")
1176111760
}
1176211761
# --- center X (no scaling) and precompute XtX / R ---------------------------
1176311762
Xc <- scale(X, center = TRUE, scale = FALSE)
@@ -11896,7 +11895,7 @@ nsa_flow_pca_fa <- function(
1189611895
} else {
1189711896
# nsa_flow proximal: we call the provided function with Y_ret as Y0
1189811897
# allow forwarding extra args via nsa_flow_args list
11899-
prox_call_args <- c(list(Y0 = Y_ret, w = nsa_w), nsa_flow_args)
11898+
prox_call_args <- c(list(Y0 = Y_ret ), nsa_flow_args)
1190011899
prox_res <- tryCatch(do.call(nsa_flow_fn, prox_call_args), error = function(e) {
1190111900
stop("nsa_flow_fn failed: ", conditionMessage(e))
1190211901
})
@@ -11915,7 +11914,7 @@ nsa_flow_pca_fa <- function(
1191511914
if (rotate == "varimax") {
1191611915
rot_res <- tryCatch(stats::varimax(Y_new, normalize = FALSE), error = function(e) NULL)
1191711916
} else if (rotate == "promax") {
11918-
rot_res <- tryCatch(psych::promax(Y_new, normalize = FALSE), error = function(e) NULL)
11917+
rot_res <- tryCatch(stats::promax(Y_new, normalize = FALSE), error = function(e) NULL)
1191911918
} else if (rotate == "oblimin") {
1192011919
rot_res <- tryCatch(psych::oblimin(Y_new, normalize = FALSE), error = function(e) NULL)
1192111920
} else rot_res <- NULL
@@ -11944,6 +11943,9 @@ nsa_flow_pca_fa <- function(
1194411943
best_energy <- energy
1194511944
best_Y <- Y_new
1194611945
improved <- TRUE
11946+
} else { # reset
11947+
# energy = best_energy
11948+
# Y_new = best_Y
1194711949
}
1194811950
if (improved) {
1194911951
no_improve_count <- 0
@@ -12004,7 +12006,7 @@ nsa_flow_pca_fa <- function(
1200412006
if (rotate != "none" && requireNamespace("psych", quietly = TRUE)) {
1200512007
rot_fun <- switch(rotate,
1200612008
varimax = stats::varimax,
12007-
promax = psych::promax,
12009+
promax = stats::promax,
1200812010
oblimin = psych::oblimin,
1200912011
NULL)
1201012012
if (!is.null(rot_fun)) {

0 commit comments

Comments
 (0)