# \donttest{
# Assume param_fun() is defined elsewhere and returns:
# list(ridge = c(0.01, 0.1, 1), lambda = exp(seq(log(0.001), log(1), length = 50)))
# Simulate small data:
set.seed(123)
n <- 100; p <- 10
X <- matrix(rnorm(n * p), nrow = n)
true_beta <- c(rep(1.5, 3), rep(0, p - 3))
lin <- X %*% true_beta
probs <- 1 / (1 + exp(-lin))
Y <- rbinom(n, 1, probs)
# Create fold assignments for labeled observations:
labeled <- sample(c(TRUE, FALSE), n, replace = TRUE, prob = c(0.8, 0.2))
foldid_labelled <- rep(NA_integer_, n)
foldid_labelled[labeled] <- sample(1:5, sum(labeled), replace = TRUE)
sub_set <- labeled
labeled_indices <- which(labeled)
# For simplicity, assign foldid to all observations (labeled & unlabeled)
foldid <- sample(1:5, n, replace = TRUE)
# Define a simple log-loss function:
log_loss_fn <- function(true, pred) {
eps <- 1e-15
pred_clipped <- pmin(pmax(pred, eps), 1 - eps)
-mean(true * log(pred_clipped) + (1 - true) * log(1 - pred_clipped))
}
# Call SMMAL_ada_lasso with all required args:
results <- SMMAL_ada_lasso(
X = X,
Y = Y,
X_full = X, # Here full data same as X for example
foldid = foldid,
foldid_labelled = foldid_labelled,
sub_set = sub_set,
labeled_indices = labeled_indices,
nfold = 5,
log_loss = log_loss_fn
)
# 'results' is a list (one element per ridge value), each a numeric vector of CV predictions.
# }
Run the code above in your browser using DataLab