R/loadAggrResults.R

Defines functions loadAggrResults getData

loadAggrResults = function(fs_results, agg_fs_results) {
  return(fs_results %>%
    dplyr::group_by(ids, classifier, dataset) %>%
    dplyr::summarise(feats = mean(numFeatures)) %>%
    dplyr::inner_join(agg_fs_results, by = c("ids", "dataset", "classifier")) %>%
    dplyr::mutate(acc = 1 - metric))
}

getData = function(path) {
  resultDfFilter = NULL
  resultDfAggFilter = NULL

  # get datasets
  datasets = list.dirs(path = path, full.names = F, recursive = F)

  for(dataset in datasets) {
    dataset_path = paste(path, dataset, sep = "/")

    # get classifier
    classifiers = list.dirs(path = dataset_path, full.names = F, recursive = F)

    for (classifier in classifiers) {
      # get iterations
      iterations = list.dirs(path = paste(dataset_path, classifier, sep = "/"), full.names = F, recursive = F)
      # print(iterations)

      for (iteration in iterations) {
        # build current path
        iteration_path = paste(dataset_path, classifier, iteration, sep = "/")

        aggr_file_path = list.files(iteration_path)
        filter_file = aggr_file_path[startsWith(aggr_file_path, "filter")]
        agg_file = aggr_file_path[startsWith(aggr_file_path, "agg_filter")]

        # check if done.txt exists
        if (length(filter_file) > 0 & length(agg_file) > 0) {
          # load result of iteration
          result_temp = readr::read_delim(
            paste(iteration_path, filter_file, sep = "/"),
            ";"
          )

          # load agg temp
          agg_result_temp = readr::read_delim(
            paste(iteration_path, agg_file, sep = "/"),
            ";"
          )

          # set classifier
          result_temp$classifier = classifier
          result_temp$dataset = dataset

          agg_result_temp$classifier = classifier
          agg_result_temp$dataset = dataset

          # append to results filter
          if (is.null(resultDfFilter)) {
            resultDfFilter = result_temp
          }
          else {
            resultDfFilter = rbind(resultDfFilter, result_temp)
          }

          # append to agg_results filter
          if (is.null(resultDfAggFilter)) {
            resultDfAggFilter = agg_result_temp
          }
          else {
            resultDfAggFilter = rbind(resultDfAggFilter, agg_result_temp)
          }
        }
      }
    }
  }

  return(list(
    fs_results = resultDfFilter,
    agg_fs_results = resultDfAggFilter
  ))
}
creil94/FeatureSelectionDashboard documentation built on Nov. 4, 2019, 9:17 a.m.