# Compairson of differend dimension reduction (dr) methods over all datasets # with default parametrs. # # Results are written to a CSV file with a dataset column and its simulation nr. # # Note: # All methods are called via interface functions defined in # 'simulation_interfaces.R'. In addition this file provides a few convenience # functions, namely: 'progress_logger' and 'subspace_dist'. # # Dependencies (list of packages loaded): # - MASS # - dr # - MAVE # - CVE source('simulation_interfaces.R') # depends on MASS, dr, MAVE and CVE # Number of simulations NR.SIM <- 100L DS <- 1L:7L # datasets run from 1 to 7. # Methods for comparison, see 'simulation_interfaces.R' for their definitions. methods <- c('CVE', 'wCVE', 'rCVE', # CVE variants 'meanOPG', 'rOPG', # OPG variants 'meanMAVE', 'rmave', # MAVE variants 'phdy', 'sir', 'save') # Methods from dr package # Build result data matrix (repeat each dataset simulation times). result <- matrix(NA, nrow = length(DS) * NR.SIM, ncol = length(methods) + 1) # +1 for dataset column. result[, 1L] <- rep(paste0("M", DS), NR.SIM) colnames(result) <- c("dataset", methods) # Create a progress logger for length many reports. logger <- progress_logger(length(DS) * NR.SIM * length(methods)) for (sim in seq_len(nrow(result))) { # Create new dataset. with(dataset(result[sim, 1L]), { X <<- X; Y <<- Y; B <<- B }) # And each reference method. for (method in methods) { # Report simulation progress to user. logger(method) # Try/Catch to avoid simulation stop on error, this should not # accure for CVE but may be the case for others like OPG. tryCatch({ # Call dimension reduction method. dr <- eval(call(method, X = X, Y = Y, k = ncol(B))) # Compute distance of estimated `B` to true `B`. result[sim, method] <- subspace_dist(B, coef(dr, ncol(B))) }, error = function(e) {}) # No-Operation error handler! } # explicit call to the garbage collector. gc() } path <- paste0(getwd(), format(Sys.time(), '/results/method_compair_%Y-%m-%dT%H%M%S')) # Write entire simulation results into a single file. write.csv(result, file = paste0(path, ".csv"), row.names = FALSE)