Skip to content

Commit

Permalink
Merge pull request #33 from mi-erasmusmc/tests_corrections
Browse files Browse the repository at this point in the history
Tests corrections
  • Loading branch information
cebarboza authored Oct 17, 2024
2 parents aa5b672 + 054aa06 commit aef8d2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
40 changes: 10 additions & 30 deletions R/MainFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ trainExplore <- function(train_data = NULL,
Subsumption = FALSE,
BranchBound = TRUE,
Parallel = FALSE,
PrintCutoffSets = TRUE,
PrintCutoffSets = FALSE,
Sorted = "none",
OutputMethod = "EVERY",
OutputMethod = "BEST",
BinaryReduction = FALSE,
resultType = c("model", "candidate_models", "cutoff_sets")) {
resultType = c("model")) {

if (!dir.exists(output_path)) {
dir.create(output_path, recursive = TRUE)
Expand Down Expand Up @@ -205,30 +205,10 @@ trainExplore <- function(train_data = NULL,

# Load results file
settings <- paste(readLines(settings_path), collapse="\n")
results <- paste(readLines(getSetting(settings, "OutputFile", type = "value")), collapse="\n")
outputFile <- getSetting(settings, "OutputFile", type = "value")

cand_models_lines <- strsplit(results, "\n")
candidate_models <- grep("Candidate model:", unlist(cand_models_lines), value = TRUE)
# length(candidate_models)
cutoff_sets<- grep("Total Count Cutoff Sets:", unlist(cand_models_lines), value = TRUE)
# result <- list("candidate_models" = candidate_models,
# "cutoff_sets" = cutoff_sets)

# Load model
rule_string <- stringr::str_extract_all(results, "Best candidate:.*?\u000A")
rule_string <- unlist(rule_string)[[length(rule_string)]] # Select the last rule as this is the final candidate

# Clean string
rule_string <- stringr::str_replace(rule_string, "Best candidate:", "")
rule_string <- stringr::str_replace_all(rule_string, " ", "")
rule_string <- stringr::str_replace_all(rule_string, "\\n", "")


results <- list("model" = rule_string,
"candidate_models" = candidate_models,
"cutoff_sets" = cutoff_sets)

result <- results[resultType]
results <- resultsExplore(outputFile=outputFile)
result <- results[[resultType]]

return(result)
}
Expand Down Expand Up @@ -392,22 +372,22 @@ resultsExplore <- function(outputFile) {

for (line in results_lines) {
# line <- "Candidate model: '198124209' = \"0\""

if (grepl(":", line)) {
if (grepl("Candidate model", line)) {
split_line <- strsplit(line, ":")[[1]]
key <- trimws(split_line[1]) %>% tolower() %>% gsub(" ", "_", .)
value <- trimws(split_line[2])
value <- stringr::str_replace_all(split_line[2], " ", "") # remove spaces
result_data[[key]] <- c(result_data[[key]], value)
} else {
split_line <- strsplit(line, ":")[[1]]
key <- trimws(split_line[1]) %>% tolower() %>% gsub(" ", "_", .)
value <- trimws(split_line[2])
value <- stringr::str_replace_all(split_line[2], " ", "") # remove spaces
result_data[[key]] <- value
}
}
}



result <- list("model" = result_data$best_candidate,
"candidateModels" = result_data$candidate_model,
"countCombinations" = result_data$total_count_combinations,
Expand Down
2 changes: 1 addition & 1 deletion src/C++/Explore/set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ string SET::PrintPerformance() {
return Result.str();
}

struct AndJibu : public std ::unary_function<int, void>
struct AndJibu : public std::__unary_function<int, void>
{
const boost::dynamic_bitset<> Source;
boost::dynamic_bitset<> Dest;
Expand Down

0 comments on commit aef8d2d

Please sign in to comment.