|
| 1 | +####################################### |
| 2 | +#### Main function for BIR #### |
| 3 | +####################################### |
| 4 | +rm(list = ls()) |
| 5 | +library(glmnet) # Lasso |
| 6 | +library(pbapply) |
| 7 | +library(GenSA) # simulated annealing |
| 8 | +#### File paths #### |
| 9 | +data.path <- "Datasets/" |
| 10 | +out.path <- "Results/" |
| 11 | +function.path <- "Functions/" |
| 12 | +source.files <- list.files(path = function.path, recursive = TRUE) |
| 13 | +invisible(sapply(source.files, function(x) source(file = paste0(function.path, x)))) |
| 14 | +Fe <- read.csv(paste0(data.path, "dataset.csv")) |
| 15 | +X <- read.csv(paste0(data.path, "embedding.csv"), header=F) |
| 16 | +lambda.vals <- seq(0.0001, 3.5, length = 10) |
| 17 | +# lambda.vals <- exp(seq(log(0.0001), log(3.5), length.out = 20)) |
| 18 | +#### Run BIR #### |
| 19 | +# Prepare fold ids |
| 20 | +seed <- 155000 |
| 21 | +set.seed(seed) |
| 22 | +eval.res.lambda <- c() |
| 23 | +lambda.vals.index = 0 |
| 24 | +best_lambda.norm = 0.06 |
| 25 | +# Compute BIR on the full dataset with the best lambda |
| 26 | +res <- RunBIR(X = scale(X, center=T, scale=F), |
| 27 | +Fe = scale(Fe, center=T, scale=T), |
| 28 | +lambda = best_lambda.norm) |
| 29 | +# Compute BIR on the full dataset with the best lambda |
| 30 | +res <- RunBIR(X = scale(X, center=T, scale=F), |
| 31 | +Fe = Fe, |
| 32 | +lambda = best_lambda.norm) |
| 33 | +View(Fe) |
| 34 | +# Compute BIR on the full dataset with the best lambda |
| 35 | +res <- RunBIR(X = scale(X, center=T, scale=F), |
| 36 | +Fe = scale(Fe, center=T, scale=F), |
| 37 | +lambda = best_lambda.norm) |
| 38 | +# Compute BIR on the full dataset with the best lambda |
| 39 | +res <- RunBIR(X = scale(X, center=T, scale=F), |
| 40 | +Fe = scale(Fe, center=T, scale=T), |
| 41 | +lambda = best_lambda.norm) |
| 42 | +Fe |
| 43 | +# Some elements of Fe can have a standard deviation (sd) equal to 0, which is an issue when scaling. |
| 44 | +# In ordre to solve the problem, the sd for these columns is set to 1. |
| 45 | +Fe.sd <- apply(Fe, 2, sd) # Check which columns have sd = 0 |
| 46 | +zero.sd <- which(Fe.sd == 0) |
| 47 | +if (length(wh.zero.sd) > 0){ |
| 48 | +Fe.sd[wh.zero.sd] <- 1 |
| 49 | +} |
| 50 | +if (length(zero.sd) > 0){ |
| 51 | +Fe.sd[zero.sd] <- 1 |
| 52 | +} |
| 53 | +# Compute BIR on the full dataset with the best lambda |
| 54 | +res <- RunBIR(X = scale(X, center=T, scale=F), |
| 55 | +Fe = scale(Fe, center=T, scale=Fe.sd), |
| 56 | +lambda = best_lambda.norm) |
| 57 | +res |
| 58 | +save(res, file = paste0(out.path, "result.RData")) |
| 59 | +save(res, file = paste0(out.path, "result_v2.RData"), version = 2) |
0 commit comments