From fc5a89b4d9b0b92af7fb339c217dba7737b236d9 Mon Sep 17 00:00:00 2001 From: Anirban166 Date: Mon, 15 Jun 2020 15:01:09 +0530 Subject: [PATCH 1/3] Add Complexity Classifier and Complexity Classification functions Check issue 11 for more details. --- R/asymptoticComplexityClass.R | 13 ++++++++++ R/asymptoticComplexityClassifier.R | 38 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 R/asymptoticComplexityClass.R create mode 100644 R/asymptoticComplexityClassifier.R diff --git a/R/asymptoticComplexityClass.R b/R/asymptoticComplexityClass.R new file mode 100644 index 0000000..1e374cf --- /dev/null +++ b/R/asymptoticComplexityClass.R @@ -0,0 +1,13 @@ +#' Function to classify the complexity trend between two selected parameters from the data frame provided as input here +#' +#' @title Asymptotic Complexity Classification function +#' +#' @param model.df A data frame. +#' +#' @return A string specifying the resultant complexity class. (Eg: 'Linear', 'Log-linear', 'Quadratic') +#' +#' @export + + + + diff --git a/R/asymptoticComplexityClassifier.R b/R/asymptoticComplexityClassifier.R new file mode 100644 index 0000000..3108e3f --- /dev/null +++ b/R/asymptoticComplexityClassifier.R @@ -0,0 +1,38 @@ +#' Function to classify the complexity trend between two selected parameters from the data frame provided as input here +#' +#' @title Asymptotic Complexity Classifier function +#' +#' @param model.df A data frame returned by asymptoticComplexityClass. +#' +#' @return A string specifying the resultant complexity class. (Eg: 'Linear', 'Log-linear', 'Quadratic') +#' +#' @export +#' @importFrom boot cv.glm +#' @importFrom stats fitted + +asymptoticComplexityClassifier = function(df) +{ + if(class(df) == "data.frame" & 'output' %in% colnames(df) & 'size' %in% colnames(df)) + { + constant <- glm(output~1, data = df); df['constant'] = fitted(constant) + linear <- glm(output~size, data = df); df['linear'] = fitted(linear) + squareroot <- glm(output~sqrt(size), data = df); df['squareroot'] = fitted(squareroot) + log <- glm(output~log(size), data = df); df['log'] = fitted(log) + log.linear <- glm(output~size*log(size), data = df); df['log-linear'] = fitted(log.linear) + quadratic <- glm(output~I(size^2), data = df); df['quadratic'] = fitted(quadratic) + cubic <- glm(output~I(size^3), data = df); df['cubic'] = fitted(cubic) + + model.list <- list('constant' = constant, + 'linear' = linear, + 'squareroot' = squareroot, + 'log' = log, + 'log-linear' = log.linear, + 'quadratic' = quadratic, + 'cubic' = cubic) + + cross.validated.errors <- lapply(model.list, function(x) cv.glm(df, x)$delta[2]) + best.model <- names(which.min(cross.validated.errors)) + print(best.model) + } + else stop("Input parameter must be a data frame containing the two specified columns passed as parameters") +} From 4c8e08f4dad470d88fdfc72933bd54832f1dc71a Mon Sep 17 00:00:00 2001 From: Anirban166 Date: Mon, 15 Jun 2020 15:07:16 +0530 Subject: [PATCH 2/3] Draft asymptoticComplexityClass body --- R/asymptoticComplexityClass.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/asymptoticComplexityClass.R b/R/asymptoticComplexityClass.R index 1e374cf..fa4412c 100644 --- a/R/asymptoticComplexityClass.R +++ b/R/asymptoticComplexityClass.R @@ -8,6 +8,9 @@ #' #' @export - - +asymptoticComplexityClass = function(df, col1, col2) +{ + d <- data.frame('output' = df[[col1]], 'size' = df[[col2]]) + asymptoticComplexityClassifier(d) +} From cbbf46e8af1a3291c2593d8665452e193f669d87 Mon Sep 17 00:00:00 2001 From: Anirban166 Date: Mon, 15 Jun 2020 15:20:53 +0530 Subject: [PATCH 3/3] Add proper documentation and update the function body (ready for testing) --- R/asymptoticComplexityClass.R | 16 ++++++++++++---- R/asymptoticComplexityClassifier.R | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/R/asymptoticComplexityClass.R b/R/asymptoticComplexityClass.R index fa4412c..68fcbe8 100644 --- a/R/asymptoticComplexityClass.R +++ b/R/asymptoticComplexityClass.R @@ -2,15 +2,23 @@ #' #' @title Asymptotic Complexity Classification function #' -#' @param model.df A data frame. +#' @param model.df A data frame composing for two columns at the least, where one should be the contain the output-parameter sizes and one should contain the data sizes. +#' +#' @param output.size A string specifying the column name in the passed data frame to be used as the output size. +#' +#' @param data.size A string specifying the column name in the passed data frame to be used as the data size. #' #' @return A string specifying the resultant complexity class. (Eg: 'Linear', 'Log-linear', 'Quadratic') #' #' @export -asymptoticComplexityClass = function(df, col1, col2) +asymptoticComplexityClass = function(df, output.size, data.size) { - d <- data.frame('output' = df[[col1]], 'size' = df[[col2]]) - asymptoticComplexityClassifier(d) + if(class(df) == "data.frame" & output.size %in% colnames(df) & data.size %in% colnames(df)) + { + d <- data.frame('output' = df[[output.size]], 'size' = df[[data.size]]) + asymptoticComplexityClassifier(d) + } + else stop("Input parameter must be a data frame containing the two specified columns passed as parameters") } diff --git a/R/asymptoticComplexityClassifier.R b/R/asymptoticComplexityClassifier.R index 3108e3f..39d1d2e 100644 --- a/R/asymptoticComplexityClassifier.R +++ b/R/asymptoticComplexityClassifier.R @@ -1,4 +1,4 @@ -#' Function to classify the complexity trend between two selected parameters from the data frame provided as input here +#' Function to classify the complexity trend between the two parameters as provided by asymptoticComplexityClass #' #' @title Asymptotic Complexity Classifier function #'