Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests result explore #34

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 51 additions & 23 deletions R/MainFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' @param BranchBound True or False
#' @param Sorted One of list with strings, e.g. "none", "jaccard", ... Sort features based on correlation with outcome variable, NOTE: only when train_data is entered
#' @param Parallel True or False
#' @param resultType Select one of: "model", "candidateModels", "countCombinations", "countFeatureOperatorPairs", "countRulesWithoutConstraints", "countRulesWithConstraints"
#'
#' @return Model
#' @export
Expand Down Expand Up @@ -368,32 +369,59 @@ resultsExplore <- function(outputFile) {
results <- paste(readLines(outputFile), collapse="\n")
results_lines <- strsplit(results, "\n") %>% unlist()

result_data <- list()
model <- grep("Best candidate:", unlist(results_lines), value = TRUE)
model <- gsub("Best candidate:", "", model[1])

for (line in results_lines) {
# line <- "Candidate model: '198124209' = \"0\""
candidateModels <- strsplit(results_lines, "\n")
candidateModels <- grep("Candidate model:", candidateModels, value = TRUE)

countCombinations <- grep("Total Count Combinations:", results_lines, value = TRUE)
countCombinations <- gsub("Total Count Combinations:", "", countCombinations[1]) %>% as.numeric()

countFeatureOperatorPairs <- grep("Total Count Cutoff Sets:", results_lines, value = TRUE)
countFeatureOperatorPairs <- gsub("Total Count Cutoff Sets:", "", countFeatureOperatorPairs) %>% as.numeric()

if (grepl(":", line)) {
if (grepl("Candidate model", line)) {
split_line <- strsplit(line, ":")[[1]]
key <- trimws(split_line[1]) %>% tolower() %>% gsub(" ", "_", .)
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 <- stringr::str_replace_all(split_line[2], " ", "") # remove spaces
result_data[[key]] <- value
}
}
}
countRulesWithoutConstraints <- grep("Total Count Feature Operator Pairs:", results_lines, value = TRUE)
countRulesWithoutConstraints <- gsub("Total Count Feature Operator Pairs:", "", countRulesWithoutConstraints) %>% as.numeric()

countRulesWithConstraints <- grep("Total Count Candidates \\(incl constraints\\):", results_lines, value = TRUE)
countRulesWithConstraints <- trimws(gsub("Total Count Candidates \\(incl constraints\\):", "", countRulesWithConstraints)) %>% as.numeric()


# result_data <- list()
#
# 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 <- 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 <- 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,
"countFeatureOperatorPairs" = result_data$total_count_feature_operator_pairs,
"countRulesWithoutConstraints" = result_data$total_count_cutoff_sets,
"countRulesWithConstraints" = result_data$`total_count_candidates_(incl_constraints)`)
# result <- list("model" = result_data$best_candidate,
# "candidateModels" = candidate_models,
# "countCombinations" = result_data$total_count_combinations,
# "countFeatureOperatorPairs" = result_data$total_count_feature_operator_pairs,
# "countRulesWithoutConstraints" = countRulesWithoutConstraints,
# "countRulesWithConstraints" = result_data$`total_count_candidates_(incl_constraints)`)


result <- list("model" = model,
"candidateModels" = candidateModels,
"countCombinations" = countCombinations,
"countFeatureOperatorPairs" = countFeatureOperatorPairs,
"countRulesWithoutConstraints" = countRulesWithoutConstraints,
"countRulesWithConstraints" = countRulesWithConstraints)

return(result)
}
Expand Down
7 changes: 4 additions & 3 deletions R/testExplore.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ testExplore <- function(dataset = "iris",
# dataset = "continuous_4"
# dataset = "categorical_4"
# dataset = "mix_4"
# StartRulelength = 2
# EndRulelength = 3
# StartRulelength = 1
# EndRulelength = 1
# BinaryReduction = FALSE
# BinaryReduction = TRUE

Expand Down Expand Up @@ -48,7 +48,8 @@ testExplore <- function(dataset = "iris",
PrintCutoffSets = TRUE,
Sorted = "none",
OutputMethod = "BEST", #"EVERY",
BinaryReduction = BinaryReduction)
BinaryReduction = BinaryReduction,
resultType = c("candidateModels"))

unlink(output_path, recursive = TRUE)
return(result)
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
Loading