Skip to content
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rtemis
Version: 0.99.990
Version: 0.99.1000
Title: Advanced Machine Learning and Visualization
Date: 2025-10-06
Date: 2025-10-18
Authors@R: person(given = "E.D.", family = "Gennatas", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0001-9280-3609"))
Description: Advanced Machine Learning and Visualization for all.
License: GPL (>= 3)
Expand Down
8 changes: 4 additions & 4 deletions R/00_S7_init.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ describe <- new_generic("describe", "x")
#' @export
present <- new_generic("present", "x")

# Get parameters that need tuning.
get_params_need_tuning <- new_generic("get_params_need_tuning", "x")
# Get parameters.
get_params <- new_generic("get_params", c("x", "param_names"))
# Get hyperparameters that need tuning.
get_hyperparams_need_tuning <- new_generic("get_hyperparams_need_tuning", "x")
# Get hyperparameters.
get_hyperparams <- new_generic("get_hyperparams", c("x", "param_names"))
# Extract rules from a model.
extract_rules <- new_generic("extract_rules", "x")

Expand Down
20 changes: 10 additions & 10 deletions R/01_S7_Hyperparameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ method(repr, Hyperparameters) <- function(
)
)
} else if (x@tuned == TUNED_STATUS_UNTUNED) {
need_tuning <- names(get_params_need_tuning(x))
need_tuning <- names(get_hyperparams_need_tuning(x))
out <- paste0(
out,
highlight2(
Expand Down Expand Up @@ -304,21 +304,21 @@ method(needs_tuning, Hyperparameters) <- function(x) {
x@tuned == 0
} # /needs_tuning.Hyperparameters

# get_params_need_tuning ----
# get_hyperparams_need_tuning ----
#' Get hyperparameters that need tuning in an algorithm-specific way.
#'
#' @keywords internal
#' @noRd
method(get_params_need_tuning, Hyperparameters) <- function(x) {
method(get_hyperparams_need_tuning, Hyperparameters) <- function(x) {
# -> list
# Get tunable hyperparameters with more than one value
x@hyperparameters[x@tunable_hyperparameters[
sapply(x@hyperparameters[x@tunable_hyperparameters], length) > 1
]]
} # /get_params_need_tuning.Hyperparameters
} # /get_hyperparams_need_tuning.Hyperparameters

# get_params.(Hyperparameters, character) ----
method(get_params, list(Hyperparameters, class_character)) <- function(
# get_hyperparams.(Hyperparameters, character) ----
method(get_hyperparams, list(Hyperparameters, class_character)) <- function(
x,
param_names
) {
Expand Down Expand Up @@ -676,7 +676,7 @@ stopifnot(all(
c(GLMNET_tunable, GLMNET_fixed) %in% names(formals(setup_GLMNET))
))

method(get_params_need_tuning, GLMNETHyperparameters) <- function(x) {
method(get_hyperparams_need_tuning, GLMNETHyperparameters) <- function(x) {
# Get tunable hyperparameters with more than one value
out <- x@hyperparameters[x@tunable_hyperparameters[
sapply(x@hyperparameters[x@tunable_hyperparameters], length) > 1
Expand All @@ -685,7 +685,7 @@ method(get_params_need_tuning, GLMNETHyperparameters) <- function(x) {
out <- c(out, list(lambda = NULL))
}
out
} # /get_params_need_tuning.GLMNETHyperparameters
} # /get_hyperparams_need_tuning.GLMNETHyperparameters

# LightCARTHyperparameters ----
LightCART_tunable <- c(
Expand Down Expand Up @@ -1189,7 +1189,7 @@ stopifnot(all(
c(LightGBM_tunable, LightGBM_fixed) %in% names(formals(setup_LightGBM))
))

method(get_params_need_tuning, LightGBMHyperparameters) <- function(x) {
method(get_hyperparams_need_tuning, LightGBMHyperparameters) <- function(x) {
# Get tunable hyperparameters with more than one value
out <- x@hyperparameters[x@tunable_hyperparameters[
sapply(x@hyperparameters[x@tunable_hyperparameters], length) > 1
Expand All @@ -1198,7 +1198,7 @@ method(get_params_need_tuning, LightGBMHyperparameters) <- function(x) {
out <- c(out, list(nrounds = NULL))
}
out
} # /get_params_need_tuning.LightGBMHyperparameters
} # /get_hyperparams_need_tuning.LightGBMHyperparameters


# LightRuleFitHyperparameters ----
Expand Down
54 changes: 27 additions & 27 deletions R/03_S7_Preprocessor.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# https://github.com/RConsortium/S7/
# https://rconsortium.github.io/S7

# PreprocessorParameters ----
#' @title PreprocessorParameters
# PreprocessorConfig ----
#' @title PreprocessorConfig
#'
#' @description
#' PreprocessorParameters class.
#' PreprocessorConfig class.
#'
#' @author EDG
#' @noRd
PreprocessorParameters <- new_class(
name = "PreprocessorParameters",
PreprocessorConfig <- new_class(
name = "PreprocessorConfig",
properties = list(
complete_cases = class_logical,
remove_features_thres = class_numeric | NULL,
Expand Down Expand Up @@ -57,58 +57,58 @@ PreprocessorParameters <- new_class(
add_holidays = class_logical,
exclude = class_character | NULL
)
) # /PreprocessorParameters
) # /PreprocessorConfig

# Names PreprocessorParameters ----
method(names, PreprocessorParameters) <- function(x) {
# Names PreprocessorConfig ----
method(names, PreprocessorConfig) <- function(x) {
names(props(x))
}

# Make props `$`-accessible ----
method(`$`, PreprocessorParameters) <- function(x, name) {
method(`$`, PreprocessorConfig) <- function(x, name) {
props(x)[[name]]
}

# DollarSign tab-complete property names ----
method(`.DollarNames`, PreprocessorParameters) <- function(x, pattern = "") {
method(`.DollarNames`, PreprocessorConfig) <- function(x, pattern = "") {
all_names <- names(props(x))
grep(pattern, all_names, value = TRUE)
}

# Make proprs `[[`-accessible ----
method(`[[`, PreprocessorParameters) <- function(x, name) {
method(`[[`, PreprocessorConfig) <- function(x, name) {
props(x)[[name]]
}

# Show PreprocessorParameters ----
method(repr, PreprocessorParameters) <- function(
# Show PreprocessorConfig ----
method(repr, PreprocessorConfig) <- function(
x,
limit = -1L,
pad = 0L,
output_type = NULL
) {
output_type <- get_output_type(output_type)
paste0(
repr_S7name("PreprocessorParameters", pad = pad, output_type = output_type),
repr_S7name("PreprocessorConfig", pad = pad, output_type = output_type),
show_ls(props(x), pad = pad, limit = limit, output_type = output_type)
)
} # /rtemis::show.PreprocessorParameters
} # /rtemis::show.PreprocessorConfig


# Print PreprocessorParameters ----
method(print, PreprocessorParameters) <- function(
# Print PreprocessorConfig ----
method(print, PreprocessorConfig) <- function(
x,
limit = -1L,
output_type = NULL,
...
) {
cat(repr(x, limit = limit, output_type = output_type))
invisible(x)
} # /rtemis::print.PreprocessorParameters
} # /rtemis::print.PreprocessorConfig


# setup_Preprocessor() ----
#' Setup `PreprocessorParameters`
#' Setup `PreprocessorConfig`
#'
#' @param complete_cases Logical: If TRUE, only retain complete cases (no missing data).
#' @param remove_cases_thres Float (0, 1): Remove cases with >= to this fraction
Expand Down Expand Up @@ -187,7 +187,7 @@ method(print, PreprocessorParameters) <- function(
#' @param add_holidays Logical: If TRUE, extract holidays from date columns.
#' @param exclude Integer, vector: Exclude these columns from preprocessing.
#'
#' @return `PreprocessorParameters` object.
#' @return `PreprocessorConfig` object.
#'
#' @author EDG
#' @export
Expand Down Expand Up @@ -244,8 +244,8 @@ setup_Preprocessor <- function(
) {
# Match args
impute_type <- match.arg(impute_type)
# Checks performed in the `PreprocessorParameters` constructor
PreprocessorParameters(
# Checks performed in the `PreprocessorConfig` constructor
PreprocessorConfig(
complete_cases = complete_cases,
remove_features_thres = remove_features_thres,
remove_cases_thres = remove_cases_thres,
Expand Down Expand Up @@ -298,11 +298,11 @@ data_dependent_props <- c(
#' @title Preprocessor
#'
#' @description
#' Class to hold output of preprocessing values after applying `PreprocessorParameters` to
#' Class to hold output of preprocessing values after applying `PreprocessorConfig` to
#' training dataset, so that the same preprocessing can be applied to validation and test
#' datasets.
#'
#' @field parameters `PreprocessorParameters` object.
#' @field config `PreprocessorConfig` object.
#' @field preprocessed Data frame or list: Preprocessed data. If a single data.frame is passed to
#' `preprocess`, this will be a data.frame. If additional data sets are passed to the
#' `dat_validation` and/or `dat_test` arguments, this will be a named list.
Expand All @@ -314,12 +314,12 @@ data_dependent_props <- c(
Preprocessor <- new_class(
name = "Preprocessor",
properties = list(
parameters = PreprocessorParameters,
config = PreprocessorConfig,
preprocessed = class_data.frame | class_list,
values = class_list
),
constructor = function(
parameters,
config,
preprocessed,
scale_centers = NULL,
scale_coefficients = NULL,
Expand All @@ -328,7 +328,7 @@ Preprocessor <- new_class(
) {
new_object(
S7_object(),
parameters = parameters,
config = config,
preprocessed = preprocessed,
values = list(
scale_centers = scale_centers,
Expand Down
Loading