Skip to content

Commit

Permalink
Merge pull request mi-erasmusmc#2 from mi-erasmusmc/development
Browse files Browse the repository at this point in the history
First version of R package for EXPLORE including parallelisation
  • Loading branch information
AniekMarkus authored Feb 2, 2023
2 parents b9520b6 + 876188d commit 21f8a50
Show file tree
Hide file tree
Showing 25 changed files with 3,275 additions and 2,207 deletions.
28 changes: 27 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
cmake_minimum_required(VERSION 3.17)
project(Explore)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -g -O3")

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v -stdlib=libc++")

# MAC
set(Boost_INCLUDE_DIR /Users/aniekmarkus/Documents/Documents/Code/C++/boost_1_74_0)
set(Boost_LIBRARY_DIR /Users/aniekmarkus/Documents/Documents/Code/C++/boost_1_74_0/libs)

# LINUX
# set(Boost_INCLUDE_DIR /data/home/amarkus/Documents/boost_1_74_0)
# set(Boost_LIBRARY_DIR /data/home/amarkus/Documents/boost_1_74_0/boost_1_74_0/libs)

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

Expand All @@ -17,6 +24,21 @@ include_directories(CMExplore/Debug)
include_directories(Explore)
include_directories(IOExplore)

# MAC
include_directories(include /usr/local/include/)
link_directories(/usr/local/lib)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ltbb -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ltbb --coverage")



# LINUX
# set(CMAKE_PREFIX_PATH "/opt/intel/oneapi/tbb/latest/lib/intel64/gcc4.8")
# find_library(TBB_LIB tbb)
# find_path(TBB_PATH
# HINTS /opt/intel/oneapi/tbb/latest/include
# NAMES tbb/parallel_for.h)

set(SOURCE_FILES
Clion/main.cpp
src/C++/CMExplore/cmdline.h
Expand Down Expand Up @@ -81,5 +103,9 @@ set(SOURCE_FILES

add_executable(Explore ${SOURCE_FILES})

# LINUX
target_link_libraries(Explore PRIVATE "${TBB_LIB}")
target_include_directories(Explore PRIVATE "${TBB_PATH}")

# add_library(ExploreLib SHARED ${SOURCE_FILES})
# add_library(ExploreLib SHARED ${SOURCE_FILES})
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Description: This package includes the implementation of EXPLORE in C++ and conn
License: GPL (>= 2)
Depends:
R (>= 3.6.1)
Imports: Rcpp (>= 1.0.5)
Imports: Rcpp (>= 1.0.5), RcppParallel
Encoding: UTF-8
LinkingTo: Rcpp, BH (>= 1.51.0)
LinkingTo: Rcpp, BH (>= 1.51.0), RcppParallel
RoxygenNote: 7.1.1
Suggests:
testthat (>= 3.0.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export(runExplore)
export(saveData)
export(trainExplore)
import(Rcpp)
import(RcppParallel)
useDynLib(Explore)
2 changes: 2 additions & 0 deletions R/HelperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ saveData <- function(output_path, train_data, file_name) {
farff::writeARFF(train_data, paste0(output_path, file_name, ".arff"))

# Create cutoff file based on column names
# TODO: add input to exclude class?
# FOR PLP: cutoff <- paste(colnames(train_data)[2:ncol(train_data)], collapse = ",")
cutoff <- paste(colnames(train_data)[1:(ncol(train_data)-1)], collapse = ",")
write.table(cutoff,
file=paste0(output_path, file_name,".cutoff"),
Expand Down
25 changes: 18 additions & 7 deletions R/MainFunctions.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: add descriptions for package manual

#' trainExplore
#'
Expand Down Expand Up @@ -35,6 +36,9 @@ trainExplore <- function(output_path, train_data = NULL, settings_path = NULL, f
settings <- paste0(paste(readLines(settings_path), collapse="\n"),"\n")
}

# TODO: check train_data and correct if necessary?
# drop nearly constant or extremely sparse values

# Save train_data if entered
if (!is.null(train_data)) {
saveData(output_path, train_data, file_name)
Expand Down Expand Up @@ -74,10 +78,10 @@ trainExplore <- function(output_path, train_data = NULL, settings_path = NULL, f
#'
#' @return
settingsExplore <- function(settings,
output_path,
output_path, # C++ cannot handle spaces in file path well, avoid those
file_name,
train_data = NULL,
OutputFile = NULL,
OutputFile = NULL,
StartRulelength = NULL,
EndRulelength = NULL,
OperatorMethod = NULL,
Expand All @@ -91,7 +95,8 @@ settingsExplore <- function(settings,
PrintSettings = NULL,
PrintPerformance = NULL,
Subsumption = NULL,
BranchBound = NULL) {
BranchBound = NULL,
Parallel = NULL) {

# Insert location training data and cutoff file if train_data is entered
if (!is.null(train_data)) {
Expand All @@ -106,16 +111,17 @@ settingsExplore <- function(settings,
settings <- changeSetting(settings, parameter = "OutputFile", input = OutputFile, default_setting = paste0(output_path, file_name, ".result"))
settings <- changeSetting(settings, parameter = "StartRulelength", input = StartRulelength, default_setting = 1)
settings <- changeSetting(settings, parameter = "EndRulelength", input = EndRulelength, default_setting = 3)
settings <- changeSetting(settings, parameter = "OperatorMethod", input = OperatorMethod, default_setting = "ROCAREA")
settings <- changeSetting(settings, parameter = "OperatorMethod", input = OperatorMethod, default_setting = "EXHAUSTIVE")
settings <- changeSetting(settings, parameter = "CutoffMethod", input = CutoffMethod, default_setting = "RVAC")
settings <- changeSetting(settings, parameter = "FeatureInclude", input = FeatureInclude, default_setting = "")
settings <- changeSetting(settings, parameter = "Maximize", input = Maximize, default_setting = "ACCURACY")
settings <- changeSetting(settings, parameter = "Accuracy", input = Accuracy, default_setting = "")
settings <- changeSetting(settings, parameter = "Accuracy", input = Accuracy, default_setting = "custom")
settings <- changeSetting(settings, parameter = "Specificity", input = Specificity, default_setting = "")
settings <- changeSetting(settings, parameter = "PrintSettings", input = PrintSettings, default_setting = "yes")
settings <- changeSetting(settings, parameter = "PrintPerformance", input = PrintPerformance, default_setting = "yes")
settings <- changeSetting(settings, parameter = "Subsumption", input = Subsumption, default_setting = "no")
settings <- changeSetting(settings, parameter = "BranchBound", input = BranchBound, default_setting = "no")
settings <- changeSetting(settings, parameter = "Subsumption", input = Subsumption, default_setting = "yes")
settings <- changeSetting(settings, parameter = "BranchBound", input = BranchBound, default_setting = "yes")
settings <- changeSetting(settings, parameter = "Parallel", input = Parallel, default_setting = "no")

# Save settings file
settings_path <- paste0(output_path, file_name,".project")
Expand All @@ -139,6 +145,11 @@ settingsExplore <- function(settings,
#' @examples
predictExplore <- function(model, test_data) {

# Return NULL if cannot make predictions
if (is.null(model) || model == "") {
return(NULL)
}

# Split string
all_terms <- stringr::str_split_fixed(model, "OR", n=Inf)

Expand Down
5 changes: 3 additions & 2 deletions inst/settings/template.project
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Accuracy=
Specificity=
[Output]
OutputMethod=BEST
PrintSettings=no
PrintSettings=yes
PrintPartitions=no
PrintFeatureOperators=no
PrintCutoffMethod=no
Expand All @@ -38,10 +38,11 @@ PrintCombinations=no
PrintFeatureSets=no
PrintCutoffSets=no
PrintCutOffsetsBestLength=no
PrintPerformance=no
PrintPerformance=yes
PrintSets=no
SavePartitions=no
[Run]
OptimizeRules=yes
Subsumption=yes
BranchBound=yes
Parallel=no
1 change: 1 addition & 0 deletions src/C++/Explore/candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "candidate.h"
#include "../common.h"
#include <tbb/concurrent_vector.h>

/**********************************************************************
Function: Size()
Expand Down
Loading

0 comments on commit 21f8a50

Please sign in to comment.