dials/0000755000176200001440000000000014565635766011375 5ustar liggesusersdials/NAMESPACE0000644000176200001440000001446414565615206012610 0ustar liggesusers# Generated by roxygen2: do not edit by hand S3method("[",parameters) S3method("names<-",parameters) S3method(encode_unit,default) S3method(encode_unit,qual_param) S3method(encode_unit,quant_param) S3method(extract_parameter_dials,parameters) S3method(finalize,default) S3method(finalize,list) S3method(finalize,logical) S3method(finalize,param) S3method(finalize,parameters) S3method(grid_latin_hypercube,list) S3method(grid_latin_hypercube,param) S3method(grid_latin_hypercube,parameters) S3method(grid_latin_hypercube,workflow) S3method(grid_max_entropy,list) S3method(grid_max_entropy,param) S3method(grid_max_entropy,parameters) S3method(grid_max_entropy,workflow) S3method(grid_random,list) S3method(grid_random,param) S3method(grid_random,parameters) S3method(grid_random,workflow) S3method(grid_regular,list) S3method(grid_regular,param) S3method(grid_regular,parameters) S3method(grid_regular,workflow) S3method(parameters,default) S3method(parameters,list) S3method(parameters,param) S3method(print,parameters) S3method(print,qual_param) S3method(print,quant_param) S3method(type_sum,param) S3method(update,parameters) S3method(vec_cast,data.frame.parameters) S3method(vec_cast,parameters.data.frame) S3method(vec_cast,parameters.parameters) S3method(vec_cast,parameters.tbl_df) S3method(vec_cast,tbl_df.parameters) S3method(vec_proxy,parameters) S3method(vec_ptype2,data.frame.parameters) S3method(vec_ptype2,parameters.data.frame) S3method(vec_ptype2,parameters.parameters) S3method(vec_ptype2,parameters.tbl_df) S3method(vec_ptype2,tbl_df.parameters) S3method(vec_restore,parameters) export(Laplace) export(activation) export(adjust_deg_free) export(all_neighbors) export(batch_size) export(class_weights) export(conditional_min_criterion) export(conditional_test_statistic) export(conditional_test_type) export(confidence_factor) export(cost) export(cost_complexity) export(deg_free) export(degree) export(degree_int) export(diagonal_covariance) export(dist_power) export(dropout) export(encode_unit) export(epochs) export(extract_parameter_dials) export(extrapolation) export(finalize) export(freq_cut) export(fuzzy_thresholding) export(get_batch_sizes) export(get_log_p) export(get_n) export(get_n_frac) export(get_n_frac_range) export(get_p) export(get_rbf_range) export(grid_latin_hypercube) export(grid_max_entropy) export(grid_random) export(grid_regular) export(harmonic_frequency) export(has_unknowns) export(hidden_units) export(initial_umap) export(is_unknown) export(kernel_offset) export(learn_rate) export(loss_reduction) export(lower_quantile) export(max_nodes) export(max_num_terms) export(max_rules) export(max_times) export(max_tokens) export(min_dist) export(min_n) export(min_times) export(min_unique) export(mixture) export(momentum) export(mtry) export(mtry_long) export(mtry_prop) export(neighbors) export(new_qual_param) export(new_quant_param) export(no_global_pruning) export(num_breaks) export(num_clusters) export(num_comp) export(num_hash) export(num_knots) export(num_leaves) export(num_random_splits) export(num_runs) export(num_terms) export(num_tokens) export(over_ratio) export(parameters) export(parameters_constr) export(penalty) export(penalty_L1) export(penalty_L2) export(predictor_prop) export(predictor_winnowing) export(prior_mixture_threshold) export(prior_outcome_range) export(prior_slab_dispersion) export(prior_terminal_node_coef) export(prior_terminal_node_expo) export(prod_degree) export(prune) export(prune_method) export(pull_dials_object) export(range_get) export(range_set) export(range_validate) export(ranger_class_rules) export(ranger_reg_rules) export(ranger_split_rules) export(rate_decay) export(rate_initial) export(rate_largest) export(rate_reduction) export(rate_schedule) export(rate_step_size) export(rate_steps) export(rbf_sigma) export(regularization_factor) export(regularization_method) export(regularize_depth) export(rule_bands) export(sample_prop) export(sample_size) export(scale_factor) export(scale_pos_weight) export(select_features) export(shrinkage_correlation) export(shrinkage_frequencies) export(shrinkage_variance) export(signed_hash) export(significance_threshold) export(smoothness) export(spline_degree) export(splitting_rule) export(stop_iter) export(summary_stat) export(surv_dist) export(survival_link) export(svm_margin) export(target_weight) export(threshold) export(token) export(tree_depth) export(trees) export(trim_amount) export(unbiased_rules) export(under_ratio) export(unique_cut) export(unknown) export(validation_set_prop) export(value_inverse) export(value_sample) export(value_seq) export(value_set) export(value_transform) export(value_validate) export(values_activation) export(values_initial_umap) export(values_prune_method) export(values_regularization_method) export(values_scheduler) export(values_summary_stat) export(values_surv_dist) export(values_survival_link) export(values_test_statistic) export(values_test_type) export(values_token) export(values_weight_func) export(values_weight_scheme) export(vocabulary_size) export(weight) export(weight_func) export(weight_scheme) export(window_size) import(rlang) importFrom(DiceDesign,dmaxDesign) importFrom(DiceDesign,lhsDesign) importFrom(dplyr,"%>%") importFrom(dplyr,filter) importFrom(dplyr,mutate) importFrom(dplyr,pull) importFrom(dplyr,select) importFrom(glue,glue) importFrom(glue,glue_collapse) importFrom(hardhat,extract_parameter_dials) importFrom(lifecycle,deprecated) importFrom(pillar,type_sum) importFrom(purrr,map) importFrom(purrr,map2) importFrom(purrr,map2_dfc) importFrom(purrr,map_chr) importFrom(purrr,map_dbl) importFrom(purrr,map_dfc) importFrom(purrr,map_int) importFrom(purrr,map_lgl) importFrom(scales,is.trans) importFrom(scales,transform_log10) importFrom(scales,transform_log2) importFrom(stats,runif) importFrom(tibble,as_tibble) importFrom(tibble,is_tibble) importFrom(tibble,new_tibble) importFrom(tibble,tibble) importFrom(utils,globalVariables) importFrom(utils,installed.packages) importFrom(vctrs,df_cast) importFrom(vctrs,new_data_frame) importFrom(vctrs,stop_incompatible_cast) importFrom(vctrs,tib_cast) importFrom(vctrs,tib_ptype2) importFrom(vctrs,vec_c) importFrom(vctrs,vec_cast) importFrom(vctrs,vec_cbind) importFrom(vctrs,vec_init) importFrom(vctrs,vec_proxy) importFrom(vctrs,vec_ptype) importFrom(vctrs,vec_ptype2) importFrom(vctrs,vec_rbind) importFrom(vctrs,vec_restore) importFrom(vctrs,vec_slice) importFrom(withr,with_seed) dials/LICENSE0000644000176200001440000000005314153712300012345 0ustar liggesusersYEAR: 2021 COPYRIGHT HOLDER: dials authors dials/README.md0000644000176200001440000000531114565617500012636 0ustar liggesusers # dials a stylized black dial on a beige background [![R-CMD-check](https://github.com/tidymodels/dials/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tidymodels/dials/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/tidymodels/dials/branch/main/graph/badge.svg)](https://app.codecov.io/gh/tidymodels/dials?branch=main) [![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/dials)](https://CRAN.R-project.org/package=dials) [![Downloads](http://cranlogs.r-pkg.org/badges/dials)](https://CRAN.R-project.org/package=dials) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) ## Overview This package contains *infrastructure* to create and manage values of tuning parameters for the tidymodels packages. If you are looking for *how to* tune parameters in tidymodels, please look at the [tune](https://tune.tidymodels.org/) package and [tidymodels.org](https://www.tidymodels.org/). The name reflects the idea that tuning predictive models can be like turning a set of dials on a complex machine under duress. two Star Trek characters in front of a machine with many dials, lights, and buttons ## Installation You can install the released version of dials from [CRAN](https://CRAN.R-project.org) with: ``` r install.packages("dials") ``` You can install the development version from Github with: ``` r # install.packages("pak") pak::pak("tidymodels/dials") ``` ## Contributing Please note that the dials project is released with a [Contributor Code of Conduct](https://dials.tidymodels.org/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms. - For questions and discussions about tidymodels packages, modeling, and machine learning, please [post on RStudio Community](https://community.rstudio.com/new-topic?category_id=15&tags=tidymodels,question). - If you think you have encountered a bug, please [submit an issue](https://github.com/tidymodels/dials/issues). - Either way, learn how to create and share a [reprex](https://reprex.tidyverse.org/articles/articles/learn-reprex.html) (a minimal, reproducible example), to clearly communicate about your code. - Check out further details on [contributing guidelines for tidymodels packages](https://www.tidymodels.org/contribute/) and [how to get help](https://www.tidymodels.org/help/). dials/man/0000755000176200001440000000000014565615206012133 5ustar liggesusersdials/man/prune_method.Rd0000644000176200001440000000116714153712300015102 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_prune_method.R \docType{data} \name{prune_method} \alias{prune_method} \alias{values_prune_method} \title{MARS pruning methods} \format{ An object of class \code{character} of length 6. } \usage{ prune_method(values = values_prune_method) values_prune_method } \arguments{ \item{values}{A character string of possible values. See \code{values_prune_method} in examples below.} } \description{ MARS pruning methods } \details{ This parameter is used in \code{parsnip:::mars()}. } \examples{ values_prune_method prune_method() } \keyword{datasets} dials/man/rbf_sigma.Rd0000644000176200001440000000205714565421125014352 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_kernel.R \name{rbf_sigma} \alias{rbf_sigma} \alias{scale_factor} \alias{kernel_offset} \title{Kernel parameters} \usage{ rbf_sigma(range = c(-10, 0), trans = transform_log10()) scale_factor(range = c(-10, -1), trans = transform_log10()) kernel_offset(range = c(0, 2), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Parameters related to the radial basis or other kernel functions. } \details{ \code{degree()} can also be used in kernel functions. } \examples{ rbf_sigma() scale_factor() kernel_offset() } dials/man/num_clusters.Rd0000644000176200001440000000144314565421125015142 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_clusters.R \name{num_clusters} \alias{num_clusters} \title{Number of Clusters} \usage{ num_clusters(range = c(1L, 10L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in most \code{tidyclust} models. } \examples{ num_clusters() } dials/man/Laplace.Rd0000644000176200001440000000171714565421125013764 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_Laplace.R \name{Laplace} \alias{Laplace} \title{Laplace correction parameter} \usage{ Laplace(range = c(0, 3), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \value{ A function with classes \code{"quant_param"} and \code{"param"}. } \description{ Laplace correction for smoothing low-frequency counts. } \details{ This parameter is often used to correct for zero-count data in tables or proportions. } \examples{ Laplace() } dials/man/prior_slab_dispersion.Rd0000644000176200001440000000257714565421125017023 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_sparse_bayes_pca.R \name{prior_slab_dispersion} \alias{prior_slab_dispersion} \alias{prior_mixture_threshold} \title{Bayesian PCA parameters} \usage{ prior_slab_dispersion(range = c(-1/2, log10(3)), trans = transform_log10()) prior_mixture_threshold(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ A numeric parameter function representing parameters for the spike-and-slab prior used by \code{embed::step_pca_sparse_bayes()}. } \details{ \code{prior_slab_dispersion()} is related to the prior for the case where a PCA loading is selected (i.e. non-zero). Smaller values result in an increase in zero coefficients. \code{prior_mixture_threshold()} is used to threshold the prior to determine which parameters are non-zero or zero. Increasing this parameter increases the number of zero coefficients. } \examples{ mixture() } dials/man/trim_amount.Rd0000644000176200001440000000144314565421125014755 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_trim_amount.R \name{trim_amount} \alias{trim_amount} \title{Amount of Trimming} \usage{ trim_amount(range = c(0, 0.5), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{recipes::step_impute_mean()}. } \examples{ trim_amount() } dials/man/window_size.Rd0000644000176200001440000000146114565421125014760 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_window_size.R \name{window_size} \alias{window_size} \title{Parameter for the moving window size} \usage{ window_size(range = c(3L, 11L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{recipes::step_window()}. } \examples{ window_size() } dials/man/max_times.Rd0000644000176200001440000000160214565421125014402 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_max_times.R \name{max_times} \alias{max_times} \alias{min_times} \title{Word frequencies for removal} \usage{ max_times(range = c(1L, as.integer(10^5)), trans = NULL) min_times(range = c(0L, 1000L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{textrecipes::step_tokenfilter()}. } \examples{ max_times() min_times() } dials/man/all_neighbors.Rd0000644000176200001440000000062314153712300015215 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_all_neighbors.R \name{all_neighbors} \alias{all_neighbors} \title{Parameter to determine which neighbors to use} \usage{ all_neighbors(values = c(TRUE, FALSE)) } \arguments{ \item{values}{A vector of possible values (TRUE or FALSE).} } \description{ Used in \code{themis::step_bsmote()}. } \examples{ all_neighbors() } dials/man/momentum.Rd0000644000176200001440000000147314565421125014263 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_momentum.R \name{momentum} \alias{momentum} \title{Gradient descent momentum parameter} \usage{ momentum(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ A useful parameter for neural network models using gradient descent } \examples{ momentum() } dials/man/class_weights.Rd0000644000176200001440000000173614565421125015263 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_class_weights.R \name{class_weights} \alias{class_weights} \title{Parameters for class weights for imbalanced problems} \usage{ class_weights(range = c(1, 10), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ This parameter can be used to moderate how much influence certain classes receive during training. } \details{ Used in \code{brulee::brulee_logistic_reg()} and \code{brulee::brulee_mlp()} } \examples{ class_weights() } dials/man/type_sum.param.Rd0000644000176200001440000000145114153712300015351 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/type_sum.R \name{type_sum.param} \alias{type_sum.param} \title{Succinct summary of parameter objects} \usage{ \method{type_sum}{param}(x) } \arguments{ \item{x}{A \code{param} object to summarise.} } \value{ A character value. } \description{ \code{type_sum()} controls how objects are shown when inside tibble columns. } \details{ For \code{param} objects, the summary prefix is either "\code{dparam}" (if a qualitative parameter) or "\code{nparam}" (if quantitative). Additionally, brackets are used to indicate if there are unknown values. For example, "\verb{nparam[?]}" would indicate that part of the numeric range is has not been finalized and "\verb{nparam[+]}" indicates a parameter that is complete. } \keyword{internal} dials/man/pull_dials_object.Rd0000644000176200001440000000216714337647441016111 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/pull_dials_object.R \name{pull_dials_object} \alias{pull_dials_object} \title{Return a dials parameter object associated with parameters} \usage{ pull_dials_object(x, id, ...) } \arguments{ \item{x}{The results of a call to \code{\link[=parameters]{parameters()}}, a recipe, model specification, or workflow.} \item{id}{A single string for the \code{id} of the parameter.} \item{...}{Not currently used.} } \value{ A \code{dials} parameter object. } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} This function has been deprecated; please use \code{hardhat::extract_parameter_dials()} instead. \code{pull_dials_object()} can extract a single \code{dials} parameter object from different types of objects (e.g. parameter sets, recipes, etc.). } \examples{ glmn_param <- parameters(lambda = penalty(), mixture()) # pull_dials_object(glmn_param, "lambda") # -> extract_parameter_dials(glmn_param, "lambda") } \keyword{internal} dials/man/mixture.Rd0000644000176200001440000000233214565421125014112 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_mixture.R \name{mixture} \alias{mixture} \title{Mixture of penalization terms} \usage{ mixture(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ A numeric parameter function representing the relative amount of penalties (e.g. L1, L2, etc) in regularized models. } \details{ This parameter is used for regularized or penalized models such as \code{parsnip::linear_reg()}, \code{parsnip::logistic_reg()}, and others. It is formulated as the proportion of L1 regularization (i.e. lasso) in the model. In the \code{glmnet} model, \code{mixture = 1} is a pure lasso model while \code{mixture = 0} indicates that ridge regression is being used. } \examples{ mixture() } dials/man/smoothness.Rd0000644000176200001440000000143214565421125014617 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_smoothness.R \name{smoothness} \alias{smoothness} \title{Kernel Smoothness} \usage{ smoothness(range = c(0.5, 1.5), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{discrim::naive_Bayes()}. } \examples{ smoothness() } dials/man/max_tokens.Rd0000644000176200001440000000147714565421125014576 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_max_tokens.R \name{max_tokens} \alias{max_tokens} \title{Maximum number of retained tokens} \usage{ max_tokens(range = c(0L, as.integer(10^3)), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{textrecipes::step_tokenfilter()}. } \examples{ max_tokens() } dials/man/xgboost_parameters.Rd0000644000176200001440000000243514565421125016331 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_xgboost.R \name{scale_pos_weight} \alias{scale_pos_weight} \alias{penalty_L2} \alias{penalty_L1} \title{Parameters for possible engine parameters for xgboost} \usage{ scale_pos_weight(range = c(0.8, 1.2), trans = NULL) penalty_L2(range = c(-10, 1), trans = transform_log10()) penalty_L1(range = c(-10, 1), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters are auxiliary to tree-based models that use the "xgboost" engine. They correspond to tuning parameters that would be specified using \code{set_engine("xgboost", ...)}. } \details{ For more information, see the \href{https://xgboost.readthedocs.io/en/latest/parameter.html}{xgboost webpage}. } \examples{ scale_pos_weight() penalty_L2() penalty_L1() } dials/man/texthash.Rd0000644000176200001440000000165414565421125014253 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_hash.R \name{num_hash} \alias{num_hash} \alias{signed_hash} \title{Text hashing parameters} \usage{ num_hash(range = c(8L, 12L), trans = transform_log2()) signed_hash(values = c(TRUE, FALSE)) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{A vector of possible values (TRUE or FALSE).} } \description{ Used in \code{textrecipes::step_texthash()}. } \examples{ num_hash() signed_hash() } dials/man/summary_stat.Rd0000644000176200001440000000116414223270317015143 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_summary_stat.R \docType{data} \name{summary_stat} \alias{summary_stat} \alias{values_summary_stat} \title{Rolling summary statistic for moving windows} \format{ An object of class \code{character} of length 8. } \usage{ summary_stat(values = values_summary_stat) values_summary_stat } \arguments{ \item{values}{A character string of possible values. See \code{values_summary_stat} in examples below.} } \description{ This parameter is used in \code{recipes::step_window()}. } \examples{ values_summary_stat summary_stat() } \keyword{datasets} dials/man/vocabulary_size.Rd0000644000176200001440000000160514565421125015620 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_vocabulary_size.R \name{vocabulary_size} \alias{vocabulary_size} \title{Number of tokens in vocabulary} \usage{ vocabulary_size(range = c(1000L, 32000L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{textrecipes::step_tokenize_sentencepiece()} and \code{textrecipes::step_tokenize_bpe()}. } \examples{ vocabulary_size() } dials/man/grid_regular.Rd0000644000176200001440000001073514412541005015060 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/grids.R \name{grid_regular} \alias{grid_regular} \alias{grid_regular.parameters} \alias{grid_regular.list} \alias{grid_regular.param} \alias{grid_regular.workflow} \alias{grid_random} \alias{grid_random.parameters} \alias{grid_random.list} \alias{grid_random.param} \alias{grid_random.workflow} \title{Create grids of tuning parameters} \usage{ grid_regular(x, ..., levels = 3, original = TRUE, filter = NULL) \method{grid_regular}{parameters}(x, ..., levels = 3, original = TRUE, filter = NULL) \method{grid_regular}{list}(x, ..., levels = 3, original = TRUE, filter = NULL) \method{grid_regular}{param}(x, ..., levels = 3, original = TRUE, filter = NULL) \method{grid_regular}{workflow}(x, ..., levels = 3, original = TRUE, filter = NULL) grid_random(x, ..., size = 5, original = TRUE, filter = NULL) \method{grid_random}{parameters}(x, ..., size = 5, original = TRUE, filter = NULL) \method{grid_random}{list}(x, ..., size = 5, original = TRUE, filter = NULL) \method{grid_random}{param}(x, ..., size = 5, original = TRUE, filter = NULL) \method{grid_random}{workflow}(x, ..., size = 5, original = TRUE, filter = NULL) } \arguments{ \item{x}{A \code{param} object, list, or \code{parameters}.} \item{...}{One or more \code{param} objects (such as \code{\link[=mtry]{mtry()}} or \code{\link[=penalty]{penalty()}}). None of the objects can have \code{unknown()} values in the parameter ranges or values.} \item{levels}{An integer for the number of values of each parameter to use to make the regular grid. \code{levels} can be a single integer or a vector of integers that is the same length as the number of parameters in \code{...}. \code{levels} can be a named integer vector, with names that match the id values of parameters.} \item{original}{A logical: should the parameters be in the original units or in the transformed space (if any)?} \item{filter}{A logical: should the parameters be filtered prior to generating the grid. Must be a single expression referencing parameter names that evaluates to a logical vector.} \item{size}{A single integer for the total number of parameter value combinations returned for the random grid. If duplicate combinations are generated from this size, the smaller, unique set is returned.} } \value{ A tibble. There are columns for each parameter and a row for every parameter combination. } \description{ Random and regular grids can be created for any number of parameter objects. } \details{ Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in \code{dials}. For example: \if{html}{\out{
}}\preformatted{mixture() }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## Proportion of Lasso Penalty (quantitative) ## Range: [0, 1] }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{set.seed(283) mix_grid_1 <- grid_random(mixture(), size = 1000) range(mix_grid_1$mixture) }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## [1] 0.001490161 0.999741096 }\if{html}{\out{
}} However, in some cases, the \code{parsnip} and \code{recipe} packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a \code{parameters} object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the \code{mixture} argument above is different for \code{glmnet} models: \if{html}{\out{
}}\preformatted{library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) \%>\% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_random(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## [1] 0.05141565 0.99975404 }\if{html}{\out{
}} } \examples{ # filter arg will allow you to filter subsequent grid data frame based on some condition. p <- parameters(penalty(), mixture()) grid_regular(p) grid_regular(p, filter = penalty <= .01) # Will fail due to unknowns: # grid_regular(mtry(), min_n()) grid_regular(penalty(), mixture()) grid_regular(penalty(), mixture(), levels = 3:4) grid_regular(penalty(), mixture(), levels = c(mixture = 4, penalty = 3)) grid_random(penalty(), mixture()) } dials/man/num_runs.Rd0000644000176200001440000000142614565421125014266 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_runs.R \name{num_runs} \alias{num_runs} \title{Number of Computation Runs} \usage{ num_runs(range = c(1L, 10L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{recipes::step_nnmf()}. } \examples{ num_runs() } dials/man/regularization_method.Rd0000644000176200001440000000140414223270317017007 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_regularization_method.R \docType{data} \name{regularization_method} \alias{regularization_method} \alias{values_regularization_method} \title{Estimation methods for regularized models} \format{ An object of class \code{character} of length 4. } \usage{ regularization_method(values = values_regularization_method) values_regularization_method } \arguments{ \item{values}{A character string of possible values. See \code{values_regularization_method} in examples below.} } \description{ Estimation methods for regularized models } \details{ This parameter is used in \code{parsnip::discrim_linear()}. } \examples{ values_regularization_method regularization_method() } \keyword{datasets} dials/man/unknown.Rd0000644000176200001440000000230114153712300014077 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/aaa_unknown.R \name{unknown} \alias{unknown} \alias{is_unknown} \alias{has_unknowns} \title{Placeholder for unknown parameter values} \usage{ unknown() is_unknown(x) has_unknowns(object) } \arguments{ \item{x}{An object or vector or objects to test for unknown-ness.} \item{object}{An object of class \code{param}.} } \value{ \code{unknown()} returns expression value for \code{unknown()}. \code{is_unknown()} returns a vector of logicals as long as \code{x} that are \code{TRUE} is the element of \code{x} is unknown, and \code{FALSE} otherwise. \code{has_unknowns()} returns a single logical indicating if the \code{range} of a \code{param} object has any unknown values. } \description{ \code{unknown()} creates an expression used to signify that the value will be specified at a later time. } \examples{ # Just returns an expression unknown() # Of course, true! is_unknown(unknown()) # Create a range with a minimum of 1 # and an unknown maximum range <- c(1, unknown()) range # The first value is known, the # second is not is_unknown(range) # mtry()'s maximum value is not known at # creation time has_unknowns(mtry()) } dials/man/shrinkage_correlation.Rd0000644000176200001440000000317414565421125016776 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_sda.R \name{shrinkage_correlation} \alias{shrinkage_correlation} \alias{shrinkage_variance} \alias{shrinkage_frequencies} \alias{diagonal_covariance} \title{Parameters for possible engine parameters for sda models} \usage{ shrinkage_correlation(range = c(0, 1), trans = NULL) shrinkage_variance(range = c(0, 1), trans = NULL) shrinkage_frequencies(range = c(0, 1), trans = NULL) diagonal_covariance(values = c(TRUE, FALSE)) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{A vector of possible values (TRUE or FALSE).} } \value{ For the functions, they return a function with classes \code{"param"} and either \code{"quant_param"} or \code{"qual_param"}. } \description{ These functions can be used to optimize engine-specific parameters of \code{sda::sda()} via \code{parsnip::discrim_linear()}. } \details{ These functions map to \code{sda::sda()} arguments via: \itemize{ \item \code{shrinkage_correlation()} to \code{lambda} \item \code{shrinkage_variance()} to \code{lambda.var} \item \code{shrinkage_frequencies()} to \code{lambda.freqs} \item \code{diagonal_covariance()} to \code{diagonal} } } dials/man/randomForest_parameters.Rd0000644000176200001440000000175314565421125017311 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_randomForest.R \name{max_nodes} \alias{max_nodes} \title{Parameters for possible engine parameters for randomForest} \usage{ max_nodes(range = c(100L, 10000L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters are auxiliary to random forest models that use the "randomForest" engine. They correspond to tuning parameters that would be specified using \code{set_engine("randomForest", ...)}. } \examples{ max_nodes() } dials/man/c5_parameters.Rd0000644000176200001440000000307014565421125015147 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_c50.R \name{confidence_factor} \alias{confidence_factor} \alias{no_global_pruning} \alias{predictor_winnowing} \alias{fuzzy_thresholding} \alias{rule_bands} \title{Parameters for possible engine parameters for C5.0} \usage{ confidence_factor(range = c(-1, 0), trans = transform_log10()) no_global_pruning(values = c(TRUE, FALSE)) predictor_winnowing(values = c(TRUE, FALSE)) fuzzy_thresholding(values = c(TRUE, FALSE)) rule_bands(range = c(2L, 500L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{For \code{no_global_pruning()}, \code{predictor_winnowing()}, and \code{fuzzy_thresholding()} either \code{TRUE} or \code{FALSE}.} } \description{ These parameters are auxiliary to tree-based models that use the "C5.0" engine. They correspond to tuning parameters that would be specified using \code{set_engine("C5.0", ...)}. } \details{ To use these, check \code{?C50::C5.0Control} to see how they are used. } \examples{ confidence_factor() no_global_pruning() predictor_winnowing() fuzzy_thresholding() rule_bands() } dials/man/num_comp.Rd0000644000176200001440000000232614565421125014235 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_comp.R \name{num_comp} \alias{num_comp} \alias{num_terms} \title{Number of new features} \usage{ num_comp(range = c(1L, unknown()), trans = NULL) num_terms(range = c(1L, unknown()), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The number of derived predictors from models or feature engineering methods. } \details{ Since the scale of these parameters often depends on the number of columns in the data set, the upper bound is set to \code{unknown}. For example, the number of PCA components is limited by the number of columns and so on. The difference between \code{num_comp()} and \code{num_terms()} is semantics. } \examples{ num_terms() num_terms(c(2L, 10L)) } dials/man/learn_rate.Rd0000644000176200001440000000205414565421125014532 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_learn_rate.R \name{learn_rate} \alias{learn_rate} \title{Learning rate} \usage{ learn_rate(range = c(-10, -1), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The parameter is used in boosting methods (\code{parsnip::boost_tree()}) or some types of neural network optimization methods. } \details{ The parameter is used on the log10 scale. The units for the \code{range} function are on this scale. \code{learn_rate()} corresponds to \code{eta} in \pkg{xgboost}. } \examples{ learn_rate() } dials/man/cost.Rd0000644000176200001440000000156014565421125013367 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_svm.R \name{cost} \alias{cost} \alias{svm_margin} \title{Support vector machine parameters} \usage{ cost(range = c(-10, 5), trans = transform_log2()) svm_margin(range = c(0, 0.2), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Parameters related to the SVM objective function(s). } \examples{ cost() svm_margin() } dials/man/stop_iter.Rd0000644000176200001440000000174614565421125014435 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_stop_iter.R \name{stop_iter} \alias{stop_iter} \title{Early stopping parameter} \usage{ stop_iter(range = c(3L, 20L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ For some models, the effectiveness of the model can decrease as training iterations continue. \code{stop_iter()} can be used to tune how many iterations without an improvement in the objective function occur before training should be halted. } \examples{ stop_iter() } dials/man/adjust_deg_free.Rd0000644000176200001440000000172314565421125015532 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_adjust_reg_free.R \name{adjust_deg_free} \alias{adjust_deg_free} \title{Parameters to adjust effective degrees of freedom} \usage{ adjust_deg_free(range = c(0.25, 4), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ This parameter can be used to moderate smoothness of spline or other terms used in generalized additive models. } \details{ Used in \code{parsnip::gen_additive_mod()}. } \examples{ adjust_deg_free() } dials/man/mtry.Rd0000644000176200001440000000466714565421125013425 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_mtry.R \name{mtry} \alias{mtry} \alias{mtry_long} \title{Number of randomly sampled predictors} \usage{ mtry(range = c(1L, unknown()), trans = NULL) mtry_long(range = c(0L, unknown()), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The number of predictors that will be randomly sampled at each split when creating tree models. } \details{ This parameter is used for regularized or penalized models such as \code{parsnip::rand_forest()} and others. \code{mtry_long()} has the values on the log10 scale and is helpful when the data contain a large number of predictors. Since the scale of the parameter depends on the number of columns in the data set, the upper bound is set to \code{unknown} but can be filled in via the \code{finalize()} method. } \section{Interpretation}{ \code{\link[=mtry_prop]{mtry_prop()}} is a variation on \code{\link[=mtry]{mtry()}} where the value is interpreted as the \emph{proportion} of predictors that will be randomly sampled at each split rather than the \emph{count}. This parameter is not intended for use in accommodating engines that take in this argument as a proportion; \code{mtry} is often a main model argument rather than an engine-specific argument, and thus should not have an engine-specific interface. When wrapping modeling engines that interpret \code{mtry} in its sense as a proportion, use the \code{\link[=mtry]{mtry()}} parameter in \code{parsnip::set_model_arg()} and process the passed argument in an internal wrapping function as \code{mtry / number_of_predictors}. In addition, introduce a logical argument \code{counts} to the wrapping function, defaulting to \code{TRUE}, that indicates whether to interpret the supplied argument as a count rather than a proportion. For an example implementation, see \code{parsnip::xgb_train()}. } \examples{ mtry(c(1L, 10L)) # in original units mtry_long(c(0, 5)) # in log10 units } \seealso{ mtry_prop } dials/man/value_validate.Rd0000644000176200001440000000610714563660313015410 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/aaa_values.R \name{value_validate} \alias{value_validate} \alias{value_seq} \alias{value_sample} \alias{value_transform} \alias{value_inverse} \alias{value_set} \title{Tools for working with parameter values} \usage{ value_validate(object, values, ..., call = caller_env()) value_seq(object, n, original = TRUE) value_sample(object, n, original = TRUE) value_transform(object, values) value_inverse(object, values) value_set(object, values) } \arguments{ \item{object}{An object with class \code{quant_param}.} \item{values}{A numeric vector or list (including \code{Inf}). Values \emph{cannot} include \code{unknown()}. For \code{value_validate()}, the units should be consistent with the parameter object's definition.} \item{...}{These dots are for future extensions and must be empty.} \item{call}{The call passed on to \code{\link[rlang:abort]{rlang::abort()}}.} \item{n}{An integer for the (maximum) number of values to return. In some cases where a sequence is requested, the result might have less than \code{n} values. See Details.} \item{original}{A single logical. Should the range values be in the natural units (\code{TRUE}) or in the transformed space (\code{FALSE}, if applicable)?} } \value{ \code{value_validate()} throws an error or silently returns \code{values} if they are contained in the values of the \code{object}. \code{value_transform()} and \code{value_inverse()} return a \emph{vector} of numeric values. \code{value_seq()} and \code{value_sample()} return a vector of values consistent with the \code{type} field of \code{object}. } \description{ Setters and validators for parameter values. Additionally, tools for creating sequences of parameter values and for transforming parameter values are provided. } \details{ For sequences of integers, the code uses \code{unique(floor(seq(min, max, length.out = n)))} and this may generate an uneven set of values shorter than \code{n}. This also means that if \code{n} is larger than the range of the integers, a smaller set will be generated. For qualitative parameters, the first \code{n} values are returned. For quantitative parameters, any \code{values} contained in the object are sampled with replacement. Otherwise, a sequence of values between the \code{range} values is returned. It is possible that less than \code{n} values are returned. For qualitative parameters, sampling of the \code{values} is conducted with replacement. For qualitative values, a random uniform distribution is used. } \examples{ library(dplyr) penalty() \%>\% value_set(-4:-1) # Is a specific value valid? penalty() penalty() \%>\% range_get() value_validate(penalty(), 17) # get a sequence of values cost_complexity() cost_complexity() \%>\% value_seq(4) cost_complexity() \%>\% value_seq(4, original = FALSE) on_log_scale <- cost_complexity() \%>\% value_seq(4, original = FALSE) nat_units <- value_inverse(cost_complexity(), on_log_scale) nat_units value_transform(cost_complexity(), nat_units) # random values in the range set.seed(3666) cost_complexity() \%>\% value_sample(2) } dials/man/weight_scheme.Rd0000644000176200001440000000123714153712300015222 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_weight_scheme.R \docType{data} \name{weight_scheme} \alias{weight_scheme} \alias{values_weight_scheme} \title{Term frequency weighting methods} \format{ An object of class \code{character} of length 5. } \usage{ weight_scheme(values = values_weight_scheme) values_weight_scheme } \arguments{ \item{values}{A character string of possible values. See \code{values_weight_scheme} in examples below.} } \description{ Term frequency weighting methods } \details{ This parameter is used in \code{textrecipes::step_tf()}. } \examples{ values_weight_scheme weight_scheme() } \keyword{datasets} dials/man/finalize.Rd0000644000176200001440000000766414223270317014227 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/finalize.R \name{finalize} \alias{finalize} \alias{finalize.list} \alias{finalize.param} \alias{finalize.parameters} \alias{finalize.logical} \alias{finalize.default} \alias{get_p} \alias{get_log_p} \alias{get_n_frac} \alias{get_n_frac_range} \alias{get_n} \alias{get_rbf_range} \alias{get_batch_sizes} \title{Functions to finalize data-specific parameter ranges} \usage{ finalize(object, ...) \method{finalize}{list}(object, x, force = TRUE, ...) \method{finalize}{param}(object, x, force = TRUE, ...) \method{finalize}{parameters}(object, x, force = TRUE, ...) \method{finalize}{logical}(object, x, force = TRUE, ...) \method{finalize}{default}(object, x, force = TRUE, ...) get_p(object, x, log_vals = FALSE, ...) get_log_p(object, x, ...) get_n_frac(object, x, log_vals = FALSE, frac = 1/3, ...) get_n_frac_range(object, x, log_vals = FALSE, frac = c(1/10, 5/10), ...) get_n(object, x, log_vals = FALSE, ...) get_rbf_range(object, x, seed = sample.int(10^5, 1), ...) get_batch_sizes(object, x, frac = c(1/10, 1/3), ...) } \arguments{ \item{object}{A \code{param} object or a list of \code{param} objects.} \item{...}{Other arguments to pass to the underlying parameter finalizer functions. For example, for \code{get_rbf_range()}, the dots are passed along to \code{\link[kernlab:sigest]{kernlab::sigest()}}.} \item{x}{The predictor data. In some cases (see below) this should only include numeric data.} \item{force}{A single logical that indicates that even if the parameter object is complete, should it update the ranges anyway?} \item{log_vals}{A logical: should the ranges be set on the log10 scale?} \item{frac}{A double for the fraction of the data to be used for the upper bound. For \code{get_n_frac_range()} and \code{get_batch_sizes()}, a vector of two fractional values are required.} \item{seed}{An integer to control the randomness of the calculations.} } \value{ An updated \code{param} object or a list of updated \code{param} objects depending on what is provided in \code{object}. } \description{ These functions take a parameter object and modify the unknown parts of \code{ranges} based on a data set and simple heuristics. } \details{ \code{finalize()} runs the embedded finalizer function contained in the \code{param} object (\code{object$finalize}) and returns the updated version. The finalization function is one of the \verb{get_*()} helpers. The \verb{get_*()} helper functions are designed to be used with the pipe and update the parameter object in-place. \code{get_p()} and \code{get_log_p()} set the upper value of the range to be the number of columns in the data (on the natural and log10 scale, respectively). \code{get_n()} and \code{get_n_frac()} set the upper value to be the number of rows in the data or a fraction of the total number of rows. \code{get_rbf_range()} sets both bounds based on the heuristic defined in \code{\link[kernlab:sigest]{kernlab::sigest()}}. It requires that all columns in \code{x} be numeric. } \examples{ \dontshow{if (interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(dplyr) car_pred <- select(mtcars, -mpg) # Needs an upper bound mtry() finalize(mtry(), car_pred) # Nothing to do here since no unknowns penalty() finalize(penalty(), car_pred) library(kernlab) library(tibble) library(purrr) params <- tribble( ~parameter, ~object, "mtry", mtry(), "num_terms", num_terms(), "rbf_sigma", rbf_sigma() ) params # Note that `rbf_sigma()` has a default range that does not need to be # finalized but will be changed if used in the function: complete_params <- params \%>\% mutate(object = map(object, finalize, car_pred)) complete_params params \%>\% dplyr::filter(parameter == "rbf_sigma") \%>\% pull(object) complete_params \%>\% dplyr::filter(parameter == "rbf_sigma") \%>\% pull(object) \dontshow{\}) # examplesIf} } dials/man/validation_set_prop.Rd0000644000176200001440000000154314565421125016465 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_validation_set_prop.R \name{validation_set_prop} \alias{validation_set_prop} \title{Proportion of data used for validation} \usage{ validation_set_prop(range = c(0.05, 0.7), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{embed::step_discretize_xgb()}. } \examples{ validation_set_prop() } dials/man/parameters_constr.Rd0000644000176200001440000000144614411575345016161 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/parameters.R \name{parameters_constr} \alias{parameters_constr} \title{Construct a new parameter set object} \usage{ parameters_constr( name, id, source, component, component_id, object, ..., call = caller_env() ) } \arguments{ \item{name, id, source, component, component_id}{Character strings with the same length.} \item{object}{A list of \code{param} objects or NA values.} \item{...}{These dots are for future extensions and must be empty.} \item{call}{The call passed on to \code{\link[rlang:abort]{rlang::abort()}}.} } \value{ A tibble that encapsulates the input vectors into a tibble with an additional class of "parameters". } \description{ Construct a new parameter set object } \keyword{internal} dials/man/update.parameters.Rd0000644000176200001440000000144014153712300016027 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/parameters.R \name{update.parameters} \alias{update.parameters} \title{Update a single parameter in a parameter set} \usage{ \method{update}{parameters}(object, ...) } \arguments{ \item{object}{A parameter set.} \item{...}{One or more unquoted named values separated by commas. The names should correspond to the \code{id} values in the parameter set. The values should be parameter objects or \code{NA} values.} } \value{ The modified parameter set. } \description{ Update a single parameter in a parameter set } \examples{ params <- list(lambda = penalty(), alpha = mixture(), `rand forest` = mtry()) pset <- parameters(params) pset update(pset, `rand forest` = finalize(mtry(), mtcars), alpha = mixture(c(.1, .2))) } dials/man/dropout.Rd0000644000176200001440000000260514565421125014114 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_network.R \name{dropout} \alias{dropout} \alias{epochs} \alias{hidden_units} \alias{batch_size} \title{Neural network parameters} \usage{ dropout(range = c(0, 1), trans = NULL) epochs(range = c(10L, 1000L), trans = NULL) hidden_units(range = c(1L, 10L), trans = NULL) batch_size(range = c(unknown(), unknown()), trans = transform_log2()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These functions generate parameters that are useful for neural network models. } \details{ \itemize{ \item \code{dropout()}: The parameter dropout rate. (See \code{parsnip:::mlp()}). \item \code{epochs()}: The number of iterations of training. (See \code{parsnip:::mlp()}). \item \code{hidden_units()}: The number of hidden units in a network layer. (See \code{parsnip:::mlp()}). \item \code{batch_size()}: The mini-batch size for neural networks. } } \examples{ dropout() } dials/man/conditional_min_criterion.Rd0000644000176200001440000000311014565421125017634 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_partykit.R \docType{data} \name{conditional_min_criterion} \alias{conditional_min_criterion} \alias{values_test_type} \alias{conditional_test_type} \alias{values_test_statistic} \alias{conditional_test_statistic} \title{Parameters for possible engine parameters for partykit models} \format{ An object of class \code{character} of length 4. An object of class \code{character} of length 2. } \usage{ conditional_min_criterion( range = c(1.386294, 15), trans = scales::transform_logit() ) values_test_type conditional_test_type(values = values_test_type) values_test_statistic conditional_test_statistic(values = values_test_statistic) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{A character string of possible values.} } \value{ For the functions, they return a function with classes "param" and either "quant_param" or "qual_param". } \description{ Parameters for possible engine parameters for partykit models } \details{ The range of \code{conditional_min_criterion()} corresponds to roughly 0.80 to 0.99997 in the natural units. For several test types, this parameter corresponds to \code{1 - {p-value}}. } \keyword{datasets} dials/man/num_knots.Rd0000644000176200001440000000157514565421125014442 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_knots.R \name{num_knots} \alias{num_knots} \title{Number of knots (integer)} \usage{ num_knots(range = c(0L, 5L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The number of knots used for spline model parameters. } \details{ One context in which this parameter is used is spline basis functions. } \examples{ num_knots() } dials/man/weight_func.Rd0000644000176200001440000000124114153712300014704 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_weight_func.R \docType{data} \name{weight_func} \alias{weight_func} \alias{values_weight_func} \title{Kernel functions for distance weighting} \format{ An object of class \code{character} of length 10. } \usage{ weight_func(values = values_weight_func) values_weight_func } \arguments{ \item{values}{A character string of possible values. See \code{values_weight_func} in examples below.} } \description{ Kernel functions for distance weighting } \details{ This parameter is used in \code{parsnip:::nearest_neighbors()}. } \examples{ values_weight_func weight_func() } \keyword{datasets} dials/man/survival_link.Rd0000644000176200001440000000124614223270317015304 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_survival_link.R \docType{data} \name{survival_link} \alias{survival_link} \alias{values_survival_link} \title{Survival Model Link Function} \format{ An object of class \code{character} of length 3. } \usage{ survival_link(values = values_survival_link) values_survival_link } \arguments{ \item{values}{A character string of possible values. See \code{values_survival_link} in examples below.} } \description{ Survival Model Link Function } \details{ This parameter is used in \code{parsnip::set_engine('flexsurvspline')}. } \examples{ values_survival_link survival_link() } \keyword{datasets} dials/man/freq_cut.Rd0000644000176200001440000000203214565421125014222 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_nzv.R \name{freq_cut} \alias{freq_cut} \alias{unique_cut} \title{Near-zero variance parameters} \usage{ freq_cut(range = c(5, 25), trans = NULL) unique_cut(range = c(0, 100), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters control the specificity of the filter for near-zero variance parameters in \code{recipes::step_nzv()}. } \details{ Smaller values of \code{freq_cut()} and \code{unique_cut()} make the filter less sensitive. } \examples{ freq_cut() unique_cut() } dials/man/over_ratio.Rd0000644000176200001440000000212314565421125014564 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_over_ratio.R \name{over_ratio} \alias{over_ratio} \alias{under_ratio} \title{Parameters for class-imbalance sampling} \usage{ over_ratio(range = c(0.8, 1.2), trans = NULL) under_ratio(range = c(0.8, 1.2), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ For up- and down-sampling methods, these parameters control how much data are added or removed from the training set. } \details{ See \code{recipes::step_upsample()} and \code{recipes::step_downsample()} for the interpretation of these parameters. } \examples{ under_ratio() over_ratio() } dials/man/earth_parameters.Rd0000644000176200001440000000204414565421125015743 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_earth.R \name{max_num_terms} \alias{max_num_terms} \title{Parameters for possible engine parameters for earth models} \usage{ max_num_terms(range = c(20L, 200L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters are auxiliary to models that use the "earth" engine. They correspond to tuning parameters that would be specified using \code{set_engine("earth", ...)}. } \details{ To use these, check \code{?earth::earth} to see how they are used. } \examples{ max_num_terms() } dials/man/figures/0000755000176200001440000000000014410272032013560 5ustar liggesusersdials/man/figures/lifecycle-defunct.svg0000644000176200001440000000242414410310706017671 0ustar liggesusers lifecycle: defunct lifecycle defunct dials/man/figures/lifecycle-maturing.svg0000644000176200001440000000243014410310706020064 0ustar liggesusers lifecycle: maturing lifecycle maturing dials/man/figures/logo.png0000644000176200001440000007753014401664742015257 0ustar liggesusersPNG  IHDRޫhgAMA a cHRMz&u0`:pQ<bKGDtIMEW]~7IDATxWtdi߇ o@z4YY;IER$E|ѺAZ\}R")$~LttWw.U"w܇@DL$keUfDoC\m)j{@# povo;ioGqZLlt?<$!1[emkҋ G8$~!)k!pd^ %O_a8$~!҈+ 86yso!}H}Cd- 5b_D8$>@y_8$p#f-t@I8$p"p1p- pPC5 M{q9`8@yYWUIX^EDuFhBh{4⚀WܷMC'bhK5$;N$C |p6cx\>}/",͛ .  5\N[c%34緻!T- xxH!wYĭ BvUUQb7;Z9sݒ|f-U\=N]U1,ilNͺ(* \MgX|DBޮI8$nY6ʡMCʲD]U1WϷs ɘ"F$\%b]\<<lqWpH-6Nޒ"'ζqÖ3qW;N@0½Cܸ܂$C;4Z]*t:lrG+nTqW;?q^; "]Vw!d#d~a2?`& ^hAZa.ITTf~)v~0tw&V-௳ H@u8Zbr9W/8O{ǹ~Ʌ4#ؖ}([|8$E\][=NТO7sT.s'jq _=ga1lȡlq8$2?6\9FeYa"j_{jv/kp$]"'OC6pHM k=m hi/څv1nB oxDBٮPM8"_Vϩ9Vr\+aw}gp$Q"m?<$ȯ^H# >O'htgw׉] ra? b61Co-{46e~m5\=FM mݸwy3F$BO8-nCg!k| aY]+%jKv Lqxs7qo!~>-͒]bYge~WϷS__2Y*U" *ynlD"іja IJE(+q7;8^緻ܖlQ!jlq \G> v@WS6N`岚׳dR ~IEU>X,|kp-$5/*,\_NM'c|Ebs?Bd ZV*[Vϗ!;箇x"I0A֌1sKZ'Q~ \6Οldjv@EIb"K] \ɔbi;_ ;=DbqvŌb|Ki021ϒk]cIp95URSQL0c"m2"2[@3SuϛυYĭFDPO}Ös.TՓseE/e/˒$1<>˿/t"L&Z8^Os}9ӳKakJ(sAE` K!n? OPZ~*mtMD1kTUú'?#TQْ\{[HeYhKE}!H6 pt$Y~hr>}?rx1^3ێ$E|G$=$a6Z̴ԗsl ,'[[UR OvHgl Êd4ڥ$ 2g Gc6{4nǺǧ}{.$ bCM)x drmA&:C,s*20maVηsee~uC(P(*?~6]:_;5ITU%(Ȓ,yzW@ ˝8OTU&~ޅX%\$Qcބo|CXԟMpΎgY-?^Va:2?DgtyC1l8QϓQ‘OGytS*\>H ҾH6Qh*j܉ C=w7IjG_U%;[xhMul~smK^]Q&d~hƎJyIAQzlpY!HAAZ>uU%4ՕgOyэO$qԲIE5E%TH* ɤ">Kؒ,c`02,!!._T KDW3>T܌zqG0%Hf.vL*nA0d-F֓- p-kd~My(_= ?}VN%ǓlF֤' aa}!|0PP8F$'OO*(I%Yh4`6mv n ӆfb6fʕH4N2`61ξ 97^BUT1&>"'BǞelD{-׷/[4 %c❵d)!@VrwtrG]9I&} /s ¹鹥H$~f]bnϒ?D(#O#Ӈ%0$LF#6M -R ÚIa܉v m9֪r4kh%B7Vo)"wG-[l/V-^ø&[4šeqj~;&+t;x R|X.gC$$7ĸpξqvSmaN#Aik(3s>cz·?&O(+C K LFF` Kby (TT$B<$KnEQH$THHdRVR@]U1%T[0rj_=靚 ]{@% 'XiJH%[h[.+7B(Bf r%%Y-Z5T!ܵYefy;NEi![y=VL<06@yDqmihD7efNnuڭجf,fAFed͂oSq<$ ax}T0DM`1:i)ڪbN۪aDct$ˋ,"{{V͗s/{tO C-ƌ萿y r捪c-p~h 2$mյjl+řo)f|D5=*ޚMF\N+en (+ȅij*uO*Y:)GND"I83grvi/>|DB/ PR䢵c-TzZ)CN6#Ƨ#UmX"]!WU^vSZXfv--s!ߕs:Rfɻ}Z$i&).tPS i7  ¢/at0mſazx5.n8\Fn g#{%gcznp$F<~4HMSiH˹u"D'QXNX7ҷYu^f6nDoIW[Jj~N;O6ҙ['×z8E% ɶ~Ŝ T~uKb~k*/rʊ,T͇n,QQD,gpio*Xax\j:ʊ&/_'LL{9}}N2-A?wnCYVڨ KnDpNHP4cS4j%1[t/R4dJ\iXK5Ubɲ&c*-L,7AW >I%>q 'k9MW-1 ml4lIX![|jDŞ1sjJv}_OUUfDG¼Q^hm!vWԲd[ b}ٗO?D:G#l v:7pT%f㤢ɽCy}cʬ./#EGfg M* ^:Bcm)EsdZ+?(X&TR_,730I4gf/>~Ӟq^}m rйdd2p ,F( v+ho><$e{IEfME?/)q 'hc$IjJS1uk˻|`0X[ʕsm5V`ޥ-򩥴jjVNFg5a.lhڅ5 =0̼ZlVԼ ͼj;ܸ߷aUɜf!CgϮݓ"w QYV#u]|d*i|g)> sZHr3G\i;RI3$'$I$Z,&f}~(VieJ:`Z,K#1;=Yj1qX.SZ-փHTU%OE.|U`P8F4'H# dj6aq;9))rѴfQo׼Zv7Z+.mᕋE0҇Mg$|g GbCQy7g|C`I(.tb2œ|z@w_=iӑ[O>-У7_>і4@xZMߗoOӃ9/ɈfAeYuUTRvflWn~ֆ >)c^"8~i/zJOF{lz^0¯?{̝$"Fho~ā!0$ &Kp `oybw;ѳq~ۇL.& ~>n9lsIdEHFփSx<7wxARYZHs}9ue1Mlv/DJ:^Kuyɽ'CIz'YX WOq6c˲YȲ܂|g}㨪^=Εm[n|@ԋ9ҼeU@7ԖⰙ\ O23:9OEi!n{uWGYX "_;뗎tX62~RU FN>O{Ƙ%RrZ\%y)5HYփr ~y3h ՌjN٬H$v0 3^"8H)) ~[DzvrW/I-,,݃S Om(E<0GlY,g[h+Ql99R]T`{enb$F|x\kFI<g%rVGJ;_ȻY8CDKQ}^%HA[U<xm\=Fu'gC]b68>p$N[k)+)Xē3QGgRY`kD=j;jFKg[ۖkO}ξ @$gъ!S>7^~I$6EU1 9w7_>+/d{-8Ds;N BEI!mlJ, +feIw?I,؝h6Na6'œxL.Q_]ӱz|@Փ:k{Րӣ;7wx3*8Y:78FQU>љ5K;BS])ԉjN[RiCWӯ߇?a`dG]#̤Vn)͗PlF4UXPi//w"g9i+_=𾘁;TfsnK쿧p$?ϣPEoonϘՉtX9sv+۩`6W\saTr2dYf^NwR1Wb1Vޕ8%KjQh~ʱYMYqΫZH.:5ކ 87$cL/13#M`?c&ghU̷8KljƌmtIə%~=zO,X\NOnxx,/iȅe7Rm(>QTऽ9J}GgYM˶aY$u[Z`a)AZLW`3F,I-]~Iz OcS ~PTQWNҡ3g_}鹥KK8e4ʴ5Vp|;@"L˲D]U E=Vw$Lئs^?z9DZX=x_|H,g#V}Ԧ=ϝH47(.rc>ZB>%ܸߧe"X#M9J?$XAGv='}">~xBk̺P^WN֕㔗dtYO6Y:9Rb@0pޡ)$I³)ʋeYEebzL]UO~}B(ZXLN.0:9Os]Yj'[BXLFKykJRD NfM+w9~]O7)F#> $("ֹ|s5VftFlh0P]ᡭD2)ʒ.I f GbW` *5"8 $ S PIy`"/01HmU1W,+iPK,ǁ[BJ TGCM }9)TqP878ZL'h͗Ox-O)tR^m$U-4l3Pb8VW{x"Pʃap%~dot2U(-L^0Ÿ}pO3|$/@kCWp Ѱ\&d9CQT'+߽B6fWhPUoXLN?a7WOS]^"1H<L&HLxfhL_;꫋M}$9~yoqme+d$w:GS]Ynf?+7Y&9ʊ*w'vik O091CY,5ATJqf5h)}$" AFUU޺ruƍ/f`[Dg"Xb6pљY/;œȲmmp;U(?X*Jy8z,nE'WGz(no'M+ʞJq~=HF~ϭWՋG0$It30:,jVjJAEs#XUE"Vzsyo#Ukbpt#U|b;,*BOs\{N)٠AXbL<#TWiӿ,+dfX%T"ՅⳛV+H$LSS顸ȵ"pVUB;8ш$,cSk>[no_9J{7^?!yF:Non3NI> g Qe[]5E*Y@ PDX~&8YX 22!1VzdG`9`cxtOpحvveݲ&ra1/?yr&vyᑑh?!4ɒD W>IikMnRKG7A'VgUU).rR^R {F)/u35c~1d3p206@_=whdR^;nYغ鋻l}6ē|SF&WtIrg[rB ^:+W%IbbןV>뫊9wIX,wz V/MYx * YX G~Oo=hySof`o(-` =*QJ]鏕e)&()rr,m#~pF`d;}/۲EGx՗ޓ! 3q(u\9ז3-tN03ch|'=te,k߿F$ A,f# 54Ֆ+/BXoH=>2ʒ߭=o>##KN5Qq {dYbjv$ӿ,WNiKG,/M|핓{ eurblI4}@2䫇kf^DMh%t췼IU&XE,/IC Mwx<'71_1;5 [q됼;=UаeYT쵠jtO)/OzV,ӨzJ^5,$M%tQMTdEu:;y3wB; jwj+㕋GVwktPY 'DmEAȁ}_:Eʊݜle\+©,ٳo[cδ}ޞO7T;x25T^z6 ܯ8PR$Ɛ$Ggu{O\XA^muAmV3o\>F˾b;9ȝG91 \6O<"|b n>[-%IM!n}Y\c*Zk1+tAuUżt cOw j)'j(*p Csy+*{_.gĞX$|~Gݣ,,Q,oI;ΒVZR+,"\rv;UʲB^:ݼGY]ɜ wD"'G5N8q;kAD%HEUYx;΍b9/I{s7RRQ>d2PSS顩XF =O/07 s<^,k8Qgwjk 2;Z)dҼCl YrG+?bJ Ȣk'(-XȺd{-wbb۱*S 4 x}"煓M <@񸨀7v+%4֖X[JEieE.\Hb.l(X?}5ʼ7{˹m53.B[de0] %'7WWx;4RO6^;2=cpl&g#B Y9x^bO o_=AeY!3O{$I0@i,f#ŅN˸vH/hDUB$-Uج Xk4x ݺ!UUq,tTr"8=CS6q~!?Ze!vXkuF=gKSñ QR}BL-er}El^‘HPWj1{$ILeYl_YVHUyQ^(^thE;Invj1QWU @,`tr5%wtrdRh"d<:Dhmf5qbVEh %T%ñ^?֎`_wjv BEi*.D"dV2AL4Օa.#gSׂJEiv$ G7x I]  ,?㢼}3Jǵ¶!Ks>|u *JE@E_0-j!_ȞXOab& #Ա$$4CFi+ 1ϪqLmʢcPD(6X5Y&C D]Uq*HH$Y&] Yĝ iֹ*.S^>5~(%E +Z>o)e-q緻1ˁCc,C|ͳ 5WTV@ǥǛ}05,-/@Cx*%جfi{]̈[ %E.x"ɼ7@2&W3s>_1>f5H*".aVXyao@u4;xoAqUl7O6$^uuDcqgmTŲ+zG:q`#<街Pj|}e޼|Agh*g/{ສb~.n՗pt"&μ7l%i}Ռn <*B'6ގXV9U5P0dFukg[%:1GD G*9yB8'CnU;ؚ%IH4& Xf$Ib6a1JYl25#*[&-ƚĈƄib26,B$ҖN"KBdž{ IB ’?o2pڅ(H E>D#-D<8/H`n!@**"kZ5qP$v ?^ae6d \vzUy)0`  GY"ᕕ{P8?AηyA` .L\<Ռj^[+ePRN6p먨h12[L|AN*ѐtU $Q -e8[e`6t%U+({.FsFgۏPQ9um#Ѹ 6 i]ߞG?1 X-fr:Aj6a63QiÂHb/|ѵ-dptx"AqO#Tnw9&ggc4֔)M=ѷ0,EQD{%0MC9TL&f!3$ Yb0b6"I‹n-U5V"Ipa?p Bcm^7 "L.QVo T6Djl264b(J<;] ˌFh${%9&CjN?ABB%F&v7dֆ ${{uaW]t Lh>ݍ =^KB$I,ĠЎI?Q3ʈ"!ʬ(ɠGzLmG]#O{`a1HiW_:d*{NH*"lm!%E.:NmRʮс gNGzC7$U[1nL͔6?a~1 3Tx֭5[S 2mM9W[]^/GMElj*{EUS*b uaѺ#}+,ϚE1p $KҪᖉDrE8D~"T'd&);H}"D `DbURPS-g DB!uLFJr:g#oz4,/mԗs ~$-bJ% )qZPQq;mXa,HG]#$I!\7Dcq~#nMe[̧AMQ-#nm,X<5[-&B8tFqhXy4 >'Ip@0¢?w)w)Ȣ//&RWU߽ &lk Nӊ/Z."1EAv;ID4ן=Ȼ8KirX7 p,U MO_K"񧿾,vS$;,*pPvPrذXLFb$ n/3^|0PH4NJ'nTUEBbhl.&,!w* ]ڸF{o҃,Ju9$kJ3;4E4+_F>X$b=Zbu}W14Օn8`NOJu'#=جfTF'7PU*V&$)7+I/,?{>X`v|XAU㢪hCe,dd|5AII %ΠvCQM +{t$D$`$s2^_% v*J $NaDPB}u1H"rdbn6HS%V9M#7/ F`(ޱ #~Gֽ++Txpm@%p:dYJ-_.TWYMO&4,HZi"j*:'Lj$֋01\U^eTy¿74ERQ02ue Z>&gWZ6KIDyF_, fYX beZ+V,*5E:]bdbRRkwbD[-i*d2ɽCoΩA^$I"OpD"#xC$N`Y֯ , !!5ԔƦ晞[BUR;u<̼I(7U8<;K&rA?Dc L&#㇯PU]i%!Ff(QՋI^Hs%:[$14>K 'j2/6C?{*\>}%w; O-U10:BjhḊ21<K~EK HjʇeoM&#O67:"%O-%Ib| vG8A/~ HRQ'OۉTD뉶y{|H,BWGX,?T.3%I"OՃ~"Xf*[k(Ί_Dhsf BџzE6||8/01fEQxޱTAn3[xU6$I(J]u1eb3<>F e[qi'N4m7'C$ρĒvî{_UdSxa㚼K0O{ԬoьQPyoE+Ye H1B 8d]CԋuvϳqXpeY!gJ{aEQ^/3Kk,̑vfv$a S]l`9*PWUBmUIAvT55dYTq$QH$E.NkwTUh4pxp0Am q,f<̤ļ'_=#OKi#A[]L2f6=lҙ洌k[(ޓ!`'W%\$2[=C78P;HSm) %O-ob#:ϵb0쌏Gy9|Nk$f>ѢŮ=0W\i$K˂45e9{; =@FLFd[rş6Txot26=e$֗S|SĊos}'S'Ts'p96 Z7tN1<1aԼ&2 \v\Nk*2+Fye\Żj6m]gkjJ|eكCSwG@wͼy8Z1#}2 _ T7;hm(m&_ޓAQT4ߨHP:p;O`2)˂0Fw, mN5N@5.dh|_ ̒?D(32m4֔21 K"#8:3B*ҟoplΪI=okCE*FV]D?{ģQJ|k\W,3ZG1 ʖ8^6E v+WϷ+2|{v+ŅNzL/!25iI[h+UWs,BtNH*TB;ep$ƗzR)V6:R9Oq3Wowv7"mf- r̂X=l.;_>_=MEia7 ~,+$H2<>G"0:1)nDZ4חᰙ3Wbg<Bɲ>@'n [ۛxGLh.Kf;NƥcT6EFW=-$t0'}0:9\nevO$#7<"E \=T(?K]j9N0blҗW3^-smCzT7@0%(ha{NBeYz-UKvH疘_ Ęs&/ՖuW IE6-#Lלj-;yRʋ(/)X6$ CS|~YZ.q(ڞQ[顩b\,& 2ev I*'/d!Sn_aa6XSʵ m5Vb4io|ue2fqI ڻ ]@L GvW}}3oK8VڴJ/[QT vΝl'[cEMTS_S1n>g|j!rJA[/Cx}Aa).tRYVHUY!e%8l&#-g~quRO$ xP8Ƣ/̼E&g6"M1%X#餐e /id{mj2ٶj**bex<ؔ@(h$m(2h86î&c{<,Mue݋9; ϧ`p#-U<!Ƨ'ڳdGbN329,ILFV3NӆiZXLL,@3k,$ #a|0`p$F,~5F]Zg2*/NզD%kp;ԷDyGXc-6"G4718:K<_h;$n?!dYbohw[}YNdʥlgp  Gi57ۂ*xxE_05$-3Uk\[d2F̸G.I"P$%HPzVpC8R*GM``(g#$2y~[vL I+zq޷'H \4S&W rf6 hkxk EXͦSsl;l6b4th``dr>c$!a6ZL9V3wSyM`I]Ih-'-Z7FK* &2jJybyz'c K"kznلx 4TXAmU1n-~犪R]^_U _bxbno+,+ǟ1=P^N`t'N+p@p9lȨE.,I.m5o&0=< / D$-@D{ȭPHz-K.b7K()a`TJ|ZІ+٣e es:4QZQȤeMƔ9yrt"賚nUoD"I Ż`v̼K0ph,N<$(bOJY ,c2XL8lf.;ŅNJ=.J=n<vk.~l^zكqc#l(<P߯9I B2TTIxdŌbH H発j_yžzX,Tzݲg{U;6P\b6(*^_T!S4@['JIRizFUTYqM`LzcS ۟\ghlȹ m潾Clj.?ڿؘgZ!UΝlʹV3hĵ m=ސW-/ `,kFh4^&ȆF,IoE_Bc_ɲTR^=,CTa0e7 KM`Yp1tyiW%Ip`*#ub2W_:Jljnm@l2 EbXͦ(ƽUq ?%'7?8^b7DN0W_]PI7? J=nN]62sHD 7 G1d*K ()ȋYX$ (JWjeJR||}5ʗw{[^s"O-_Q(.T[``*3]H+ҩHw)ȟ}x9*J Db q6Y[rK wVE Yt=2q%I>M4+'?>' :^h`<ʇHģQ!KC{:{:ІtL,^uR Љĸq)^:̹)1!/"XFU8+C!FF(;A?ޥ@Fe9HҒ/xG<vTaRy@{OX(p8\"?Nh,Ӟ1aljAsl3k m/9gqKϪ8<>"G*v-|qUg*4T{߻"%TzɛH&Q"HH ? <~ #u g>z$Iw286K.mԳXz;Vz*[k!2}3>n~0Pde | 1}&b&o9N`(gVav4 $h@4#`D,V]e'W40eⓛϘ zJ^+t;ioʋ eedboX,iP(S+HiDV;k@ ?exwz`MmfLF#D@0J<'$ o]9NOهDIUIn3[QT`(J$#aLHj~>og_!s +cM?Y}6?~=fH'?7;ʹ6NnH"%p0$ON 5VYEb MqsLk!t[lV3M#1Nj,9`H21緻EUU17VT[s! _ WRіj^}ŅNE0G:8or90_ezާ[. d?\A Gֲzgc~-UUejv~pZXfK}yZOd%]ۛ"By+S Q2 -wewKg[(.rjw%%~"pG]4֔&RoyV(*pX[J4ϩ~@:q$=CS|~ms?:#Z6} ?r%( N221#\9JUYQJIA0~$Ic޹v#MU(i9gmm'_"Hnݡ!,Z/)͙cuL."021G8fms Tz۲bn{|K~6}Z;=<KU>70܈cSCcK\b eu4~zx l1pgRNh VLQT#UTxaRg}HDu@< G̛ 0B4n3op#%֣~n?d> &B?l:I?B8n̹R'ts|'l1>\bZjљm г}(n%H$,!%+{\TP^ƨ%{Wx8lT]q(09lk; kB^FVʬe4?!Kg3瓵?~6Fz2 i_% ~`1./JŽy’'̎Zdi/K!DDR!-UUED~lEUii($>g}|3|EX-,n] sGKWǎ~#B2PsdOl1uOZ\idgc 2Mr5EX&dm&\{^O<[m}}C<oh@( @ Ly;edo7:{S2$o 4y9UfZVDTgəE4Wq|[%D@H k w˜l隒D$(퍕_.WTUTԿZ[+Hx#UM-W]t#3^nݕBB+z,{`x|[2 g?E@W Iu{2n8].n?^de>Ǹvƽ-몊yD$&^0USDrI>љZn6_UqI; 'd((@0,Bz5hJUe`tD"JˎjޓwsG'~ξcn2$>quY?A쏷,[tMxzod:[+8^˝HϾfjJMQ'h_ L[c^F\R^R@Hn.u B9o|F  ڬ4qgޟ&Y<{+y=}4Vawm]X rAw?Edwձ2,\a~{g}飵vY*f`oxI]j1a2#qTU/rXt?.ɤb?W1,C,x$s'=bd tL2:9<Â,CT m]!oa׈-"d~9v {N`XU"yے-NlQdP:{'<2`8blXk5rJDD2"DY?}q_ wzc1gS2ʅSMv(?]FgI$C,oUER3K%I+xCvX[ؗ=4k6v-9ts'l#}dcYUd~ :\ oI",X%j+v/[7oe~eebfϥ2?xtr"74w!}"1R[x1{$[7?"_q(Ȏ>bWNjի@l[,W[ܞl&[tl1\^4_?ޥq{&lM[9_JX6lq/Nh4Γ1a|ja21D5}%-^"1wنld4Xɵ 4֔(boplV''߾wyȒ-rاA'f- L̯sXvG@gEY->бsejE-fa=>/{,!\[=fduU\=j̐Feia껍Eˣ}r5^[8$."-.ӗ>ۏve~2s(ux`e8Z%M,bqsN7c J[$Fɻ8$a ⏀͞kYhiE246tN^j~8) XEW[ܖḻz.w"Ip^; U e~yC dG%'[,t$D52C GZVװ,[j>P8$pb'-n2}C1vbe~wpH}4"jwpH}eu=˲Ūmz!9;x!Kxe٢sȊqC߾!)d X_! T?P淯qH}U-udC-/h5Cd[{Xky_qH,,o882W%tEXtdate:create2023-03-07T15:14:00+00:00#%tEXtdate:modify2023-03-07T15:14:00+00:00RS tEXtSoftwareAdobe ImageReadyqe<IENDB`dials/man/figures/lifecycle-archived.svg0000644000176200001440000000243014410310706020023 0ustar liggesusers lifecycle: archived lifecycle archived dials/man/figures/lifecycle-soft-deprecated.svg0000644000176200001440000000246614410310706021320 0ustar liggesusers lifecycle: soft-deprecated lifecycle soft-deprecated dials/man/figures/lifecycle-questioning.svg0000644000176200001440000000244414410310706020610 0ustar liggesusers lifecycle: questioning lifecycle questioning dials/man/figures/lifecycle-superseded.svg0000644000176200001440000000244014410310706020402 0ustar liggesusers lifecycle: superseded lifecycle superseded dials/man/figures/lifecycle-stable.svg0000644000176200001440000000247214410310706017516 0ustar liggesusers lifecycle: stable lifecycle stable dials/man/figures/lifecycle-experimental.svg0000644000176200001440000000245014410310706020735 0ustar liggesusers lifecycle: experimental lifecycle experimental dials/man/figures/lifecycle-deprecated.svg0000644000176200001440000000244014410310706020337 0ustar liggesusers lifecycle: deprecated lifecycle deprecated dials/man/mtry_prop.Rd0000644000176200001440000000412014565421125014445 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_mtry_prop.R \name{mtry_prop} \alias{mtry_prop} \title{Proportion of Randomly Selected Predictors} \usage{ mtry_prop(range = c(0.1, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \value{ A \code{dials} object with classes "quant_param" and "param". The \code{range} element of the object is always converted to a list with elements "lower" and "upper". } \description{ The proportion of predictors that will be randomly sampled at each split when creating tree models. } \section{Interpretation}{ \code{\link[=mtry_prop]{mtry_prop()}} is a variation on \code{\link[=mtry]{mtry()}} where the value is interpreted as the \emph{proportion} of predictors that will be randomly sampled at each split rather than the \emph{count}. This parameter is not intended for use in accommodating engines that take in this argument as a proportion; \code{mtry} is often a main model argument rather than an engine-specific argument, and thus should not have an engine-specific interface. When wrapping modeling engines that interpret \code{mtry} in its sense as a proportion, use the \code{\link[=mtry]{mtry()}} parameter in \code{parsnip::set_model_arg()} and process the passed argument in an internal wrapping function as \code{mtry / number_of_predictors}. In addition, introduce a logical argument \code{counts} to the wrapping function, defaulting to \code{TRUE}, that indicates whether to interpret the supplied argument as a count rather than a proportion. For an example implementation, see \code{parsnip::xgb_train()}. } \examples{ mtry_prop() } \seealso{ mtry, mtry_long } dials/man/reexports.Rd0000644000176200001440000000070014223270317014441 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/reexports.R \docType{import} \name{reexports} \alias{reexports} \alias{extract_parameter_dials} \title{Objects exported from other packages} \keyword{internal} \description{ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ \item{hardhat}{\code{\link[hardhat:hardhat-extract]{extract_parameter_dials}}} }} dials/man/initial_umap.Rd0000644000176200001440000000170214565615206015075 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_initial_umap.R \docType{data} \name{initial_umap} \alias{initial_umap} \alias{values_initial_umap} \title{Initialization method for UMAP} \format{ An object of class \code{character} of length 8. } \usage{ initial_umap(values = values_initial_umap) values_initial_umap } \arguments{ \item{values}{A character string of possible values. See \code{values_initial_umap} in examples below.} } \description{ This parameter is the type of initialization for the UMAP coordinates. Can be one of \code{"spectral"}, \code{"normlaplacian"}, \code{"random"}, \code{"lvrandom"}, \code{"laplacian"}, \code{"pca"}, \code{"spca"}, or \code{"agspectral"}. See \code{\link[uwot:umap]{uwot::umap()}} for more details. } \details{ This parameter is used in \code{recipes} via \code{\link[embed:step_umap]{embed::step_umap()}}. } \examples{ values_initial_umap initial_umap() } \keyword{datasets} dials/man/deg_free.Rd0000644000176200001440000000160114565421125014153 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_deg_free.R \name{deg_free} \alias{deg_free} \title{Degrees of freedom (integer)} \usage{ deg_free(range = c(1L, 5L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The number of degrees of freedom used for model parameters. } \details{ One context in which this parameter is used is spline basis functions. } \examples{ deg_free() } dials/man/predictor_prop.Rd0000644000176200001440000000165014565421125015452 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_predictor_prop.R \name{predictor_prop} \alias{predictor_prop} \title{Proportion of predictors} \usage{ predictor_prop(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The parameter is used in models where a parameter is the proportion of predictor variables. } \details{ \code{predictor_prop()} is used in \code{step_pls()}. } \examples{ predictor_prop() } dials/man/parameters.Rd0000644000176200001440000000126614223270317014561 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/parameters.R \name{parameters} \alias{parameters} \alias{parameters.default} \alias{parameters.param} \alias{parameters.list} \title{Information on tuning parameters within an object} \usage{ parameters(x, ...) \method{parameters}{default}(x, ...) \method{parameters}{param}(x, ...) \method{parameters}{list}(x, ...) } \arguments{ \item{x}{An object, such as a list of \code{param} objects or an actual \code{param} object.} \item{...}{Only used for the \code{param} method so that multiple \code{param} objects can be passed to the function.} } \description{ Information on tuning parameters within an object } dials/man/degree.Rd0000644000176200001440000000311514565421125013650 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_degree.R \name{degree} \alias{degree} \alias{degree_int} \alias{spline_degree} \alias{prod_degree} \title{Parameters for exponents} \usage{ degree(range = c(1, 3), trans = NULL) degree_int(range = c(1L, 3L), trans = NULL) spline_degree(range = c(1L, 10L), trans = NULL) prod_degree(range = c(1L, 2L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters help model cases where an exponent is of interest (e.g. \code{degree()} or \code{spline_degree()}) or a product is used (e.g. \code{prod_degree}). } \details{ \code{degree()} is helpful for parameters that are real number exponents (e.g. \code{x^degree}) whereas \code{degree_int()} is for cases where the exponent should be an integer. The difference between \code{degree_int()} and \code{spline_degree()} is the default ranges (which is based on the context of how/where they are used). \code{prod_degree()} is used by \code{parsnip::mars()} for the number of terms in interactions (and generates an integer). } \examples{ degree() degree_int() spline_degree() prod_degree() } dials/man/threshold.Rd0000644000176200001440000000162714565421125014417 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_threshold.R \name{threshold} \alias{threshold} \title{General thresholding parameter} \usage{ threshold(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ In a number of cases, there are arguments that are threshold values for data falling between zero and one. For example, \code{recipes::step_other()} and so on. } \examples{ threshold() } dials/man/penalty.Rd0000644000176200001440000000201014565421125014062 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_penalty.R \name{penalty} \alias{penalty} \title{Amount of regularization/penalization} \usage{ penalty(range = c(-10, 0), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ A numeric parameter function representing the amount of penalties (e.g. L1, L2, etc) in regularized models. } \details{ This parameter is used for regularized or penalized models such as \code{parsnip::linear_reg()}, \code{parsnip::logistic_reg()}, and others. } \examples{ penalty() } dials/man/bart-param.Rd0000644000176200001440000000237314565421125014450 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_bart.R \name{bart-param} \alias{bart-param} \alias{prior_terminal_node_coef} \alias{prior_terminal_node_expo} \alias{prior_outcome_range} \title{Parameters for BART models These parameters are used for constructing Bayesian adaptive regression tree (BART) models.} \usage{ prior_terminal_node_coef(range = c(0, 1), trans = NULL) prior_terminal_node_expo(range = c(1, 3), trans = NULL) prior_outcome_range(range = c(0, 5), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Parameters for BART models These parameters are used for constructing Bayesian adaptive regression tree (BART) models. } \details{ These parameters are often used with Bayesian adaptive regression trees (BART) via \code{parsnip::bart()}. } dials/man/trees.Rd0000644000176200001440000000544114565421125013543 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_trees.R \name{trees} \alias{trees} \alias{min_n} \alias{sample_size} \alias{sample_prop} \alias{loss_reduction} \alias{tree_depth} \alias{prune} \alias{cost_complexity} \title{Parameter functions related to tree- and rule-based models.} \usage{ trees(range = c(1L, 2000L), trans = NULL) min_n(range = c(2L, 40L), trans = NULL) sample_size(range = c(unknown(), unknown()), trans = NULL) sample_prop(range = c(1/10, 1), trans = NULL) loss_reduction(range = c(-10, 1.5), trans = transform_log10()) tree_depth(range = c(1L, 15L), trans = NULL) prune(values = c(TRUE, FALSE)) cost_complexity(range = c(-10, -1), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{A vector of possible values (\code{TRUE} or \code{FALSE}).} } \description{ These are parameter generating functions that can be used for modeling, especially in conjunction with the \pkg{parsnip} package. } \details{ These functions generate parameters that are useful when the model is based on trees or rules. \itemize{ \item \code{trees()}: The number of trees contained in a random forest or boosted ensemble. In the latter case, this is equal to the number of boosting iterations. (See \code{parsnip::rand_forest()} and \code{parsnip::boost_tree()}). \item \code{min_n()}: The minimum number of data points in a node that is required for the node to be split further. (See \code{parsnip::rand_forest()} and \code{parsnip::boost_tree()}). \item \code{sample_size()}: The size of the data set used for modeling within an iteration of the modeling algorithm, such as stochastic gradient boosting. (See \code{parsnip::boost_tree()}). \item \code{sample_prop()}: The same as \code{sample_size()} but as a proportion of the total sample. \item \code{loss_reduction()}: The reduction in the loss function required to split further. (See \code{parsnip::boost_tree()}). This corresponds to \code{gamma} in \pkg{xgboost}. \item \code{tree_depth()}: The maximum depth of the tree (i.e. number of splits). (See \code{parsnip::boost_tree()}). \item \code{prune()}: A logical for whether a tree or set of rules should be pruned. \item \code{cost_complexity()}: The cost-complexity parameter in classical CART models. } } \examples{ trees() min_n() sample_size() loss_reduction() tree_depth() prune() cost_complexity() } dials/man/grid_max_entropy.Rd0000644000176200001440000001176414565421125016000 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/space_filling.R \name{grid_max_entropy} \alias{grid_max_entropy} \alias{grid_max_entropy.parameters} \alias{grid_max_entropy.list} \alias{grid_max_entropy.param} \alias{grid_max_entropy.workflow} \alias{grid_latin_hypercube} \alias{grid_latin_hypercube.parameters} \alias{grid_latin_hypercube.list} \alias{grid_latin_hypercube.param} \alias{grid_latin_hypercube.workflow} \title{Space-filling parameter grids} \usage{ grid_max_entropy( x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000 ) \method{grid_max_entropy}{parameters}( x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000 ) \method{grid_max_entropy}{list}( x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000 ) \method{grid_max_entropy}{param}( x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000 ) \method{grid_max_entropy}{workflow}( x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000 ) grid_latin_hypercube(x, ..., size = 3, original = TRUE) \method{grid_latin_hypercube}{parameters}(x, ..., size = 3, original = TRUE) \method{grid_latin_hypercube}{list}(x, ..., size = 3, original = TRUE) \method{grid_latin_hypercube}{param}(x, ..., size = 3, original = TRUE) \method{grid_latin_hypercube}{workflow}(x, ..., size = 3, original = TRUE) } \arguments{ \item{x}{A \code{param} object, list, or \code{parameters}.} \item{...}{One or more \code{param} objects (such as \code{\link[=mtry]{mtry()}} or \code{\link[=penalty]{penalty()}}). None of the objects can have \code{unknown()} values in the parameter ranges or values.} \item{size}{A single integer for the total number of parameter value combinations returned. If duplicate combinations are generated from this size, the smaller, unique set is returned.} \item{original}{A logical: should the parameters be in the original units or in the transformed space (if any)?} \item{variogram_range}{A numeric value greater than zero. Larger values reduce the likelihood of empty regions in the parameter space.} \item{iter}{An integer for the maximum number of iterations used to find a good design.} } \description{ Experimental designs for computer experiments are used to construct parameter grids that try to cover the parameter space such that any portion of the space has an observed combination that is not too far from it. } \details{ The types of designs supported here are latin hypercube designs and designs that attempt to maximize the determinant of the spatial correlation matrix between coordinates. Both designs use random sampling of points in the parameter space. Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in \code{dials}. For example: \if{html}{\out{
}}\preformatted{mixture() }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## Proportion of Lasso Penalty (quantitative) ## Range: [0, 1] }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{set.seed(283) mix_grid_1 <- grid_latin_hypercube(mixture(), size = 1000) range(mix_grid_1$mixture) }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## [1] 0.0001530482 0.9999530388 }\if{html}{\out{
}} However, in some cases, the \code{parsnip} and \code{recipe} packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a \code{parameters} object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the \code{mixture} argument above is different for \code{glmnet} models: \if{html}{\out{
}}\preformatted{library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) \%>\% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_latin_hypercube(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) }\if{html}{\out{
}} \if{html}{\out{
}}\preformatted{## [1] 0.0501454 0.9999554 }\if{html}{\out{
}} } \examples{ grid_max_entropy( hidden_units(), penalty(), epochs(), activation(), learn_rate(c(0, 1), trans = scales::transform_log()), size = 10, original = FALSE ) grid_latin_hypercube(penalty(), mixture(), original = TRUE) } \references{ Sacks, Jerome & Welch, William & J. Mitchell, Toby, and Wynn, Henry. (1989). Design and analysis of computer experiments. With comments and a rejoinder by the authors. Statistical Science. 4. 10.1214/ss/1177012413. Santner, Thomas, Williams, Brian, and Notz, William. (2003). The Design and Analysis of Computer Experiments. Springer. Dupuy, D., Helbert, C., and Franco, J. (2015). DiceDesign and DiceEval: Two R packages for design and analysis of computer experiments. Journal of Statistical Software, 65(11) } dials/man/min_dist.Rd0000644000176200001440000000151114565421125014221 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_min_dist.R \name{min_dist} \alias{min_dist} \title{Parameter for the effective minimum distance between embedded points} \usage{ min_dist(range = c(-4, 0), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{embed::step_umap()}. } \examples{ min_dist() } dials/man/range_validate.Rd0000644000176200001440000000301614563660313015364 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/aaa_ranges.R \name{range_validate} \alias{range_validate} \alias{range_get} \alias{range_set} \title{Tools for working with parameter ranges} \usage{ range_validate(object, range, ukn_ok = TRUE, ..., call = caller_env()) range_get(object, original = TRUE) range_set(object, range) } \arguments{ \item{object}{An object with class \code{quant_param}.} \item{range}{A two-element numeric vector or list (including \code{Inf}). Values can include \code{unknown()} when \code{ukn_ok = TRUE}.} \item{ukn_ok}{A single logical for whether \code{unknown()} is an acceptable value.} \item{...}{These dots are for future extensions and must be empty.} \item{call}{The call passed on to \code{\link[rlang:abort]{rlang::abort()}}.} \item{original}{A single logical. Should the range values be in the natural units (\code{TRUE}) or in the transformed space (\code{FALSE}, if applicable)?} } \value{ \code{range_validate()} returns the new range if it passes the validation process (and throws an error otherwise). \code{range_get()} returns the current range of the object. \code{range_set()} returns an updated version of the parameter object with a new range. } \description{ Setters, getters, and validators for parameter ranges. } \examples{ library(dplyr) my_lambda <- penalty() \%>\% value_set(-4:-1) try( range_validate(my_lambda, c(-10, NA)), silent = TRUE ) \%>\% print() range_get(my_lambda) my_lambda \%>\% range_set(c(-10, 2)) \%>\% range_get() } dials/man/target_weight.Rd0000644000176200001440000000227614565615206015266 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_target_weight.R \name{target_weight} \alias{target_weight} \title{Amount of supervision parameter} \usage{ target_weight(range = c(0, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ For \code{\link[uwot:umap]{uwot::umap()}} and \code{\link[embed:step_umap]{embed::step_umap()}}, this is a weighting factor between data topology and target topology. A value of 0.0 weights entirely on data, a value of 1.0 weights entirely on target. The default of 0.5 balances the weighting equally between data and target. } \details{ This parameter is used in \code{recipes} via \code{\link[embed:step_umap]{embed::step_umap()}}. } \examples{ target_weight() } dials/man/select_features.Rd0000644000176200001440000000063314153712300015563 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_select_features.R \name{select_features} \alias{select_features} \title{Parameter to enable feature selection} \usage{ select_features(values = c(TRUE, FALSE)) } \arguments{ \item{values}{A vector of possible values (TRUE or FALSE).} } \description{ Used in \code{parsnip::gen_additive_mod()}. } \examples{ select_features() } dials/man/cubist_parameters.Rd0000644000176200001440000000242714565421125016136 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_cubist.R \name{extrapolation} \alias{extrapolation} \alias{unbiased_rules} \alias{max_rules} \title{Parameters for possible engine parameters for Cubist} \usage{ extrapolation(range = c(1, 110), trans = NULL) unbiased_rules(values = c(TRUE, FALSE)) max_rules(range = c(1L, 100L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{For \code{unbiased_rules()}, either \code{TRUE} or \code{FALSE}.} } \description{ These parameters are auxiliary to models that use the "Cubist" engine. They correspond to tuning parameters that would be specified using \code{set_engine("Cubist0", ...)}. } \details{ To use these, check \code{?Cubist::cubistControl} to see how they are used. } \examples{ extrapolation() unbiased_rules() max_rules() } dials/man/scheduler-param.Rd0000644000176200001440000000443414565421125015476 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_schedulers.R \docType{data} \name{scheduler-param} \alias{scheduler-param} \alias{rate_initial} \alias{rate_largest} \alias{rate_reduction} \alias{rate_steps} \alias{rate_step_size} \alias{rate_decay} \alias{rate_schedule} \alias{values_scheduler} \title{Parameters for neural network learning rate schedulers These parameters are used for constructing neural network models.} \format{ An object of class \code{character} of length 5. } \usage{ rate_initial(range = c(-3, -1), trans = transform_log10()) rate_largest(range = c(-1, -1/2), trans = transform_log10()) rate_reduction(range = c(1/5, 1), trans = NULL) rate_steps(range = c(2, 10), trans = NULL) rate_step_size(range = c(2, 20), trans = NULL) rate_decay(range = c(0, 2), trans = NULL) rate_schedule(values = values_scheduler) values_scheduler } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{A character string of possible values. See \code{values_scheduler} in examples below.} } \description{ Parameters for neural network learning rate schedulers These parameters are used for constructing neural network models. } \details{ These parameters are often used with neural networks via \code{parsnip::mlp(engine = "brulee")}. The details for how the \pkg{brulee} schedulers change the rates: \itemize{ \item \code{schedule_decay_time()}: \eqn{rate(epoch) = initial/(1 + decay \times epoch)} \item \code{schedule_decay_expo()}: \eqn{rate(epoch) = initial\exp(-decay \times epoch)} \item \code{schedule_step()}: \eqn{rate(epoch) = initial \times reduction^{floor(epoch / steps)}} \item \code{schedule_cyclic()}: \eqn{cycle = floor( 1 + (epoch / 2 / step size) )}, \eqn{x = abs( ( epoch / step size ) - ( 2 * cycle) + 1 )}, and \eqn{rate(epoch) = initial + ( largest - initial ) * \max( 0, 1 - x)} } } \keyword{datasets} dials/man/num_breaks.Rd0000644000176200001440000000151614565421125014546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_breaks.R \name{num_breaks} \alias{num_breaks} \title{Number of cut-points for binning} \usage{ num_breaks(range = c(2L, 10L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ This parameter controls how many bins are used when discretizing predictors. } \examples{ num_breaks() } dials/man/activation.Rd0000644000176200001440000000130214223270317014546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_activation.R \docType{data} \name{activation} \alias{activation} \alias{values_activation} \title{Activation functions between network layers} \format{ An object of class \code{character} of length 5. } \usage{ activation(values = values_activation) values_activation } \arguments{ \item{values}{A character string of possible values. See \code{values_activation} in examples below.} } \description{ Activation functions between network layers } \details{ This parameter is used in \code{parsnip} models for neural networks such as \code{parsnip:::mlp()}. } \examples{ values_activation activation() } \keyword{datasets} dials/man/new-param.Rd0000644000176200001440000000732614563660313014316 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/constructors.R \name{new-param} \alias{new-param} \alias{new_quant_param} \alias{new_qual_param} \title{Tools for creating new parameter objects} \usage{ new_quant_param( type = c("double", "integer"), range = NULL, inclusive = NULL, default = deprecated(), trans = NULL, values = NULL, label = NULL, finalize = NULL, ..., call = caller_env() ) new_qual_param( type = c("character", "logical"), values, default = deprecated(), label = NULL, finalize = NULL, ..., call = caller_env() ) } \arguments{ \item{type}{A single character value. For quantitative parameters, valid choices are \code{"double"} and \code{"integer"} while for qualitative factors they are \code{"character"} and \code{"logical"}.} \item{range}{A two-element vector with the smallest or largest possible values, respectively. If these cannot be set when the parameter is defined, the \code{unknown()} function can be used. If a transformation is specified, these values should be in the \emph{transformed units}. If \code{values} is supplied, and \code{range} is \code{NULL}, \code{range} will be set to \code{range(values)}.} \item{inclusive}{A two-element logical vector for whether the range values should be inclusive or exclusive. If \code{values} is supplied, and \code{inclusive} is \code{NULL}, \code{inclusive} will be set to \code{c(TRUE, TRUE)}.} \item{default}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} No longer used. If a value is supplied, it will be ignored and a warning will be thrown.} \item{trans}{A \code{trans} object from the \pkg{scales} package, such as \code{\link[scales:transform_log]{scales::transform_log()}} or \code{\link[scales:transform_reciprocal]{scales::transform_reciprocal()}}. Create custom transforms with \code{\link[scales:new_transform]{scales::new_transform()}}.} \item{values}{A vector of possible values that is required when \code{type} is \code{"character"} or \code{"logical"} but optional otherwise. For quantitative parameters, this can be used as an alternative to \code{range} and \code{inclusive}. If set, these will be used by \code{\link[=value_seq]{value_seq()}} and \code{\link[=value_sample]{value_sample()}}.} \item{label}{An optional named character string that can be used for printing and plotting. The name should match the object name (e.g. \code{"mtry"}, \code{"neighbors"}, etc.)} \item{finalize}{A function that can be used to set the data-specific values of a parameter (such as the \code{range}).} \item{...}{These dots are for future extensions and must be empty.} \item{call}{The call passed on to \code{\link[rlang:abort]{rlang::abort()}}.} } \value{ An object of class \code{"param"} with the primary class being either \code{"quant_param"} or \code{"qual_param"}. The \code{range} element of the object is always converted to a list with elements \code{"lower"} and \code{"upper"}. } \description{ These functions are used to construct new parameter objects. Generally, these functions are called from higher level parameter generating functions like \code{\link[=mtry]{mtry()}}. } \examples{ # Create a function that generates a quantitative parameter # corresponding to the number of subgroups. num_subgroups <- function(range = c(1L, 20L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_subgroups = "# Subgroups"), finalize = NULL ) } num_subgroups() num_subgroups(range = c(3L, 5L)) # Custom parameters instantly have access # to sequence generating functions value_seq(num_subgroups(), 5) } dials/man/lightgbm_parameters.Rd0000644000176200001440000000227114565421125016437 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_lightgbm.R \name{num_leaves} \alias{num_leaves} \title{Possible engine parameters for lightbgm} \usage{ num_leaves(range = c(5, 100), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ These parameters are auxiliary to tree-based models that use the "lightgbm" engine. They correspond to tuning parameters that would be specified using \code{set_engine("lightgbm", ...)}. } \details{ "lightbgm" is an available engine in the parsnip extension package \href{https://bonsai.tidymodels.org/}{bonsai} For more information, see the \href{https://lightgbm.readthedocs.io/en/latest/Parameters.html}{lightgbm webpage}. } \examples{ num_leaves() } dials/man/dials-package.Rd0000644000176200001440000000337514401664742015115 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/dials-package.R \docType{package} \name{dials-package} \alias{dials} \alias{dials-package} \title{dials: Tools for working with tuning parameters} \description{ \code{dials} provides a framework for defining, creating, and managing tuning parameters for modeling. It contains functions to create tuning parameter objects (e.g. \code{mtry()} or \code{penalty()}) and others for creating tuning grids (e.g. \code{grid_regular()}). There are also functions for generating random values or specifying a transformation of the parameters. } \examples{ # Suppose we were tuning a linear regression model that was fit with glmnet # and there was a predictor that used a spline basis function to enable a # nonlinear fit. We can use `penalty()` and `mixture()` for the glmnet parts # and `deg_free()` for the spline. # A full 3^3 factorial design where the regularization parameter is on # the log scale: simple_set <- grid_regular(penalty(), mixture(), deg_free(), levels = 3) simple_set # A random grid of 5 combinations set.seed(362) random_set <- grid_random(penalty(), mixture(), deg_free(), size = 5) random_set # A small space-filling design based on experimental design methods: design_set <- grid_max_entropy(penalty(), mixture(), deg_free(), size = 5) design_set } \seealso{ Useful links: \itemize{ \item \url{https://dials.tidymodels.org} \item \url{https://github.com/tidymodels/dials} \item Report bugs at \url{https://github.com/tidymodels/dials/issues} } } \author{ \strong{Maintainer}: Hannah Frick \email{hannah@posit.co} Authors: \itemize{ \item Max Kuhn \email{max@posit.co} } Other contributors: \itemize{ \item Posit Software, PBC [copyright holder, funder] } } \keyword{internal} dials/man/ranger_parameters.Rd0000644000176200001440000000433714565421125016125 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_engine_ranger.R \docType{data} \name{regularization_factor} \alias{regularization_factor} \alias{regularize_depth} \alias{significance_threshold} \alias{lower_quantile} \alias{splitting_rule} \alias{ranger_class_rules} \alias{ranger_reg_rules} \alias{ranger_split_rules} \alias{num_random_splits} \title{Parameters for possible engine parameters for ranger} \format{ An object of class \code{character} of length 4. An object of class \code{character} of length 3. An object of class \code{character} of length 7. } \usage{ regularization_factor(range = c(0, 1), trans = NULL) regularize_depth(values = c(TRUE, FALSE)) significance_threshold(range = c(-10, 0), trans = transform_log10()) lower_quantile(range = c(0, 1), trans = NULL) splitting_rule(values = ranger_split_rules) ranger_class_rules ranger_reg_rules ranger_split_rules num_random_splits(range = c(1L, 15L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} \item{values}{For \code{splitting_rule()}, a character string of possible values. See \code{ranger_split_rules}, \code{ranger_class_rules}, and \code{ranger_reg_rules} for appropriate values. For \code{regularize_depth()}, either \code{TRUE} or \code{FALSE}.} } \description{ These parameters are auxiliary to random forest models that use the "ranger" engine. They correspond to tuning parameters that would be specified using \code{set_engine("ranger", ...)}. } \details{ To use these, check \code{?ranger::ranger} to see how they are used. Some are conditional on others. For example, \code{significance_threshold()}, \code{num_random_splits()}, and others are only used when \code{splitting_rule = "extratrees"}. } \examples{ regularization_factor() regularize_depth() } \keyword{datasets} dials/man/weight.Rd0000644000176200001440000000150614565421125013706 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_weight.R \name{weight} \alias{weight} \title{Parameter for \code{"double normalization"} when creating token counts} \usage{ weight(range = c(-10, 0), trans = transform_log10()) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{textrecipes::step_tf()}. } \examples{ weight() } dials/man/dist_power.Rd0000644000176200001440000000174014565421125014576 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_dist_power.R \name{dist_power} \alias{dist_power} \title{Minkowski distance parameter} \usage{ dist_power(range = c(1, 2), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{parsnip::nearest_neighbor()}. } \details{ This parameter controls how distances are calculated. For example, \code{dist_power = 1} corresponds to Manhattan distance while \code{dist_power = 2} is Euclidean distance. } \examples{ dist_power() } dials/man/token.Rd0000644000176200001440000000105414153712300013524 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_token.R \docType{data} \name{token} \alias{token} \alias{values_token} \title{Token types} \format{ An object of class \code{character} of length 12. } \usage{ token(values = values_token) values_token } \arguments{ \item{values}{A character string of possible values. See \code{values_token} in examples below.} } \description{ Token types } \details{ This parameter is used in \code{textrecipes::step_tokenize()}. } \examples{ values_token token() } \keyword{datasets} dials/man/neighbors.Rd0000644000176200001440000000205014565421125014372 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_neighbors.R \name{neighbors} \alias{neighbors} \title{Number of neighbors} \usage{ neighbors(range = c(1L, 10L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ The number of neighbors is used for models (\code{parsnip::nearest_neighbor()}), imputation (\code{recipes::step_impute_knn()}), and dimension reduction (\code{recipes::step_isomap()}). } \details{ A static range is used but a broader range should be used if the data set is large or more neighbors are required. } \examples{ neighbors() } dials/man/rmd/0000755000176200001440000000000014223270317012704 5ustar liggesusersdials/man/rmd/sfd_notes.md0000644000176200001440000000217014223270317015212 0ustar liggesusers Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in `dials`. For example: ```r mixture() ``` ``` ## Proportion of Lasso Penalty (quantitative) ## Range: [0, 1] ``` ```r set.seed(283) mix_grid_1 <- grid_latin_hypercube(mixture(), size = 1000) range(mix_grid_1$mixture) ``` ``` ## [1] 0.0001530482 0.9999530388 ``` However, in some cases, the `parsnip` and `recipe` packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a `parameters` object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the `mixture` argument above is different for `glmnet` models: ```r library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) %>% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_latin_hypercube(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) ``` ``` ## [1] 0.0501454 0.9999554 ``` dials/man/rmd/rand_notes.md0000644000176200001440000000214714223270317015366 0ustar liggesusers Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in `dials`. For example: ```r mixture() ``` ``` ## Proportion of Lasso Penalty (quantitative) ## Range: [0, 1] ``` ```r set.seed(283) mix_grid_1 <- grid_random(mixture(), size = 1000) range(mix_grid_1$mixture) ``` ``` ## [1] 0.001490161 0.999741096 ``` However, in some cases, the `parsnip` and `recipe` packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a `parameters` object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the `mixture` argument above is different for `glmnet` models: ```r library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) %>% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_random(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) ``` ``` ## [1] 0.05141565 0.99975404 ``` dials/man/rmd/rand_notes.Rmd0000644000176200001440000000204214223270317015502 0ustar liggesusers```{r rsetup, include = FALSE} library(tidymodels) ``` Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in `dials`. For example: ```{r rand-from-dials} mixture() set.seed(283) mix_grid_1 <- grid_random(mixture(), size = 1000) range(mix_grid_1$mixture) ``` However, in some cases, the `parsnip` and `recipe` packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a `parameters` object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the `mixture` argument above is different for `glmnet` models: ```{r rand-from-parsnip} library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) %>% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_random(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) ``` dials/man/rmd/sfd_notes.Rmd0000644000176200001440000000206114223270317015333 0ustar liggesusers```{r rsetup, include = FALSE} library(tidymodels) ``` Note that there may a difference in grids depending on how the function is called. If the call uses the parameter objects directly the possible ranges come from the objects in `dials`. For example: ```{r sfd-from-dials} mixture() set.seed(283) mix_grid_1 <- grid_latin_hypercube(mixture(), size = 1000) range(mix_grid_1$mixture) ``` However, in some cases, the `parsnip` and `recipe` packages overrides the default ranges for specific models and preprocessing steps. If the grid function uses a `parameters` object created from a model or recipe, the ranges may have different defaults (specific to those models). Using the example above, the `mixture` argument above is different for `glmnet` models: ```{r sfd-from-parsnip} library(parsnip) library(tune) # When used with glmnet, the range is [0.05, 1.00] glmn_mod <- linear_reg(mixture = tune()) %>% set_engine("glmnet") set.seed(283) mix_grid_2 <- grid_latin_hypercube(extract_parameter_set_dials(glmn_mod), size = 1000) range(mix_grid_2$mixture) ``` dials/man/surv_dist.Rd0000644000176200001440000000121414223270317014431 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_surv_dist.R \docType{data} \name{surv_dist} \alias{surv_dist} \alias{values_surv_dist} \title{Parametric distributions for censored data} \format{ An object of class \code{character} of length 6. } \usage{ surv_dist(values = values_surv_dist) values_surv_dist } \arguments{ \item{values}{A character string of possible values. See \code{values_surv_dist} in examples below.} } \description{ Parametric distributions for censored data } \details{ This parameter is used in \code{parsnip::survival_reg()}. } \examples{ values_surv_dist surv_dist() } \keyword{datasets} dials/man/harmonic_frequency.Rd0000644000176200001440000000150414565421125016276 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_harmonic_frequency.R \name{harmonic_frequency} \alias{harmonic_frequency} \title{Harmonic Frequency} \usage{ harmonic_frequency(range = c(0.01, 1), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{recipes::step_harmonic()}. } \examples{ harmonic_frequency() } dials/man/num_tokens.Rd0000644000176200001440000000147014565421125014601 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_num_tokens.R \name{num_tokens} \alias{num_tokens} \title{Parameter to determine number of tokens in ngram} \usage{ num_tokens(range = c(1, 3), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Used in \code{textrecipes::step_ngram()}. } \examples{ num_tokens() } dials/man/min_unique.Rd0000644000176200001440000000154514565421125014573 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/param_min_unique.R \name{min_unique} \alias{min_unique} \title{Number of unique values for pre-processing} \usage{ min_unique(range = c(5L, 15L), trans = NULL) } \arguments{ \item{range}{A two-element vector holding the \emph{defaults} for the smallest and largest possible values, respectively. If a transformation is specified, these values should be in the \emph{transformed units}.} \item{trans}{A \code{trans} object from the \code{scales} package, such as \code{scales::transform_log10()} or \code{scales::transform_reciprocal()}. If not provided, the default is used which matches the units used in \code{range}. If no transformation, \code{NULL}.} } \description{ Some pre-processing parameters require a minimum number of unique data points to proceed. } \examples{ min_unique() } dials/man/encode_unit.Rd0000644000176200001440000000174114565412260014714 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/encode_unit.R \name{encode_unit} \alias{encode_unit} \alias{encode_unit.quant_param} \alias{encode_unit.qual_param} \title{Class for converting parameter values back and forth to the unit range} \usage{ encode_unit(x, value, direction, ...) \method{encode_unit}{quant_param}(x, value, direction, original = TRUE, ...) \method{encode_unit}{qual_param}(x, value, direction, ...) } \arguments{ \item{x}{A \code{param} object.} \item{value}{The original values should be either numeric or character. When converting back, these should be on \code{[0, 1]}.} \item{direction}{Either "forward" (to \code{[0, 1]}) or "backward".} \item{original}{A logical; should the values be transformed into their natural units.} } \value{ A vector of values. } \description{ Class for converting parameter values back and forth to the unit range } \details{ For integer parameters, the encoding can be lossy. } \keyword{internal} dials/DESCRIPTION0000644000176200001440000000254614565635766013112 0ustar liggesusersPackage: dials Title: Tools for Creating Tuning Parameter Values Version: 1.2.1 Authors@R: c( person("Max", "Kuhn", , "max@posit.co", role = "aut"), person("Hannah", "Frick", , "hannah@posit.co", role = c("aut", "cre")), person(given = "Posit Software, PBC", role = c("cph", "fnd")) ) Description: Many models contain tuning parameters (i.e. parameters that cannot be directly estimated from the data). These tools can be used to define objects for creating, simulating, or validating values for such parameters. License: MIT + file LICENSE URL: https://dials.tidymodels.org, https://github.com/tidymodels/dials BugReports: https://github.com/tidymodels/dials/issues Depends: R (>= 3.4), scales (>= 1.3.0) Imports: cli, DiceDesign, dplyr (>= 0.8.5), glue, hardhat (>= 1.1.0), lifecycle, pillar, purrr, rlang (>= 1.1.0), tibble, utils, vctrs (>= 0.3.8), withr Suggests: covr, kernlab, knitr, rmarkdown, rpart, testthat (>= 3.1.9), xml2 VignetteBuilder: knitr ByteCompile: true Config/testthat/edition: 3 Config/Needs/website: tidyverse/tidytemplate Encoding: UTF-8 RoxygenNote: 7.3.1 NeedsCompilation: no Packaged: 2024-02-22 11:45:34 UTC; hannah Author: Max Kuhn [aut], Hannah Frick [aut, cre], Posit Software, PBC [cph, fnd] Maintainer: Hannah Frick Repository: CRAN Date/Publication: 2024-02-22 12:20:06 UTC dials/build/0000755000176200001440000000000014565631734012463 5ustar liggesusersdials/build/vignette.rds0000644000176200001440000000032614565631734015023 0ustar liggesusersmP0 cp7<OAx!DLY` 擋av]GaDl q@"ȃ+8mUy%*^k?VL1h)U%;6QOxH[@l1z7J{90Έ! lsi3,g{i>Lb.z]*qo.lͺdials/tests/0000755000176200001440000000000014153712300012504 5ustar liggesusersdials/tests/testthat/0000755000176200001440000000000014565635766014377 5ustar liggesusersdials/tests/testthat/test-compat-vctrs-helpers-parameters.R0000644000176200001440000000525714223270317023705 0ustar liggesusers# ------------------------------------------------------------------------------ # tib_upcast() test_that("parameters can be upcast to a tibble", { x <- parameters(penalty()) expect_s3_class_bare_tibble(tib_upcast(x)) }) test_that("upcasting drops extra attributes", { x <- parameters(penalty()) attr(x, "foo") <- "bar" x <- tib_upcast(x) expect_identical(attr(x, "foo"), NULL) }) # ------------------------------------------------------------------------------ # parameters_reconstructable() test_that("identical parameters are reconstructable", { x <- parameters(penalty()) expect_true(parameters_reconstructable(x, x)) }) test_that("column order doesn't matter", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to)[rev(names(to))] expect_true(parameters_reconstructable(x, to)) }) test_that("all columns must exist", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to)["name"] expect_false(parameters_reconstructable(x, to)) }) test_that("can't have extra columns", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) x[["extra"]] <- 1 expect_false(parameters_reconstructable(x, to)) }) test_that("can't rename a column to unknown name", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) names <- names(x) names[[1]] <- "foo" names(x) <- names expect_false(parameters_reconstructable(x, to)) }) test_that("can technically swap column names", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) names <- names(x) one <- names[[1]] names[[1]] <- names[[3]] names[[3]] <- one names(x) <- names # This is a necessary evil but we can prevent it causing problems # in `rename()` and `names<-` with a `names<-` method. It shouldn't # cause problems for anything user facing. expect_true(parameters_reconstructable(x, to)) }) test_that("column type can't change", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) x[["name"]] <- 1 expect_false(parameters_reconstructable(x, to)) }) test_that("`$object` must be a list of `params`", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) x[["object"]] <- list(1) expect_false(parameters_reconstructable(x, to)) }) test_that("`$id` can't be duplicated", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) x <- x[c(1, 1), ] expect_false(parameters_reconstructable(x, to)) }) test_that("number of rows and row order doesn't matter", { to <- parameters(list(penalty(), mixture())) x <- as_tibble(to) idx <- 1 expect_true(parameters_reconstructable(x[idx, ], to)) idx <- rev(seq_len(nrow(x))) expect_true(parameters_reconstructable(x[idx, ], to)) }) dials/tests/testthat/test-constructors.R0000644000176200001440000001163614552525142020234 0ustar liggesusers test_that("qualitative parameter object creation - bad args", { expect_snapshot( error = TRUE, new_qual_param("character", 1:2) ) expect_snapshot( error = TRUE, new_qual_param("logical", letters[1:2]) ) }) test_that("quantitative parameter object creation - bad args", { expect_snapshot( error = TRUE, new_quant_param("mucus", range = 1:2, inclusive = c(TRUE, TRUE)) ) expect_snapshot( error = TRUE, new_quant_param("double", range = 1, inclusive = c(TRUE, TRUE)) ) expect_snapshot( error = TRUE, new_quant_param("double", range = c(1, NA), inclusive = c(TRUE, TRUE)) ) expect_snapshot( error = TRUE, new_quant_param("double", range = c(1, NA), inclusive = TRUE) ) expect_snapshot( error = TRUE, new_quant_param("double", range = c(1, NA), inclusive = c("(", "]")) ) expect_snapshot( error = TRUE, new_quant_param("double", range = c(1, NA), inclusive = c(TRUE, TRUE)) ) expect_snapshot( error = TRUE, new_quant_param("integer", range = 1:2, inclusive = c(TRUE, NA)) ) expect_snapshot( error = TRUE, new_quant_param("integer", range = 1:2, inclusive = c(TRUE, unknown())) ) expect_snapshot( error = TRUE, new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), trans = log) ) expect_snapshot( error = TRUE, new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), values = 1:4) ) expect_snapshot( error = TRUE, new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), finalize = "not a function or NULL") ) }) test_that("bad args to range_validate", { expect_snapshot( error = TRUE, range_validate(mtry(), range = 1) ) expect_snapshot( error = TRUE, range_validate(mtry(), range = c(1, NA)) ) expect_snapshot( error = TRUE, range_validate(mtry(), range = c(1, unknown()), FALSE) ) expect_snapshot( error = TRUE, range_validate(mtry(), range = letters[1:2]) ) }) test_that("printing", { expect_snapshot(mtry()) expect_snapshot(surv_dist()) expect_snapshot( value_set(cost_complexity(), log10(c(.09, .0001))) ) }) test_that("converting doubles to integers", { expect_type( mtry(c(1, unknown()))$range$lower, "integer" ) expect_type( mtry(c(unknown(), 1))$range$upper, "integer" ) expect_type( mtry(c(1, 10))$range$lower, "integer" ) expect_type( mtry(c(1, 10))$range$upper, "integer" ) }) test_that("bad ranges", { expect_snapshot(error = TRUE, mixture(c(1L, 3L))) expect_snapshot(error = TRUE, mixture(c(1L, unknown()))) expect_snapshot(error = TRUE, mixture(c(unknown(), 1L))) expect_snapshot(error = TRUE, mixture(letters[1:2])) expect_snapshot(error = TRUE, mtry(c(.1, .5))) expect_snapshot(error = TRUE, mtry(c(.1, unknown()))) expect_snapshot(error = TRUE, mtry(c(unknown(), .5))) }) test_that("can supply `values` without `range` and `inclusive` (#87)", { x <- new_quant_param( type = "integer", values = c(1L, 5L, 10L), label = c(foo = "Foo") ) expect_identical(x$range, list(lower = 1L, upper = 10L)) expect_identical(x$inclusive, c("lower" = TRUE, "upper" = TRUE)) expect_identical(x$values, c(1L, 5L, 10L)) }) test_that("`values` must be compatible with `range` and `inclusive`", { expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = c(1L, 5L, 10L), range = c(1L, 5L), label = c(foo = "Foo") ) }) expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = c(1L, 5L, 10L), inclusive = c(TRUE, FALSE), label = c(foo = "Foo") ) }) expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = NULL, range = NULL, inclusive = c(TRUE, FALSE), label = c(foo = "Foo") ) }) expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = NULL, range = c(1L, 10L), inclusive = NULL, label = c(foo = "Foo") ) }) }) test_that("`values` is validated", { expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = "not_numeric", label = c(foo = "Foo") ) }) expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = NA_integer_, label = c(foo = "Foo") ) }) expect_snapshot(error = TRUE, { new_quant_param( type = "integer", values = integer(), label = c(foo = "Foo") ) }) }) test_that("`default` arg is deprecated", { expect_snapshot({ quant_param <- new_quant_param( type = "integer", default = 5L, values = 1:10, label = c(foo = "Foo") ) }) expect_null(quant_param$default) expect_snapshot({ qual_param <- new_qual_param( type = "logical", values = c(FALSE, TRUE), default = TRUE, label = c(foo = "Foo") ) }) expect_null(qual_param$default) }) dials/tests/testthat/test-aaa_unknown.R0000644000176200001440000000277414533336606017774 0ustar liggesusers test_that("is_unknown", { expect_true( is_unknown(unknown()) ) expect_false( is_unknown("unknown") ) expect_false( is_unknown(7) ) expect_equal( is_unknown(c(1:2, unknown(), NA)), c(FALSE, FALSE, TRUE, FALSE) ) }) test_that("has_unknown", { expect_true( has_unknowns(mtry()) ) expect_equal( has_unknowns(list(mtry(), mixture())), c(TRUE, FALSE) ) }) test_that("unknowns in grid functions", { p1 <- parameters(q = mtry(), min_n()) p2 <- parameters(mtry()) p3 <- parameters(mtry(), q = mtry()) expect_snapshot(error = TRUE, grid_regular(p1)) expect_snapshot(error = TRUE, grid_regular(p2)) expect_snapshot(error = TRUE, grid_regular(p3)) expect_snapshot(error = TRUE, grid_random(p1)) expect_snapshot(error = TRUE, grid_random(p2)) expect_snapshot(error = TRUE, grid_latin_hypercube(p1)) expect_snapshot(error = TRUE, grid_latin_hypercube(p2)) expect_snapshot(error = TRUE, grid_max_entropy(p1)) expect_snapshot(error = TRUE, grid_max_entropy(p2)) expect_snapshot(error = TRUE, grid_regular(min_n(), q = mtry())) expect_snapshot(error = TRUE, grid_regular(mtry())) expect_snapshot(error = TRUE, grid_random(min_n(), q = mtry())) expect_snapshot(error = TRUE, grid_random(mtry())) expect_snapshot(error = TRUE, grid_regular(min_n(), q = mtry())) expect_snapshot(error = TRUE, grid_latin_hypercube(mtry())) expect_snapshot(error = TRUE, grid_max_entropy(min_n(), q = mtry())) expect_snapshot(error = TRUE, grid_max_entropy(mtry())) }) dials/tests/testthat/test-finalize.R0000644000176200001440000000370714565421125017265 0ustar liggesusers suppressMessages(library(kernlab)) test_that("estimate columns", { expect_snapshot(error = TRUE, get_p(1:10)) expect_snapshot(error = TRUE, get_p(1:10, 1:10)) expect_snapshot(error = TRUE, get_p(mtry(), 1:10)) expect_equal( range_get(get_p(mtry(), mtcars)), list(lower = 1, upper = ncol(mtcars)) ) expect_equal( range_get(get_log_p(mtry_long(), mtcars), original = FALSE), list(lower = 0, upper = log10(ncol(mtcars))) ) }) test_that("estimate rows", { expect_snapshot(error = TRUE, get_n(1:10)) expect_snapshot(error = TRUE, get_n(1:10, 1:10)) expect_snapshot(error = TRUE, get_n(mtry(), 1:10)) expect_equal( range_get(get_n_frac(mtry_long(), mtcars, log_vals = TRUE), original = FALSE), list(lower = 0, upper = 1) ) expect_equal( get_n_frac_range(sample_size(c(unknown(), unknown())), warpbreaks, frac = c(.3, .7))$range, list(lower = 16, upper = 37) ) expect_equal( get_n_frac_range( sample_size(c(unknown(), unknown()), trans = transform_log10()), x = warpbreaks, log_vals = TRUE, frac = c(.3, .7) )$range, list(lower = log10(16), upper = log10(37)) ) expect_equal( get_batch_sizes(batch_size(), iris, frac = c(.3, .7))$range, list(lower = log2(45), upper = log2(105)) ) }) test_that("estimate sigma", { expect_snapshot(error = TRUE, get_rbf_range(rbf_sigma(), iris)) run_1 <- range_get(get_rbf_range(rbf_sigma(), mtcars, seed = 5624)) run_2 <- range_get(get_rbf_range(rbf_sigma(), mtcars, seed = 5624)) expect_equal(run_1, run_2) }) test_that("force", { rbf_sigma_final <- finalize(rbf_sigma(), mtcars) rbf_sigma_same <- finalize(rbf_sigma(), mtcars, force = FALSE) expect_false(rbf_sigma_final$range$lower == rbf_sigma()$range$lower) expect_false(rbf_sigma_final$range$upper == rbf_sigma()$range$upper) expect_true(rbf_sigma_same$range$lower == rbf_sigma()$range$lower) expect_true(rbf_sigma_same$range$upper == rbf_sigma()$range$upper) }) dials/tests/testthat/test-aaa_ranges.R0000644000176200001440000000126114410310573017527 0ustar liggesusers test_that("no transforms", { expect_equal( range_get(trees()), list(lower = 1L, upper = 2000L) ) expect_equal( range_get(mixture()), list(lower = 0.0, upper = 1.0) ) expect_equal( range_get(mtry()), list(lower = 1L, upper = unknown()) ) }) test_that("transforms", { expect_equal( range_get(penalty(), FALSE), list(lower = -10, upper = 0) ) expect_equal( range_get(penalty()), list(lower = 10^-10, upper = 10^0) ) }) test_that("setting ranges", { expect_equal( range_set(mtry(), c(5L, 10L))$range, list(lower = 5L, upper = 10L) ) expect_equal( range_set(mtry(), c(unknown(), 10L))$range, list(lower = unknown(), upper = 10L) ) }) dials/tests/testthat/test-encode_unit.R0000644000176200001440000000521614411312735017751 0ustar liggesusers test_that("to [0, 1] for qualitative values", { z <- prune_method() z_0 <- encode_unit(z, prune_method()$values, direction = "forward") expect_equal(z_0, (0:5) / 5) z_back <- encode_unit(z, rev(z_0), direction = "backward") expect_equal(z_back, rev(prune_method()$values)) }) test_that("to [0, 1] for quantitative values", { x <- mtry(c(2L, 7L)) y <- mtry_long(c(1L, 3L)) x_0 <- encode_unit(x, 2:7, direction = "forward") expect_equal(x_0, seq(0, 1, length = 6)) x_back <- encode_unit(x, c(0.000001, 1 / 3, .99999, 1), direction = "backward") expect_equal(x_back, c(2L, 4L, 7L, 7L)) y_0 <- encode_unit(y, log10(214), direction = "forward") expect_equal(y_0, 0.66, tolerance = 0.01) y_orig <- encode_unit(y, y_0, direction = "backward", original = TRUE) y_trans <- encode_unit(y, y_0, direction = "backward", original = FALSE) expect_equal(y_orig, 214, tolerance = 0.01) expect_equal(y_trans, log10(214), tolerance = 0.01) }) test_that("missing data", { x <- mtry(c(2L, 7L)) z <- prune_method() x_0 <- encode_unit(x, c(2L, NA_integer_), direction = "forward") expect_equal(x_0, c(0, NA_real_)) z_0 <- encode_unit(z, c("backward", NA_character_), direction = "forward") expect_equal(z_0, c(0, NA_real_)) }) test_that("bad args", { x <- mtry(c(2L, 7L)) z <- prune_method() z_0 <- encode_unit(z, prune_method()$values, direction = "forward") x_0 <- encode_unit(x, 2:7, direction = "forward") expect_snapshot( error = TRUE, encode_unit(2, prune_method()$values, direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(z, prune_method()$values, direction = "forwards") ) expect_snapshot( error = TRUE, encode_unit(x, prune_method()$values, direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(z, 1, direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(x, matrix(letters[1:4], ncol = 2), direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(x, matrix(1:4, ncol = 2), direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(z, matrix(1:4, ncol = 2), direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(z, matrix(letters[1:4], ncol = 2), direction = "forward") ) expect_snapshot( error = TRUE, encode_unit(x, prune_method()$values, direction = "backward") ) expect_snapshot( error = TRUE, encode_unit(z, prune_method()$values, direction = "backward") ) expect_snapshot( error = TRUE, encode_unit(x, 1:2, direction = "backward") ) expect_snapshot( error = TRUE, encode_unit(z, 1:2, direction = "backward") ) }) dials/tests/testthat/test-params.R0000644000176200001440000001671414565615206016756 0ustar liggesusers test_that("param ranges", { expect_equal(min_n(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(sample_size(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(learn_rate(c(.1, .9))$range, list(lower = 0.1, upper = 0.9)) expect_equal(loss_reduction(c(.1, .9))$range, list(lower = 0.1, upper = 0.9)) expect_equal(cost_complexity(c(.1, .9))$range, list(lower = 0.1, upper = 0.9)) expect_equal(epochs(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(degree()$range, list(lower = 1, upper = 3)) expect_equal(degree_int()$range, list(lower = 1L, upper = 3L)) expect_equal(spline_degree()$range, list(lower = 1L, upper = 10L)) expect_equal(spline_degree(c(2L, 5L))$range, list(lower = 2L, upper = 5L)) expect_equal(prod_degree(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(num_terms(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(num_comp(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(cost(c(-2.0, -1.0))$range, list(lower = -2, upper = -1)) expect_equal(scale_factor(c(-2.0, -1.0))$range, list(lower = -2, upper = -1)) expect_equal(svm_margin(c(.1, .15))$range, list(lower = .1, upper = .15)) expect_equal(deg_free(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(hidden_units(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(batch_size(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(Laplace(c(.1, .9))$range, list(lower = 0.1, upper = 0.9)) expect_equal(dist_power(c(.1, .9))$range, list(lower = 0.1, upper = 0.9)) expect_equal(threshold(c(.1, .15))$range, list(lower = .1, upper = .15)) expect_equal(weight(c(-2.0, -1.0))$range, list(lower = -2, upper = -1)) expect_equal(max_times(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(min_times(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(max_tokens(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(window_size(c(3L, 5L))$range, list(lower = 3L, upper = 5L)) expect_equal(neighbors()$range, list(lower = 1L, upper = 10L)) expect_equal(neighbors(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(num_breaks()$range, list(lower = 2L, upper = 10L)) expect_equal(num_breaks(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(min_unique()$range, list(lower = 5L, upper = 15L)) expect_equal(min_unique(1:2)$range, list(lower = 1L, upper = 2L)) expect_equal(freq_cut(c(1.0, 2.0))$range, list(lower = 1, upper = 2)) expect_equal(unique_cut(c(1.0, 2.0))$range, list(lower = 1, upper = 2)) expect_equal(over_ratio(c(.5, 1.5))$range, list(lower = .5, upper = 1.5)) expect_equal(under_ratio(c(.5, 1.5))$range, list(lower = .5, upper = 1.5)) expect_equal(rbf_sigma(c(-2.0, -1.0))$range, list(lower = -2, upper = -1)) expect_equal(kernel_offset(c(0.0, 1.0))$range, list(lower = 0, upper = 1)) expect_equal(min_dist(c(-2.0, -1.0))$range, list(lower = -2, upper = -1)) expect_equal(sample_prop(c(.5, .6))$range, list(lower = .5, upper = .6)) expect_equal(num_hash(1:2)$range, list(lower = 1, upper = 2)) expect_equal(smoothness(c(.25, 1.75))$range, list(lower = .25, upper = 1.75)) expect_equal(predictor_prop(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(num_random_splits(c(7L, 15L))$range, list(lower = 7L, upper = 15L)) expect_equal(lower_quantile(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(significance_threshold(c(-3, -2))$range, list(lower = -3, upper = -2)) expect_equal(regularization_factor(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(confidence_factor(c(-1, -.5))$range, list(lower = -1, upper = -.5)) expect_equal(rule_bands(c(5L, 10L))$range, list(lower = 5L, upper = 10L)) expect_equal(max_rules(c(5L, 10L))$range, list(lower = 5L, upper = 10L)) expect_equal(extrapolation(c(1, 10))$range, list(lower = 1, upper = 10)) expect_equal(momentum(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(stop_iter(c(7L, 15L))$range, list(lower = 7L, upper = 15L)) expect_equal(conditional_min_criterion(c(1, 2))$range, list(lower = 1, upper = 2)) expect_equal(adjust_deg_free(c(1 / 2, 3.0))$range, list(lower = 1 / 2, upper = 3.0)) expect_equal(scale_pos_weight(c(1 / 2, 3.0))$range, list(lower = 1 / 2, upper = 3.0)) expect_equal(prior_slab_dispersion(c(1, 2))$range, list(lower = 1, upper = 2)) expect_equal(prior_mixture_threshold(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(shrinkage_correlation(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(shrinkage_variance(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(shrinkage_frequencies(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(penalty_L1(c(-5, 3))$range, list(lower = -5, upper = 3)) expect_equal(penalty_L2(c(-5, 3))$range, list(lower = -5, upper = 3)) expect_equal(class_weights(c(1, 5))$range, list(lower = 1, upper = 5)) expect_equal(prior_terminal_node_coef(c(.1, .5))$range, list(lower = .1, upper = .5)) expect_equal(prior_terminal_node_expo(c(1, 2))$range, list(lower = 1, upper = 2)) expect_equal(prior_outcome_range(c(1, 5))$range, list(lower = 1, upper = 5)) expect_equal(num_knots(c(1, 5))$range, list(lower = 1, upper = 5)) expect_equal(vocabulary_size(c(1000, 10000))$range, list(lower = 1000, upper = 10000)) expect_equal(rate_initial(c(-2, -1))$range, list(lower = -2, upper = -1)) expect_equal(rate_largest(c(-2, -1))$range, list(lower = -2, upper = -1)) expect_equal(rate_reduction(c(1 / 3, 2 / 3))$range, list(lower = 1 / 3, upper = 2 / 3)) expect_equal(rate_steps(c(7L, 15L))$range, list(lower = 7L, upper = 15L)) expect_equal(rate_step_size(c(7L, 15L))$range, list(lower = 7L, upper = 15L)) expect_equal(rate_decay(c(1, 2))$range, list(lower = 1, upper = 2)) expect_equal(num_clusters(c(1, 2))$range, list(lower = 1, upper = 2)) expect_equal(num_leaves(c(31,100))$range, list(lower = 31, upper = 100)) expect_equal(trim_amount(c(0.1, 0.4))$range, list(lower = 0.1, upper = 0.4)) expect_equal(num_runs(c(2, 100))$range, list(lower = 2, upper = 100)) expect_equal(harmonic_frequency(c(2, 100))$range, list(lower = 2, upper = 100)) expect_equal(validation_set_prop(c(0.1, 0.4))$range, list(lower = 0.1, upper = 0.4)) expect_equal(target_weight(c(0.1, 0.4))$range, list(lower = 0.1, upper = 0.4)) }) test_that("param values", { expect_equal(token(letters[1:3])$values, letters[1:3]) expect_equal(weight_scheme(letters[1:3])$values, letters[1:3]) expect_equal(prune_method(letters[1:3])$values, letters[1:3]) expect_equal(weight_func(letters[1:3])$values, letters[1:3]) expect_equal(weight_func(letters[1:3])$values, letters[1:3]) expect_equal(signed_hash(TRUE)$values, TRUE) expect_equal(regularize_depth(TRUE)$values, TRUE) expect_equal(no_global_pruning(TRUE)$values, TRUE) expect_equal(predictor_winnowing(TRUE)$values, TRUE) expect_equal(fuzzy_thresholding(TRUE)$values, TRUE) expect_equal(splitting_rule("gini")$values, "gini") expect_equal(unbiased_rules(TRUE)$values, TRUE) expect_equal(conditional_test_type()$values, dials:::values_test_type) expect_equal(conditional_test_statistic()$values, dials:::values_test_statistic) expect_equal(select_features(TRUE)$values, TRUE) expect_equal(regularization_method()$values, dials:::values_regularization_method) expect_equal(diagonal_covariance(TRUE)$values, TRUE) expect_equal(summary_stat()$values, values_summary_stat) expect_equal(survival_link()$values, values_survival_link) expect_equal(activation()$values, values_activation) expect_equal(rate_schedule()$values, values_scheduler) expect_equal(initial_umap()$values, values_initial_umap) }) dials/tests/testthat/test-space_filling.R0000644000176200001440000000347214223270317020256 0ustar liggesusers test_that("max entropy designs", { grid_1 <- grid_max_entropy( cost(), mixture(), size = 11, original = FALSE ) expect_equal(nrow(grid_1), 11L) expect_true(all(grid_1$mixture > 0 & grid_1$mixture < 1)) expect_true(all(grid_1$cost > -10 & grid_1$cost < 5)) grid_2 <- grid_max_entropy( cost(), mixture(), size = 11, original = TRUE ) expect_true(all(grid_2$cost > 2^-10 & grid_2$cost < 2^5)) grid_3 <- grid_max_entropy( cost(), size = 11, original = FALSE ) expect_equal(ncol(grid_3), 1L) expect_error( grid_max_entropy( cost, size = 11, original = FALSE ) ) expect_snapshot( error = TRUE, grid_max_entropy( mtry(), size = 11, original = FALSE ) ) expect_error( grid_max_entropy( size = 11, original = FALSE ) ) }) test_that("latin square designs", { grid_1 <- grid_latin_hypercube( cost(), mixture(), size = 11, original = FALSE ) expect_equal(nrow(grid_1), 11L) expect_true(all(grid_1$mixture > 0 & grid_1$mixture < 1)) expect_true(all(grid_1$cost > -10 & grid_1$cost < 5)) grid_2 <- grid_latin_hypercube( cost(), mixture(), size = 11, original = TRUE ) expect_true(all(grid_2$cost > 2^-10 & grid_2$cost < 2^5)) grid_3 <- grid_latin_hypercube( cost(), size = 11, original = FALSE ) expect_equal(ncol(grid_3), 1L) expect_lt( nrow(grid_latin_hypercube(prod_degree(), prune_method(), size = 20)), 20 ) expect_error( grid_latin_hypercube( cost, size = 11, original = FALSE ) ) expect_snapshot( error = TRUE, grid_latin_hypercube( mtry(), size = 11, original = FALSE ) ) expect_error( grid_latin_hypercube( size = 11, original = FALSE ) ) }) dials/tests/testthat/test-compat-dplyr-old-parameters.R0000644000176200001440000000567514223270317023016 0ustar liggesusers# These tests should pass on all supported versions of dplyr. Both pre and # post dplyr 1.0.0 should work. # When `compat-dplyr-old-parameters.R` is removed and support for dplyr < 1.0.0 is # deprecated, these tests should move to `test-compat-dplyr-parameters.R` instead. # Do not just delete them, as they are important tests and are not repeated in # `test-compat-dplyr-parameters.R`. suppressMessages(library(dplyr)) # ------------------------------------------------------------------------------ # mutate() test_that("mutate() can keep parameters class", { x <- parameters(list(penalty())) expect_s3_class_parameters(mutate(x)) }) test_that("mutate() drops parameters class if any columns are added", { x <- parameters(list(penalty())) expect_s3_class_bare_tibble(mutate(x, x = 1)) }) # ------------------------------------------------------------------------------ # arrange() test_that("arrange() keeps parameters class when row order is modified", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(arrange(x, name)) }) test_that("arrange() keeps parameters class when row order is untouched", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(arrange(x)) }) # ------------------------------------------------------------------------------ # filter() test_that("filter() keeps parameters class when rows are modified", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(filter(x)) expect_s3_class_parameters(filter(x, 0 == 1)) expect_s3_class_parameters(filter(x, is.numeric(id))) }) # ------------------------------------------------------------------------------ # rename() test_that("renaming can keep the parameters class if nothing is renamed", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(rename(x)) expect_s3_class_parameters(rename(x, name = name)) }) test_that("renaming drops the parameters class if anything is renamed", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(rename(x, foo = name)) }) # ------------------------------------------------------------------------------ # select() test_that("select() can keep parameters class", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(select(x, everything())) }) test_that("select() drops parameters class if any parameters columns aren't selected", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(select(x, name)) }) # ------------------------------------------------------------------------------ # slice() test_that("slice() generally keepy parameters class when rows are modified", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(slice(x, 0)) expect_s3_class_parameters(slice(x, seq_len(nrow(x)))) }) test_that("slice() drops parameters class when rows are duplicated", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(slice(x, c(1, 1))) }) dials/tests/testthat/test-type_sum.R0000644000176200001440000000027014223270317017315 0ustar liggesusers test_that("type_sum basics", { expect_equal(type_sum(mtry()), "nparam[?]") expect_equal(type_sum(rbf_sigma()), "nparam[+]") expect_equal(type_sum(activation()), "dparam[+]") }) dials/tests/testthat/test-compat-dplyr-parameters.R0000644000176200001440000002214114331236453022230 0ustar liggesusers# Skip entire file if dplyr < 1.0.0 skip_if(dplyr_pre_1.0.0()) suppressMessages(library(dplyr)) # ------------------------------------------------------------------------------ # dplyr_reconstruct() test_that("dplyr_reconstruct() returns a parameters subclass if `x` retains parameters structure", { x <- parameters(penalty()) expect_identical(dplyr_reconstruct(x, x), x) expect_s3_class_parameters(dplyr_reconstruct(x, x)) }) test_that("dplyr_reconstruct() returns bare tibble if `x` loses parameters structure", { x <- parameters(penalty()) col <- x[1] row <- x[c(1, 1), ] expect_s3_class_bare_tibble(dplyr_reconstruct(col, x)) expect_s3_class_bare_tibble(dplyr_reconstruct(row, x)) }) test_that("dplyr_reconstruct() retains extra attributes of `to` when not falling back", { x <- parameters(penalty()) to <- x attr(to, "foo") <- "bar" x_tbl <- x[1] expect_identical(attr(dplyr_reconstruct(x, to), "foo"), "bar") expect_identical(attr(dplyr_reconstruct(x_tbl, to), "foo"), NULL) expect_s3_class_parameters(dplyr_reconstruct(x, to)) expect_s3_class_bare_tibble(dplyr_reconstruct(x_tbl, to)) }) # ------------------------------------------------------------------------------ # dplyr_col_modify() test_that("adding columns drops the parameters class", { x <- parameters(list(penalty(), mixture())) cols <- list(x = rep(1, vctrs::vec_size(x))) result <- dplyr_col_modify(x, cols) expect_s3_class_bare_tibble(result) expect_identical(result$x, cols$x) }) test_that("modifying parameters columns removes parameters class", { x <- parameters(list(penalty(), mixture())) cols <- list(name = rep(1, vctrs::vec_size(x))) result <- dplyr_col_modify(x, cols) expect_s3_class_bare_tibble(result) expect_identical(result$name, cols$name) }) test_that("replacing parameters columns with the exact same column retains parameters class", { x <- parameters(list(penalty(), mixture())) cols <- list(name = x$name) result <- dplyr_col_modify(x, cols) expect_s3_class_parameters(result) expect_identical(result, x) }) # ------------------------------------------------------------------------------ # dplyr_row_slice() test_that("row slicing generally keeps the parameters subclass", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(dplyr_row_slice(x, 0)) expect_s3_class_parameters(dplyr_row_slice(x, c(1, 2))) }) test_that("row slicing and duplicating any rows removes the parameters subclass", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(dplyr_row_slice(x, c(1, 1))) }) test_that("parameters subclass is kept if row order is changed but all rows are present", { x <- parameters(list(penalty(), mixture())) locs <- rev(seq_len(nrow(x))) expect_s3_class_parameters(dplyr_row_slice(x, locs)) }) # ------------------------------------------------------------------------------ # summarise() test_that("summarise() always drops the parameters class", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(summarise(x, y = 1)) }) # ------------------------------------------------------------------------------ # group_by() test_that("group_by() always returns a bare grouped-df or bare tibble", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(group_by(x)) expect_s3_class(group_by(x, name), c("grouped_df", "tbl_df", "tbl", "data.frame"), exact = TRUE) }) # ------------------------------------------------------------------------------ # ungroup() test_that("ungroup() returns a parameters class", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(ungroup(x)) }) # ------------------------------------------------------------------------------ # relocate() test_that("can relocate() and keep the class", { x <- parameters(list(penalty(), mixture())) x <- relocate(x, id) expect_s3_class_parameters(x) }) # ------------------------------------------------------------------------------ # distinct() test_that("distinct() keeps the class if everything is intact", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(distinct(x)) }) test_that("distinct() drops the class if any parameters columns are lost", { x <- parameters(list(penalty(), mixture())) expect_s3_class_bare_tibble(distinct(x, name)) }) # ------------------------------------------------------------------------------ # left_join() test_that("left_join() can keep parameters class if parameters structure is intact", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(left_join(x, x, by = names(x))) }) test_that("left_join() can lose the parameters class if rows are duplicated", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = c(x$id[[1]], x$id[[1]])) expect_s3_class_bare_tibble(left_join(x, y, by = "id")) }) test_that("left_join() can lose the parameters class if columns are added", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = x$id[[1]], x = 1) expect_s3_class_bare_tibble(left_join(x, y, by = "id")) }) # ------------------------------------------------------------------------------ # right_join() test_that("right_join() can keep parameters class if parameters structure is intact", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(right_join(x, x, by = names(x))) }) test_that("right_join() can lose parameters class if rows are duplicated", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = x$id[[1]], x = 1:2) expect_s3_class_bare_tibble(right_join(x, y, by = "id")) }) test_that("right_join() can lose the parameters class if rows with `NA` are added", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = c(x$id, "foo"), object = x$object[1]) expect_s3_class_bare_tibble(right_join(x, y, by = c("id", "object"))) }) test_that("right_join() restores to the type of first input", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = x$id[[1]]) # technically parameters structure is intact, but `y` is a bare tibble! expect_s3_class_bare_tibble(right_join(y, x, by = "id")) }) # ------------------------------------------------------------------------------ # full_join() test_that("full_join() can keep parameters class if parameters structure is intact", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(full_join(x, x, by = names(x))) }) test_that("full_join() can lose parameters class if rows are added", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = "foo", x = 1) expect_s3_class_bare_tibble(full_join(x, y, by = "id")) }) # ------------------------------------------------------------------------------ # anti_join() test_that("anti_join() can keep parameters class if parameters structure is intact", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = "foo") expect_s3_class_parameters(anti_join(x, y, by = "id")) }) test_that("anti_join() can keep parameters class if only rows are removed", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = x$id[[1]]) expect_s3_class_parameters(anti_join(x, y, by = "id")) }) # ------------------------------------------------------------------------------ # semi_join() test_that("semi_join() can keep parameters class if parameters structure is intact", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(semi_join(x, x, by = names(x))) }) test_that("semi_join() can keep parameters class if only rows are removed", { x <- parameters(list(penalty(), mixture())) y <- tibble(id = "foo") expect_s3_class_parameters(semi_join(x, y, by = "id")) }) # ------------------------------------------------------------------------------ # bind_rows() test_that("bind_rows() keeps the class if there are no new rows/cols and the first object is an parameters subclass", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(bind_rows(x)) expect_s3_class_parameters(bind_rows(x, tibble())) expect_s3_class_bare_tibble(bind_rows(tibble(), x)) }) test_that("bind_rows() drops the class with new cols", { x <- parameters(list(penalty(), mixture())) y <- tibble(x = 1) expect_s3_class_bare_tibble(bind_rows(x, y)) }) test_that("bind_rows() keeps the class with new non duplicated rows", { x <- parameters(list(penalty())) y <- parameters(list(mixture())) expect_s3_class_parameters(bind_rows(x, y)) }) test_that("bind_rows() drops the class with new duplicated rows", { x <- parameters(list(penalty())) expect_s3_class_bare_tibble(bind_rows(x, x)) }) test_that("bind_rows() drops the class with new rows with any `NA`", { x <- parameters(list(penalty())) y <- vec_init(x, 1) y$object[[1]] <- x$object[[1]] expect_s3_class_bare_tibble(bind_rows(x, y)) }) # ------------------------------------------------------------------------------ # bind_cols() test_that("bind_cols() keeps the class if there are no new rows/cols", { x <- parameters(list(penalty(), mixture())) expect_s3_class_parameters(bind_cols(x)) }) test_that("bind_cols() drops the class with new cols", { x <- parameters(list(penalty(), mixture())) y <- tibble(x = 1) expect_s3_class_bare_tibble(bind_cols(x, y)) }) dials/tests/testthat/test-validation.R0000644000176200001440000000050014411575345017606 0ustar liggesuserstest_that("errors from validate_params()", { expect_snapshot(error = TRUE, validate_params()) expect_snapshot(error = TRUE, validate_params(1:2)) expect_snapshot(error = TRUE, validate_params(mtry())) expect_snapshot(error = TRUE, { unfinalized_param <- mtry() validate_params(unfinalized_param) }) }) dials/tests/testthat/test-grids.R0000644000176200001440000000403114223270317016557 0ustar liggesusers test_that("regular grid", { expect_error( grid_regular(mtcars) ) expect_error( grid_regular() ) expect_snapshot( error = TRUE, grid_regular(mixture(), trees(), levels = 1:4) ) expect_equal( nrow(grid_regular(mixture(), trees(), levels = 2)), 4 ) expect_equal( nrow(grid_regular(mixture(), trees(), levels = 2:3)), prod(2:3) ) expect_equal( dplyr::n_distinct( select( grid_regular(mixture(), trees(), levels = c(trees = 2, mixture = 3)), trees ) ), 2 ) expect_equal( dplyr::n_distinct( select( grid_regular(mixture(), trees(), levels = c(mixture = 3, trees = 2)), trees ) ), 2 ) }) test_that("random grid", { expect_error( grid_random(mtcars) ) expect_error( grid_random() ) expect_equal( nrow(grid_random(mixture(), trees(), size = 2)), 2 ) set.seed(1) expect_lte( # There are 6x2 possible combinations nrow(grid_random(prod_degree(), prune_method(), size = 50)), 12 ) }) test_that("wrong argument name", { skip_if_below_r_version("3.6") p <- parameters(penalty(), mixture()) expect_snapshot(grid_latin_hypercube(p, levels = 5)) expect_snapshot(grid_max_entropy(p, levels = 5)) expect_snapshot(grid_random(p, levels = 5)) expect_snapshot(grid_regular(p, size = 5)) }) test_that("filter arg yields same results", { p <- parameters(penalty(), mixture()) expect_equal( filter(with_seed(36L, grid_random(p)), penalty < .01), with_seed(36L, grid_random(p, filter = penalty < .01)) ) expect_equal( filter(with_seed(36L, grid_random(p)), penalty > .001), with_seed(36L, grid_random(p, filter = penalty > .001)) ) expect_equal( filter(with_seed(36L, grid_random(p)), mixture == .01), with_seed(36L, grid_random(p, filter = mixture == .01)) ) }) test_that("new param grid from conventional data frame", { x <- data.frame(num_comp = 1:3) expect_error(y <- dials:::new_param_grid(x), regexp = NA) expect_true(tibble::is_tibble(y)) }) dials/tests/testthat/_snaps/0000755000176200001440000000000014565617021015642 5ustar liggesusersdials/tests/testthat/_snaps/misc.md0000644000176200001440000000231414565616455017131 0ustar liggesusers# check_label() Code check_label("unnamed label") Condition Error: ! `label` must be named. --- Code check_label(c("more", "than", "one", "label")) Condition Error: ! `label` must be a single string or `NULL`, not a character vector. # check_values_quant() Code check_values_quant("should have been a numeric") Condition Error: ! `values` must be numeric. --- Code check_values_quant(c(1, NA)) Condition Error: ! `values` can't be `NA`. --- Code check_values_quant(numeric()) Condition Error: ! `values` can't be empty. # check_inclusive() Code check_inclusive(TRUE) Condition Error: ! `inclusive` must be a logical vector of length 2, not `TRUE`. --- Code check_inclusive(NULL) Condition Error: ! `inclusive` must be a logical vector of length 2, not `NULL`. --- Code check_inclusive(c(TRUE, NA)) Condition Error: ! `inclusive` cannot contain missings. --- Code check_inclusive(1:2) Condition Error: ! `inclusive` must be a logical vector of length 2, not an integer vector. dials/tests/testthat/_snaps/constructors.md0000644000176200001440000001532414565617021020741 0ustar liggesusers# qualitative parameter object creation - bad args Code new_qual_param("character", 1:2) Condition Error: ! `values` must be a character vector, not an integer vector. --- Code new_qual_param("logical", letters[1:2]) Condition Error: ! `values` must be a logical vector, not a character vector. # quantitative parameter object creation - bad args Code new_quant_param("mucus", range = 1:2, inclusive = c(TRUE, TRUE)) Condition Error in `new_quant_param()`: ! `type` must be one of "double" or "integer", not "mucus". --- Code new_quant_param("double", range = 1, inclusive = c(TRUE, TRUE)) Condition Error in `names(range) <- names(inclusive) <- c("lower", "upper")`: ! 'names' attribute [2] must be the same length as the vector [1] --- Code new_quant_param("double", range = c(1, NA), inclusive = c(TRUE, TRUE)) Condition Error: ! Value ranges must be non-missing. --- Code new_quant_param("double", range = c(1, NA), inclusive = TRUE) Condition Error: ! `inclusive` must be a logical vector of length 2, not `TRUE`. --- Code new_quant_param("double", range = c(1, NA), inclusive = c("(", "]")) Condition Error: ! `inclusive` must be a logical vector of length 2, not a character vector. --- Code new_quant_param("double", range = c(1, NA), inclusive = c(TRUE, TRUE)) Condition Error: ! Value ranges must be non-missing. --- Code new_quant_param("integer", range = 1:2, inclusive = c(TRUE, NA)) Condition Error: ! `inclusive` cannot contain missings. --- Code new_quant_param("integer", range = 1:2, inclusive = c(TRUE, unknown())) Condition Error: ! `inclusive` must be a logical vector of length 2, not a list. --- Code new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), trans = log) Condition Error: x `trans` must be a class object (or `NULL`). i See `scales::trans_new()`. --- Code new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), values = 1:4) Condition Error: ! Some values are not valid: 3 and 4. --- Code new_quant_param("integer", range = 1:2, inclusive = c(TRUE, TRUE), finalize = "not a function or NULL") Condition Error: ! `finalize` must be a function or `NULL`, not the string "not a function or NULL". # bad args to range_validate Code range_validate(mtry(), range = 1) Condition Error: ! `range` must have two values: an upper and lower bound. `Inf` and `unknown()` are acceptable values. --- Code range_validate(mtry(), range = c(1, NA)) Condition Error: ! Value ranges must be non-missing. --- Code range_validate(mtry(), range = c(1, unknown()), FALSE) Condition Error: ! Cannot validate ranges when they contains 1+ unknown values. --- Code range_validate(mtry(), range = letters[1:2]) Condition Error: ! Value ranges must be numeric. # printing Code mtry() Output # Randomly Selected Predictors (quantitative) Range: [1, ?] --- Code surv_dist() Output Distribution (qualitative) Message 6 possible values include: Output 'weibull', 'exponential', 'gaussian', 'logistic', 'lognormal' and 'loglogistic' --- Code value_set(cost_complexity(), log10(c(0.09, 1e-04))) Output Cost-Complexity Parameter (quantitative) Transformer: log-10 [1e-100, Inf] Range (transformed scale): [-10, -1] Values: 2 # bad ranges Code mixture(c(1L, 3L)) Condition Error in `mixture()`: ! Since `type = 'double'`, please use that data type for the range. --- Code mixture(c(1L, unknown())) Condition Error in `mixture()`: ! Since `type = 'double'`, please use that data type for the range. --- Code mixture(c(unknown(), 1L)) Condition Error in `mixture()`: ! Since `type = 'double'`, please use that data type for the range. --- Code mixture(letters[1:2]) Condition Error in `mixture()`: ! Since `type = 'double'`, please use that data type for the range. --- Code mtry(c(0.1, 0.5)) Condition Error in `mtry()`: ! An integer is required for the range and these do not appear to be whole numbers: 0.1, 0.5 --- Code mtry(c(0.1, unknown())) Condition Error in `mtry()`: ! An integer is required for the range and these do not appear to be whole numbers: 0.1 --- Code mtry(c(unknown(), 0.5)) Condition Error in `mtry()`: ! An integer is required for the range and these do not appear to be whole numbers: 0.5 # `values` must be compatible with `range` and `inclusive` Code new_quant_param(type = "integer", values = c(1L, 5L, 10L), range = c(1L, 5L), label = c(foo = "Foo")) Condition Error: ! Some values are not valid: 10. --- Code new_quant_param(type = "integer", values = c(1L, 5L, 10L), inclusive = c(TRUE, FALSE), label = c(foo = "Foo")) Condition Error: ! Some values are not valid: 10. --- Code new_quant_param(type = "integer", values = NULL, range = NULL, inclusive = c( TRUE, FALSE), label = c(foo = "Foo")) Condition Error: ! `range` must be supplied if `values` is `NULL`. --- Code new_quant_param(type = "integer", values = NULL, range = c(1L, 10L), inclusive = NULL, label = c(foo = "Foo")) Condition Error: ! `inclusive` must be supplied if `values` is `NULL`. # `values` is validated Code new_quant_param(type = "integer", values = "not_numeric", label = c(foo = "Foo")) Condition Error: ! `values` must be numeric. --- Code new_quant_param(type = "integer", values = NA_integer_, label = c(foo = "Foo")) Condition Error: ! `values` can't be `NA`. --- Code new_quant_param(type = "integer", values = integer(), label = c(foo = "Foo")) Condition Error: ! `values` can't be empty. # `default` arg is deprecated Code quant_param <- new_quant_param(type = "integer", default = 5L, values = 1:10, label = c(foo = "Foo")) Condition Warning: The `default` argument of `new_quant_param()` is deprecated as of dials 1.1.0. --- Code qual_param <- new_qual_param(type = "logical", values = c(FALSE, TRUE), default = TRUE, label = c(foo = "Foo")) Condition Warning: The `default` argument of `new_qual_param()` is deprecated as of dials 1.1.0. dials/tests/testthat/_snaps/finalize.md0000644000176200001440000000215314565616455020000 0ustar liggesusers# estimate columns Code get_p(1:10) Condition Error in `get_p()`: ! `object` must be a single parameter object, not an integer vector. --- Code get_p(1:10, 1:10) Condition Error in `get_p()`: ! `object` must be a single parameter object, not an integer vector. --- Code get_p(mtry(), 1:10) Condition Error in `get_p()`: ! Cannot determine number of columns. Is `x` a 2D data object? # estimate rows Code get_n(1:10) Condition Error in `get_n_frac()`: ! `object` must be a single parameter object, not an integer vector. --- Code get_n(1:10, 1:10) Condition Error in `get_n_frac()`: ! `object` must be a single parameter object, not an integer vector. --- Code get_n(mtry(), 1:10) Condition Error in `get_n_frac()`: ! Cannot determine number of columns. Is `x` a 2D data object? # estimate sigma Code get_rbf_range(rbf_sigma(), iris) Condition Error in `get_rbf_range()`: ! The matrix version of the initialization data is not numeric. dials/tests/testthat/_snaps/parameters.md0000644000176200001440000000644214565616456020350 0ustar liggesusers# parameters_const() input checks Code parameters_constr(2) Condition Error: ! `name` must be a character vector, not the number 2. --- Code ab <- c("a", "b") parameters_constr(ab, c("a", "a"), ab, ab, ab) Condition Error: ! Element `id` should have unique values. Duplicates exist for item(s): 'a' --- Code ab <- c("a", "b") parameters_constr(ab, ab, ab, ab, ab, "not a params list") Condition Error: ! `object` must be a list of `param` objects. --- Code ab <- c("a", "b") parameters_constr("a", ab, ab, ab, ab, list(penalty(), mtry())) Condition Error: ! All inputs must contain contain the same number of elements. --- Code ab <- c("a", "b") parameters_constr(ab, ab, ab, ab, ab, list(penalty())) Condition Error: ! All inputs must contain contain the same number of elements. # create from lists of param objects Code parameters(list(a = mtry(), a = penalty())) Condition Error in `parameters()`: ! Element `id` should have unique values. Duplicates exist for item(s): 'a' # updating Code update(p_1, new_pen) Condition Error in `update()`: ! All arguments should be named. --- Code update(p_1, penalty = 1:2) Condition Error in `update()`: ! At least one parameter is not a dials parameter object or NA: penalty. --- Code update(p_1, penalty(), mtry = mtry(3:4)) Condition Error in `update()`: ! All arguments should be named. # printing Code parameters(list(mtry(), penalty())) Output Collection of 2 parameters for tuning identifier type object mtry mtry nparam[?] penalty penalty nparam[+] Parameters needing finalization: # Randomly Selected Predictors ('mtry') See `?dials::finalize` or `?dials::update.parameters` for more information. --- Code ex_params[1, ] %>% structure(class = c("parameters", class(.))) Output Collection of 1 parameters for tuning identifier type object trials trials missing Message The parameter `trials` needs a `param` object. See `vignette('dials')` to learn more. --- Code ex_params[1:2, ] %>% structure(class = c("parameters", class(.))) Output Collection of 2 parameters for tuning identifier type object trials trials missing rules rules missing Message The parameters `trials` and `rules` need `param` objects. See `vignette('dials')` to learn more. --- Code ex_params[1:3, ] %>% structure(class = c("parameters", class(.))) Output Collection of 3 parameters for tuning identifier type object trials trials missing rules rules missing costs costs missing Message The parameters `trials`, `rules`, and `costs` need `param` objects. See `vignette('dials')` to learn more. # parameters.default Code parameters(tibble::as_tibble(mtcars)) Condition Error in `parameters()`: ! `parameters` objects cannot be created from objects of class `tbl_df`. dials/tests/testthat/_snaps/pull_dials_object.md0000644000176200001440000000040714565616456021656 0ustar liggesusers# pull_dials_object is deprecated Code pull_dials_object(mod_param, "mixture") Condition Error: ! `pull_dials_object()` was deprecated in dials 0.1.0 and is now defunct. i Please use `hardhat::extract_parameter_dials()` instead. dials/tests/testthat/_snaps/validation.md0000644000176200001440000000117714565616457020340 0ustar liggesusers# errors from validate_params() Code validate_params() Condition Error: ! At least one parameter object is required. --- Code validate_params(1:2) Condition Error: ! This argument must have class : `1:2`. --- Code validate_params(mtry()) Condition Error: x This argument contains unknowns: ``. i See the `dials::finalize()` function. --- Code unfinalized_param <- mtry() validate_params(unfinalized_param) Condition Error: x This argument contains unknowns: ``. i See the `dials::finalize()` function. dials/tests/testthat/_snaps/space_filling.md0000644000176200001440000000074714565616456021006 0ustar liggesusers# max entropy designs Code grid_max_entropy(mtry(), size = 11, original = FALSE) Condition Error in `grid_max_entropy()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. # latin square designs Code grid_latin_hypercube(mtry(), size = 11, original = FALSE) Condition Error in `grid_latin_hypercube()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. dials/tests/testthat/_snaps/grids.md0000644000176200001440000000331614565616455017311 0ustar liggesusers# regular grid Code grid_regular(mixture(), trees(), levels = 1:4) Condition Error in `grid_regular()`: ! `levels` should have length 1 or 2 # wrong argument name Code grid_latin_hypercube(p, levels = 5) Condition Warning: `levels` is not an argument to `grid_latin_hypercube()`. Did you mean `size`? Output # A tibble: 3 x 2 penalty mixture 1 0.000000438 0.191 2 0.0000000918 0.688 3 0.00102 0.395 --- Code grid_max_entropy(p, levels = 5) Condition Warning: `levels` is not an argument to `grid_max_entropy()`. Did you mean `size`? Output # A tibble: 3 x 2 penalty mixture 1 0.281 0.251 2 0.108 0.943 3 0.000000124 0.0366 --- Code grid_random(p, levels = 5) Condition Warning: `levels` is not an argument to `grid_random()`. Did you mean `size`? Output # A tibble: 5 x 2 penalty mixture 1 1.27e-10 0.642 2 1.43e- 2 0.942 3 5.29e- 4 0.284 4 7.45e- 2 0.523 5 4.91e-10 0.00216 --- Code grid_regular(p, size = 5) Condition Warning: `size` is not an argument to `grid_regular()`. Did you mean `levels`? Output # A tibble: 9 x 2 penalty mixture 1 0.0000000001 0 2 0.00001 0 3 1 0 4 0.0000000001 0.5 5 0.00001 0.5 6 1 0.5 7 0.0000000001 1 8 0.00001 1 9 1 1 dials/tests/testthat/_snaps/encode_unit.md0000644000176200001440000000405014565616455020471 0ustar liggesusers# bad args Code encode_unit(2, prune_method()$values, direction = "forward") Condition Error in `encode_unit()`: ! `x` should be a dials parameter object. --- Code encode_unit(z, prune_method()$values, direction = "forwards") Condition Error in `encode_unit()`: ! `direction` must be one of "forward" or "backward", not "forwards". i Did you mean "forward"? --- Code encode_unit(x, prune_method()$values, direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a numeric vector. --- Code encode_unit(z, 1, direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a character vector. --- Code encode_unit(x, matrix(letters[1:4], ncol = 2), direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a numeric vector. --- Code encode_unit(x, matrix(1:4, ncol = 2), direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a numeric vector. --- Code encode_unit(z, matrix(1:4, ncol = 2), direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a character vector. --- Code encode_unit(z, matrix(letters[1:4], ncol = 2), direction = "forward") Condition Error in `encode_unit()`: ! `value` should be a character vector. --- Code encode_unit(x, prune_method()$values, direction = "backward") Condition Error in `encode_unit()`: ! `value` should be a numeric vector. --- Code encode_unit(z, prune_method()$values, direction = "backward") Condition Error in `encode_unit()`: ! Values should be on [0, 1]. --- Code encode_unit(x, 1:2, direction = "backward") Condition Error in `encode_unit()`: ! Values should be on [0, 1]. --- Code encode_unit(z, 1:2, direction = "backward") Condition Error in `encode_unit()`: ! Values should be on [0, 1]. dials/tests/testthat/_snaps/aaa_unknown.md0000644000176200001440000000623214565616452020477 0ustar liggesusers# unknowns in grid functions Code grid_regular(p1) Condition Error in `grid_regular()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_regular(p2) Condition Error in `grid_regular()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_regular(p3) Condition Error in `grid_regular()`: x These arguments contain unknowns: `mtry` and `q`. i See the `dials::finalize()` function. --- Code grid_random(p1) Condition Error in `grid_random()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_random(p2) Condition Error in `grid_random()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_latin_hypercube(p1) Condition Error in `grid_latin_hypercube()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_latin_hypercube(p2) Condition Error in `grid_latin_hypercube()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_max_entropy(p1) Condition Error in `grid_max_entropy()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_max_entropy(p2) Condition Error in `grid_max_entropy()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_regular(min_n(), q = mtry()) Condition Error in `grid_regular()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_regular(mtry()) Condition Error in `grid_regular()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_random(min_n(), q = mtry()) Condition Error in `grid_random()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_random(mtry()) Condition Error in `grid_random()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_regular(min_n(), q = mtry()) Condition Error in `grid_regular()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_latin_hypercube(mtry()) Condition Error in `grid_latin_hypercube()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. --- Code grid_max_entropy(min_n(), q = mtry()) Condition Error in `grid_max_entropy()`: x This argument contains unknowns: `q`. i See the `dials::finalize()` function. --- Code grid_max_entropy(mtry()) Condition Error in `grid_max_entropy()`: x This argument contains unknowns: `mtry`. i See the `dials::finalize()` function. dials/tests/testthat/_snaps/extract.md0000644000176200001440000000242714565616455017655 0ustar liggesusers# bad arguments Code extract_parameter_dials(mod_param, "lambdas") Condition Error in `extract_parameter_dials()`: ! No parameter exists with id "lambdas". --- Code extract_parameter_dials(mod_param) Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not absent. --- Code extract_parameter_dials(mod_param, 1) Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not the number 1. --- Code extract_parameter_dials(mod_param, 1:2) Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not an integer vector. --- Code extract_parameter_dials(mod_param, letters[1:2]) Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not a character vector. --- Code extract_parameter_dials(mod_param, NA_character_) Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not a character `NA`. --- Code extract_parameter_dials(mod_param, "") Condition Error in `extract_parameter_dials()`: ! `parameter` must be a single string, not the empty string "". dials/tests/testthat/_snaps/aaa_values.md0000644000176200001440000000224514565616452020277 0ustar liggesusers# transforms with unknowns Code value_transform(penalty(), unknown()) Condition Error in `value_transform()`: ! Unknowns not allowed. --- Code value_transform(penalty(), c(unknown(), 1, unknown())) Condition Error in `value_transform()`: ! Unknowns not allowed. --- Code value_inverse(penalty(), unknown()) Condition Error in `value_inverse()`: ! Unknowns not allowed. --- Code value_inverse(penalty(), c(unknown(), 1, unknown())) Condition Error in `value_inverse()`: ! Unknowns not allowed. # transforms Code value_object <- value_transform(penalty(), -1:3) Condition Warning in `log()`: NaNs produced Code value_expected <- c(NaN, -Inf, log10(1:3)) # sequences - logical Code value_seq(prune(), 1) Output [1] TRUE # validate unknowns Code value_validate(mtry(), 17) Condition Error: ! Unknowns not allowed. # value_set() checks inputs Code value_set(cost_complexity(), numeric(0)) Condition Error in `value_set()`: ! `values` must have at least one element. dials/tests/testthat/test-pull_dials_object.R0000644000176200001440000000032014337647441021136 0ustar liggesusers test_that("pull_dials_object is deprecated", { mod_param <- parameters(list("lambda" = penalty(), mixture(range = c(0.05, 1)))) expect_snapshot(error = TRUE, pull_dials_object(mod_param, "mixture")) }) dials/tests/testthat/test-aaa_values.R0000644000176200001440000001425214565421125017562 0ustar liggesusers test_that("transforms with unknowns", { expect_snapshot( error = TRUE, value_transform(penalty(), unknown()) ) expect_snapshot( error = TRUE, value_transform(penalty(), c(unknown(), 1, unknown())) ) expect_snapshot( error = TRUE, value_inverse(penalty(), unknown()) ) expect_snapshot( error = TRUE, value_inverse(penalty(), c(unknown(), 1, unknown())) ) }) test_that("transforms", { skip_if_below_r_version("3.5") expect_equal( value_transform(penalty(), 1:3), log10(1:3) ) expect_snapshot({ value_object <- value_transform(penalty(), -1:3) value_expected <- c(NaN, -Inf, log10(1:3)) }) expect_equal(value_object, value_expected) expect_equal( value_transform(mtry(), 1:3), 1:3 ) }) test_that("inverses", { expect_equal( value_inverse(penalty(), 1:3), 10^(1:3) ) expect_equal( value_inverse(penalty(), c(NA, 1:3)), c(NA, 10^(1:3)) ) expect_equal( value_inverse(mtry(), 1:3), 1:3 ) }) test_that("sequences - doubles", { param_with_transformation <- new_quant_param( type = "double", range = c(0.5, 1.5), inclusive = c(TRUE, TRUE), trans = scales::transform_sqrt(), label = c(param = "param") ) param_with_values <- new_quant_param( type = "double", range = c(0.0, 1.0), inclusive = c(TRUE, TRUE), trans = NULL, values = (0:5) / 5, label = c(param = "param") ) expect_equal( value_seq(mixture(), 5), seq(0, 1, length = 5) ) expect_equal( value_seq(mixture(), 1), 0 ) expect_equal( value_seq(penalty(), 5, FALSE), seq(-10, 0, length = 5) ) expect_equal( value_seq(penalty(), 1, FALSE), -10 ) expect_equal( value_seq(param_with_transformation, 1), 0.5^2 ) expect_equal( value_seq(param_with_transformation, 1, FALSE), 0.5 ) expect_equal( value_seq(param_with_values, 2), (0:1) / 5 ) expect_equal( value_seq(param_with_values, 2, FALSE), (0:1) / 5 ) }) test_that("sequences - integers", { param_with_transformation <- new_quant_param( type = "integer", range = c(2.1, 5.3), inclusive = c(TRUE, TRUE), trans = scales::transform_sqrt(), label = c(param = "param") ) param_with_values <- new_quant_param( type = "integer", range = c(0L, 100L), inclusive = c(TRUE, TRUE), trans = NULL, values = 1:10, label = c(param = "param") ) expect_equal( value_seq(tree_depth(), 5), c(1, 4, 8, 11, 15) ) expect_equal( value_seq(tree_depth(), 1), 1L ) expect_equal( value_seq(tree_depth(), 15), 1L:15L ) expect_equal( value_seq(tree_depth(), 5, FALSE), seq(1, 15, length = 5) ) expect_equal( value_seq(tree_depth(), 1, FALSE), 1L ) expect_equal( value_seq(tree_depth(), 15, FALSE), 1L:15L ) expect_equal( value_seq(param_with_transformation, 1), 2L^2 ) expect_equal( value_seq(param_with_transformation, 1, FALSE), 2.1 ) expect_equal( value_seq(param_with_values, 2, FALSE), 1:2 ) expect_equal( value_seq(param_with_values, 1, FALSE), 1 ) }) test_that("sampling - doubles", { value_seq <- new_quant_param( type = "double", range = c(0.0, 1.0), inclusive = c(TRUE, TRUE), trans = NULL, values = (0:5) / 5, label = c(param = "param") ) mix_test <- value_sample(mixture(), 5000) expect_true(min(mix_test) > 0) expect_true(max(mix_test) < 1) L2_orig <- value_sample(penalty(), 5000) expect_true(min(L2_orig) > 10^penalty()$range$lower) expect_true(max(L2_orig) < 10^penalty()$range$upper) L2_tran <- value_sample(penalty(), 5000, FALSE) expect_true(min(L2_tran) > penalty()$range$lower) expect_true(max(L2_tran) < penalty()$range$upper) expect_in(value_sample(value_seq, 40), value_seq$values) }) test_that("sampling - integers", { test_param_2 <- new_quant_param( type = "integer", range = c(2.1, 5.3), inclusive = c(TRUE, TRUE), trans = scales::transform_sqrt(), label = c(param = "param") ) int_seq <- new_quant_param( type = "integer", range = c(0L, 100L), inclusive = c(TRUE, TRUE), trans = NULL, values = 1:10, label = c(param = "param") ) depth_test <- value_sample(tree_depth(), 500) expect_true(min(depth_test) >= tree_depth()$range$lower) expect_true(max(depth_test) <= tree_depth()$range$upper) expect_true(is.integer(depth_test)) p2_orig <- value_sample(test_param_2, 500) expect_true(min(p2_orig) >= floor(2^test_param_2$range$lower)) expect_true(max(p2_orig) <= floor(2^test_param_2$range$upper)) expect_true(is.integer(p2_orig)) p2_tran <- value_sample(test_param_2, 500, FALSE) expect_true(min(p2_tran) > test_param_2$range$lower) expect_true(max(p2_tran) < test_param_2$range$upper) expect_true(!is.integer(p2_tran)) expect_in(value_sample(int_seq, 50), int_seq$values) }) # ------------------------------------------------------------------------- test_that("sequences - character", { test_param_5 <- new_qual_param( type = "character", values = letters[1:10], label = c(param = "param") ) expect_equal( value_seq(surv_dist(), 5), surv_dist()$values[1:5] ) expect_equal( value_seq(surv_dist(), 1), surv_dist()$values[1] ) expect_equal( value_seq(surv_dist(), Inf), surv_dist()$values ) expect_equal(value_seq(test_param_5, 1), "a") }) test_that("sequences - logical", { test_param_6 <- new_qual_param( type = "logical", values = TRUE, label = c(param = "param") ) expect_snapshot( value_seq(prune(), 1) ) expect_equal( value_seq(prune(), 2), c(TRUE, FALSE) ) expect_equal( value_seq(prune(), 21), c(TRUE, FALSE) ) expect_equal( value_seq(test_param_6, Inf), TRUE ) }) test_that("sampling - character and logical", { expect_in(value_sample(surv_dist(), 500), surv_dist()$values) expect_in(value_sample(prune(), 500), prune()$values) }) test_that("validate unknowns", { expect_snapshot( error = TRUE, value_validate(mtry(), 17) ) }) test_that("value_set() checks inputs", { expect_snapshot(error = TRUE, { value_set(cost_complexity(), numeric(0)) }) }) dials/tests/testthat/helper-skip_if_below_r_version.R0000644000176200001440000000023714223270317022655 0ustar liggesusersskip_if_below_r_version <- function(v) { testthat::skip_if( getRversion() < v, message = paste0("Skipping because R version is less than ", v) ) } dials/tests/testthat/test-parameters.R0000644000176200001440000001541014411575345017625 0ustar liggesuserstest_that("parameters_const() input checks", { expect_snapshot(error = TRUE, { parameters_constr(2) }) expect_snapshot(error = TRUE, { ab <- c("a", "b") parameters_constr(ab, c("a", "a"), ab, ab, ab) }) expect_snapshot(error = TRUE, { ab <- c("a", "b") parameters_constr(ab, ab, ab, ab, ab, "not a params list") }) expect_snapshot(error = TRUE, { ab <- c("a", "b") parameters_constr("a", ab, ab, ab, ab, list(penalty(), mtry())) }) expect_snapshot(error = TRUE, { ab <- c("a", "b") parameters_constr(ab, ab, ab, ab, ab, list(penalty())) }) }) test_that("create from param objects", { expect_error(p_1 <- parameters(mtry(), penalty()), NA) expect_s3_class_parameters(p_1) expect_equal(p_1 %>% nrow(), 2) expect_error(p_2 <- parameters(penalty()), NA) expect_s3_class_parameters(p_2) expect_equal(p_2 %>% nrow(), 1) }) test_that("create from lists of param objects", { expect_error(p_1 <- parameters(list(mtry(), penalty())), NA) expect_s3_class_parameters(p_1) expect_equal(p_1 %>% nrow(), 2) expect_error(p_2 <- parameters(list(penalty())), NA) expect_s3_class_parameters(p_2) expect_equal(p_2 %>% nrow(), 1) expect_error(p_3 <- parameters(list(a = mtry(), "some name" = penalty())), NA) expect_s3_class_parameters(p_3) expect_equal(p_3 %>% nrow(), 2) expect_equal(p_3$id, c("a", "some name")) expect_snapshot(error = TRUE, parameters(list(a = mtry(), a = penalty()))) }) test_that("updating", { p_1 <- parameters(list(mtry(), penalty())) p_2 <- update(p_1, penalty = NA) expect_s3_class_parameters(p_2) expect_true(is.na(p_2$object[2])) new_pen <- penalty(c(-5, -3)) p_3 <- update(p_1, penalty = new_pen) expect_s3_class_parameters(p_3) expect_equal(p_3$object[[2]], new_pen) expect_snapshot(error = TRUE, update(p_1, new_pen)) expect_snapshot(error = TRUE, update(p_1, penalty = 1:2)) expect_snapshot(error = TRUE, update(p_1, penalty(), mtry = mtry(3:4))) expect_error(update(p_1, penalty = NA), NA) }) test_that("printing", { expect_snapshot(parameters(list(mtry(), penalty()))) ex_params <- tibble::tribble( ~name, ~id, ~source, ~component, ~call_info, ~component_id, ~object, "trials", "trials", "model_spec", "boost_tree", NULL, "engine", NA, "rules", "rules", "model_spec", "boost_tree", NULL, "engine", NA, "costs", "costs", "model_spec", "boost_tree", NULL, "engine", NA, ) expect_snapshot( ex_params[1,] %>% structure(class = c("parameters", class(.))) ) expect_snapshot( ex_params[1:2,] %>% structure(class = c("parameters", class(.))) ) expect_snapshot( ex_params[1:3,] %>% structure(class = c("parameters", class(.))) ) }) test_that("parameters.default", { expect_snapshot(error = TRUE, parameters(tibble::as_tibble(mtcars))) }) # ------------------------------------------------------------------------------ # `[]` test_that("subsetting with nothing returns parameters", { x <- parameters(penalty()) expect_s3_class_parameters(x[]) }) # ------------------------------------------------------------------------------ # `[i]` test_that("can subset with just `i` and return parameters if all columns are present", { x <- parameters(penalty()) loc <- seq_len(ncol(x)) expect_s3_class_parameters(x[loc]) }) test_that("removing any parameters specific columns falls back", { x <- parameters(penalty()) expect_s3_class_bare_tibble(x[1]) }) test_that("duplicating an parameters column falls back", { x <- parameters(penalty()) loc <- c(1, seq_len(ncol(x))) expect_s3_class_bare_tibble(x[loc]) }) test_that("can reorder columns and keep parameters class", { x <- parameters(penalty()) loc <- rev(seq_len(ncol(x))) expect_s3_class_parameters(x[loc]) }) # ------------------------------------------------------------------------------ # `[i,]` test_that("row subsetting generally keeps parameters subclass", { x <- parameters(penalty(), mixture()) expect_s3_class_parameters(x[0, ]) expect_s3_class_parameters(x[seq_len(nrow(x)), ]) }) test_that("duplicating rows removes parameters subclass because `id` is duplicated", { x <- parameters(penalty(), mixture()) expect_s3_class_bare_tibble(x[c(1, 2, 1), ]) }) test_that("row slicing with `NA_integer_` drops the subclass", { x <- parameters(penalty(), mixture()) expect_s3_class_bare_tibble(x[NA_integer_, ]) expect_s3_class_bare_tibble(x[c(1, NA_integer_), ]) }) # ------------------------------------------------------------------------------ # `[,j]` # Most of these tests should be the same as `[i]`. test_that("can subset with just `j` and keep parameters class", { x <- parameters(penalty()) loc <- seq_len(ncol(x)) expect_s3_class_parameters(x[, loc]) }) test_that("removing a parameters specific class drops the parameters class", { x <- parameters(penalty()) expect_s3_class_bare_tibble(x[, 1]) }) # ------------------------------------------------------------------------------ # `[i, j]` test_that("row subsetting mixed with col subsetting can drop to tibble", { x <- parameters(penalty(), mixture()) row_loc <- seq_len(nrow(x)) col_loc <- seq_len(ncol(x)) expect_s3_class_bare_tibble(x[row_loc, 1]) expect_s3_class_bare_tibble(x[c(1, 1), col_loc]) }) test_that("row subsetting mixed with col subsetting can keep parameters subclass", { x <- parameters(penalty(), mixture()) row_loc <- seq_len(nrow(x)) col_loc <- seq_len(ncol(x)) expect_s3_class_parameters(x[row_loc, col_loc]) }) # ------------------------------------------------------------------------------ # Misc `[` tests test_that("additional attributes are kept when subsetting and parameters class is kept", { x <- parameters(penalty(), mixture()) attr(x, "foo") <- "bar" loc <- seq_len(ncol(x)) result <- x[loc] expect_s3_class_parameters(result) expect_identical(attr(result, "foo"), "bar") }) test_that("additional attributes are dropped when subsetting and rset class is dropped", { x <- parameters(penalty(), mixture()) attr(x, "foo") <- "bar" result <- x[1] expect_s3_class_bare_tibble(result) expect_identical(attr(result, "foo"), NULL) }) # ------------------------------------------------------------------------------ # `names<-` test_that("renaming triggers a fallback", { x <- parameters(list(penalty(), mixture())) names <- names(x) names[[1]] <- "foo" names(x) <- names expect_s3_class_bare_tibble(x) }) test_that("swapping names triggers a fallback", { x <- parameters(list(penalty(), mixture())) names <- names(x) one <- names[[1]] names[[1]] <- names[[3]] names[[3]] <- one names(x) <- names expect_s3_class_bare_tibble(x) }) test_that("renaming with the same names doesn't fall back", { x <- parameters(list(penalty(), mixture())) names(x) <- names(x) expect_s3_class_parameters(x) }) dials/tests/testthat/helper-s3.R0000644000176200001440000000030614153712300016270 0ustar liggesusersexpect_s3_class_parameters <- function(x) { expect_s3_class(x, "parameters") } expect_s3_class_bare_tibble <- function(x) { expect_s3_class(x, c("tbl_df", "tbl", "data.frame"), exact = TRUE) } dials/tests/testthat/test-extract.R0000644000176200001440000000207214410336366017131 0ustar liggesusers test_that("regular usage", { wflow_param <- parameters( list( "disp" = spline_degree(range = c(1, 15)), "lambda" = penalty(), mixture(range = c(0.05, 1)) ) ) expect_equal(extract_parameter_dials(wflow_param, "lambda"), penalty()) expect_equal(extract_parameter_dials(wflow_param, "mixture"), mixture(c(0.05, 1))) expect_equal(extract_parameter_dials(wflow_param, "disp"), spline_degree(c(1, 15))) }) test_that("bad arguments", { mod_param <- parameters(list("lambda" = penalty(), mixture(range = c(0.05, 1)))) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, "lambdas")) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param)) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, 1)) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, 1:2)) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, letters[1:2])) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, NA_character_)) expect_snapshot(error = TRUE, extract_parameter_dials(mod_param, "")) }) dials/tests/testthat/test-compat-vctrs-parameters.R0000644000176200001440000001134314223270317022236 0ustar liggesusers# ------------------------------------------------------------------------------ # vec_restore() test_that("vec_restore() returns a parameters if `x` retains parameters structure", { x <- parameters(penalty()) expect_s3_class_parameters(vec_restore(x, x)) }) test_that("vec_restore() returns bare tibble if `x` loses parameters structure", { to <- parameters(penalty()) x <- as_tibble(to) x <- x["name"] expect_s3_class_bare_tibble(vec_restore(x, to)) }) test_that("vec_restore() retains extra attributes of `to` when not falling back", { x <- parameters(penalty()) to <- x attr(to, "foo") <- "bar" x_tbl <- as_tibble(x) x_tbl <- x_tbl[1] expect_identical(attr(vec_restore(x, to), "foo"), "bar") expect_identical(attr(vec_restore(x_tbl, to), "foo"), NULL) expect_s3_class_parameters(vec_restore(x, to)) expect_s3_class_bare_tibble(vec_restore(x_tbl, to)) }) # ------------------------------------------------------------------------------ # vec_proxy() test_that("parameters proxy is a bare data frame", { x <- parameters(penalty()) expect_s3_class(vec_proxy(x), "data.frame", exact = TRUE) }) # ------------------------------------------------------------------------------ # vec_ptype2() test_that("vec_ptype2() is working", { x <- parameters(penalty()) y <- parameters(mixture()) tbl <- tibble::tibble(x = 1) df <- data.frame(x = 1) # parameters-parameters expect_identical(vec_ptype2(x, x), dials_global_empty_parameters) expect_identical(vec_ptype2(x, y), dials_global_empty_parameters) # parameters-tbl_df expect_identical(vec_ptype2(x, tbl), vec_ptype2(tib_upcast(x), tbl)) expect_identical(vec_ptype2(tbl, x), vec_ptype2(tbl, tib_upcast(x))) # parameters-df expect_identical(vec_ptype2(x, df), vec_ptype2(tib_upcast(x), df)) expect_identical(vec_ptype2(df, x), vec_ptype2(df, tib_upcast(x))) }) # ------------------------------------------------------------------------------ # vec_cast() test_that("vec_cast() is working", { x <- parameters(penalty()) tbl <- tib_upcast(x) df <- as.data.frame(tbl) # rset-rset expect_identical(vec_cast(x, x), x) # rset-tbl_df expect_identical(vec_cast(x, tbl), tbl) expect_error(vec_cast(tbl, x), class = "vctrs_error_incompatible_type") # rset-df expect_identical(vec_cast(x, df), df) expect_error(vec_cast(df, x), class = "vctrs_error_incompatible_type") }) # ------------------------------------------------------------------------------ # vctrs methods test_that("vec_ptype() returns a parameters", { x <- parameters(penalty()) expect_identical(vec_ptype(x), dials_global_empty_parameters) expect_s3_class_parameters(vec_ptype(x)) }) test_that("vec_slice() generally returns a parameters", { params <- list(penalty(), mixture()) x <- parameters(params) expect_identical(vec_slice(x, 0), dials_global_empty_parameters) expect_identical(vec_slice(x, 1), parameters(params[1])) expect_s3_class_parameters(vec_slice(x, 0)) }) test_that("vec_slice() can return an bare tibble if `id` is duplicated", { params <- list(penalty(), mixture()) x <- parameters(params) expect_identical(vec_slice(x, c(1, 1)), vec_slice(tib_upcast(x), c(1, 1))) expect_s3_class_bare_tibble(vec_slice(x, c(1, 1))) }) test_that("vec_c() returns a parameters when all inputs are parameters unless `id` is duplicated", { params <- list(penalty(), mixture()) x <- parameters(params[1]) y <- parameters(params[2]) tbl <- tib_upcast(x) expect_identical(vec_c(x), x) expect_identical(vec_c(x, x), vec_c(tbl, tbl)) expect_identical(vec_c(x, tbl), vec_c(tbl, tbl)) expect_identical(vec_c(x, y), parameters(params)) expect_identical(vec_c(y, x), parameters(params[2:1])) }) test_that("vec_rbind() returns a parameters when all inputs are parameters unless `id` is duplicated", { params <- list(penalty(), mixture()) x <- parameters(params[1]) y <- parameters(params[2]) tbl <- tib_upcast(x) expect_identical(vec_rbind(x), x) expect_identical(vec_rbind(x, x), vec_rbind(tbl, tbl)) expect_identical(vec_rbind(x, tbl), vec_rbind(tbl, tbl)) expect_identical(vec_rbind(tbl, x), vec_rbind(tbl, tbl)) expect_identical(vec_rbind(x, y), parameters(params)) expect_identical(vec_rbind(y, x), parameters(params[2:1])) }) test_that("vec_cbind() returns a bare tibble", { params <- list(penalty(), mixture()) x <- parameters(params[1]) y <- parameters(params[2]) tbl <- tib_upcast(x) expect_identical(vec_cbind(x), vec_cbind(tbl)) expect_identical( suppressMessages(vec_cbind(x, x)), suppressMessages(vec_cbind(tbl, tbl)) ) expect_identical( suppressMessages(vec_cbind(x, tbl)), suppressMessages(vec_cbind(tbl, tbl)) ) expect_identical( suppressMessages(vec_cbind(tbl, x)), suppressMessages(vec_cbind(tbl, tbl)) ) }) dials/tests/testthat/test-misc.R0000644000176200001440000000272514563657650016432 0ustar liggesusers test_that("formatting", { expect_equal( dials:::format_bounds(c(TRUE, TRUE)), c("[", "]") ) expect_equal( dials:::format_bounds(c(FALSE, TRUE)), c("(", "]") ) expect_equal( dials:::format_bounds(c(TRUE, FALSE)), c("[", ")") ) expect_equal( dials:::format_bounds(c(FALSE, FALSE)), c("(", ")") ) expect_equal( dials:::format_range_val(13214.131), format(13214.131, digits = 3) ) expect_equal( dials:::format_range_val(13214.131, digits = 1), format(13214.131, digits = 1) ) expect_equal( dials:::format_range_val(unknown()), "?" ) }) test_that("check_label()", { expect_no_error(check_label(NULL)) expect_no_error(check_label(c("label_name" = "label"))) expect_snapshot(error = TRUE, check_label("unnamed label")) expect_snapshot(error = TRUE, check_label(c("more", "than", "one", "label"))) }) test_that("check_values_quant()", { expect_no_error(check_values_quant(NULL)) expect_snapshot(error = TRUE, check_values_quant("should have been a numeric")) expect_snapshot(error = TRUE, check_values_quant(c(1, NA))) expect_snapshot(error = TRUE, check_values_quant(numeric())) }) test_that("check_inclusive()", { expect_no_error(check_inclusive(c(TRUE, TRUE))) expect_snapshot(error = TRUE, check_inclusive(TRUE)) expect_snapshot(error = TRUE, check_inclusive(NULL)) expect_snapshot(error = TRUE, check_inclusive(c(TRUE, NA))) expect_snapshot(error = TRUE, check_inclusive(1:2)) }) dials/tests/testthat.R0000644000176200001440000000035414153712300014471 0ustar liggesuserslibrary(testthat) library(dials) if (requireNamespace("xml2")) { test_check("dials", reporter = MultiReporter$new(reporters = list(JunitReporter$new(file = "test-results.xml"), CheckReporter$new()))) } else { test_check("dials") } dials/vignettes/0000755000176200001440000000000014565631734013374 5ustar liggesusersdials/vignettes/dials.Rmd0000644000176200001440000001765614262004201015124 0ustar liggesusers--- title: "Working with Tuning Parameters" vignette: > %\VignetteEngine{knitr::rmarkdown} %\VignetteIndexEntry{Working with Tuning Parameters} output: knitr:::html_vignette: toc: yes --- ```{r setup, include = FALSE} knitr::opts_chunk$set( message = FALSE, digits = 3, collapse = TRUE, comment = "#>" ) options(digits = 3) library(dials) library(rpart) ``` ## Tuning Parameters Some statistical and machine learning models contain _tuning parameters_ (also known as _hyperparameters_), which are parameters that cannot be directly estimated by the model. An example would be the number of neighbors in a _K_-nearest neighbors model. To determine reasonable values of these elements, some indirect method is used such as resampling or profile likelihood. Search methods, such as genetic algorithms or Bayesian search can also be used to [determine good values](https://github.com/topepo/Optimization-Methods-for-Tuning-Predictive-Models). In any case, some information is needed to create a grid or to validate whether a candidate value is appropriate (e.g. the number of neighbors should be a positive integer). `dials` is designed to: * Create an easy to use framework for describing and querying tuning parameters. This can include getting sequences or random tuning values, validating current values, transforming parameters, and other tasks. * Standardize the names of different parameters. Different packages in R use different argument names for the same quantities. `dials` proposes some standardized names so that the user doesn't need to memorize the syntactical minutiae of every package. * Work with the other [tidymodels](https://www.tidymodels.org) packages for modeling and machine learning using [tidyverse](https://www.tidyverse.org/) principles. ## Parameter Objects Parameter objects contain information about possible values, ranges, types, and other aspects. They have two classes: the general `param` class and a more specific subclass related to the type of variable. Double and integer valued data have the subclass `quant_param` while character and logicals have `qual_param`. There are some common elements for each: * Labels are strings that describe the parameter (e.g. "Number of Components"). * Defaults are optional single values that can be set when one non-random value is requested. Otherwise, the information contained in parameter objects are different for different data types. ### Numeric Parameters An example of a numeric tuning parameter is the cost-complexity parameter of CART trees, otherwise known as $C_p$. A parameter object for $C_p$ can be created in `dials` using: ```{r cp} library(dials) cost_complexity() ``` Note that this parameter is handled in log units and the default range of values is between `10^-10` and `0.1`. The range of possible values can be returned and changed based on some utility functions. We'll use the pipe operator here: ```{r cp-range} library(dplyr) cost_complexity() %>% range_get() cost_complexity() %>% range_set(c(-5, 1)) # Or using the `range` argument # during creation cost_complexity(range = c(-5, 1)) ``` Values for this parameter can be obtained in a few different ways. To get a sequence of values that span the range: ```{r cp-seq} # Natural units: cost_complexity() %>% value_seq(n = 4) # Stay in the transformed space: cost_complexity() %>% value_seq(n = 4, original = FALSE) ``` Random values can be sampled too. A random uniform distribution is used (between the range values). Since this parameter has a transformation associated with it, the values are simulated in the transformed scale and then returned in the natural units (although the `original` argument can be used here): ```{r cp-sim} set.seed(5473) cost_complexity() %>% value_sample(n = 4) ``` For CART trees, there is a discrete set of values that exist for a given data set. It may be a good idea to assign these possible values to the object. We can get them by fitting an initial `rpart` model and then adding the values to the object. For `mtcars`, there are only three values: ```{r rpart, error=TRUE} library(rpart) cart_mod <- rpart(mpg ~ ., data = mtcars, control = rpart.control(cp = 0.000001)) cart_mod$cptable cp_vals <- cart_mod$cptable[, "CP"] # We should only keep values associated with at least one split: cp_vals <- cp_vals[ cart_mod$cptable[, "nsplit"] > 0 ] # Here the specific Cp values, on their natural scale, are added: mtcars_cp <- cost_complexity() %>% value_set(cp_vals) ``` The error occurs because the values are not in the transformed scale: ```{r rpart-cp} mtcars_cp <- cost_complexity() %>% value_set(log10(cp_vals)) mtcars_cp ``` Now, if a sequence or random sample is requested, it uses the set values: ```{r rpart-cp-vals} mtcars_cp %>% value_seq(2) # Sampling specific values is done with replacement mtcars_cp %>% value_sample(20) %>% table() ``` Any transformations from the `scales` package can be used with the numeric parameters, or a custom transformation generated with `scales::trans_new()`. ```{r custom-transform} trans_raise <- scales::trans_new( "raise", transform = function(x) 2^x , inverse = function(x) -log2(x) ) custom_cost <- cost(range = c(1, 10), trans = trans_raise) custom_cost ``` Note that if a transformation is used, the `range` argument specifies the parameter range _on the transformed scale_. For this version of `cost()`, parameter values are sampled between 1 and 10 and then transformed back to the original scale by the inverse `-log2()`. So on the original scale, the sampled values are between `-log2(10)` and `-log2(1)`. ```{r custom-cost} -log2(c(10, 1)) value_sample(custom_cost, 100) %>% range() ``` ### Discrete Parameters In the discrete case there is no notion of a range. The parameter objects are defined by their discrete values. For example, consider a parameter for the types of kernel functions that is used with distance functions: ```{r wts} weight_func() ``` The helper functions are analogues to the quantitative parameters: ```{r wts-ex} # redefine values weight_func() %>% value_set(c("rectangular", "triangular")) weight_func() %>% value_sample(3) # the sequence is returned in the order of the levels weight_func() %>% value_seq(3) ``` ## Creating Novel Parameters The package contains two constructors that can be used to create new quantitative and qualitative parameters, `new_quant_param()` and `new_qual_param()`. The [How to create a tuning parameter function](https://www.tidymodels.org/learn/develop/parameters/) article walks you through a detailed example. ## Unknown Values There are some cases where the range of parameter values are data dependent. For example, the upper bound on the number of neighbors cannot be known if the number of data points in the training set is not known. For that reason, some parameters have an _unknown_ placeholder: ```{r unk} mtry() sample_size() num_terms() num_comp() # and so on ``` These values must be initialized prior to generating parameter values. The `finalize()` methods can be used to help remove the unknowns: ```{r finalize-mtry} finalize(mtry(), x = mtcars[, -1]) ``` ## Parameter Sets These are collection of parameters used in a model, recipe, or other object. They can also be created manually and can have alternate identification fields: ```{r p-set} glmnet_set <- parameters(list(lambda = penalty(), alpha = mixture())) glmnet_set # can be updated too update(glmnet_set, alpha = mixture(c(.3, .6))) ``` These objects can be very helpful when creating tuning grids. ## Parameter Grids Sets or combinations of parameters can be created for use in grid search. `grid_regular()`, `grid_random()`, `grid_max_entropy()`, and `grid_latin_hypercube()` take any number of `param` objects or a parameter set. For example, for a glmnet model, a regular grid might be: ```{r glm-reg} grid_regular( mixture(), penalty(), levels = 3 # or c(3, 4), etc ) ``` and, similarly, a random grid is created using ```{r glm-rnd} set.seed(1041) grid_random( mixture(), penalty(), size = 6 ) ``` dials/R/0000755000176200001440000000000014565617025011562 5ustar liggesusersdials/R/param_max_times.R0000644000176200001440000000130514153712300015033 0ustar liggesusers#' Word frequencies for removal #' #' Used in `textrecipes::step_tokenfilter()`. #' #' @inheritParams Laplace #' @examples #' max_times() #' min_times() #' @export max_times <- function(range = c(1L, as.integer(10^5)), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(max_times = "Maximum Token Frequency"), finalize = NULL ) } #' @export #' @rdname max_times min_times <- function(range = c(0L, 1000L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(min_times = "Minimum Token Frequency"), finalize = NULL ) } dials/R/param_validation_set_prop.R0000644000176200001440000000067514410263562017132 0ustar liggesusers#' Proportion of data used for validation #' #' Used in `embed::step_discretize_xgb()`. #' #' @inheritParams Laplace #' @examples #' validation_set_prop() #' @export validation_set_prop <- function(range = c(0.05, 0.7), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(validation_set_prop = "Proportion of data for validation"), finalize = NULL ) } dials/R/param_network.R0000644000176200001440000000305414565421125014552 0ustar liggesusers#' Neural network parameters #' #' These functions generate parameters that are useful for neural network models. #' @inheritParams Laplace #' @details #' * `dropout()`: The parameter dropout rate. (See `parsnip:::mlp()`). #' #' * `epochs()`: The number of iterations of training. (See `parsnip:::mlp()`). #' #' * `hidden_units()`: The number of hidden units in a network layer. #' (See `parsnip:::mlp()`). #' #' * `batch_size()`: The mini-batch size for neural networks. #' @examples #' dropout() #' @export dropout <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, FALSE), trans = trans, label = c(dropout = "Dropout Rate"), finalize = NULL ) } #' @rdname dropout #' @export epochs <- function(range = c(10L, 1000L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(epochs = "# Epochs"), finalize = NULL ) } #' @export #' @rdname dropout hidden_units <- function(range = c(1L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(hidden_units = "# Hidden Units"), finalize = NULL ) } #' @export #' @rdname dropout batch_size <- function(range = c(unknown(), unknown()), trans = transform_log2()) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(batch_size = "Batch Size"), finalize = get_batch_sizes ) } dials/R/param_smoothness.R0000644000176200001440000000056614223270317015264 0ustar liggesusers#' Kernel Smoothness #' #' Used in `discrim::naive_Bayes()`. #' #' @inheritParams Laplace #' @examples #' smoothness() #' @export smoothness <- function(range = c(0.5, 1.5), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(smoothness = "Kernel Smoothness"), finalize = NULL ) } dials/R/param_trees.R0000644000176200001440000000742314565421125014207 0ustar liggesusers#' Parameter functions related to tree- and rule-based models. #' #' These are parameter generating functions that can be used for modeling, #' especially in conjunction with the \pkg{parsnip} package. #' @inheritParams Laplace #' @param values A vector of possible values (`TRUE` or `FALSE`). #' @details #' These functions generate parameters that are useful when the model is #' based on trees or rules. #' #' * `trees()`: The number of trees contained in a random forest or boosted #' ensemble. In the latter case, this is equal to the number of boosting #' iterations. (See `parsnip::rand_forest()` and `parsnip::boost_tree()`). #' #' * `min_n()`: The minimum number of data points in a node that is required #' for the node to be split further. (See `parsnip::rand_forest()` and #' `parsnip::boost_tree()`). #' #' * `sample_size()`: The size of the data set used for modeling within an #' iteration of the modeling algorithm, such as stochastic gradient boosting. #' (See `parsnip::boost_tree()`). #' #' * `sample_prop()`: The same as `sample_size()` but as a proportion of the #' total sample. #' #' * `loss_reduction()`: The reduction in the loss function required to split #' further. (See `parsnip::boost_tree()`). This corresponds to `gamma` in #' \pkg{xgboost}. #' #' * `tree_depth()`: The maximum depth of the tree (i.e. number of splits). #' (See `parsnip::boost_tree()`). #' #' * `prune()`: A logical for whether a tree or set of rules should be pruned. #' #' * `cost_complexity()`: The cost-complexity parameter in classical CART models. #' @examples #' trees() #' min_n() #' sample_size() #' loss_reduction() #' tree_depth() #' prune() #' cost_complexity() #' @export trees <- function(range = c(1L, 2000L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(trees = "# Trees"), finalize = NULL ) } #' @rdname trees #' @export min_n <- function(range = c(2L, 40L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(min_n = "Minimal Node Size"), finalize = get_n_frac ) } #' @rdname trees #' @export sample_size <- function(range = c(unknown(), unknown()), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(sample_size = "# Observations Sampled"), finalize = get_n_frac_range ) } #' @rdname trees #' @export sample_prop <- function(range = c(1/10, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(sample_size = "Proportion Observations Sampled"), finalize = NULL ) } #' @rdname trees #' @export loss_reduction <- function(range = c(-10, 1.5), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(loss_reduction = "Minimum Loss Reduction"), finalize = NULL ) } #' @rdname trees #' @export tree_depth <- function(range = c(1L, 15L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(tree_depth = "Tree Depth"), finalize = NULL ) } #' @export #' @rdname trees prune <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(prune = "Pruning"), finalize = NULL ) } #' @export #' @rdname trees cost_complexity <- function(range = c(-10, -1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(cost_complexity = "Cost-Complexity Parameter"), finalize = NULL ) } dials/R/encode_unit.R0000644000176200001440000000624014565412260014175 0ustar liggesusers# An internal class to go back and forth between encodings for the parameters. # In some cases, we will have to map the parameters to a numeric scale on [0, 1]. # This class goes between the original encoding and the "unit" encoding. #' Class for converting parameter values back and forth to the unit range #' @param x A `param` object. #' @param value The original values should be either numeric or character. When #' converting back, these should be on \code{[0, 1]}. #' @param direction Either "forward" (to \code{[0, 1]}) or "backward". #' @param original A logical; should the values be transformed into their #' natural units. #' @details For integer parameters, the encoding can be lossy. #' @return A vector of values. #' @keywords internal #' @export encode_unit <- function(x, value, direction, ...) { arg_match0(direction, values = c("forward", "backward")) UseMethod("encode_unit") } #' @export encode_unit.default <- function(x, value, direction, ...) { rlang::abort("`x` should be a dials parameter object.") } #' @rdname encode_unit #' @export encode_unit.quant_param <- function(x, value, direction, original = TRUE, ...) { if (has_unknowns(x)) { rlang::abort("The parameter object contains unknowns.") } if (!is.numeric(value) || is.matrix(value)) { rlang::abort("`value` should be a numeric vector.") } param_rng <- x$range$upper - x$range$lower if (direction == "forward") { # convert to [0, 1] value <- (value - x$range$lower) / param_rng } else { # convert [0, 1] to original range compl <- value[!is.na(value)] if (any(compl < 0) | any(compl > 1)) { rlang::abort("Values should be on [0, 1].") } value <- (value * param_rng) + x$range$lower # convert to natural units if req if (original && !is.null(x$trans)) { value <- x$trans$inverse(value) } if (x$type == "integer" && original) { value <- round(value) value <- as.integer(value) } } value } #' @rdname encode_unit #' @export encode_unit.qual_param <- function(x, value, direction, ...) { if (has_unknowns(x)) { rlang::abort("The parameter object contains unknowns.") } ref_vals <- x$values num_lvl <- length(ref_vals) if (direction == "forward") { # convert to [0, 1] if (!is.character(value) || is.matrix(value)) { rlang::abort("`value` should be a character vector.") } compl <- value[!is.na(value)] if (!all(compl %in% ref_vals)) { bad_vals <- compl[!(compl %in% ref_vals)] rlang::abort( "Some values are not in the reference set of possible values: ", paste0("'", unique(bad_vals), "'", collapse = ", ") ) } fac <- factor(value, levels = ref_vals) value <- (as.numeric(fac) - 1) / (num_lvl - 1) } else { # convert [0, 1] to original values compl <- value[!is.na(value)] if (any(compl < 0) | any(compl > 1)) { rlang::abort("Values should be on [0, 1].") } if (!is.numeric(value) || is.matrix(value)) { rlang::abort("`value` should be a numeric vector.") } ind <- cut(value, breaks = seq(0, 1, length.out = num_lvl + 1), include.lowest = TRUE) value <- ref_vals[as.integer(ind)] } value } dials/R/compat-vctrs-helpers-parameters.R0000644000176200001440000000604414331236453020125 0ustar liggesusers# ------------------------------------------------------------------------------ # parameters parameters_reconstruct <- function(x, to) { if (parameters_reconstructable(x, to)) { df_reconstruct(x, to) } else { tib_upcast(x) } } # Invariants: # - Column order doesn't matter # - Column names must be exactly the same after sorting them # - Row order doesn't matter # - Row presence / absence doesn't matter # - Caveat that the `$id` column cannot be duplicated # - Caveat that no rows can have `NA` values # - Column types must be the same # - And `$object` must be a list of `param`s parameters_reconstructable <- function(x, to) { x_names <- names(x) to_names <- names(to) # Must have same number of columns if (length(x_names) != length(to_names)) { return(FALSE) } # Column order doesn't matter x_names <- sort(x_names) to_names <- sort(to_names) # Names must be exactly the same if (!identical(x_names, to_names)) { return(FALSE) } # Strip all extra attributes to only check underlying data x_df <- new_data_frame(x) to_df <- new_data_frame(to) x_df <- x_df[, x_names, drop = FALSE] to_df <- to_df[, x_names, drop = FALSE] x_ptype <- vec_ptype(x_df) to_ptype <- vec_ptype(to_df) # Column types must be identical if (!identical(x_ptype, to_ptype)) { return(FALSE) } # `$object` must be a list of `param` objects x_col_object <- x_df[["object"]] all_params <- all(map_lgl(x_col_object, is_param)) if (!all_params) { return(FALSE) } # `$id` must not be duplicated x_col_id <- x_df[["id"]] any_duplicates <- vctrs::vec_duplicate_any(x_col_id) if (any_duplicates) { return(FALSE) } # Rows must not contain any `NA` values. # `$object` is checked earlier. x_cols <- unclass(x_df) x_cols[["object"]] <- NULL any_na <- any(map_lgl(x_cols, anyNA)) if (any_na) { return(FALSE) } TRUE } # ------------------------------------------------------------------------------ is_param <- function(x) { inherits(x, "param") } is_parameters <- function(x) { inherits(x, "parameters") } # ------------------------------------------------------------------------------ # Maybe this should live in vctrs? # Fallback to a tibble from the current data frame subclass. # Removes subclass specific attributes and additional ones added by the user. tib_upcast <- function(x) { size <- df_size(x) # Strip all attributes except names to construct # a bare list to build the tibble back up from. attributes(x) <- list(names = names(x)) tibble::new_tibble(x, nrow = size) } df_size <- function(x) { if (!is.list(x)) { rlang::abort("Cannot get the df size of a non-list.", .internal = TRUE) } if (length(x) == 0L) { return(0L) } col <- x[[1L]] vctrs::vec_size(col) } # ------------------------------------------------------------------------------ # Maybe this should live in vctrs? df_reconstruct <- function(x, to) { attrs <- attributes(to) attrs$names <- names(x) attrs$row.names <- .row_names_info(x, type = 0L) attributes(x) <- attrs x } dials/R/param_threshold.R0000644000176200001440000000076314263241752015062 0ustar liggesusers#' General thresholding parameter #' #' In a number of cases, there are arguments that are threshold values for #' data falling between zero and one. For example, `recipes::step_other()` and #' so on. #' #' @inheritParams Laplace #' @examples #' threshold() #' @export threshold <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(threshold = "Threshold"), finalize = NULL ) } dials/R/param_mixture.R0000644000176200001440000000150414153712300014543 0ustar liggesusers#' Mixture of penalization terms #' #' A numeric parameter function representing the relative amount of penalties #' (e.g. L1, L2, etc) in regularized models. #' #' @inheritParams Laplace #' @details #' This parameter is used for regularized or penalized models such as #' `parsnip::linear_reg()`, `parsnip::logistic_reg()`, and others. It is #' formulated as the proportion of L1 regularization (i.e. lasso) in the model. #' In the `glmnet` model, `mixture = 1` is a pure lasso model while `mixture = 0` #' indicates that ridge regression is being used. #' @examples #' mixture() #' @export mixture <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(mixture = "Proportion of Lasso Penalty"), finalize = NULL ) } dials/R/type_sum.R0000644000176200001440000000153414153712300013536 0ustar liggesusers#' Succinct summary of parameter objects #' #' `type_sum()` controls how objects are shown when inside tibble #' columns. #' #' @param x A `param` object to summarise. #' #' @details #' #' For `param` objects, the summary prefix is either #' "`dparam`" (if a qualitative parameter) or "`nparam`" (if #' quantitative). Additionally, brackets are used to indicate if #' there are unknown values. For example, "`nparam[?]`" would #' indicate that part of the numeric range is has not been #' finalized and "`nparam[+]`" indicates a parameter that is #' complete. #' #' @return A character value. #' #' @method type_sum param #' @keywords internal #' @export type_sum.param <- function(x) { res <- ifelse(inherits(x, "qual_param"), "dparam", "nparam") if (!has_unknowns(x)) { res <- paste0(res, "[+]") } else { res <- paste0(res, "[?]") } res } dials/R/param_vocabulary_size.R0000644000176200001440000000074214223270317016257 0ustar liggesusers#' Number of tokens in vocabulary #' #' Used in `textrecipes::step_tokenize_sentencepiece()` and #' `textrecipes::step_tokenize_bpe()`. #' #' @inheritParams Laplace #' @examples #' vocabulary_size() #' @export vocabulary_size <- function(range = c(1000L, 32000L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(vocabulary_size = "# Unique Tokens in Vocabulary"), finalize = NULL ) } dials/R/param_momentum.R0000644000176200001440000000065014223270317014715 0ustar liggesusers#' Gradient descent momentum parameter #' #' A useful parameter for neural network models using gradient descent #' #' @inheritParams Laplace #' @examples #' momentum() #' @export momentum <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(momentum = "Gradient Descent Momentum"), finalize = NULL ) } dials/R/param_learn_rate.R0000644000176200001440000000120314565421125015167 0ustar liggesusers#' Learning rate #' #' The parameter is used in boosting methods (`parsnip::boost_tree()`) or some #' types of neural network optimization methods. #' #' @inheritParams Laplace #' @details #' The parameter is used on the log10 scale. The units for the `range` function #' are on this scale. #' #' `learn_rate()` corresponds to `eta` in \pkg{xgboost}. #' @examples #' learn_rate() #' @export learn_rate <- function(range = c(-10, -1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(learn_rate = "Learning Rate"), finalize = NULL ) } dials/R/param_class_weights.R0000644000176200001440000000107114263241752015716 0ustar liggesusers#' Parameters for class weights for imbalanced problems #' #' This parameter can be used to moderate how much influence certain classes #' receive during training. #' #' @inheritParams Laplace #' @details #' Used in `brulee::brulee_logistic_reg()` and `brulee::brulee_mlp()` #' @examples #' class_weights() #' @export class_weights <- function(range = c(1, 10), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(class_weights = "Minority Class Weight"), finalize = NULL ) } dials/R/param_num_breaks.R0000644000176200001440000000066314263241752015213 0ustar liggesusers#' Number of cut-points for binning #' #' This parameter controls how many bins are used when discretizing predictors. #' #' @inheritParams Laplace #' @examples #' num_breaks() #' @export num_breaks <- function(range = c(2L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_breaks = "Number of Cut Points"), finalize = NULL ) } dials/R/aaa_unknown.R0000644000176200001440000000420114526063272014177 0ustar liggesusers#' Placeholder for unknown parameter values #' #' `unknown()` creates an expression used to signify that the value will be #' specified at a later time. #' #' @param x An object or vector or objects to test for unknown-ness. #' #' @param object An object of class `param`. #' #' @return #' #' `unknown()` returns expression value for `unknown()`. #' #' `is_unknown()` returns a vector of logicals as long as `x` that are `TRUE` #' is the element of `x` is unknown, and `FALSE` otherwise. #' #' `has_unknowns()` returns a single logical indicating if the `range` of a `param` #' object has any unknown values. #' #' @examples #' #' # Just returns an expression #' unknown() #' #' # Of course, true! #' is_unknown(unknown()) #' #' # Create a range with a minimum of 1 #' # and an unknown maximum #' range <- c(1, unknown()) #' #' range #' #' # The first value is known, the #' # second is not #' is_unknown(range) #' #' # mtry()'s maximum value is not known at #' # creation time #' has_unknowns(mtry()) #' #' @export unknown <- function() { quote(unknown()) } #' @export #' @rdname unknown is_unknown <- function(x) { # in case `x` is not a vector (language) if (length(x) == 1) { return(is_unknown_val(x)) } map_lgl(x, is_unknown_val) } is_unknown_val <- function(x) { isTRUE(all.equal(x, quote(unknown()))) } #' @export #' @rdname unknown has_unknowns <- function(object) { if (inherits(object, "param")) { return(has_unknowns_val(object)) } map_lgl(object, has_unknowns_val) } has_unknowns_val <- function(object) { if (all(is.na(object))) { return(FALSE) } if (any(names(object) == "range")) { rng_check <- any(is_unknown(object$range)) } else { rng_check <- FALSE } val_check <- any(is_unknown(object$values)) any(rng_check) | any(val_check) } check_for_unknowns <- function(x, ..., call = caller_env()) { check_dots_empty() if (is.atomic(x)) { return(invisible(TRUE)) } if (length(x) == 1 && is_unknown(x)) { rlang::abort("Unknowns not allowed.", call = call) } is_ukn <- map_lgl(x, is_unknown) if (any(is_ukn)) { rlang::abort("Unknowns not allowed.", call = call) } invisible(TRUE) } dials/R/param_window_size.R0000644000176200001440000000060614153712300015411 0ustar liggesusers#' Parameter for the moving window size #' #' Used in `recipes::step_window()`. #' #' @inheritParams Laplace #' @examples #' window_size() #' @export window_size <- function(range = c(3L, 11L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(window_size = "Window Size"), finalize = NULL ) } dials/R/zzz.R0000644000176200001440000000130414153712300012521 0ustar liggesusers# nocov start .onLoad <- function(libname, pkgname) { if (dplyr_pre_1.0.0()) { vctrs::s3_register("dplyr::mutate", "parameters", method = mutate_parameters) vctrs::s3_register("dplyr::arrange", "parameters", method = arrange_parameters) vctrs::s3_register("dplyr::filter", "parameters", method = filter_parameters) vctrs::s3_register("dplyr::rename", "parameters", method = rename_parameters) vctrs::s3_register("dplyr::select", "parameters", method = select_parameters) vctrs::s3_register("dplyr::slice", "parameters", method = slice_parameters) } else { vctrs::s3_register("dplyr::dplyr_reconstruct", "parameters", method = dplyr_reconstruct_parameters) } } # nocov end dials/R/param_engine_c50.R0000644000176200001440000000362514565421125015001 0ustar liggesusers#' Parameters for possible engine parameters for C5.0 #' #' These parameters are auxiliary to tree-based models that use the "C5.0" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("C5.0", ...)`. #' #' @inheritParams Laplace #' @param values For `no_global_pruning()`, `predictor_winnowing()`, and #' `fuzzy_thresholding()` either `TRUE` or `FALSE`. #' @details #' To use these, check `?C50::C5.0Control` to see how they are used. #' @examples #' confidence_factor() #' no_global_pruning() #' predictor_winnowing() #' fuzzy_thresholding() #' rule_bands() #' @rdname c5_parameters #' @export confidence_factor <- function(range = c(-1, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(confidence_factor = "Confidence Factor for Splitting"), finalize = NULL ) } #' @export #' @rdname c5_parameters no_global_pruning <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(no_global_pruning = "Skip Global Pruning?"), finalize = NULL ) } #' @export #' @rdname c5_parameters predictor_winnowing <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(predictor_winnowing = "Use Initial Feature Selection?"), finalize = NULL ) } #' @export #' @rdname c5_parameters fuzzy_thresholding <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(fuzzy_thresholding = "Use Fuzzy Thresholding?"), finalize = NULL ) } #' @export #' @rdname c5_parameters rule_bands <- function(range = c(2L, 500L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rule_bands = "Number of Rule Bands"), finalize = NULL ) } dials/R/param_deg_free.R0000644000176200001440000000075314153712300014613 0ustar liggesusers#' Degrees of freedom (integer) #' #' The number of degrees of freedom used for model parameters. #' #' @inheritParams Laplace #' @details #' One context in which this parameter is used is spline basis functions. #' @examples #' deg_free() #' @export deg_free <- function(range = c(1L, 5L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(deg_free = "Degrees of Freedom"), finalize = NULL ) } dials/R/param_engine_cubist.R0000644000176200001440000000244314263241752015701 0ustar liggesusers#' Parameters for possible engine parameters for Cubist #' #' These parameters are auxiliary to models that use the "Cubist" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("Cubist0", ...)`. #' #' @inheritParams Laplace #' @param values For `unbiased_rules()`, either `TRUE` or `FALSE`. #' @details #' To use these, check `?Cubist::cubistControl` to see how they are used. #' @examples #' extrapolation() #' unbiased_rules() #' max_rules() #' @rdname cubist_parameters #' @export extrapolation <- function(range = c(1, 110), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(extrapolation = "Percent Allowable Extrapolation"), finalize = NULL ) } #' @export #' @rdname cubist_parameters unbiased_rules <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(unbiased_rules = "Use Unbiased Rules?"), finalize = NULL ) } #' @export #' @rdname cubist_parameters max_rules <- function(range = c(1L, 100L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(max_rules = "Maximum Number of Rules"), finalize = NULL ) } dials/R/finalize.R0000644000176200001440000001613114563657650013516 0ustar liggesusers#' Functions to finalize data-specific parameter ranges #' #' These functions take a parameter object and modify the unknown parts of #' `ranges` based on a data set and simple heuristics. #' #' @param object A `param` object or a list of `param` objects. #' #' @param x The predictor data. In some cases (see below) this should only #' include numeric data. #' #' @param force A single logical that indicates that even if the parameter #' object is complete, should it update the ranges anyway? #' #' @param log_vals A logical: should the ranges be set on the log10 scale? #' #' @param ... Other arguments to pass to the underlying parameter #' finalizer functions. For example, for `get_rbf_range()`, the dots are passed #' along to [kernlab::sigest()]. #' #' @param frac A double for the fraction of the data to be used for the upper #' bound. For `get_n_frac_range()` and `get_batch_sizes()`, a vector of two #' fractional values are required. #' #' @param seed An integer to control the randomness of the calculations. #' #' @return #' #' An updated `param` object or a list of updated `param` objects depending #' on what is provided in `object`. #' #' @details #' #' `finalize()` runs the embedded finalizer function contained in the `param` #' object (`object$finalize`) and returns the updated version. The finalization #' function is one of the `get_*()` helpers. #' #' The `get_*()` helper functions are designed to be used with the pipe #' and update the parameter object in-place. #' #' `get_p()` and `get_log_p()` set the upper value of the range to be #' the number of columns in the data (on the natural and #' log10 scale, respectively). #' #' `get_n()` and `get_n_frac()` set the upper value to be the number of #' rows in the data or a fraction of the total number of rows. #' #' `get_rbf_range()` sets both bounds based on the heuristic defined in #' [kernlab::sigest()]. It requires that all columns in `x` be numeric. #' #' @examplesIf interactive() || identical(Sys.getenv("IN_PKGDOWN"), "true") #' library(dplyr) #' car_pred <- select(mtcars, -mpg) #' #' # Needs an upper bound #' mtry() #' finalize(mtry(), car_pred) #' #' # Nothing to do here since no unknowns #' penalty() #' finalize(penalty(), car_pred) #' #' library(kernlab) #' library(tibble) #' library(purrr) #' #' params <- #' tribble( #' ~parameter, ~object, #' "mtry", mtry(), #' "num_terms", num_terms(), #' "rbf_sigma", rbf_sigma() #' ) #' params #' #' # Note that `rbf_sigma()` has a default range that does not need to be #' # finalized but will be changed if used in the function: #' complete_params <- #' params %>% #' mutate(object = map(object, finalize, car_pred)) #' complete_params #' #' params %>% #' dplyr::filter(parameter == "rbf_sigma") %>% #' pull(object) #' complete_params %>% #' dplyr::filter(parameter == "rbf_sigma") %>% #' pull(object) #' #' @export finalize <- function(object, ...) { UseMethod("finalize") } #' @export #' @rdname finalize finalize.list <- function(object, x, force = TRUE, ...) { map(object, finalize, x, force, ...) } #' @export #' @rdname finalize finalize.param <- function(object, x, force = TRUE, ...) { if (is.null(object$finalize)) { return(object) } if (!has_unknowns(object) & !force) { return(object) } object$finalize(object, x = x, ...) } safe_finalize <- function(object, x, force = TRUE, ...) { if (all(is.na(object))) { res <- NA } else { res <- finalize(object, x, force = TRUE, ...) } res } #' @export #' @rdname finalize finalize.parameters <- function(object, x, force = TRUE, ...) { object$object <- map(object$object, safe_finalize, x, force, ...) object } # These two finalize methods are for cases when a tuning parameter has no # parameter object or isn't listed in the tunable method. #' @export #' @rdname finalize finalize.logical <- function(object, x, force = TRUE, ...) { object } #' @export #' @rdname finalize finalize.default <- function(object, x, force = TRUE, ...) { if (all(is.na(object))) { return(object) } else { cls <- paste0("'", class(x), "'", collapse = ", ") rlang::abort(paste0("Cannot finalize an object with class(es): ", cls)) } object } #' @export #' @rdname finalize get_p <- function(object, x, log_vals = FALSE, ...) { check_param(object) rngs <- range_get(object, original = FALSE) if (!is_unknown(rngs$upper)) { return(object) } x_dims <- dim(x) if (is.null(x_dims)) { rlang::abort("Cannot determine number of columns. Is `x` a 2D data object?") } if (log_vals) { rngs[2] <- log10(x_dims[2]) } else { rngs[2] <- x_dims[2] } if (object$type == "integer" & is.null(object$trans)) { rngs <- as.integer(rngs) } range_set(object, rngs) } #' @export #' @rdname finalize get_log_p <- function(object, x, ...) { get_p(object, x, log_vals = TRUE, ...) } #' @export #' @rdname finalize get_n_frac <- function(object, x, log_vals = FALSE, frac = 1/3, ...) { check_param(object) rngs <- range_get(object, original = FALSE) if (!is_unknown(rngs$upper)) { return(object) } x_dims <- dim(x) if (is.null(x_dims)) { rlang::abort("Cannot determine number of columns. Is `x` a 2D data object?") } n_frac <- floor(x_dims[1] * frac) if (log_vals) { rngs[2] <- log10(n_frac) } else { rngs[2] <- n_frac } if (object$type == "integer" & is.null(object$trans) & !log_vals) { rngs <- as.integer(rngs) } range_set(object, rngs) } #' @export #' @rdname finalize get_n_frac_range <- function(object, x, log_vals = FALSE, frac = c(1/10, 5/10), ...) { rngs <- range_get(object, original = FALSE) if (!is_unknown(rngs$upper)) { return(object) } x_dims <- dim(x) if (is.null(x_dims)) { rlang::abort("Cannot determine number of columns. Is `x` a 2D data object?") } n_frac <- sort(floor(x_dims[1] * frac)) if (log_vals) { rngs <- log10(n_frac) } else { rngs <- n_frac } if (object$type == "integer" & is.null(object$trans) & !log_vals) { rngs <- as.integer(rngs) } range_set(object, rngs) } #' @export #' @rdname finalize get_n <- function(object, x, log_vals = FALSE, ...) { get_n_frac(object, x, log_vals, frac = 1, ...) } #' @export #' @rdname finalize get_rbf_range <- function(object, x, seed = sample.int(10^5, 1), ...) { rlang::check_installed("kernlab") suppressPackageStartupMessages(requireNamespace("kernlab", quietly = TRUE)) x_mat <- as.matrix(x) if (!is.numeric(x_mat)) { rlang::abort("The matrix version of the initialization data is not numeric.") } with_seed(seed, rng <- kernlab::sigest(x_mat, ...)[-2]) rng <- log10(rng) range_set(object, rng) } #' @export #' @rdname finalize get_batch_sizes <- function(object, x, frac = c(1/10, 1/3), ...) { rngs <- range_get(object, original = FALSE) if (!is_unknown(rngs$lower) & !is_unknown(rngs$upper)) { return(object) } x_dims <- dim(x) if (is.null(x_dims)) { rlang::abort("Cannot determine number of columns. Is `x` a 2D data object?") } n_frac <- sort(floor(x_dims[1] * frac)) n_frac <- log2(n_frac) if (object$type == "integer" & is.null(object$trans)) { n_frac <- as.integer(n_frac) } range_set(object, n_frac) } dials/R/param_degree.R0000644000176200001440000000344714401405555014320 0ustar liggesusers#' Parameters for exponents #' #' These parameters help model cases where an exponent is of interest (e.g. #' `degree()` or `spline_degree()`) or a product is used (e.g. `prod_degree`). #' #' @inheritParams Laplace #' @details #' `degree()` is helpful for parameters that are real number exponents (e.g. #' `x^degree`) whereas `degree_int()` is for cases where the exponent should be #' an integer. #' #' The difference between `degree_int()` and `spline_degree()` is the default ranges #' (which is based on the context of how/where they are used). #' #' `prod_degree()` is used by `parsnip::mars()` for the number of terms in #' interactions (and generates an integer). #' @examples #' degree() #' degree_int() #' spline_degree() #' prod_degree() #' @export degree <- function(range = c(1, 3), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(degree = "Polynomial Degree"), finalize = NULL ) } #' @rdname degree #' @export degree_int <- function(range = c(1L, 3L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(degree_int = "Polynomial Degree"), finalize = NULL ) } #' @rdname degree #' @export spline_degree <- function(range = c(1L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(spline_degree = "Spline Degrees of Freedom"), finalize = NULL ) } #' @rdname degree #' @export prod_degree <- function(range = c(1L, 2L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(prod_degree = "Degree of Interaction"), finalize = NULL ) } dials/R/param_stop_iter.R0000644000176200001440000000113114153712300015052 0ustar liggesusers#' Early stopping parameter #' #' For some models, the effectiveness of the model can decrease as training #' iterations continue. `stop_iter()` can be used to tune how many iterations #' without an improvement in the objective function occur before training should #' be halted. #' #' @inheritParams Laplace #' @examples #' stop_iter() #' @export stop_iter <- function(range = c(3L, 20L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(stop_iter = "# Iterations Before Stopping"), finalize = NULL ) } dials/R/param_weight_func.R0000644000176200001440000000126214223270317015356 0ustar liggesusers#' Kernel functions for distance weighting #' #' @param values A character string of possible values. See `values_weight_func` #' in examples below. #' #' @details #' This parameter is used in `parsnip:::nearest_neighbors()`. #' @examples #' values_weight_func #' weight_func() #' @export weight_func <- function(values = values_weight_func) { new_qual_param( type = "character", values = values, label = c(weight_func = "Distance Weighting Function"), finalize = NULL ) } #' @rdname weight_func #' @export values_weight_func <- c( "rectangular", "triangular", "epanechnikov", "biweight", "triweight", "cos", "inv", "gaussian", "rank", "optimal" ) dials/R/pull_dials_object.R0000644000176200001440000000175014337647441015370 0ustar liggesusers#' Return a dials parameter object associated with parameters #' #' @description #' `r lifecycle::badge("deprecated")` #' #' This function has been deprecated; please use #' `hardhat::extract_parameter_dials()` instead. #' #' `pull_dials_object()` can extract a single `dials` parameter object from #' different types of objects (e.g. parameter sets, recipes, etc.). #' @param x The results of a call to [parameters()], a recipe, model #' specification, or workflow. #' @param id A single string for the `id` of the parameter. #' @param ... Not currently used. #' @return A `dials` parameter object. #' @keywords internal #' @examples #' glmn_param <- parameters(lambda = penalty(), mixture()) #' # pull_dials_object(glmn_param, "lambda") #' # -> #' extract_parameter_dials(glmn_param, "lambda") #' @export pull_dials_object <- function(x, id, ...) { lifecycle::deprecate_stop( "0.1.0", "pull_dials_object()", "hardhat::extract_parameter_dials()" ) UseMethod("pull_dials_object") } dials/R/param_max_tokens.R0000644000176200001440000000063414223270317015226 0ustar liggesusers#' Maximum number of retained tokens #' #' Used in `textrecipes::step_tokenfilter()`. #' #' @inheritParams Laplace #' @examples #' max_tokens() #' @export max_tokens <- function(range = c(0L, as.integer(10^3)), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(max_tokens = "# Retained Tokens"), finalize = NULL ) } dials/R/param_predictor_prop.R0000644000176200001440000000101014223270317016076 0ustar liggesusers#' Proportion of predictors #' #' The parameter is used in models where a parameter is the proportion of #' predictor variables. #' #' @inheritParams Laplace #' #' @details #' `predictor_prop()` is used in `step_pls()`. #' @examples #' predictor_prop() #' @export predictor_prop <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(FALSE, TRUE), trans = trans, label = c(predictor_prop = "Proportion of Predictors"), finalize = NULL ) } dials/R/dials-package.R0000644000176200001440000000443714565421125014374 0ustar liggesusers#' dials: Tools for working with tuning parameters #' #' `dials` provides a framework for defining, creating, and #' managing tuning parameters for modeling. It contains functions #' to create tuning parameter objects (e.g. `mtry()` or #' `penalty()`) and others for creating tuning grids (e.g. #' `grid_regular()`). There are also functions for generating #' random values or specifying a transformation of the parameters. #' @examples #' #' # Suppose we were tuning a linear regression model that was fit with glmnet #' # and there was a predictor that used a spline basis function to enable a #' # nonlinear fit. We can use `penalty()` and `mixture()` for the glmnet parts #' # and `deg_free()` for the spline. #' #' # A full 3^3 factorial design where the regularization parameter is on #' # the log scale: #' simple_set <- grid_regular(penalty(), mixture(), deg_free(), levels = 3) #' simple_set #' #' # A random grid of 5 combinations #' set.seed(362) #' random_set <- grid_random(penalty(), mixture(), deg_free(), size = 5) #' random_set #' #' # A small space-filling design based on experimental design methods: #' design_set <- grid_max_entropy(penalty(), mixture(), deg_free(), size = 5) #' design_set #' @keywords internal "_PACKAGE" # The following block is used by usethis to automatically manage # roxygen namespace tags. Modify with care! ## usethis namespace: start #' @import rlang #' @importFrom DiceDesign dmaxDesign lhsDesign #' @importFrom dplyr %>% filter mutate pull select #' @importFrom glue glue glue_collapse #' @importFrom lifecycle deprecated #' @importFrom pillar type_sum #' @importFrom purrr map_lgl map2_dfc map_chr map map2 map_dfc map_dbl map_int #' @importFrom scales transform_log2 is.trans transform_log10 #' @importFrom stats runif #' @importFrom tibble as_tibble is_tibble tibble new_tibble #' @importFrom utils installed.packages globalVariables #' @importFrom vctrs df_cast new_data_frame stop_incompatible_cast #' @importFrom vctrs tib_cast tib_ptype2 #' @importFrom vctrs vec_c vec_cast vec_cbind vec_init vec_proxy #' @importFrom vctrs vec_ptype vec_ptype2 vec_rbind vec_restore vec_slice #' @importFrom withr with_seed ## usethis namespace: end NULL utils::globalVariables(c( "component_id", "call_info", "object", "label", "id", "not_final", "component", "name" )) dials/R/import-standalone-types-check.R0000644000176200001440000002761614410617257017572 0ustar liggesusers# Standalone file: do not edit by hand # Source: # ---------------------------------------------------------------------- # # --- # repo: r-lib/rlang # file: standalone-types-check.R # last-updated: 2023-03-13 # license: https://unlicense.org # dependencies: standalone-obj-type.R # imports: rlang (>= 1.1.0) # --- # # ## Changelog # # 2023-03-13: # - Improved error messages of number checkers (@teunbrand) # - Added `allow_infinite` argument to `check_number_whole()` (@mgirlich). # - Added `check_data_frame()` (@mgirlich). # # 2023-03-07: # - Added dependency on rlang (>= 1.1.0). # # 2023-02-15: # - Added `check_logical()`. # # - `check_bool()`, `check_number_whole()`, and # `check_number_decimal()` are now implemented in C. # # - For efficiency, `check_number_whole()` and # `check_number_decimal()` now take a `NULL` default for `min` and # `max`. This makes it possible to bypass unnecessary type-checking # and comparisons in the default case of no bounds checks. # # 2022-10-07: # - `check_number_whole()` and `_decimal()` no longer treat # non-numeric types such as factors or dates as numbers. Numeric # types are detected with `is.numeric()`. # # 2022-10-04: # - Added `check_name()` that forbids the empty string. # `check_string()` allows the empty string by default. # # 2022-09-28: # - Removed `what` arguments. # - Added `allow_na` and `allow_null` arguments. # - Added `allow_decimal` and `allow_infinite` arguments. # - Improved errors with absent arguments. # # # 2022-09-16: # - Unprefixed usage of rlang functions with `rlang::` to # avoid onLoad issues when called from rlang (#1482). # # 2022-08-11: # - Added changelog. # # nocov start # Scalars ----------------------------------------------------------------- .standalone_types_check_dot_call <- .Call check_bool <- function(x, ..., allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x) && .standalone_types_check_dot_call(ffi_standalone_is_bool_1.0.7, x, allow_na, allow_null)) { return(invisible(NULL)) } stop_input_type( x, c("`TRUE`", "`FALSE`"), ..., allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } check_string <- function(x, ..., allow_empty = TRUE, allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { is_string <- .rlang_check_is_string( x, allow_empty = allow_empty, allow_na = allow_na, allow_null = allow_null ) if (is_string) { return(invisible(NULL)) } } stop_input_type( x, "a single string", ..., allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } .rlang_check_is_string <- function(x, allow_empty, allow_na, allow_null) { if (is_string(x)) { if (allow_empty || !is_string(x, "")) { return(TRUE) } } if (allow_null && is_null(x)) { return(TRUE) } if (allow_na && (identical(x, NA) || identical(x, na_chr))) { return(TRUE) } FALSE } check_name <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { is_string <- .rlang_check_is_string( x, allow_empty = FALSE, allow_na = FALSE, allow_null = allow_null ) if (is_string) { return(invisible(NULL)) } } stop_input_type( x, "a valid name", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } IS_NUMBER_true <- 0 IS_NUMBER_false <- 1 IS_NUMBER_oob <- 2 check_number_decimal <- function(x, ..., min = NULL, max = NULL, allow_infinite = TRUE, allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (missing(x)) { exit_code <- IS_NUMBER_false } else if (0 == (exit_code <- .standalone_types_check_dot_call( ffi_standalone_check_number_1.0.7, x, allow_decimal = TRUE, min, max, allow_infinite, allow_na, allow_null ))) { return(invisible(NULL)) } .stop_not_number( x, ..., exit_code = exit_code, allow_decimal = TRUE, min = min, max = max, allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } check_number_whole <- function(x, ..., min = NULL, max = NULL, allow_infinite = FALSE, allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (missing(x)) { exit_code <- IS_NUMBER_false } else if (0 == (exit_code <- .standalone_types_check_dot_call( ffi_standalone_check_number_1.0.7, x, allow_decimal = FALSE, min, max, allow_infinite, allow_na, allow_null ))) { return(invisible(NULL)) } .stop_not_number( x, ..., exit_code = exit_code, allow_decimal = FALSE, min = min, max = max, allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } .stop_not_number <- function(x, ..., exit_code, allow_decimal, min, max, allow_na, allow_null, arg, call) { if (allow_decimal) { what <- "a number" } else { what <- "a whole number" } if (exit_code == IS_NUMBER_oob) { min <- min %||% -Inf max <- max %||% Inf if (min > -Inf && max < Inf) { what <- sprintf("%s between %s and %s", what, min, max) } else if (x < min) { what <- sprintf("%s larger than or equal to %s", what, min) } else if (x > max) { what <- sprintf("%s smaller than or equal to %s", what, max) } else { abort("Unexpected state in OOB check", .internal = TRUE) } } stop_input_type( x, what, ..., allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } check_symbol <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_symbol(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a symbol", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_arg <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_symbol(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "an argument name", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_call <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_call(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a defused call", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_environment <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_environment(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "an environment", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_function <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_function(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a function", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_closure <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_closure(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "an R function", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_formula <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_formula(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a formula", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } # Vectors ----------------------------------------------------------------- check_character <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_character(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a character vector", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_logical <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is_logical(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a logical vector", ..., allow_na = FALSE, allow_null = allow_null, arg = arg, call = call ) } check_data_frame <- function(x, ..., allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x)) { if (is.data.frame(x)) { return(invisible(NULL)) } if (allow_null && is_null(x)) { return(invisible(NULL)) } } stop_input_type( x, "a data frame", ..., allow_null = allow_null, arg = arg, call = call ) } # nocov end dials/R/param_engine_lightgbm.R0000644000176200001440000000146714331000264016175 0ustar liggesusers#' Possible engine parameters for lightbgm #' #' These parameters are auxiliary to tree-based models that use the "lightgbm" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("lightgbm", ...)`. #' #' "lightbgm" is an available engine in the parsnip extension package [bonsai](https://bonsai.tidymodels.org/) #' #' @inheritParams Laplace #' @details #' For more information, see the [lightgbm webpage](https://lightgbm.readthedocs.io/en/latest/Parameters.html). #' @examples #' #' num_leaves() #' #' @rdname lightgbm_parameters #' @export num_leaves <- function(range = c(5, 100), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_leaves = "Number of Leaves"), finalize = NULL ) } dials/R/param_dist_power.R0000644000176200001440000000105614153712300015227 0ustar liggesusers#' Minkowski distance parameter #' #' Used in `parsnip::nearest_neighbor()`. #' #' @inheritParams Laplace #' @details #' This parameter controls how distances are calculated. For example, #' `dist_power = 1` corresponds to Manhattan distance while `dist_power = 2` is #' Euclidean distance. #' @examples #' dist_power() #' @export dist_power <- function(range = c(1, 2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(dist_power = "Minkowski Distance Order") ) } dials/R/param_weight_scheme.R0000644000176200001440000000121614223270317015666 0ustar liggesusers#' Term frequency weighting methods #' #' @param values A character string of possible values. See `values_weight_scheme` #' in examples below. #' #' @details #' This parameter is used in `textrecipes::step_tf()`. #' @examples #' values_weight_scheme #' weight_scheme() #' @export weight_scheme <- function(values = values_weight_scheme) { new_qual_param( type = "character", values = values, label = c(weight_scheme = "Term Frequency Weight Method"), finalize = NULL ) } #' @rdname weight_scheme #' @export values_weight_scheme <- c( "raw count", "binary", "term frequency", "log normalization", "double normalization" ) dials/R/param_engine_earth.R0000644000176200001440000000124214263241752015507 0ustar liggesusers#' Parameters for possible engine parameters for earth models #' #' These parameters are auxiliary to models that use the "earth" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("earth", ...)`. #' #' @inheritParams Laplace #' @details #' To use these, check `?earth::earth` to see how they are used. #' @examples #' max_num_terms() #' @rdname earth_parameters #' @export max_num_terms <- function(range = c(20L, 200L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(max_num_terms = "Maximum Number of Terms"), finalize = NULL ) } dials/R/param_num_hash.R0000644000176200001440000000130514565421125014660 0ustar liggesusers#' Text hashing parameters #' #' Used in `textrecipes::step_texthash()`. #' #' @inheritParams Laplace #' @param values A vector of possible values (TRUE or FALSE). #' @examples #' num_hash() #' signed_hash() #' @export #' @rdname texthash num_hash <- function(range = c(8L, 12L), trans = transform_log2()) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_hash = "# Hash Features"), finalize = NULL ) } #' @export #' @rdname texthash signed_hash <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(signed_hash = "Signed Hash Value"), finalize = NULL ) } dials/R/param_num_clusters.R0000644000176200001440000000056514331000264015574 0ustar liggesusers#' Number of Clusters #' #' Used in most `tidyclust` models. #' #' @inheritParams Laplace #' @examples #' num_clusters() #' @export num_clusters <- function(range = c(1L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_clusters = "# Clusters"), finalize = NULL ) } dials/R/constructors.R0000644000176200001440000001676414563660313014467 0ustar liggesusers#' Tools for creating new parameter objects #' #' These functions are used to construct new parameter objects. Generally, #' these functions are called from higher level parameter generating functions #' like [mtry()]. #' #' @param type A single character value. For quantitative parameters, valid #' choices are `"double"` and `"integer"` while for qualitative factors they are #' `"character"` and `"logical"`. #' #' @param range A two-element vector with the smallest or largest possible #' values, respectively. If these cannot be set when the parameter is defined, #' the `unknown()` function can be used. If a transformation is specified, #' these values should be in the _transformed units_. If `values` is supplied, #' and `range` is `NULL`, `range` will be set to `range(values)`. #' #' @param inclusive A two-element logical vector for whether the range #' values should be inclusive or exclusive. If `values` is supplied, #' and `inclusive` is `NULL`, `inclusive` will be set to `c(TRUE, TRUE)`. #' #' @param default `r lifecycle::badge("deprecated")` #' No longer used. If a value is supplied, it will be ignored and #' a warning will be thrown. #' #' @param trans A `trans` object from the \pkg{scales} package, such as #' [scales::transform_log()] or [scales::transform_reciprocal()]. Create custom #' transforms with [scales::new_transform()]. #' #' @param values A vector of possible values that is required when `type` is #' `"character"` or `"logical"` but optional otherwise. For quantitative #' parameters, this can be used as an alternative to `range` and `inclusive`. #' If set, these will be used by [value_seq()] and [value_sample()]. #' #' @param label An optional named character string that can be used for #' printing and plotting. The name should match the object name (e.g. #' `"mtry"`, `"neighbors"`, etc.) #' #' @param finalize A function that can be used to set the data-specific #' values of a parameter (such as the `range`). #' #' @inheritParams rlang::args_dots_empty #' #' @param call The call passed on to [rlang::abort()]. #' #' @return #' #' An object of class `"param"` with the primary class being either #' `"quant_param"` or `"qual_param"`. The `range` element of the object #' is always converted to a list with elements `"lower"` and `"upper"`. #' #' @examples #' # Create a function that generates a quantitative parameter #' # corresponding to the number of subgroups. #' num_subgroups <- function(range = c(1L, 20L), trans = NULL) { #' new_quant_param( #' type = "integer", #' range = range, #' inclusive = c(TRUE, TRUE), #' trans = trans, #' label = c(num_subgroups = "# Subgroups"), #' finalize = NULL #' ) #' } #' #' num_subgroups() #' #' num_subgroups(range = c(3L, 5L)) #' #' # Custom parameters instantly have access #' # to sequence generating functions #' value_seq(num_subgroups(), 5) #' #' @name new-param #' NULL #' @export #' @rdname new-param new_quant_param <- function(type = c("double", "integer"), range = NULL, inclusive = NULL, default = deprecated(), trans = NULL, values = NULL, label = NULL, finalize = NULL, ..., call = caller_env()) { if (lifecycle::is_present(default)) { lifecycle::deprecate_warn( when = "1.1.0", what = "new_quant_param(default)" ) } check_dots_empty() type <- arg_match0(type, values = c("double", "integer")) check_values_quant(values, call = call) if (!is.null(values)) { # fill in range if user didn't supply one if (is.null(range)) { range <- range(values) } # fill in inclusive if user didn't supply one if (is.null(inclusive)) { inclusive <- c(TRUE, TRUE) } } if (is.null(range)) { cli::cli_abort( "{.arg range} must be supplied if {.arg values} is {.code NULL}.", call = call ) } if (is.null(inclusive)) { cli::cli_abort( "{.arg inclusive} must be supplied if {.arg values} is {.code NULL}.", call = call ) } range <- check_range(range, type, trans, call = call) if (!is.list(range)) { range <- as.list(range) } check_inclusive(inclusive, call = call) if (!is.null(trans) && !is.trans(trans)) { cli::cli_abort( c( x = "{.arg trans} must be a {.cls trans} class object (or {.code NULL}).", i = "See {.fn scales::trans_new}." ), call = call ) } check_label(label, call = call) check_function(finalize, allow_null = TRUE, call = call) names(range) <- names(inclusive) <- c("lower", "upper") res <- list( type = type, range = range, inclusive = inclusive, trans = trans, label = label, finalize = finalize ) class(res) <- c("quant_param", "param") range_validate(res, range, call = call) if (!is.null(values)) { ok_vals <- value_validate(res, values, call = call) if (!all(ok_vals)) { offenders <- values[!ok_vals] cli::cli_abort( "Some values are not valid: {.val {offenders}}.", call = call ) } res$values <- values } res } #' @export #' @rdname new-param new_qual_param <- function(type = c("character", "logical"), values, default = deprecated(), label = NULL, finalize = NULL, ..., call = caller_env()) { if (lifecycle::is_present(default)) { lifecycle::deprecate_warn(when = "1.1.0", what = "new_qual_param(default)") } type <- arg_match0(type, values = c("character", "logical")) switch( type, "logical" = check_logical(values, call = call), "character" = check_character(values, call = call) ) check_label(label, call = call) check_function(finalize, allow_null = TRUE, call = call) res <- list( type = type, label = label, values = values, finalize = finalize ) class(res) <- c("qual_param", "param") res } ################################################################### #' @export print.quant_param <- function(x, digits = 3, ...) { cat_quant_param_header(x) print_transformer(x) cat_quant_param_range(x) cat_quant_param_values(x) invisible(x) } cat_quant_param_header <- function(x) { if (!is.null(x$label)) { cat_line(x$label, " (quantitative)") } else { cat_line("Quantitative Parameter") } } cat_quant_param_range <- function(x) { label <- format_range_label(x, "Range") range <- map_chr(x$range, format_range_val) range <- format_range(x, range) cat_line(label, range) } cat_quant_param_values <- function(x) { values <- x$values if (is.null(values)) { return() } n_values <- length(values) cat_line(glue("Values: {n_values}")) } print_transformer <- function(x) { if (!is.null(x$trans)) { print(eval(x$trans)) } } cat_line <- function(...) { cat(paste0(..., "\n", collapse = "")) } #' @export print.qual_param <- function(x, ...) { if (!is.null(x$label)) { cat(x$label, " (qualitative)\n") } else { cat("Qualitative Parameter\n") } n_values <- length(x$values) cli::cli_text("{n_values} possible value{?s} include:") if (x$type == "character") { lvls <- paste0("'", x$values, "'") } else { lvls <- x$values } cat( glue_collapse( lvls, sep = ", ", last = " and ", width = options()$width ), "\n" ) invisible(x) } dials/R/param_over_ratio.R0000644000176200001440000000161714263241752015236 0ustar liggesusers#' Parameters for class-imbalance sampling #' #' For up- and down-sampling methods, these parameters control how much data are #' added or removed from the training set. #' #' @inheritParams Laplace #' @details #' See `recipes::step_upsample()` and `recipes::step_downsample()` for the #' interpretation of these parameters. #' @examples #' under_ratio() #' over_ratio() #' @export over_ratio <- function(range = c(0.8, 1.2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(over_ratio = "Over-Sampling Ratio"), finalize = NULL ) } #' @export #' @rdname over_ratio under_ratio <- function(range = c(0.8, 1.2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(under_ratio = "Under-Sampling Ratio"), finalize = NULL ) } dials/R/param_trim_amount.R0000644000176200001440000000057614410262711015416 0ustar liggesusers#' Amount of Trimming #' #' Used in `recipes::step_impute_mean()`. #' #' @inheritParams Laplace #' @examples #' trim_amount() #' @export trim_amount <- function(range = c(0, 0.5), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(trim_amount = "Amount of Trimming"), finalize = NULL ) } dials/R/param_engine_ranger.R0000644000176200001440000000544614565421125015673 0ustar liggesusers#' Parameters for possible engine parameters for ranger #' #' These parameters are auxiliary to random forest models that use the "ranger" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("ranger", ...)`. #' #' #' @inheritParams Laplace #' @param values For `splitting_rule()`, a character string of possible values. #' See `ranger_split_rules`, `ranger_class_rules`, and `ranger_reg_rules` for #' appropriate values. For `regularize_depth()`, either `TRUE` or `FALSE`. #' @details #' To use these, check `?ranger::ranger` to see how they are used. Some are #' conditional on others. For example, `significance_threshold()`, #' `num_random_splits()`, and others are only used when #' `splitting_rule = "extratrees"`. #' @examples #' regularization_factor() #' regularize_depth() #' @rdname ranger_parameters #' @export regularization_factor <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(regularization_factor = "Gain Penalization"), finalize = NULL ) } #' @export #' @rdname ranger_parameters regularize_depth <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(regularize_depth = "Regularize Tree Depth?"), finalize = NULL ) } #' @export #' @rdname ranger_parameters significance_threshold <- function(range = c(-10, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(significance_threshold = "Threshold for Significance"), finalize = NULL ) } #' @export #' @rdname ranger_parameters lower_quantile <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(lower_quantile = "Lower Distribution Quantile"), finalize = NULL ) } #' @rdname ranger_parameters #' @export splitting_rule <- function(values = ranger_split_rules) { new_qual_param( type = "character", values = values, label = c(splitting_rule = "Splitting Rule"), finalize = NULL ) } #' @rdname ranger_parameters #' @export ranger_class_rules <- c("variance", "extratrees", "maxstat", "beta") #' @rdname ranger_parameters #' @export ranger_reg_rules <- c("gini", "extratrees", "hellinger") #' @rdname ranger_parameters #' @export ranger_split_rules <- c(ranger_class_rules, ranger_reg_rules) #' @rdname ranger_parameters #' @export num_random_splits <- function(range = c(1L, 15L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_random_splits = "Number of Random Splits"), finalize = NULL ) } dials/R/param_select_features.R0000644000176200001440000000060714153712300016226 0ustar liggesusers#' Parameter to enable feature selection #' #' Used in `parsnip::gen_additive_mod()`. #' #' @param values A vector of possible values (TRUE or FALSE). #' @examples #' select_features() #' @export select_features <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(select_features = "Select Features?"), finalize = NULL ) } dials/R/param_summary_stat.R0000644000176200001440000000114014223270317015577 0ustar liggesusers#' Rolling summary statistic for moving windows #' #' This parameter is used in `recipes::step_window()`. #' #' @param values A character string of possible values. See `values_summary_stat` #' in examples below. #' #' @examples #' values_summary_stat #' summary_stat() #' @export summary_stat <- function(values = values_summary_stat) { new_qual_param( type = "character", values = values, label = c(summary_stat = "Rolling Summary Statistic"), finalize = NULL ) } #' @rdname summary_stat #' @export values_summary_stat <- c("mean", "median", "sd", "var", "sum", "prod", "min", "max") dials/R/param_nzv.R0000644000176200001440000000153514263241752013701 0ustar liggesusers#' Near-zero variance parameters #' #' These parameters control the specificity of the filter for near-zero #' variance parameters in `recipes::step_nzv()`. #' #' @inheritParams Laplace #' @details #' Smaller values of `freq_cut()` and `unique_cut()` make the filter less #' sensitive. #' @examples #' freq_cut() #' unique_cut() #' @export freq_cut <- function(range = c(5, 25), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(freq_cut = "Frequency Distribution Ratio"), finalize = NULL ) } #' @export #' @rdname freq_cut unique_cut <- function(range = c(0, 100), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(unique_cut = "% Unique Values"), finalize = NULL ) } dials/R/param_kernel.R0000644000176200001440000000210214565421125014332 0ustar liggesusers#' Kernel parameters #' #' Parameters related to the radial basis or other kernel functions. #' #' @inheritParams Laplace #' @details #' `degree()` can also be used in kernel functions. #' @examples #' rbf_sigma() #' scale_factor() #' kernel_offset() #' @export rbf_sigma <- function(range = c(-10, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rbf_sigma = "Radial Basis Function sigma"), finalize = get_rbf_range ) } #' @rdname rbf_sigma #' @export scale_factor <- function(range = c(-10, -1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(scale_factor = "Scale Factor"), finalize = NULL ) } #' @rdname rbf_sigma #' @export kernel_offset <- function(range = c(0, 2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(kernel_offset = "Offset"), finalize = NULL ) } dials/R/param_num_runs.R0000644000176200001440000000060014410270702014711 0ustar liggesusers#' Number of Computation Runs #' #' Used in `recipes::step_nnmf()`. #' #' @inheritParams Laplace #' @examples #' num_runs() #' @export num_runs <- function(range = c(1L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_runs = "Number of Computation Runs"), finalize = NULL ) } dials/R/compat-vctrs-parameters.R0000644000176200001440000000414414153712300016454 0ustar liggesusers# ------------------------------------------------------------------------------ # globals delayedAssign("dials_global_empty_parameters", parameters(list())) # ------------------------------------------------------------------------------ # parameters #' @export vec_restore.parameters <- function(x, to, ...) { parameters_reconstruct(x, to) } #' @export vec_proxy.parameters <- function(x, ...) { new_data_frame(x) } #' @export vec_ptype2.parameters.parameters <- function(x, y, ..., x_arg = "", y_arg = "") { dials_global_empty_parameters } #' @export vec_ptype2.parameters.tbl_df <- function(x, y, ..., x_arg = "", y_arg = "") { tib_ptype2(x, y, ..., x_arg = x_arg, y_arg = y_arg) } #' @export vec_ptype2.tbl_df.parameters <- function(x, y, ..., x_arg = "", y_arg = "") { tib_ptype2(x, y, ..., x_arg = x_arg, y_arg = y_arg) } #' @export vec_ptype2.parameters.data.frame <- function(x, y, ..., x_arg = "", y_arg = "") { tib_ptype2(x, y, ..., x_arg = x_arg, y_arg = y_arg) } #' @export vec_ptype2.data.frame.parameters <- function(x, y, ..., x_arg = "", y_arg = "") { tib_ptype2(x, y, ..., x_arg = x_arg, y_arg = y_arg) } #' @export vec_cast.parameters.parameters <- function(x, to, ..., x_arg = "", to_arg = "") { x } #' @export vec_cast.parameters.tbl_df <- function(x, to, ..., x_arg = "", to_arg = "") { stop_incompatible_cast_parameters(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export vec_cast.tbl_df.parameters <- function(x, to, ..., x_arg = "", to_arg = "") { tib_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export vec_cast.parameters.data.frame <- function(x, to, ..., x_arg = "", to_arg = "") { stop_incompatible_cast_parameters(x, to, ..., x_arg = x_arg, to_arg = to_arg) } #' @export vec_cast.data.frame.parameters <- function(x, to, ..., x_arg = "", to_arg = "") { df_cast(x, to, ..., x_arg = x_arg, to_arg = to_arg) } stop_incompatible_cast_parameters <- function(x, to, ..., x_arg, to_arg) { details <- "Can't cast to a because columns names and types are likely incompatible." stop_incompatible_cast(x, to, x_arg = x_arg, to_arg = to_arg, details = details) } dials/R/param_engine_partykit.R0000644000176200001440000000360514565421125016257 0ustar liggesusers#' Parameters for possible engine parameters for partykit models #' #' @param range A two-element vector holding the _defaults_ for the smallest and #' largest possible values, respectively. #' #' @param trans A `trans` object from the `scales` package, such as #' `scales::transform_log10()` or `scales::transform_reciprocal()`. If not provided, #' the default is used which matches the units used in `range`. If no #' transformation, `NULL`. #' @param values A character string of possible values. #' @return For the functions, they return a function with classes "param" and #' either "quant_param" or "qual_param". #' @details #' The range of `conditional_min_criterion()` corresponds to roughly 0.80 to #' 0.99997 in the natural units. For several test types, this parameter #' corresponds to `1 - {p-value}`. #' @export conditional_min_criterion <- function(range = c(1.386294, 15), trans = scales::transform_logit()) { dials::new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(conditional_min_criterion = "Value Needed for Split") ) } #' @export #' @rdname conditional_min_criterion values_test_type <- c("Bonferroni", "MonteCarlo", "Univariate", "Teststatistic") #' @export #' @rdname conditional_min_criterion conditional_test_type <- function(values = values_test_type) { dials::new_qual_param( type = "character", values = values, label = c(conditional_test_type = "Splitting Function Test Type"), finalize = NULL ) } #' @export #' @rdname conditional_min_criterion values_test_statistic <- c("quadratic", "maximum") #' @export #' @rdname conditional_min_criterion conditional_test_statistic <- function(values = values_test_statistic) { dials::new_qual_param( type = "character", values = values, label = c(conditional_test_statistic = "Splitting Function Test Statistic"), finalize = NULL ) } dials/R/param_survival_link.R0000644000176200001440000000110614223270317015741 0ustar liggesusers#' Survival Model Link Function #' #' @param values A character string of possible values. #' See `values_survival_link` in examples below. #' #' @details #' This parameter is used in `parsnip::set_engine('flexsurvspline')`. #' #' @examples #' values_survival_link #' survival_link() #' @export survival_link <- function(values = values_survival_link) { new_qual_param( type = "character", values = values, label = c(survival_link = "Survival Link"), finalize = NULL ) } #' @rdname survival_link #' @export values_survival_link <- c("hazard", "odds", "normal") dials/R/param_adjust_reg_free.R0000644000176200001440000000105714335403714016211 0ustar liggesusers#' Parameters to adjust effective degrees of freedom #' #' This parameter can be used to moderate smoothness of spline or other terms #' used in generalized additive models. #' #' @inheritParams Laplace #' @details #' Used in `parsnip::gen_additive_mod()`. #' @examples #' adjust_deg_free() #' @export adjust_deg_free <- function(range = c(0.25, 4), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(adjust_deg_free = "Smoothness Adjustment"), finalize = NULL ) } dials/R/param_mtry_prop.R0000644000176200001440000000324014262004201015073 0ustar liggesusers#' Proportion of Randomly Selected Predictors #' #' The proportion of predictors that will be randomly sampled at each split when #' creating tree models. #' #' @inheritParams mtry #' #' @return A `dials` object with classes "quant_param" and "param". The #' `range` element of the object is always converted to a list with elements #' "lower" and "upper". #' #' @section Interpretation: #' #' [mtry_prop()] is a variation on [mtry()] where the value is #' interpreted as the _proportion_ of predictors that will be randomly sampled #' at each split rather than the _count_. #' #' This parameter is not intended for use in accommodating engines that take in #' this argument as a proportion; `mtry` is often a main model argument #' rather than an engine-specific argument, and thus should not have an #' engine-specific interface. #' #' When wrapping modeling engines that interpret `mtry` in its sense as a #' proportion, use the [mtry()] parameter in `parsnip::set_model_arg()` and #' process the passed argument in an internal wrapping function as #' `mtry / number_of_predictors`. In addition, introduce a logical argument #' `counts` to the wrapping function, defaulting to `TRUE`, that indicates #' whether to interpret the supplied argument as a count rather than a proportion. #' #' For an example implementation, see `parsnip::xgb_train()`. #' #' @seealso mtry, mtry_long #' #' @examples #' mtry_prop() #' #' @export mtry_prop <- function(range = c(0.1, 1), trans = NULL) { dials::new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(mtry_prop = "Proportion Randomly Selected Predictors"), finalize = NULL ) } dials/R/misc.R0000644000176200001440000000644514565376704012657 0ustar liggesusers### For printing format_range_val <- function(val, ukn = "?", digits = 3) { if (!is_unknown(val)) { txt <- format(val, digits = digits) } else { txt <- ukn } txt } format_range_label <- function(param, header) { if (!is.null(param$trans)) { glue("{header} (transformed scale): ") } else { glue("{header}: ") } } format_range <- function(param, vals) { bnds <- format_bounds(param$inclusive) glue("{bnds[1]}{vals[1]}, {vals[2]}{bnds[2]}") } format_bounds <- function(bnds) { res <- c("(", ")") if (bnds[1]) { res[1] <- "[" } if (bnds[2]) { res[2] <- "]" } res } # checking functions ----------------------------------------------------------- check_label <- function(label, ..., call = caller_env()) { check_dots_empty() check_string(label, allow_null = TRUE, call = call) if (!is.null(label) && length(names(label)) != 1) { cli::cli_abort( "{.arg label} must be named.", call = call ) } invisible(NULL) } check_range <- function(x, type, trans, ..., call = caller_env()) { check_dots_empty() if (!is.null(trans)) { return(invisible(x)) } if (!is.list(x)) { x <- as.list(x) } x0 <- x known <- !is_unknown(x) x <- x[known] x_type <- purrr::map_chr(x, typeof) wrong_type <- any(x_type != type) convert_type <- all(x_type == "double") & type == "integer" if (length(x) > 0 && wrong_type) { if (convert_type) { # logic from from ?is.integer whole <- purrr::map_lgl(x0[known], ~ abs(.x - round(.x)) < .Machine$double.eps^0.5) if (!all(whole)) { msg <- paste(x0[known][!whole], collapse = ", ") msg <- paste0( "An integer is required for the range and these do not appear to be ", "whole numbers: ", msg ) rlang::abort(msg, call = call) } x0[known] <- as.integer(x0[known]) } else { msg <- paste0( "Since `type = '", type, "'`, please use that data type for the range." ) rlang::abort(msg, call = call) } } invisible(x0) } check_values_quant <- function(x, ..., call = caller_env()) { check_dots_empty() if (is.null(x)) { return(invisible(x)) } if (!is.numeric(x)) { rlang::abort("`values` must be numeric.", call = call) } if (anyNA(x)) { rlang::abort("`values` can't be `NA`.", call = call) } if (length(x) == 0) { rlang::abort("`values` can't be empty.", call = call) } invisible(x) } check_inclusive <- function(x, ..., call = caller_env()) { check_dots_empty() if (any(is.na(x))) { cli::cli_abort("{.arg inclusive} cannot contain missings.", call = call) } if (is_logical(x, n = 2)) { return(invisible(NULL)) } stop_input_type( x, "a logical vector of length 2", allow_na = FALSE, allow_null = FALSE, arg = "inclusive", call = call ) } check_param <- function(x, ..., allow_na = FALSE, allow_null = FALSE, arg = caller_arg(x), call = caller_env()) { if (!missing(x) && inherits(x, "param")) { return(invisible(NULL)) } stop_input_type( x, c("a single parameter object"), ..., allow_na = allow_na, allow_null = allow_null, arg = arg, call = call ) } dials/R/param_regularization_method.R0000644000176200001440000000125414223270317017454 0ustar liggesusers#' Estimation methods for regularized models #' #' @param values A character string of possible values. See `values_regularization_method` #' in examples below. #' #' @details #' This parameter is used in `parsnip::discrim_linear()`. #' @examples #' values_regularization_method #' regularization_method() #' @export regularization_method <- function(values = values_regularization_method) { new_qual_param( type = "character", values = values, label = c(regularization_method = "Regularization Method"), finalize = NULL ) } #' @rdname regularization_method #' @export values_regularization_method <- c("diagonal", "min_distance", "shrink_cov", "shrink_mean") dials/R/param_neighbors.R0000644000176200001440000000121314223270317015030 0ustar liggesusers#' Number of neighbors #' #' The number of neighbors is used for models (`parsnip::nearest_neighbor()`), #' imputation (`recipes::step_impute_knn()`), and dimension reduction #' (`recipes::step_isomap()`). #' #' @inheritParams Laplace #' @details #' A static range is used but a broader range should be used if the data set #' is large or more neighbors are required. #' @examples #' neighbors() #' @export neighbors <- function(range = c(1L, 10L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(neighbors = "# Nearest Neighbors"), finalize = NULL ) } dials/R/param_activation.R0000644000176200001440000000115114223270317015212 0ustar liggesusers#' Activation functions between network layers #' @param values A character string of possible values. See `values_activation` #' in examples below. #' #' @details #' This parameter is used in `parsnip` models for neural networks such as #' `parsnip:::mlp()`. #' @examples #' values_activation #' activation() #' @export activation <- function(values = values_activation) { new_qual_param( type = "character", values = values, label = c(activation = "Activation Function"), finalize = NULL ) } #' @rdname activation #' @export values_activation <- c("linear", "softmax", "relu", "elu", "tanh") dials/R/validation.R0000644000176200001440000000161314533336606014036 0ustar liggesusersvalidate_params <- function(..., call = caller_env()) { param_quos <- quos(...) param_expr <- purrr::map_chr(param_quos, rlang::quo_text) if (length(param_quos) == 0) { cli::cli_abort("At least one parameter object is required.", call = call) } params <- map(param_quos, eval_tidy) is_param <- map_lgl(params, function(x) inherits(x, "param")) if (!all(is_param)) { offenders <- param_expr[!is_param] cli::cli_abort( "Th{?is/ese} argument{?s} must have class {.cls param}: \\ {.arg {offenders}}.", call = call ) } bad_param <- has_unknowns(params) if (any(bad_param)) { bad_param <- names(bad_param)[bad_param] cli::cli_abort( c( x = "Th{?is/ese} argument{?s} contain{?s/} unknowns: \\ {.arg {bad_param}}.", i = "See the {.fn dials::finalize} function." ), call = call ) } invisible(NULL) } dials/R/param_harmonic_frequency.R0000644000176200001440000000062114410270702016727 0ustar liggesusers#' Harmonic Frequency #' #' Used in `recipes::step_harmonic()`. #' #' @inheritParams Laplace #' @examples #' harmonic_frequency() #' @export harmonic_frequency <- function(range = c(0.01, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(harmonic_frequency = "Harmonic Frequency"), finalize = NULL ) } dials/R/param_surv_dist.R0000644000176200001440000000114414223270317015075 0ustar liggesusers#' Parametric distributions for censored data #' #' @param values A character string of possible values. See `values_surv_dist` #' in examples below. #' #' @details #' This parameter is used in `parsnip::survival_reg()`. #' @examples #' values_surv_dist #' surv_dist() #' @export surv_dist <- function(values = values_surv_dist) { new_qual_param( type = "character", values = values, label = c(surv_dist = "Distribution"), finalize = NULL ) } #' @rdname surv_dist #' @export values_surv_dist <- c( "weibull", "exponential", "gaussian", "logistic", "lognormal", "loglogistic" ) dials/R/param_all_neighbors.R0000644000176200001440000000060714153712300015661 0ustar liggesusers#' Parameter to determine which neighbors to use #' #' Used in `themis::step_bsmote()`. #' #' @param values A vector of possible values (TRUE or FALSE). #' @examples #' all_neighbors() #' @export all_neighbors <- function(values = c(TRUE, FALSE)) { dials::new_qual_param( type = "logical", values = values, label = c(all_neighbors = "All Neighbors"), finalize = NULL ) } dials/R/param_min_unique.R0000644000176200001440000000071714263241752015236 0ustar liggesusers#' Number of unique values for pre-processing #' #' Some pre-processing parameters require a minimum number of unique data points #' to proceed. #' #' @inheritParams Laplace #' @examples #' min_unique() #' @export min_unique <- function(range = c(5L, 15L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(min_unique = "Unique Value Threshold"), finalize = NULL ) } dials/R/param_engine_sda.R0000644000176200001440000000346314262004201015143 0ustar liggesusers#' Parameters for possible engine parameters for sda models #' #' These functions can be used to optimize engine-specific parameters of #' `sda::sda()` via `parsnip::discrim_linear()`. #' #' @inheritParams Laplace #' @param values A vector of possible values (TRUE or FALSE). #' #' @details #' These functions map to `sda::sda()` arguments via: #' #' \itemize{ #' \item \code{shrinkage_correlation()} to `lambda` #' \item \code{shrinkage_variance()} to `lambda.var` #' \item \code{shrinkage_frequencies()} to `lambda.freqs` #' \item \code{diagonal_covariance()} to `diagonal` #' } #' #' @return For the functions, they return a function with classes `"param"` and #' either `"quant_param"` or `"qual_param"`. #' #' @export shrinkage_correlation <- function(range = c(0, 1), trans = NULL) { dials::new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(shrinkage_correlation = "Correlation Shrinkage Intensity") ) } #' @export #' @rdname shrinkage_correlation shrinkage_variance <- function(range = c(0, 1), trans = NULL) { dials::new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(shrinkage_variance = "Variance Shrinkage Intensity") ) } #' @export #' @rdname shrinkage_correlation shrinkage_frequencies <- function(range = c(0, 1), trans = NULL) { dials::new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(shrinkage_frequencies = "Frequencies Shrinkage Intensity") ) } #' @export #' @rdname shrinkage_correlation diagonal_covariance <- function(values = c(TRUE, FALSE)) { new_qual_param( type = "logical", values = values, label = c(diagonal_covariance = "Diagonal Covariance?"), finalize = NULL ) } dials/R/param_engine_randomForest.R0000644000176200001440000000117014153712300017035 0ustar liggesusers#' Parameters for possible engine parameters for randomForest #' #' These parameters are auxiliary to random forest models that use the "randomForest" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("randomForest", ...)`. #' #' @inheritParams Laplace #' @examples #' max_nodes() #' @rdname randomForest_parameters #' @export max_nodes <- function(range = c(100L, 10000L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(max_nodes = "Maximum Number of Terminal Nodes"), finalize = NULL ) } dials/R/aaa_ranges.R0000644000176200001440000000567114565617025013777 0ustar liggesusers#' Tools for working with parameter ranges #' #' Setters, getters, and validators for parameter ranges. #' #' @param object An object with class `quant_param`. #' #' @param range A two-element numeric vector or list (including `Inf`). Values #' can include `unknown()` when `ukn_ok = TRUE`. #' #' @param ukn_ok A single logical for whether `unknown()` is #' an acceptable value. #' #' @param original A single logical. Should the range values be in the natural #' units (`TRUE`) or in the transformed space (`FALSE`, if applicable)? #' #' @inheritParams new-param #' #' @return #' #' `range_validate()` returns the new range if it passes the validation #' process (and throws an error otherwise). #' #' `range_get()` returns the current range of the object. #' #' `range_set()` returns an updated version of the parameter object with #' a new range. #' #' @examples #' library(dplyr) #' #' my_lambda <- penalty() %>% #' value_set(-4:-1) #' #' try( #' range_validate(my_lambda, c(-10, NA)), #' silent = TRUE #' ) %>% #' print() #' #' range_get(my_lambda) #' #' my_lambda %>% #' range_set(c(-10, 2)) %>% #' range_get() #' #' @export range_validate <- function(object, range, ukn_ok = TRUE, ..., call = caller_env() ) { ukn_txt <- if (ukn_ok) { "`Inf` and `unknown()` are acceptable values." } else { "" } if (length(range) != 2) { rlang::abort( paste("`range` must have two values: an upper and lower bound.", ukn_txt), call = call ) } is_unk <- is_unknown(range) is_na <- is.na(range) is_num <- map_lgl(range, is.numeric) if (!ukn_ok) { if (any(is_unk)) { rlang::abort( "Cannot validate ranges when they contains 1+ unknown values.", call = call ) } if (!any(is_num)) { rlang::abort("`range` should be numeric.", call = call) } # TODO check with transform } else { if (any(is_na[!is_unk])) { rlang::abort("Value ranges must be non-missing.", ukn_txt, call = call) } if (any(!is_num[!is_unk])) { rlang::abort("Value ranges must be numeric.", ukn_txt, call = call) } } range } #' @export #' @rdname range_validate range_get <- function(object, original = TRUE) { if (original & !is.null(object$trans)) { res <- map(object$range, inv_wrap, object) } else { res <- object$range } res } #' @export #' @rdname range_validate range_set <- function(object, range) { if (length(range) != 2) { rlang::abort("`range` should have two elements.") } if (inherits(object, "quant_param")) { object <- new_quant_param( type = object$type, range = range, inclusive = object$inclusive, trans = object$trans, values = object$values, label = object$label ) } else { rlang::abort("`object` should be a 'quant_param' object") } object } dials/R/reexports.R0000644000176200001440000000013314223270317013723 0ustar liggesusers#' @importFrom hardhat extract_parameter_dials #' @export hardhat::extract_parameter_dials dials/R/param_num_knots.R0000644000176200001440000000074214223270317015073 0ustar liggesusers#' Number of knots (integer) #' #' The number of knots used for spline model parameters. #' #' @inheritParams Laplace #' @details #' One context in which this parameter is used is spline basis functions. #' @examples #' num_knots() #' @export num_knots <- function(range = c(0L, 5L), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_knots = "Number of knots"), finalize = NULL ) } dials/R/param_initial_umap.R0000644000176200001440000000162514565615206015543 0ustar liggesusers#' Initialization method for UMAP #' #' This parameter is the type of initialization for the UMAP coordinates. Can be #' one of `"spectral"`, `"normlaplacian"`, `"random"`, `"lvrandom"`, #' `"laplacian"`, `"pca"`, `"spca"`, or `"agspectral"`. See [uwot::umap()] for #' more details. #' #' @param values A character string of possible values. See `values_initial_umap` #' in examples below. #' #' @details #' This parameter is used in `recipes` via [embed::step_umap()]. #' #' @examples #' values_initial_umap #' initial_umap() #' @export initial_umap <- function(values = values_initial_umap) { new_qual_param( type = "character", values = values, label = c(initial_umap = "UMAP Initialization"), finalize = NULL ) } #' @rdname initial_umap #' @export values_initial_umap <- c("spectral", "normlaplacian", "random", "lvrandom", "laplacian", "pca", "spca", "agspectral") dials/R/compat-dplyr-parameters.R0000644000176200001440000000020214153712300016434 0ustar liggesusers# Registered in `.onLoad()` dplyr_reconstruct_parameters <- function(data, template) { parameters_reconstruct(data, template) } dials/R/param_min_dist.R0000644000176200001440000000066314565421125014672 0ustar liggesusers#' Parameter for the effective minimum distance between embedded points #' #' Used in `embed::step_umap()`. #' #' @inheritParams Laplace #' @examples #' min_dist() #' @export min_dist <- function(range = c(-4, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(min_dist = "Min Distance between Points"), finalize = NULL ) } dials/R/extract.R0000644000176200001440000000047614565376704013374 0ustar liggesusers#' @export extract_parameter_dials.parameters <- function(x, parameter, ...) { check_dots_empty() check_string(parameter, allow_empty = FALSE) which_id <- which(x$id == parameter) if (length(which_id) == 0) { cli::cli_abort("No parameter exists with id {.val {parameter}}.") } x$object[[which_id]] } dials/R/param_token.R0000644000176200001440000000116614223270317014177 0ustar liggesusers#' Token types #' #' @param values A character string of possible values. See `values_token` #' in examples below. #' #' @details #' This parameter is used in `textrecipes::step_tokenize()`. #' @examples #' values_token #' token() #' @export token <- function(values = values_token) { new_qual_param( type = "character", values = values, label = c(token = "Token Unit"), finalize = NULL ) } #' @rdname token #' @export values_token <- c( "words", "characters", "character_shingle", "lines", "ngrams", "paragraphs", "ptb", "regex", "sentences", "skip_ngrams", "tweets", "word_stems" ) dials/R/param_target_weight.R0000644000176200001440000000133414565615206015722 0ustar liggesusers#' Amount of supervision parameter #' #' For [uwot::umap()] and [embed::step_umap()], this is a weighting factor #' between data topology and target topology. A value of 0.0 weights entirely #' on data, a value of 1.0 weights entirely on target. The default of 0.5 #' balances the weighting equally between data and target. #' #' @inheritParams Laplace #' #' @details #' This parameter is used in `recipes` via [embed::step_umap()]. #' #' @examples #' target_weight() #' @export target_weight <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, FALSE), trans = trans, label = c(target_weight = "Proportion Supervised"), finalize = NULL ) } dials/R/param_engine_xgboost.R0000644000176200001440000000256614565421125016102 0ustar liggesusers#' Parameters for possible engine parameters for xgboost #' #' These parameters are auxiliary to tree-based models that use the "xgboost" #' engine. They correspond to tuning parameters that would be specified using #' `set_engine("xgboost", ...)`. #' #' @inheritParams Laplace #' @details #' For more information, see the [xgboost webpage](https://xgboost.readthedocs.io/en/latest/parameter.html). #' @examples #' #' scale_pos_weight() #' penalty_L2() #' penalty_L1() #' #' @rdname xgboost_parameters #' @export scale_pos_weight <- function(range = c(0.8, 1.2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(scale_pos_weight = "Balance of Events and Non-Events"), finalize = NULL ) } #' @rdname xgboost_parameters #' @export penalty_L2 <- function(range = c(-10, 1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(penalty_L2 = "Amount of L2 Regularization"), finalize = NULL ) } #' @rdname xgboost_parameters #' @export penalty_L1 <- function(range = c(-10, 1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(penalty_L1 = "Amount of L1 Regularization"), finalize = NULL ) } dials/R/param_bart.R0000644000176200001440000000227114322001611013772 0ustar liggesusers#' Parameters for BART models # #' These parameters are used for constructing Bayesian adaptive regression tree #' (BART) models. #' #' @inheritParams Laplace #' #' @details #' These parameters are often used with Bayesian adaptive regression trees (BART) #' via `parsnip::bart()`. #' @name bart-param #' @export prior_terminal_node_coef <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(FALSE, TRUE), trans = trans, label = c(prior_terminal_node_coef = "Terminal Node Prior Coefficient"), finalize = NULL ) } #' @rdname bart-param #' @export prior_terminal_node_expo <- function(range = c(1, 3), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(FALSE, TRUE), trans = trans, label = c(prior_terminal_node_expo = "Terminal Node Prior Exponent"), finalize = NULL ) } #' @rdname bart-param #' @export prior_outcome_range <- function(range = c(0, 5), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(FALSE, TRUE), trans = trans, label = c(prior_outcome_range = "Prior for Outcome Range"), finalize = NULL ) } dials/R/param_num_comp.R0000644000176200001440000000201614223270317014667 0ustar liggesusers#' Number of new features #' #' The number of derived predictors from models or feature engineering methods. #' #' @inheritParams Laplace #' @details #' Since the scale of these parameters often depends on the number of columns #' in the data set, the upper bound is set to `unknown`. For example, the #' number of PCA components is limited by the number of columns and so on. #' #' The difference between `num_comp()` and `num_terms()` is semantics. #' @examples #' num_terms() #' num_terms(c(2L, 10L)) #' @export num_comp <- function(range = c(1L, unknown()), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_comp = "# Components"), finalize = get_p ) } #' @rdname num_comp #' @export num_terms <- function(range = c(1L, unknown()), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_terms = "# Model Terms"), finalize = get_p ) } dials/R/parameters.R0000644000176200001440000002044514533336606014053 0ustar liggesusers#' Information on tuning parameters within an object #' #' @param x An object, such as a list of `param` objects or an actual `param` #' object. #' @param ... Only used for the `param` method so that multiple `param` objects #' can be passed to the function. #' @export parameters <- function(x, ...) { UseMethod("parameters") } #' @export #' @rdname parameters parameters.default <- function(x, ...) { rlang::abort( glue( "`parameters` objects cannot be created from objects ", "of class `{class(x)[1]}`." ) ) } #' @export #' @rdname parameters parameters.param <- function(x, ...) { x <- list(x, ...) res <- parameters(x) res } #' @export #' @rdname parameters parameters.list <- function(x, ...) { elem_param <- purrr::map_lgl(x, inherits, "param") if (any(!elem_param)) { rlang::abort("The objects should all be `param` objects.") } elem_name <- purrr::map_chr(x, ~ names(.x$label)) elem_id <- names(x) if (length(elem_id) == 0) { elem_id <- elem_name } else { elem_id[elem_id == ""] <- elem_name[elem_id == ""] } p <- length(x) parameters_constr( elem_name, elem_id, rep("list", p), rep("unknown", p), rep("unknown", p), x ) } unique_check <- function(x, ..., call = caller_env()) { check_dots_empty() x2 <- x[!is.na(x)] is_dup <- duplicated(x2) if (any(is_dup)) { dup_list <- x2[is_dup] cl <- match.call() msg <- paste0( "Element `", deparse(cl$x), "` should have unique values. Duplicates exist ", "for item(s): ", paste0("'", dup_list, "'", collapse = ", ") ) rlang::abort(msg, call = call) } invisible(TRUE) } param_or_na <- function(x) { inherits(x, "param") | all(is.na(x)) } check_list_of_param <- function(x, ..., call = caller_env()) { check_dots_empty() if (!is.list(x)) { abort("`object` must be a list of `param` objects.", call = call) } is_good_boi <- map_lgl(x, param_or_na) if (any(!is_good_boi)) { rlang::abort( paste0( "`object` elements in the following positions must be `NA` or a ", "`param` object:", paste0(which(!is_good_boi), collapse = ", ") ), call = call ) } } #' Construct a new parameter set object #' #' @param name,id,source,component,component_id Character strings with the same #' length. #' @param object A list of `param` objects or NA values. #' @inheritParams rlang::args_dots_empty #' @param call The call passed on to [rlang::abort()]. #' #' @return A tibble that encapsulates the input vectors into a tibble with an #' additional class of "parameters". #' @keywords internal #' @export parameters_constr <- function(name, id, source, component, component_id, object, ..., call = caller_env()) { check_dots_empty() check_character(name, call = call) check_character(id, call = call) unique_check(id, call = call) check_character(source, call = call) check_character(component, call = call) check_character(component_id, call = call) check_list_of_param(object, call = call) n_elements <- map_int( list(name, id, source, component, component_id, object), length ) n_elements_unique <- unique(n_elements) if (length(n_elements_unique) > 1) { abort( "All inputs must contain contain the same number of elements.", call = call ) } res <- new_tibble( list( name = name, id = id, source = source, component = component, component_id = component_id, object = object ), nrow = length(name) ) class(res) <- c("parameters", class(res)) res } unk_check <- function(x) { if (all(is.na(x))) { res <- NA } else { res <- has_unknowns(x) } res } #' @export print.parameters <- function(x, ...) { x <- tibble::as_tibble(x) cat("Collection of", nrow(x), "parameters for tuning\n\n") print_x <- x %>% dplyr::select(identifier = id, type = name, object) print_x$object <- purrr::map_chr( print_x$object, ~ if (all(is.na(.x))) { "missing" } else { pillar::type_sum(.x) } ) print.data.frame(print_x, row.names = FALSE) cat("\n") null_obj <- map_lgl(x$object, ~ all(is.na(.x))) if (any(null_obj)) { needs_param <- print_x$identifier[null_obj] last_sep <- if (length(needs_param) == 2) { "` and `" } else { "`, and `" } param_descs <- paste0( "`", glue::glue_collapse(print_x$identifier[null_obj], sep = "`, `", last = last_sep), "`" ) plural <- length(needs_param) != 1 rlang::inform( glue::glue( "The parameter{if (plural) 's' else ''} {param_descs} ", "{if (plural) {'need `param` objects'} else {'needs a `param` object'}}. ", "\nSee `vignette('dials')` to learn more." ) ) } other_obj <- x %>% dplyr::filter(!is.na(object)) %>% mutate( not_final = map_lgl(object, unk_check), label = map_chr(object, ~ .x$label), note = paste0(" ", label, " ('", id, "')\n") ) if (any(other_obj$not_final)) { # There's a more elegant way to do this, I'm sure: mod_obj <- as_tibble(other_obj) %>% dplyr::filter(source == "model_spec" & not_final) if (nrow(mod_obj) > 0) { cat("Model parameters needing finalization:\n") cat(mod_obj$note, sep = "") cat("\n") } rec_obj <- as_tibble(other_obj) %>% dplyr::filter(source == "recipe" & not_final) if (nrow(rec_obj) > 0) { cat("Recipe parameters needing finalization:\n") cat(rec_obj$note, sep = "") cat("\n") } lst_obj <- as_tibble(other_obj) %>% dplyr::filter(source == "list" & not_final) if (nrow(lst_obj) > 0) { cat("Parameters needing finalization:\n") cat(lst_obj$note, sep = "") cat("\n") } cat("See `?dials::finalize` or `?dials::update.parameters` for more information.\n\n") } invisible(x) } # ------------------------------------------------------------------------------ #' Update a single parameter in a parameter set #' #' @param object A parameter set. #' @param ... One or more unquoted named values separated by commas. The names #' should correspond to the `id` values in the parameter set. The values should #' be parameter objects or `NA` values. #' @return The modified parameter set. #' @examples #' params <- list(lambda = penalty(), alpha = mixture(), `rand forest` = mtry()) #' pset <- parameters(params) #' pset #' #' update(pset, `rand forest` = finalize(mtry(), mtcars), alpha = mixture(c(.1, .2))) #' @export update.parameters <- function(object, ...) { args <- rlang::list2(...) if (length(args) == 0) { rlang::abort("Please supply at least one parameter object.") } nms <- names(args) if (length(nms) == 0 || any(nms == "")) { rlang::abort("All arguments should be named.") } in_set <- nms %in% object$id if (!all(in_set)) { msg <- paste0("'", nms[!in_set], "'", collapse = ", ") msg <- paste( "At least one parameter does not match any id's in the set:", msg ) rlang::abort(msg) } not_param <- !purrr::map_lgl(args, inherits, "param") not_null <- !purrr::map_lgl(args, ~ all(is.na(.x))) bad_input <- not_param & not_null if (any(bad_input)) { offenders <- nms[bad_input] cli::cli_abort( "At least one parameter is not a dials parameter object or NA: \\ {offenders}." ) } for (p in nms) { ind <- which(object$id == p) object$object[[ind]] <- args[[p]] } object } # ------------------------------------------------------------------------------ #' @export `[.parameters` <- function(x, i, j, drop = FALSE, ...) { out <- NextMethod() parameters_reconstruct(out, x) } # ------------------------------------------------------------------------------ #' @export `names<-.parameters` <- function(x, value) { out <- NextMethod() # If anything is renamed, we fall back. This ensures # that simply swapping existing column names triggers a fall back. if (!identical_names(out, x)) { out <- tib_upcast(out) return(out) } parameters_reconstruct(out, x) } identical_names <- function(x, y) { x_names <- names(x) y_names <- names(y) identical(x_names, y_names) } dials/R/param_prune_method.R0000644000176200001440000000112314263241752015546 0ustar liggesusers#' MARS pruning methods #' #' @param values A character string of possible values. See `values_prune_method` #' in examples below. #' #' @details #' This parameter is used in `parsnip:::mars()`. #' @examples #' values_prune_method #' prune_method() #' @export prune_method <- function(values = values_prune_method) { new_qual_param( type = c("character"), values = values, label = c(prune_method = "Pruning Method"), finalize = NULL ) } #' @rdname prune_method #' @export values_prune_method <- c( "backward", "none", "exhaustive", "forward", "seqrep", "cv" ) dials/R/param_schedulers.R0000644000176200001440000000577314565421125015234 0ustar liggesusers#' Parameters for neural network learning rate schedulers # #' These parameters are used for constructing neural network models. #' #' @inheritParams Laplace #' @param values A character string of possible values. See `values_scheduler` #' in examples below. #' @details #' These parameters are often used with neural networks via #' `parsnip::mlp(engine = "brulee")`. #' #' The details for how the \pkg{brulee} schedulers change the rates: #' #' * `schedule_decay_time()`: \eqn{rate(epoch) = initial/(1 + decay \times epoch)} #' * `schedule_decay_expo()`: \eqn{rate(epoch) = initial\exp(-decay \times epoch)} #' * `schedule_step()`: \eqn{rate(epoch) = initial \times reduction^{floor(epoch / steps)}} #' * `schedule_cyclic()`: \eqn{cycle = floor( 1 + (epoch / 2 / step size) )}, #' \eqn{x = abs( ( epoch / step size ) - ( 2 * cycle) + 1 )}, and #' \eqn{rate(epoch) = initial + ( largest - initial ) * \max( 0, 1 - x)} #' #' @name scheduler-param #' @export rate_initial <- function (range = c(-3,-1), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_initial = "Initial Learning Rate"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_largest <- function (range = c(-1, -1 / 2), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_largest = "Maximum Learning Rate"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_reduction <- function (range = c(1 / 5, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_reduction = "Learning Rate Reduction"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_steps <- function (range = c(2, 10), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_steps = "Epochs Until Reduction"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_step_size <- function (range = c(2, 20), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_step_size = "Half-Size of Cycle"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_decay <- function (range = c(0, 2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(rate_decay = "Learning Rate Decay"), finalize = NULL ) } #' @rdname scheduler-param #' @export rate_schedule <- function(values = values_scheduler) { new_qual_param( type = "character", values = values, label = c(rate_schedule = "Learning Rate Scheduler"), finalize = NULL ) } #' @rdname scheduler-param #' @export values_scheduler <- c("none", "decay_time", "decay_expo", "cyclic", "step") dials/R/import-standalone-obj-type.R0000644000176200001440000002032314410617257017070 0ustar liggesusers# Standalone file: do not edit by hand # Source: # ---------------------------------------------------------------------- # # --- # repo: r-lib/rlang # file: standalone-obj-type.R # last-updated: 2022-10-04 # license: https://unlicense.org # imports: rlang (>= 1.1.0) # --- # # ## Changelog # # 2022-10-04: # - `obj_type_friendly(value = TRUE)` now shows numeric scalars # literally. # - `stop_friendly_type()` now takes `show_value`, passed to # `obj_type_friendly()` as the `value` argument. # # 2022-10-03: # - Added `allow_na` and `allow_null` arguments. # - `NULL` is now backticked. # - Better friendly type for infinities and `NaN`. # # 2022-09-16: # - Unprefixed usage of rlang functions with `rlang::` to # avoid onLoad issues when called from rlang (#1482). # # 2022-08-11: # - Prefixed usage of rlang functions with `rlang::`. # # 2022-06-22: # - `friendly_type_of()` is now `obj_type_friendly()`. # - Added `obj_type_oo()`. # # 2021-12-20: # - Added support for scalar values and empty vectors. # - Added `stop_input_type()` # # 2021-06-30: # - Added support for missing arguments. # # 2021-04-19: # - Added support for matrices and arrays (#141). # - Added documentation. # - Added changelog. # # nocov start #' Return English-friendly type #' @param x Any R object. #' @param value Whether to describe the value of `x`. Special values #' like `NA` or `""` are always described. #' @param length Whether to mention the length of vectors and lists. #' @return A string describing the type. Starts with an indefinite #' article, e.g. "an integer vector". #' @noRd obj_type_friendly <- function(x, value = TRUE) { if (is_missing(x)) { return("absent") } if (is.object(x)) { if (inherits(x, "quosure")) { type <- "quosure" } else { type <- paste(class(x), collapse = "/") } return(sprintf("a <%s> object", type)) } if (!is_vector(x)) { return(.rlang_as_friendly_type(typeof(x))) } n_dim <- length(dim(x)) if (!n_dim) { if (!is_list(x) && length(x) == 1) { if (is_na(x)) { return(switch( typeof(x), logical = "`NA`", integer = "an integer `NA`", double = if (is.nan(x)) { "`NaN`" } else { "a numeric `NA`" }, complex = "a complex `NA`", character = "a character `NA`", .rlang_stop_unexpected_typeof(x) )) } show_infinites <- function(x) { if (x > 0) { "`Inf`" } else { "`-Inf`" } } str_encode <- function(x, width = 30, ...) { if (nchar(x) > width) { x <- substr(x, 1, width - 3) x <- paste0(x, "...") } encodeString(x, ...) } if (value) { if (is.numeric(x) && is.infinite(x)) { return(show_infinites(x)) } if (is.numeric(x) || is.complex(x)) { number <- as.character(round(x, 2)) what <- if (is.complex(x)) "the complex number" else "the number" return(paste(what, number)) } return(switch( typeof(x), logical = if (x) "`TRUE`" else "`FALSE`", character = { what <- if (nzchar(x)) "the string" else "the empty string" paste(what, str_encode(x, quote = "\"")) }, raw = paste("the raw value", as.character(x)), .rlang_stop_unexpected_typeof(x) )) } return(switch( typeof(x), logical = "a logical value", integer = "an integer", double = if (is.infinite(x)) show_infinites(x) else "a number", complex = "a complex number", character = if (nzchar(x)) "a string" else "\"\"", raw = "a raw value", .rlang_stop_unexpected_typeof(x) )) } if (length(x) == 0) { return(switch( typeof(x), logical = "an empty logical vector", integer = "an empty integer vector", double = "an empty numeric vector", complex = "an empty complex vector", character = "an empty character vector", raw = "an empty raw vector", list = "an empty list", .rlang_stop_unexpected_typeof(x) )) } } vec_type_friendly(x) } vec_type_friendly <- function(x, length = FALSE) { if (!is_vector(x)) { abort("`x` must be a vector.") } type <- typeof(x) n_dim <- length(dim(x)) add_length <- function(type) { if (length && !n_dim) { paste0(type, sprintf(" of length %s", length(x))) } else { type } } if (type == "list") { if (n_dim < 2) { return(add_length("a list")) } else if (is.data.frame(x)) { return("a data frame") } else if (n_dim == 2) { return("a list matrix") } else { return("a list array") } } type <- switch( type, logical = "a logical %s", integer = "an integer %s", numeric = , double = "a double %s", complex = "a complex %s", character = "a character %s", raw = "a raw %s", type = paste0("a ", type, " %s") ) if (n_dim < 2) { kind <- "vector" } else if (n_dim == 2) { kind <- "matrix" } else { kind <- "array" } out <- sprintf(type, kind) if (n_dim >= 2) { out } else { add_length(out) } } .rlang_as_friendly_type <- function(type) { switch( type, list = "a list", NULL = "`NULL`", environment = "an environment", externalptr = "a pointer", weakref = "a weak reference", S4 = "an S4 object", name = , symbol = "a symbol", language = "a call", pairlist = "a pairlist node", expression = "an expression vector", char = "an internal string", promise = "an internal promise", ... = "an internal dots object", any = "an internal `any` object", bytecode = "an internal bytecode object", primitive = , builtin = , special = "a primitive function", closure = "a function", type ) } .rlang_stop_unexpected_typeof <- function(x, call = caller_env()) { abort( sprintf("Unexpected type <%s>.", typeof(x)), call = call ) } #' Return OO type #' @param x Any R object. #' @return One of `"bare"` (for non-OO objects), `"S3"`, `"S4"`, #' `"R6"`, or `"R7"`. #' @noRd obj_type_oo <- function(x) { if (!is.object(x)) { return("bare") } class <- inherits(x, c("R6", "R7_object"), which = TRUE) if (class[[1]]) { "R6" } else if (class[[2]]) { "R7" } else if (isS4(x)) { "S4" } else { "S3" } } #' @param x The object type which does not conform to `what`. Its #' `obj_type_friendly()` is taken and mentioned in the error message. #' @param what The friendly expected type as a string. Can be a #' character vector of expected types, in which case the error #' message mentions all of them in an "or" enumeration. #' @param show_value Passed to `value` argument of `obj_type_friendly()`. #' @param ... Arguments passed to [abort()]. #' @inheritParams args_error_context #' @noRd stop_input_type <- function(x, what, ..., allow_na = FALSE, allow_null = FALSE, show_value = TRUE, arg = caller_arg(x), call = caller_env()) { # From standalone-cli.R cli <- env_get_list( nms = c("format_arg", "format_code"), last = topenv(), default = function(x) sprintf("`%s`", x), inherit = TRUE ) if (allow_na) { what <- c(what, cli$format_code("NA")) } if (allow_null) { what <- c(what, cli$format_code("NULL")) } if (length(what)) { what <- oxford_comma(what) } message <- sprintf( "%s must be %s, not %s.", cli$format_arg(arg), what, obj_type_friendly(x, value = show_value) ) abort(message, ..., call = call, arg = arg) } oxford_comma <- function(chr, sep = ", ", final = "or") { n <- length(chr) if (n < 2) { return(chr) } head <- chr[seq_len(n - 1)] last <- chr[n] head <- paste(head, collapse = sep) # Write a or b. But a, b, or c. if (n > 2) { paste0(head, sep, final, " ", last) } else { paste0(head, " ", final, " ", last) } } # nocov end dials/R/aaa_values.R0000644000176200001440000002013414563647103014004 0ustar liggesusers#' Tools for working with parameter values #' #' Setters and validators for parameter values. Additionally, tools for creating #' sequences of parameter values and for transforming parameter values #' are provided. #' #' @param object An object with class `quant_param`. #' #' @param values A numeric vector or list (including `Inf`). Values #' _cannot_ include `unknown()`. For `value_validate()`, the units should be #' consistent with the parameter object's definition. #' #' @param n An integer for the (maximum) number of values to return. In some #' cases where a sequence is requested, the result might have less than `n` #' values. See Details. #' #' @param original A single logical. Should the range values be in the natural #' units (`TRUE`) or in the transformed space (`FALSE`, if applicable)? #' #' @inheritParams new-param #' #' @return #' #' `value_validate()` throws an error or silently returns `values` if they are #' contained in the values of the `object`. #' #' `value_transform()` and `value_inverse()` return a _vector_ of #' numeric values. #' #' `value_seq()` and `value_sample()` return a vector of values consistent #' with the `type` field of `object`. #' #' @details #' #' For sequences of integers, the code uses #' `unique(floor(seq(min, max, length.out = n)))` and this may generate an #' uneven set of values shorter than `n`. This also means that if `n` is larger #' than the range of the integers, a smaller set will be generated. For #' qualitative parameters, the first `n` values are returned. #' #' For quantitative parameters, any `values` contained in the object #' are sampled with replacement. Otherwise, a sequence of values #' between the `range` values is returned. It is possible that less #' than `n` values are returned. #' #' For qualitative parameters, sampling of the `values` is conducted #' with replacement. For qualitative values, a random uniform distribution #' is used. #' #' @examples #' library(dplyr) #' #' penalty() %>% value_set(-4:-1) #' #' # Is a specific value valid? #' penalty() #' penalty() %>% range_get() #' value_validate(penalty(), 17) #' #' # get a sequence of values #' cost_complexity() #' cost_complexity() %>% value_seq(4) #' cost_complexity() %>% value_seq(4, original = FALSE) #' #' on_log_scale <- cost_complexity() %>% value_seq(4, original = FALSE) #' nat_units <- value_inverse(cost_complexity(), on_log_scale) #' nat_units #' value_transform(cost_complexity(), nat_units) #' #' # random values in the range #' set.seed(3666) #' cost_complexity() %>% value_sample(2) #' #' @export value_validate <- function(object, values, ..., call = caller_env()) { res <- switch(object$type, double = , integer = value_validate_quant(object, values, call = call), character = , logical = value_validate_qual(object, values, call = call) ) unlist(res) } value_validate_quant <- function(object, values, ..., call = caller_env()) { check_dots_empty() check_for_unknowns(object$range, call = call) check_for_unknowns(values, call = call) is_valid <- rep(TRUE, length(values)) # Are they in a valid range (no matter the scale)? if (object$inclusive[1]) { is_valid <- ifelse(values >= object$range[[1]], is_valid, FALSE) } else { is_valid <- ifelse(values > object$range[[1]], is_valid, FALSE) } if (object$inclusive[2]) { is_valid <- ifelse(values <= object$range[[2]], is_valid, FALSE) } else { is_valid <- ifelse(values < object$range[[2]], is_valid, FALSE) } if (!is.null(object$trans)) { orig_scale <- value_inverse(object, values) is_valid[is.na(orig_scale)] <- FALSE } is_valid[is.na(values)] <- FALSE is_valid } value_validate_qual <- function(object, values, ..., call = caller_env()) { check_dots_empty() check_for_unknowns(object$range) check_for_unknowns(values) res <- values %in% object$values res[is.na(res)] <- FALSE res } #' @export #' @rdname value_validate value_seq <- function(object, n, original = TRUE) { if (inherits(object, "quant_param")) { range_validate(object, object$range, ukn_ok = FALSE) } res <- switch(object$type, double = value_seq_dbl(object, n, original), integer = value_seq_int(object, n, original), character = , logical = value_seq_qual(object, n) ) unlist(res) } value_seq_dbl <- function(object, n, original = TRUE) { if (!is.null(object$values)) { n_safely <- min(length(object$values), n) res <- object$values[seq_len(n_safely)] } else { res <- seq( from = min(unlist(object$range)), to = max(unlist(object$range)), length.out = n ) } if (original) { res <- value_inverse(object, res) } res } value_seq_int <- function(object, n, original = TRUE) { if (!is.null(object$values)) { n_safely <- min(length(object$values), n) res <- object$values[seq_len(n_safely)] } else { res <- seq( from = min(unlist(object$range)), to = max(unlist(object$range)), length.out = n ) } if (original) { res <- value_inverse(object, res) res <- unique(floor(res)) res <- as.integer(res) } else { res <- unique(res) } res } value_seq_qual <- function(object, n) { n_safely <- min(length(object$values), n) res <- object$values[seq_len(n_safely)] res } #' @export #' @rdname value_validate value_sample <- function(object, n, original = TRUE) { if (inherits(object, "quant_param")) { range_validate(object, object$range, ukn_ok = FALSE) } res <- switch(object$type, double = value_samp_dbl(object, n, original), integer = value_samp_int(object, n, original), character = , logical = value_samp_qual(object, n) ) unlist(res) } value_samp_dbl <- function(object, n, original = TRUE) { if (is.null(object$values)) { res <- runif( n, min = min(unlist(object$range)), max = max(unlist(object$range)) ) } else { res <- sample( object$values, size = n, replace = TRUE ) } if (original) { res <- value_inverse(object, res) } res } value_samp_int <- function(object, n, original = TRUE) { if (is.null(object$trans)) { if (is.null(object$values)) { res <- sample( min(unlist(object$range)):max(unlist(object$range)), size = n, replace = TRUE ) } else { res <- sample( object$values, size = n, replace = TRUE ) } } else { if (is.null(object$values)) { res <- runif( n, min = min(unlist(object$range)), max = max(unlist(object$range)) ) } else { res <- sample( object$values, size = n, replace = TRUE ) } if (original) { res <- value_inverse(object, res) res <- floor(res) res <- as.integer(res) } } res } value_samp_qual <- function(object, n) { res <- sample( object$values, size = n, replace = TRUE ) } #' @export #' @rdname value_validate value_transform <- function(object, values) { check_for_unknowns(values) if (is.null(object$trans)) { return(values) } map_dbl(values, trans_wrap, object) } trans_wrap <- function(x, object) { if (!is_unknown(x)) { object$trans$transform(x) } else { unknown() } } #' @export #' @rdname value_validate value_inverse <- function(object, values) { check_for_unknowns(values) if (is.null(object$trans)) { return(values) } map_dbl(values, inv_wrap, object) } inv_wrap <- function(x, object) { if (!is_unknown(x)) { object$trans$inverse(x) } else { unknown() } } #' @export #' @rdname value_validate value_set <- function(object, values) { check_for_unknowns(values) if (length(values) == 0) { cli::cli_abort("{.arg values} must have at least one element.") } check_param(object) if (inherits(object, "quant_param")) { object <- new_quant_param( type = object$type, range = object$range, inclusive = object$inclusive, trans = object$trans, values = unname(values), label = object$label ) } else { object <- new_qual_param( type = object$type, values = unname(values), label = object$label ) } object } dials/R/param_svm.R0000644000176200001440000000124014565421125013661 0ustar liggesusers#' Support vector machine parameters #' #' Parameters related to the SVM objective function(s). #' #' @inheritParams Laplace #' @examples #' cost() #' svm_margin() #' @export cost <- function(range = c(-10, 5), trans = transform_log2()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(cost = "Cost"), finalize = NULL ) } #' @rdname cost #' @export svm_margin <- function(range = c(0, .2), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(margin = "Insensitivity Margin"), finalize = NULL ) } dials/R/compat-dplyr-old-parameters.R0000644000176200001440000000156314153712300017223 0ustar liggesusersdplyr_pre_1.0.0 <- function() { utils::packageVersion("dplyr") <= "0.8.5" } # Registered in `.onLoad()` mutate_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } # Registered in `.onLoad()` arrange_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } # Registered in `.onLoad()` filter_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } # Registered in `.onLoad()` rename_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } # Registered in `.onLoad()` select_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } # Registered in `.onLoad()` slice_parameters <- function(.data, ...) { out <- NextMethod() parameters_reconstruct(out, .data) } dials/R/param_num_tokens.R0000644000176200001440000000063314153712300015232 0ustar liggesusers#' Parameter to determine number of tokens in ngram #' #' Used in `textrecipes::step_ngram()`. #' #' @inheritParams Laplace #' @examples #' num_tokens() #' @export num_tokens <- function(range = c(1, 3), trans = NULL) { dials::new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(num_tokens = "Number of tokens"), finalize = NULL ) } dials/R/space_filling.R0000644000176200001440000001636514565421125014511 0ustar liggesusers#' Space-filling parameter grids #' #' Experimental designs for computer experiments are used to construct parameter #' grids that try to cover the parameter space such that any portion of the #' space has an observed combination that is not too far from it. #' #' The types of designs supported here are latin hypercube designs and designs #' that attempt to maximize the determinant of the spatial correlation matrix #' between coordinates. Both designs use random sampling of points in the #' parameter space. #' #' @includeRmd man/rmd/sfd_notes.md details #' #' @inheritParams grid_random #' @param size A single integer for the total number of parameter value #' combinations returned. If duplicate combinations are #' generated from this size, the smaller, unique set is returned. #' @param variogram_range A numeric value greater than zero. Larger values #' reduce the likelihood of empty regions in the parameter space. #' @param iter An integer for the maximum number of iterations used to find #' a good design. #' @references Sacks, Jerome & Welch, William & J. Mitchell, Toby, and Wynn, Henry. #' (1989). Design and analysis of computer experiments. With comments and a #' rejoinder by the authors. Statistical Science. 4. 10.1214/ss/1177012413. #' #' Santner, Thomas, Williams, Brian, and Notz, William. (2003). The Design and #' Analysis of Computer Experiments. Springer. #' #' Dupuy, D., Helbert, C., and Franco, J. (2015). DiceDesign and DiceEval: Two R #' packages for design and analysis of computer experiments. Journal of #' Statistical Software, 65(11) #' @examples #' grid_max_entropy( #' hidden_units(), #' penalty(), #' epochs(), #' activation(), #' learn_rate(c(0, 1), trans = scales::transform_log()), #' size = 10, #' original = FALSE #' ) #' #' grid_latin_hypercube(penalty(), mixture(), original = TRUE) #' @export grid_max_entropy <- function(x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000) { dots <- list(...) if (any(names(dots) == "levels")) { rlang::warn("`levels` is not an argument to `grid_max_entropy()`. Did you mean `size`?") } UseMethod("grid_max_entropy") } #' @export #' @rdname grid_max_entropy grid_max_entropy.parameters <- function(x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000) { # test for NA and finalized # test for empty ... params <- x$object names(params) <- x$id grd <- make_max_entropy_grid( !!!params, size = size, original = original, variogram_range = variogram_range, iter = iter ) names(grd) <- x$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_max_entropy.list <- function(x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000) { y <- parameters(x) params <- y$object names(params) <- y$id grd <- make_max_entropy_grid( !!!params, size = size, original = original, variogram_range = variogram_range, iter = iter ) names(grd) <- y$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_max_entropy.param <- function(x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000) { y <- parameters(list(x, ...)) params <- y$object names(params) <- y$id grd <- make_max_entropy_grid( !!!params, size = size, original = original, variogram_range = variogram_range, iter = iter ) names(grd) <- y$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_max_entropy.workflow <- function(x, ..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000) { lifecycle::deprecate_stop( when = "1.2.0", what = "grid_max_entropy.workflow()", details = "Alternatively, first extract the parameter set with `extract_parameter_set_dials()`, then create the grid from that object." ) } make_max_entropy_grid <- function(..., size = 3, original = TRUE, variogram_range = 0.5, iter = 1000, call = caller_env()) { validate_params(..., call = call) param_quos <- quos(...) params <- map(param_quos, eval_tidy) param_names <- names(param_quos) param_labs <- map_chr(params, function(x) x$label) names(param_labs) <- param_names # ---------------------------------------------------------------------------- rngs <- map(params, range_get, original = FALSE) sfd <- DiceDesign::dmaxDesign( n = size, dimension = length(params), range = variogram_range, niter_max = iter, seed = sample.int(10^5, 1) ) colnames(sfd$design) <- param_names sf_grid <- as_tibble(sfd$design) # Get back to parameter units sf_grid <- map2_dfc( params, sf_grid, encode_unit, direction = "backward", original = original ) colnames(sf_grid) <- param_names sf_grid } #' @export #' @rdname grid_max_entropy grid_latin_hypercube <- function(x, ..., size = 3, original = TRUE) { dots <- list(...) if (any(names(dots) == "levels")) { rlang::warn("`levels` is not an argument to `grid_latin_hypercube()`. Did you mean `size`?") } UseMethod("grid_latin_hypercube") } #' @export #' @rdname grid_max_entropy grid_latin_hypercube.parameters <- function(x, ..., size = 3, original = TRUE) { # test for NA and finalized # test for empty ... params <- x$object names(params) <- x$id grd <- make_latin_hypercube_grid(!!!params, size = size, original = original) names(grd) <- x$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_latin_hypercube.list <- function(x, ..., size = 3, original = TRUE) { y <- parameters(x) params <- y$object names(params) <- y$id grd <- make_latin_hypercube_grid(!!!params, size = size, original = original) names(grd) <- y$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_latin_hypercube.param <- function(x, ..., size = 3, original = TRUE) { y <- parameters(list(x, ...)) params <- y$object names(params) <- y$id grd <- make_latin_hypercube_grid(!!!params, size = size, original = original) names(grd) <- y$id new_param_grid(grd) } #' @export #' @rdname grid_max_entropy grid_latin_hypercube.workflow <- function(x, ..., size = 3, original = TRUE) { lifecycle::deprecate_stop( when = "1.2.0", what = "grid_latin_hypercube.workflow()", details = "Alternatively, first extract the parameter set with `extract_parameter_set_dials()`, then create the grid from that object." ) } make_latin_hypercube_grid <- function(..., size = 3, original = TRUE, call = caller_env()) { validate_params(..., call = call) param_quos <- quos(...) params <- map(param_quos, eval_tidy) param_labs <- map_chr(params, function(x) x$label) param_names <- names(param_quos) names(param_labs) <- param_names # ---------------------------------------------------------------------------- sfd <- DiceDesign::lhsDesign( n = size, dimension = length(params), seed = sample.int(10^5, 1) ) colnames(sfd$design) <- param_names sf_grid <- as_tibble(sfd$design) # Get back to parameter units sf_grid <- map2_dfc( params, sf_grid, encode_unit, direction = "backward", original = original ) colnames(sf_grid) <- param_names sf_grid } dials/R/param_Laplace.R0000644000176200001440000000176314565421125014427 0ustar liggesusers#' Laplace correction parameter #' #' Laplace correction for smoothing low-frequency counts. #' #' @param range A two-element vector holding the _defaults_ for the smallest and #' largest possible values, respectively. If a transformation is specified, #' these values should be in the _transformed units_. #' #' @param trans A `trans` object from the `scales` package, such as #' `scales::transform_log10()` or `scales::transform_reciprocal()`. If not provided, #' the default is used which matches the units used in `range`. If no #' transformation, `NULL`. #' #' @details #' This parameter is often used to correct for zero-count data in tables or #' proportions. #' #' @return A function with classes `"quant_param"` and `"param"`. #' #' @examples #' Laplace() #' @export Laplace <- function(range = c(0, 3), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(Laplace = "Laplace Correction"), finalize = NULL ) } dials/R/param_weight.R0000644000176200001440000000063214565421125014347 0ustar liggesusers#' Parameter for `"double normalization"` when creating token counts #' #' Used in `textrecipes::step_tf()`. #' #' @inheritParams Laplace #' @examples #' weight() #' @export weight <- function(range = c(-10, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(weight = "Weight"), finalize = NULL ) } dials/R/param_sparse_bayes_pca.R0000644000176200001440000000231314565421125016361 0ustar liggesusers#' Bayesian PCA parameters #' #' A numeric parameter function representing parameters for the spike-and-slab #' prior used by `embed::step_pca_sparse_bayes()`. #' #' #' @inheritParams Laplace #' @details #' `prior_slab_dispersion()` is related to the prior for the case where a PCA #' loading is selected (i.e. non-zero). Smaller values result in an increase in #' zero coefficients. #' #' `prior_mixture_threshold()` is used to threshold the prior to determine which #' parameters are non-zero or zero. Increasing this parameter increases the #' number of zero coefficients. #' @examples #' mixture() #' @export prior_slab_dispersion <- function(range = c(-1/2, log10(3)), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(prior_slab_dispersion = "Dispersion of Slab Prior"), finalize = NULL ) } #' @export #' @rdname prior_slab_dispersion prior_mixture_threshold <- function(range = c(0, 1), trans = NULL) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, FALSE), trans = trans, label = c(prior_mixture_threshold = "Threshold for Mixture Prior"), finalize = NULL ) } dials/R/param_mtry.R0000644000176200001440000000245014565421125014053 0ustar liggesusers#' Number of randomly sampled predictors #' #' The number of predictors that will be randomly sampled at each split when #' creating tree models. #' #' @inheritParams Laplace #' @details #' This parameter is used for regularized or penalized models such as #' `parsnip::rand_forest()` and others. `mtry_long()` has the values on the #' log10 scale and is helpful when the data contain a large number of predictors. #' #' Since the scale of the parameter depends on the number of columns in the #' data set, the upper bound is set to `unknown` but can be filled in via the #' `finalize()` method. #' @inheritSection mtry_prop Interpretation #' @examples #' mtry(c(1L, 10L)) # in original units #' mtry_long(c(0, 5)) # in log10 units #' @seealso mtry_prop #' @export mtry <- function(range = c(1L, unknown()), trans = NULL) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(mtry = "# Randomly Selected Predictors"), finalize = get_p ) } #' @export #' @rdname mtry mtry_long <- function(range = c(0L, unknown()), trans = transform_log10()) { new_quant_param( type = "integer", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(mtry = "# Randomly Selected Predictors"), finalize = get_log_p ) } dials/R/grids.R0000644000176200001440000002036014412554265013013 0ustar liggesusers#' Create grids of tuning parameters #' #' Random and regular grids can be created for any number of parameter objects. #' #' @param x A `param` object, list, or `parameters`. #' @param ... One or more `param` objects (such as [mtry()] or #' [penalty()]). None of the objects can have `unknown()` values in #' the parameter ranges or values. #' #' @param levels An integer for the number of values of each parameter to use #' to make the regular grid. `levels` can be a single integer or a vector of #' integers that is the same length as the number of parameters in `...`. #' `levels` can be a named integer vector, with names that match the id values #' of parameters. #' #' @param size A single integer for the total number of parameter value #' combinations returned for the random grid. If duplicate combinations are #' generated from this size, the smaller, unique set is returned. #' #' @param original A logical: should the parameters be in the original units or #' in the transformed space (if any)? #' #' @param filter A logical: should the parameters be filtered prior to #' generating the grid. Must be a single expression referencing parameter #' names that evaluates to a logical vector. #' #' @includeRmd man/rmd/rand_notes.md details #' #' @return #' #' A tibble. There are columns for each parameter and a row for every #' parameter combination. #' #' @examples #' # filter arg will allow you to filter subsequent grid data frame based on some condition. #' p <- parameters(penalty(), mixture()) #' grid_regular(p) #' grid_regular(p, filter = penalty <= .01) #' #' # Will fail due to unknowns: #' # grid_regular(mtry(), min_n()) #' #' grid_regular(penalty(), mixture()) #' grid_regular(penalty(), mixture(), levels = 3:4) #' grid_regular(penalty(), mixture(), levels = c(mixture = 4, penalty = 3)) #' grid_random(penalty(), mixture()) #' #' @export grid_regular <- function(x, ..., levels = 3, original = TRUE, filter = NULL) { dots <- list(...) if (any(names(dots) == "size")) { rlang::warn("`size` is not an argument to `grid_regular()`. Did you mean `levels`?") } UseMethod("grid_regular") } #' @export #' @rdname grid_regular grid_regular.parameters <- function(x, ..., levels = 3, original = TRUE, filter = NULL) { # test for NA and finalized # test for empty ... params <- x$object names(params) <- x$id grd <- make_regular_grid( !!!params, levels = levels, original = original, filter = {{ filter }} ) names(grd) <- x$id grd } #' @export #' @rdname grid_regular grid_regular.list <- function(x, ..., levels = 3, original = TRUE, filter = NULL) { y <- parameters(x) params <- y$object names(params) <- y$id grd <- make_regular_grid( !!!params, levels = levels, original = original, filter = {{ filter }} ) names(grd) <- y$id grd } #' @export #' @rdname grid_regular grid_regular.param <- function(x, ..., levels = 3, original = TRUE, filter = NULL) { y <- parameters(list(x, ...)) params <- y$object names(params) <- y$id grd <- make_regular_grid( !!!params, levels = levels, original = original, filter = {{ filter }} ) names(grd) <- y$id grd } #' @export #' @rdname grid_regular grid_regular.workflow <- function(x, ..., levels = 3, original = TRUE, filter = NULL) { lifecycle::deprecate_stop( when = "1.2.0", what = "grid_regular.workflow()", details = "Alternatively, first extract the parameter set with `extract_parameter_set_dials()`, then create the grid from that object." ) } make_regular_grid <- function(..., levels = 3, original = TRUE, filter = NULL, call = caller_env()) { validate_params(..., call = call) filter_quo <- enquo(filter) param_quos <- quos(...) params <- map(param_quos, eval_tidy) param_names <- names(param_quos) # check levels p <- length(levels) if (p > 1 && p != length(param_quos)) { rlang::abort( paste0("`levels` should have length 1 or ", length(param_quos)), call = call ) } if (p == 1) { param_seq <- map(params, value_seq, n = levels, original = original) } else { if (all(rlang::has_name(levels, names(params)))) { levels <- levels[names(params)] } else if (any(rlang::has_name(levels, names(params)))) { rlang::abort( "Elements of `levels` should either be all named or unnamed, not mixed.", call = call ) } param_seq <- map2(params, as.list(levels), value_seq, original = original) } names(param_seq) <- param_names parameters <- expand.grid(param_seq, stringsAsFactors = FALSE) if (!(quo_is_null(filter_quo))) { parameters <- dplyr::filter(parameters, !!filter_quo) } new_param_grid(parameters) } # ------------------------------------------------------------------------------ #' @export #' @rdname grid_regular grid_random <- function(x, ..., size = 5, original = TRUE, filter = NULL) { dots <- list(...) if (any(names(dots) == "levels")) { rlang::warn( "`levels` is not an argument to `grid_random()`. Did you mean `size`?" ) } UseMethod("grid_random") } #' @export #' @rdname grid_regular grid_random.parameters <- function(x, ..., size = 5, original = TRUE, filter = NULL) { # test for NA and finalized # test for empty ... params <- x$object names(params) <- x$id grd <- make_random_grid( !!!params, size = size, original = original, filter = {{ filter }} ) names(grd) <- x$id grd } #' @export #' @rdname grid_regular grid_random.list <- function(x, ..., size = 5, original = TRUE, filter = NULL) { y <- parameters(x) params <- y$object names(params) <- y$id grd <- make_random_grid( !!!params, size = size, original = original, filter = {{ filter }} ) names(grd) <- y$id grd } #' @export #' @rdname grid_regular grid_random.param <- function(x, ..., size = 5, original = TRUE, filter = NULL) { y <- parameters(list(x, ...)) params <- y$object names(params) <- y$id grd <- make_random_grid( !!!params, size = size, original = original, filter = {{ filter }} ) names(grd) <- y$id grd } #' @export #' @rdname grid_regular grid_random.workflow <- function(x, ..., size = 5, original = TRUE, filter = NULL) { lifecycle::deprecate_stop( when = "1.2.0", what = "grid_random.workflow()", details = "Alternatively, first extract the parameter set with `extract_parameter_set_dials()`, then create the grid from that object." ) } make_random_grid <- function(..., size = 5, original = TRUE, filter = NULL, call = caller_env()) { validate_params(..., call = call) filter_quo <- enquo(filter) param_quos <- quos(...) params <- map(param_quos, eval_tidy) # for now assume equal levels parameters <- map_dfc(params, value_sample, n = size, original = original) param_names <- names(param_quos) names(parameters) <- param_names if (!(quo_is_null(filter_quo))) { parameters <- dplyr::filter(parameters, !!filter_quo) } new_param_grid(parameters) } # ------------------------------------------------------------------------------ new_param_grid <- function(x = new_data_frame()) { if (!is.data.frame(x)) { rlang::abort("`x` must be a data frame to construct a new grid from.") } x <- vctrs::vec_unique(x) size <- vctrs::vec_size(x) # Strip down to a named list with no extra attributes. This serves # as the core object to build the tibble from. attributes(x) <- list(names = names(x)) tibble::new_tibble( x = x, nrow = size ) } dials/R/param_penalty.R0000644000176200001440000000117014565421125014532 0ustar liggesusers#' Amount of regularization/penalization #' #' A numeric parameter function representing the amount of penalties (e.g. L1, #' L2, etc) in regularized models. #' #' @inheritParams Laplace #' #' @details #' This parameter is used for regularized or penalized models such as #' `parsnip::linear_reg()`, `parsnip::logistic_reg()`, and others. #' @examples #' penalty() #' @export penalty <- function(range = c(-10, 0), trans = transform_log10()) { new_quant_param( type = "double", range = range, inclusive = c(TRUE, TRUE), trans = trans, label = c(penalty = "Amount of Regularization"), finalize = NULL ) } dials/NEWS.md0000644000176200001440000002074214565617346012472 0ustar liggesusers# dials 1.2.1 ## New parameters * Added `initial_umap()` and `target_weight()` for `recipes::step_umap()` (#324). ## Other changes * Improving styling of error messages by switching to cli (#315, #317, #321). * Update usage of tranformation functions from the scales package to their new names and require the corresponding version v1.3.0 (#323). # dials 1.2.0 ## New parameters * Added `trim_amount()` for `recipes::step_impute_mean()`. * Added `num_runs()` for `recipes::step_nnmf()` (#281). * Added `harmonic_frequency()` for `recipes::step_harmonic()` (#281). * Added `validation_set_prop()` for `embed::step_discretize_xgb()` (#280). ## Other changes * Deprecation of `pull_dials_object()` has been escalated to an error. Please use `extract_parameter_dials()` instead (#265). * The methods `grid_regular.workflow()`, `grid_random.workflow()`, `grid_max_entropy.workflow()`, and `grid_latin_hypercube.workflow()` have been deprecated (#302). * The constructor functions for single parameters, `new_quant_param()` and `new_qual_param()`, as well as for parameter sets, `parameters_constr()`, now have improved handling of the call shown in error messages (#291, #295). * The constructor for parameter sets, `parameters_constr()`, now checks that all inputs have the same length (#295). # dials 1.1.0 ## New parameters * Added learning rate scheduler parameters `rate_decay()`, `rate_initial()`, `rate_largest()`, `rate_reduction()`, `rate_schedule()`, `rate_step_size()`, and `rate_steps()` for the new [brulee functions](https://github.com/tidymodels/brulee/pull/56) (#253). * Added `num_clusters()` parameter for tidyclust models (#259). * Added `num_leaves()` parameter for lightbgm models (@joeycouse, #256). ## Other changes * The `default` argument to the constructors `new_quant_param()` and `new_qual_param()` is deprecated. `value_seq()` now uses the same logic to generate a sequence of parameter values regardless of how long that sequence is (#153, #229). * `prior_terminal_node_expo()` for Bayesian adaptive regression trees (BART) now defaults to a range greater than 1 to limit explosive tree growth (#251). * The label for `spline_degree()` was improved. # dials 1.0.0 * The new parameter `mtry_prop()` is a variation on `mtry()` where the value is interpreted as the proportion (rather than the count) of predictors that will be randomly sampled at each split (#233). * `conditional_test_statistic()` and `conditional_test_type()` now work with the partykit engine rather than the party engine (#224). * `new_quant_param()` no longer requires `range` and `inclusive` if `values` is supplied (#87). # dials 0.1.1 * The `Chicago` data set was removed. It can be found in the `modeldata` package. # dials 0.1.0 ## New parameters * `summary_stat()` is a new parameter for use in `recipes::step_window()`. * A general `class_weights()` parameter was added for imbalanced models. * `prior_outcome_range()`, `prior_terminal_node_coef()`, and `prior_terminal_node_expo()` are new parameters for prior distribution specification related to `parsnip::bart()`. * `num_knots()` and `survival_link()` are new parameters for spline survival models (@mattwarkentin, #195). * `vocabulary_size()` is a new parameter used in `textrecipes::step_tokenize_sentencepiece()` and `textrecipes::step_tokenize_bpe()`. ## Other changes * The new `extract_parameter_dials()` method supersedes `pull_dials_object()` which has been deprecated. * `activation()` now supports values of `"tanh"`. * New link to article explaining how to make custom parameter objects was added to the pkgdown site. # dials 0.0.10 ## New parameters * `adjust_deg_free()` and `select_features()` for generalized additive models. * `conditional_min_criterion`, `conditional_test_statistic`, `conditional_test_type` for models with the `party` engine. * `diagonal_covariance()`, `regularization_method()`, `shrinkage_correlation()`, `shrinkage_frequencies()`, and `shrinkage_variance()` for linear and quadratic discriminant analysis. * `penalty_L1()`, `penalty_L2()`, and `scale_pos_weight()` for boosted trees with the `xgboost` engine (@joeycouse, #176). * `prior_mixture_threshold()` and `prior_slab_dispersion()` for sparse PCA. * `stop_iter()` for early stopping. ## Other changes * Re-licensed package from GPL-2 to MIT. See [consent from copyright holders here](https://github.com/tidymodels/dials/issues/156). * `param_set()`, scheduled for removal in version 0.0.5, is now removed. # dials 0.0.9 * Quantitative parameters now print the number of possible values if they have been set with `value_set()` (@kmdupr33, #138). * The `print()` method for `parameters()` has changed to be more clear. * A new function, `pull_dials_object()` was also added. * Duplicate parameter combinations are now automatically removed from grid results. * The range for `epochs()` was change to start at 10 iterations instead of 1. * The lower range for `spline_degree()` now starts at 1 instead of 3. * The upper range for `cost()` now goes to `2^5` instead of `2^-1`. # dials 0.0.8 * A number of new parameter objects associated with engine-specific functions were added for engines "ranger", "randomForest", "earth" and "C5.0". # dials 0.0.7 * The `grid_*()` functions no longer generate subclassed tibbles. * `predictor_prop()` was added. * The `levels` argument for `tune_grid()` can now handle a named vector, to account for differences in ordering. ## Breaking changes * The range of `dist_power()` was changed so that the lower limit is 1. * The deprecation period for `margin()` is over; please use `svm_margin()` instead. # dials 0.0.6 * Quick bug fix release related to range checks in 0.0.5. The check is more forgiving when the required type is integer and a double is provided. # dials 0.0.5 * When kept in the original units, a parameter's range must now be the same data type as the parameter. * Renamed `margin()` to `svm_margin()` (@gabrielodom and @gralgomez, #85) * A bug in space filling designs with qualitative parameters was fixed (#94) * A better error message was created when grids are used with parameters sets that contain parameters that require finalization (#99) * Space-filling desings now share the same attributes as other grid objects (#100) * The range for `sample_frac()` was fixed (#96) # dials 0.0.4 ## New parameter functions: * Parameters `smoothness()` was added. ## Other changes * `param_set()` is being renamed `parameters()`. The old name implied that you _only_ use it to set parameters (say from a recipe or model rather than _de novo_). `param_set()` will be available until version 0.0.5. * The range for `num_hash()` was increase to be `2^8` to `2^12`. * The range for `max_tokens()` was changed to be 0 to 1000. ## Breaking changes * `offset()` has been renamed `kernel_offset()` to avoid name conflicts. # dials 0.0.3 ## Breaking changes * All parameter _objects_ are now parameter _functions_. For example, the pre-configured object `mtry` is now a function, `mtry()`, with arguments for the `range` and the `trans`. This provides greater flexibility in parameter creation, and should feel more natural. * `deg_free()` erroneously produced real values; integers are now returned. * Default ranges were changed for `learn_rate()` and `neighbors()` were changed. * `update.param_set()` now takes multiple named arguments. ## Other changes * Two functions for space-filling designs were added: `grid_max_entropy()` and `grid_latin_hypercube()`. * A data set was added for modeling ridership on the Chicago L trains. ## New parameter functions: * Parameters `spline_degree()`, `over_ratio()`, `under_ratio()`, `freq_cut()`, `unique_cut()`, `num_breaks()`, `min_unique()`, `num_hash()`, `signed_hash()`, `sample_prop()`, `window_size()`, `min_dist()`, and `degree_int()` were added. # dials 0.0.2 * Parameter objects now contain code to finalize their values and a number of helper functions for certain data-specific parameters. A `force` option can be used to avoid updating the values. * Parameter objects are printed differently inside of tibbles. * `regularization` was changed to `penalty` in a few models to be consistent with [this change](https://tidymodels.github.io/model-implementation-principles/standardized-argument-names.html#tuning-parameters). * `batch_size` and `threshold` were added. * Added a set of parameters for the `textrecipes` package [issue 16](https://github.com/tidymodels/dials/issues/16). # dials 0.0.1 * First CRAN version dials/MD50000644000176200001440000003112414565635766011706 0ustar liggesusers25b77e577228630c875feabe01371f0a *DESCRIPTION 2d9526e900597c5c4a6216cd9bc36dee *LICENSE 87d78da8e4814176e523b42d29e2bb48 *NAMESPACE 4baf55223c6fc75c2716b00211e2488b *NEWS.md fb6304201981dfabf825dde47eeabeec *R/aaa_ranges.R 250617d276ac540a8b788e3a9ed018a5 *R/aaa_unknown.R 72ae2a0636ff509e94e00dbab987af99 *R/aaa_values.R 600344e21423923c4bfb7ac9c2dc628f *R/compat-dplyr-old-parameters.R 38c8ff7687db224e9e7563518f2d9a58 *R/compat-dplyr-parameters.R 493c5edf307f9e9d90cacf7f10adec7f *R/compat-vctrs-helpers-parameters.R 9168fe5982ccabb1a19f3077900e39fb *R/compat-vctrs-parameters.R 51b6444a57b98131859f97bb59195353 *R/constructors.R 5150addd79081284061189529fb8f35d *R/dials-package.R 54defceaa16baed677aca6c50d08219f *R/encode_unit.R fb60ccde54c747ff42a038d5d82112b3 *R/extract.R 6fbf5d9bfc00e28109da9bb67ccfa516 *R/finalize.R 153958632634c8ab43ee7810fc7c3eb9 *R/grids.R 70258ae742d15ec71336f7a42bf23956 *R/import-standalone-obj-type.R c40f882046a958444c6058a9e2cb9a3b *R/import-standalone-types-check.R 88d9d3b5f838a0a3eef0e45c5de4f919 *R/misc.R d0ba800a3594e8b65e16cf21d52aab2b *R/param_Laplace.R fef7f91509321aedee2cbc1f83b69a4d *R/param_activation.R 2dfa98b54c0c6b38721c44f88e143543 *R/param_adjust_reg_free.R c2650f8b934134c685177222bb859e13 *R/param_all_neighbors.R d64d72cc64dd44112b3e07459c7359d5 *R/param_bart.R f36b438adb330ce50b1ece74b6ce80af *R/param_class_weights.R 67c5e796be22aef9c0de577579005b7a *R/param_deg_free.R 56b01c3da473d7c38564a973f8be9866 *R/param_degree.R fa92b4aafb5f49afd4a905bc89a13752 *R/param_dist_power.R f86d77d54fdf9499709d2095a2fdfd76 *R/param_engine_c50.R 04df86b00183fda5906c73db153ea596 *R/param_engine_cubist.R 6e2b9d4c404f58fdd569de049f686854 *R/param_engine_earth.R bd66d3177c221c8eb1f0c23a87c0c776 *R/param_engine_lightgbm.R a3f24aebb31b6f156acfe6e0a8686677 *R/param_engine_partykit.R 8a4bbbf94ac2fa6e234a1986802ef575 *R/param_engine_randomForest.R 3eff5e67c2d8e1e27ca02a2ffdeb8f7f *R/param_engine_ranger.R 6407ca50ce5bb972ffb0115a45b343b8 *R/param_engine_sda.R cb6472d2be309674e2402fb1d409d88c *R/param_engine_xgboost.R 8e25fd0f9f503a2946bd517a6a366444 *R/param_harmonic_frequency.R 1ec5b801c986cfec866051a354846d58 *R/param_initial_umap.R 494f74c7fd93f86bf1554a9db3644eca *R/param_kernel.R 45528b409953f4cfe8e0f2415975ce58 *R/param_learn_rate.R b3b3458834c41a2b8a87d5556428c210 *R/param_max_times.R 3098b4447a05fbf9b51f23f04646f372 *R/param_max_tokens.R aae1e4544d5eea768eaa371c2b802729 *R/param_min_dist.R cb8833211ee8b1b9c92fc2ceb012b0e7 *R/param_min_unique.R 840ac6e36491cad5052744a20e3b48ce *R/param_mixture.R 2a9f8748608f3871f23f7c49fc101306 *R/param_momentum.R eaf55510c869cc0ec87037e8744120a3 *R/param_mtry.R eff8503a5c3761b9e8ad082c158661ee *R/param_mtry_prop.R ec5b2a3fd983a009769b3a3292d1c663 *R/param_neighbors.R af3059bf077fb703b80ced8eae0b8348 *R/param_network.R 073530b3a72229536093e5227b75e23c *R/param_num_breaks.R 1cc1c4481e92b4507400ae69c8555a64 *R/param_num_clusters.R 05bf26a34e97f5f77413ec2ffe036370 *R/param_num_comp.R e07b80d3c4b460487221586b0802b168 *R/param_num_hash.R 97f4f960058e62d197b3f80d9a71970a *R/param_num_knots.R 9f2d52a9820bbbf1f94baf3af5f6d5a7 *R/param_num_runs.R 36796fa091b82dcd861871756925a154 *R/param_num_tokens.R e09f34310d4f7a272490bb5838b76ead *R/param_nzv.R 682d9fc448aa9f5e6a8e4cd3d3eb277d *R/param_over_ratio.R 4bb1cc10b549c4cd0b2762032b8eab0a *R/param_penalty.R b1b2b360c2ff8eba4aa9f7a1cd6c038d *R/param_predictor_prop.R 8e0a13be1e96d041b24b12d8edcb03dc *R/param_prune_method.R 8e93158a33ceba628351f985c59b6062 *R/param_regularization_method.R 4a316cd39bbd383ab11bfe8427aacab1 *R/param_schedulers.R c756021b78d326f6d422ca94137671d3 *R/param_select_features.R 162dbe2b85eded415c79105e3412d31f *R/param_smoothness.R dca2839ad55eaf27537f463f78954216 *R/param_sparse_bayes_pca.R 895384db1857ed9ee0294025339771db *R/param_stop_iter.R 812c31242c0af61331768bcc6e4e56b7 *R/param_summary_stat.R 4da89b18f5933a4cb0f7ede541851b10 *R/param_surv_dist.R 29a3568e288f8bcf66bcf71089d5b507 *R/param_survival_link.R bb9bb173f104571f8292d8ed2bfe27a8 *R/param_svm.R 9a43006aae4d2876eb8c13377f04e36f *R/param_target_weight.R 394200b8b4e537080cc2821cb6d72f9a *R/param_threshold.R f289c99b41a48e95297e3e2b5e49f1fc *R/param_token.R 2670b3ca489bfce95720ad8d9527d86f *R/param_trees.R 9ec2fe5e958993f72f96e9b693721d1f *R/param_trim_amount.R 8724bac6824a3069ff33fd56ddf7ed49 *R/param_validation_set_prop.R c8aa6f5089e93ed3f6ebf070ae843604 *R/param_vocabulary_size.R 73e15267fbd56908c41b6ccf424ae30f *R/param_weight.R f274713d73a70e3db963b1ea86b5565e *R/param_weight_func.R 7c8218b1f03dd364575bbef7d5e47257 *R/param_weight_scheme.R aad2ccbed3bf69b1568f39f21d95ff18 *R/param_window_size.R 1665e6eaaa26759bbeb8161133aabc1d *R/parameters.R 9d2057ebed4e5b3d616572033bf3c9e9 *R/pull_dials_object.R eb40e1b1ae59b5dbd07cb0c3eef4905e *R/reexports.R 8e8b8216d06df7713ee602a35a8b940c *R/space_filling.R 1a72f01fef22562acec7999d2aae93d8 *R/type_sum.R 5a9ea2befb4b13e34d81cf1c023722af *R/validation.R 2d0ed80d5a55e7a6d3a29eea273ceb92 *R/zzz.R ad44f6e3a6f688ec8cde0ed0ac171ed6 *README.md 2f05091019772ba63de59d363cd0549a *build/vignette.rds 2745d2f2c906ed622187b2e9a3d1f1ec *inst/doc/dials.R d3d8ee9c9b96ce6a6e3cf7fb37eb03b8 *inst/doc/dials.Rmd 270ec4d71e3b2572e0ff0fb6e84f6981 *inst/doc/dials.html 11a005d6cc8d0e4b53600e73bdfdc09f *man/Laplace.Rd c4d06c7fe48ea58c2f00699a5383565c *man/activation.Rd 0953a145de60ee2716e8eb45eb18dc6d *man/adjust_deg_free.Rd 7de470de1d07b9624bd92dc200c4d0d0 *man/all_neighbors.Rd 79c7a2e97363c32bd45e48dc708d0482 *man/bart-param.Rd a9f044f12790b5c26d2b093fadf81c35 *man/c5_parameters.Rd 0ec57c1baa31fe211028992e5c115a69 *man/class_weights.Rd c222b0a2ea872a558e3a7b5dc908a152 *man/conditional_min_criterion.Rd c1720a0db986d47417b05d7c24b5a0f8 *man/cost.Rd d76a436c9bef00653f3472422e460363 *man/cubist_parameters.Rd 7950d60f191186398baf262928057610 *man/deg_free.Rd bde0c210820b64962b49ae9e8b23bf40 *man/degree.Rd 6f017aa569255d4ce551ee9aa7aef1df *man/dials-package.Rd bc6d3fc4a5d65a84b82c5686a29525d4 *man/dist_power.Rd 7dc2f53c72d47343f9adf4e6da565378 *man/dropout.Rd e80b5e5409832a9f5cf21195ff1ecea8 *man/earth_parameters.Rd 6d7ddfc4d6d255d926386efc00922428 *man/encode_unit.Rd a1cbaf3f328e8d74e747faacf640c7fc *man/figures/lifecycle-archived.svg 6f521fb1819410630e279d1abf88685a *man/figures/lifecycle-defunct.svg 391f696f961e28914508628a7af31b74 *man/figures/lifecycle-deprecated.svg 691b1eb2aec9e1bec96b79d11ba5e631 *man/figures/lifecycle-experimental.svg 405e252e54a79b33522e9699e4e9051c *man/figures/lifecycle-maturing.svg f41ed996be135fb35afe00641621da61 *man/figures/lifecycle-questioning.svg 306bef67d1c636f209024cf2403846fd *man/figures/lifecycle-soft-deprecated.svg ed42e3fbd7cc30bc6ca8fa9b658e24a8 *man/figures/lifecycle-stable.svg bf2f1ad432ecccee3400afe533404113 *man/figures/lifecycle-superseded.svg 618b9cb06d5bc5c641b033f95b1beaa4 *man/figures/logo.png 8da47ecf7426ba56c4da0adf644f6d7e *man/finalize.Rd 765cdf88ec65802681dc735a92e48c14 *man/freq_cut.Rd d7109c2d106a78354e29233badcdc32b *man/grid_max_entropy.Rd 4b0ebffeaf0333671994343e7bad0c94 *man/grid_regular.Rd e2c8e1e119e17f17a76256c5f6cef1f1 *man/harmonic_frequency.Rd e5042f836f20d43eaa1d54429e10ff1e *man/initial_umap.Rd 83ad6689bec242ec6232364ce227299b *man/learn_rate.Rd dc3f67215da995f698ee887d045c21f4 *man/lightgbm_parameters.Rd 181fe40e810ada62449cc97f06953ae0 *man/max_times.Rd 5b698d83f1a901623cd9e73d6feb3003 *man/max_tokens.Rd 51f8fb75397445cd6ed2f5deb5c79d71 *man/min_dist.Rd 39f8c6c9b97755eac927590675fe68ac *man/min_unique.Rd 6988289d0f6f725b2f31e69cb5fd9ad6 *man/mixture.Rd 93cfb88245fb235bc73354f4df0fa2c5 *man/momentum.Rd ef24bbc7b0ce77cc89bbecab42afebdb *man/mtry.Rd c4818d63033a4fc7289cd1b8e7d58969 *man/mtry_prop.Rd b509ff1dc8d9e4e6c75b05e1af78c936 *man/neighbors.Rd a62df7c5cf17e1e8932a394d46c2634d *man/new-param.Rd fa504858df85f21b9d25fdd16c580019 *man/num_breaks.Rd 2ec1f8dad3fd11e47c6b130b4267d2fc *man/num_clusters.Rd daf14457d31a54067081b04751c1532e *man/num_comp.Rd e59a8ce2003462b9ed7d85f84914923a *man/num_knots.Rd 2bcbc2df8503f569db6c691d76dfc436 *man/num_runs.Rd 6f285168a251791c5fb54f18e1c21a08 *man/num_tokens.Rd 927d4277c97e7eba3ebfbf8a02b05342 *man/over_ratio.Rd 3035317a9a0675721aaf97c494358a1a *man/parameters.Rd b68ef0772f1a2be10114181153fc1bba *man/parameters_constr.Rd 0d35854957c6b7495ffeff59369be30d *man/penalty.Rd 266abfededb51c92f218013d5adbb2a3 *man/predictor_prop.Rd 8314e14f7e62bd28732c00c992431ea7 *man/prior_slab_dispersion.Rd 990a31a4bc05523c4feda3fdcc938bb9 *man/prune_method.Rd 96313e3b0f8a495dec91365b8982d18e *man/pull_dials_object.Rd f7168acce90d7419a7ab9d6cc463652f *man/randomForest_parameters.Rd 522830a55f3e15e547c74b76234a62c8 *man/range_validate.Rd e4fa0787efbf68de6456d5a83a4754be *man/ranger_parameters.Rd 6c40aa7590ed530cbfedf334678eed2e *man/rbf_sigma.Rd 11b062c402d7daa13928a88518c1e3b5 *man/reexports.Rd 03ee0aa7175045a9c094b2527abff8c8 *man/regularization_method.Rd 3e9ccf4eff224e345f726a920826442e *man/rmd/rand_notes.Rmd d84b917930e131becf56e4b6e20bc41b *man/rmd/rand_notes.md 422b3abc1a97308c4392d70a24ae2ab3 *man/rmd/sfd_notes.Rmd ee5f80e02c907a01f65dee138ccf0f18 *man/rmd/sfd_notes.md f8296f3b8bb1a54fe278218ce48f6645 *man/scheduler-param.Rd 28ec47d2de6e124d9793e0c36b2e379c *man/select_features.Rd 950689aa77bb6e32a14811f0a6fb8fd9 *man/shrinkage_correlation.Rd d2f16690085f734b0f8df1041b7626fc *man/smoothness.Rd f6d2ccaae0e369043d9d5e1a352daf6c *man/stop_iter.Rd 67e49fa498ad7e14684c80788fe62551 *man/summary_stat.Rd a5b16be6c3931f661bdfe8524f7c194e *man/surv_dist.Rd c54e73c9544aae96ca977b98d9f2b148 *man/survival_link.Rd 8663e12faee12efc375d41ee480a026d *man/target_weight.Rd 244cb740ce72d72d018513ed89b875ae *man/texthash.Rd 08bea4aac16941b6ba70b5740d0b6846 *man/threshold.Rd 5ec6c7aa2d15f34a327dcad3b5ebc868 *man/token.Rd d39f23e9150b7fc5f6cc2875ae33815f *man/trees.Rd 5fa5f951be5e454cc1fd60f012820589 *man/trim_amount.Rd 44ec6ab5d668f41502baa52e3424a0fd *man/type_sum.param.Rd da2e91e1050c4168828a790621787e08 *man/unknown.Rd 3e72f0ebc79bf5cfa5b244ba1aaa2fc3 *man/update.parameters.Rd 4f1dfb36c6eaa314ac680606e1d7eae0 *man/validation_set_prop.Rd 27a249a55730f1e1e3e3b7858b4e07e2 *man/value_validate.Rd 9c8460cccaaea3f24e53b32b4891358f *man/vocabulary_size.Rd d085a283d531962608ebead2b0ca745d *man/weight.Rd db6119abe5f0c18c7a55f69282e7fd15 *man/weight_func.Rd 667712f5eb34694d44ce28a213f2f507 *man/weight_scheme.Rd c58adf985d9f6fa6d582a38e8404a071 *man/window_size.Rd e221d9b820431736f3f1c00f2bbe7fd6 *man/xgboost_parameters.Rd 82d029c660befa9164bc7e8af75962ea *tests/testthat.R 8dc0c448280909d7a048328fee66fbe7 *tests/testthat/_snaps/aaa_unknown.md e409c47b434a9899a4a44f2d478caf7e *tests/testthat/_snaps/aaa_values.md c1878b0e1f7a0d61afe176272e91e2c6 *tests/testthat/_snaps/constructors.md c40a256b26729e56f1543dde11b35515 *tests/testthat/_snaps/encode_unit.md 46e71006e293ee2b040304f29f7da6e3 *tests/testthat/_snaps/extract.md 813119b3ed3d60b23d114b799876bc78 *tests/testthat/_snaps/finalize.md 7ecf40d0357e7229f7d5b25ccc74cf57 *tests/testthat/_snaps/grids.md 8cb42c7cadef1945120907b77d746af7 *tests/testthat/_snaps/misc.md 7f9337de679441a13309845ff803cf79 *tests/testthat/_snaps/parameters.md b531e19a5b711d4792f2e030e4c04a91 *tests/testthat/_snaps/pull_dials_object.md 6811ce98136d6c417ca2131543d73d5b *tests/testthat/_snaps/space_filling.md 5cf1c5878c62c2df2454ab5f2d47797b *tests/testthat/_snaps/validation.md e6807fc0165a5b2e54eadc3078a520d8 *tests/testthat/helper-s3.R bec29b762d5f689f7cd1bfa9e5f3779b *tests/testthat/helper-skip_if_below_r_version.R ba9299bccfe78535171ab4f50e21a370 *tests/testthat/test-aaa_ranges.R 06c640c3487c01986afe7e0082ec24f1 *tests/testthat/test-aaa_unknown.R 3bb2e7e73e863aa816edf2a073dd7aab *tests/testthat/test-aaa_values.R 94e64b13e465292c878bdc6d8605a451 *tests/testthat/test-compat-dplyr-old-parameters.R da028e8778c5927d85ba54f55e0d485c *tests/testthat/test-compat-dplyr-parameters.R 11c9382cb2584264ef55e0e6c223ed0b *tests/testthat/test-compat-vctrs-helpers-parameters.R 45428f97ecc4ca63310313d7177d3f78 *tests/testthat/test-compat-vctrs-parameters.R aac565be7fe582b7eaa74c6a9edfaeaa *tests/testthat/test-constructors.R b46a8ead5fdf1d5deb2520a1f06a3c46 *tests/testthat/test-encode_unit.R e1fd7dab717804a8bb01c801326ae3e3 *tests/testthat/test-extract.R e5e0cdf5fe0135c462ec3561be4c0972 *tests/testthat/test-finalize.R 7052c0b0526896baa3299baf543fa82c *tests/testthat/test-grids.R 7e68225a0315f16578a90c7e9895d025 *tests/testthat/test-misc.R e8329267dd41207041b941f2c0d0dc06 *tests/testthat/test-parameters.R 187308df746b60bf8e1dbd22a6af23ed *tests/testthat/test-params.R ba3e1853e7eabf660c5602ad8d6457fd *tests/testthat/test-pull_dials_object.R 4ba2cdad4ea4b7f85bbdf65d8cf096aa *tests/testthat/test-space_filling.R c53ba3c9ab8e95d6be203f218a640342 *tests/testthat/test-type_sum.R aff997a1f094f110f8fe1841a7026cb7 *tests/testthat/test-validation.R d3d8ee9c9b96ce6a6e3cf7fb37eb03b8 *vignettes/dials.Rmd dials/inst/0000755000176200001440000000000014565631734012341 5ustar liggesusersdials/inst/doc/0000755000176200001440000000000014565631734013106 5ustar liggesusersdials/inst/doc/dials.html0000644000176200001440000011375514565631734015104 0ustar liggesusers Working with Tuning Parameters

Working with Tuning Parameters

Tuning Parameters

Some statistical and machine learning models contain tuning parameters (also known as hyperparameters), which are parameters that cannot be directly estimated by the model. An example would be the number of neighbors in a K-nearest neighbors model. To determine reasonable values of these elements, some indirect method is used such as resampling or profile likelihood. Search methods, such as genetic algorithms or Bayesian search can also be used to determine good values.

In any case, some information is needed to create a grid or to validate whether a candidate value is appropriate (e.g. the number of neighbors should be a positive integer). dials is designed to:

  • Create an easy to use framework for describing and querying tuning parameters. This can include getting sequences or random tuning values, validating current values, transforming parameters, and other tasks.
  • Standardize the names of different parameters. Different packages in R use different argument names for the same quantities. dials proposes some standardized names so that the user doesn’t need to memorize the syntactical minutiae of every package.
  • Work with the other tidymodels packages for modeling and machine learning using tidyverse principles.

Parameter Objects

Parameter objects contain information about possible values, ranges, types, and other aspects. They have two classes: the general param class and a more specific subclass related to the type of variable. Double and integer valued data have the subclass quant_param while character and logicals have qual_param. There are some common elements for each:

  • Labels are strings that describe the parameter (e.g. “Number of Components”).
  • Defaults are optional single values that can be set when one non-random value is requested.

Otherwise, the information contained in parameter objects are different for different data types.

Numeric Parameters

An example of a numeric tuning parameter is the cost-complexity parameter of CART trees, otherwise known as \(C_p\). A parameter object for \(C_p\) can be created in dials using:

library(dials)
cost_complexity()
#> Cost-Complexity Parameter (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-10, -1]

Note that this parameter is handled in log units and the default range of values is between 10^-10 and 0.1. The range of possible values can be returned and changed based on some utility functions. We’ll use the pipe operator here:

library(dplyr)
cost_complexity() %>% range_get()
#> $lower
#> [1] 1e-10
#> 
#> $upper
#> [1] 0.1
cost_complexity() %>% range_set(c(-5, 1))
#> Cost-Complexity Parameter (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-5, 1]

# Or using the `range` argument
# during creation
cost_complexity(range = c(-5, 1))
#> Cost-Complexity Parameter (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-5, 1]

Values for this parameter can be obtained in a few different ways. To get a sequence of values that span the range:

# Natural units:
cost_complexity() %>% value_seq(n = 4)
#> [1] 1e-10 1e-07 1e-04 1e-01

# Stay in the transformed space:
cost_complexity() %>% value_seq(n = 4, original = FALSE)
#> [1] -10  -7  -4  -1

Random values can be sampled too. A random uniform distribution is used (between the range values). Since this parameter has a transformation associated with it, the values are simulated in the transformed scale and then returned in the natural units (although the original argument can be used here):

set.seed(5473)
cost_complexity() %>% value_sample(n = 4)
#> [1] 6.91e-09 8.46e-04 3.45e-06 5.90e-10

For CART trees, there is a discrete set of values that exist for a given data set. It may be a good idea to assign these possible values to the object. We can get them by fitting an initial rpart model and then adding the values to the object. For mtcars, there are only three values:

library(rpart)
cart_mod <- rpart(mpg ~ ., data = mtcars, control = rpart.control(cp = 0.000001))
cart_mod$cptable
#>         CP nsplit rel error xerror  xstd
#> 1 0.643125      0     1.000  1.064 0.258
#> 2 0.097484      1     0.357  0.687 0.180
#> 3 0.000001      2     0.259  0.576 0.126
cp_vals <- cart_mod$cptable[, "CP"]

# We should only keep values associated with at least one split:
cp_vals <- cp_vals[ cart_mod$cptable[, "nsplit"] > 0 ]

# Here the specific Cp values, on their natural scale, are added:
mtcars_cp <- cost_complexity() %>% value_set(cp_vals)
#> Error in `value_set()`:
#> ! Some values are not valid: 0.0974840733898344 and 1e-06.

The error occurs because the values are not in the transformed scale:

mtcars_cp <- cost_complexity() %>% value_set(log10(cp_vals))
mtcars_cp
#> Cost-Complexity Parameter (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-10, -1]
#> Values: 2

Now, if a sequence or random sample is requested, it uses the set values:

mtcars_cp %>% value_seq(2)
#> [1] 0.097484 0.000001
# Sampling specific values is done with replacement
mtcars_cp %>% 
  value_sample(20) %>% 
  table()
#> .
#>              1e-06 0.0974840733898344 
#>                  9                 11

Any transformations from the scales package can be used with the numeric parameters, or a custom transformation generated with scales::trans_new().

trans_raise <- scales::trans_new(
  "raise", 
  transform = function(x) 2^x , 
  inverse = function(x) -log2(x)
)
custom_cost <- cost(range = c(1, 10), trans = trans_raise)
custom_cost
#> Cost (quantitative)
#> Transformer: raise [-Inf, Inf]
#> Range (transformed scale): [1, 10]

Note that if a transformation is used, the range argument specifies the parameter range on the transformed scale. For this version of cost(), parameter values are sampled between 1 and 10 and then transformed back to the original scale by the inverse -log2(). So on the original scale, the sampled values are between -log2(10) and -log2(1).

-log2(c(10, 1))
#> [1] -3.32  0.00
value_sample(custom_cost, 100) %>% range()
#> [1] -3.3172 -0.0314

Discrete Parameters

In the discrete case there is no notion of a range. The parameter objects are defined by their discrete values. For example, consider a parameter for the types of kernel functions that is used with distance functions:

weight_func()
#> Distance Weighting Function  (qualitative)
#> 'rectangular', 'triangular', 'epanechnikov', 'biweight', 'triweight', 'cos', ...

The helper functions are analogues to the quantitative parameters:

# redefine values
weight_func() %>% value_set(c("rectangular", "triangular"))
#> Distance Weighting Function  (qualitative)
#> 'rectangular' and 'triangular'
weight_func() %>% value_sample(3)
#> [1] "triangular" "inv"        "triweight"

# the sequence is returned in the order of the levels
weight_func() %>% value_seq(3)
#> [1] "rectangular"  "triangular"   "epanechnikov"

Creating Novel Parameters

The package contains two constructors that can be used to create new quantitative and qualitative parameters, new_quant_param() and new_qual_param(). The How to create a tuning parameter function article walks you through a detailed example.

Unknown Values

There are some cases where the range of parameter values are data dependent. For example, the upper bound on the number of neighbors cannot be known if the number of data points in the training set is not known. For that reason, some parameters have an unknown placeholder:

mtry()
#> # Randomly Selected Predictors (quantitative)
#> Range: [1, ?]
sample_size()
#> # Observations Sampled (quantitative)
#> Range: [?, ?]
num_terms()
#> # Model Terms (quantitative)
#> Range: [1, ?]
num_comp()
#> # Components (quantitative)
#> Range: [1, ?]
# and so on

These values must be initialized prior to generating parameter values. The finalize() methods can be used to help remove the unknowns:

finalize(mtry(), x = mtcars[, -1])
#> # Randomly Selected Predictors (quantitative)
#> Range: [1, 10]

Parameter Sets

These are collection of parameters used in a model, recipe, or other object. They can also be created manually and can have alternate identification fields:

glmnet_set <- parameters(list(lambda = penalty(), alpha = mixture()))
glmnet_set
#> Collection of 2 parameters for tuning
#> 
#>  identifier    type    object
#>      lambda penalty nparam[+]
#>       alpha mixture nparam[+]

# can be updated too
update(glmnet_set, alpha = mixture(c(.3, .6)))
#> Collection of 2 parameters for tuning
#> 
#>  identifier    type    object
#>      lambda penalty nparam[+]
#>       alpha mixture nparam[+]

These objects can be very helpful when creating tuning grids.

Parameter Grids

Sets or combinations of parameters can be created for use in grid search. grid_regular(), grid_random(), grid_max_entropy(), and grid_latin_hypercube() take any number of param objects or a parameter set.

For example, for a glmnet model, a regular grid might be:

grid_regular(
  mixture(),
  penalty(),
  levels = 3 # or c(3, 4), etc
)
#> # A tibble: 9 × 2
#>   mixture      penalty
#>     <dbl>        <dbl>
#> 1     0   0.0000000001
#> 2     0.5 0.0000000001
#> 3     1   0.0000000001
#> 4     0   0.00001     
#> 5     0.5 0.00001     
#> 6     1   0.00001     
#> 7     0   1           
#> 8     0.5 1           
#> 9     1   1

and, similarly, a random grid is created using

set.seed(1041)
grid_random(
  mixture(),
  penalty(),
  size = 6 
)
#> # A tibble: 6 × 2
#>   mixture     penalty
#>     <dbl>       <dbl>
#> 1   0.200 0.0176     
#> 2   0.750 0.000388   
#> 3   0.191 0.000000159
#> 4   0.929 0.00000176 
#> 5   0.143 0.0442     
#> 6   0.973 0.0110
dials/inst/doc/dials.R0000644000176200001440000000646614565631733014340 0ustar liggesusers## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( message = FALSE, digits = 3, collapse = TRUE, comment = "#>" ) options(digits = 3) library(dials) library(rpart) ## ----cp----------------------------------------------------------------------- library(dials) cost_complexity() ## ----cp-range----------------------------------------------------------------- library(dplyr) cost_complexity() %>% range_get() cost_complexity() %>% range_set(c(-5, 1)) # Or using the `range` argument # during creation cost_complexity(range = c(-5, 1)) ## ----cp-seq------------------------------------------------------------------- # Natural units: cost_complexity() %>% value_seq(n = 4) # Stay in the transformed space: cost_complexity() %>% value_seq(n = 4, original = FALSE) ## ----cp-sim------------------------------------------------------------------- set.seed(5473) cost_complexity() %>% value_sample(n = 4) ## ----rpart, error=TRUE-------------------------------------------------------- library(rpart) cart_mod <- rpart(mpg ~ ., data = mtcars, control = rpart.control(cp = 0.000001)) cart_mod$cptable cp_vals <- cart_mod$cptable[, "CP"] # We should only keep values associated with at least one split: cp_vals <- cp_vals[ cart_mod$cptable[, "nsplit"] > 0 ] # Here the specific Cp values, on their natural scale, are added: mtcars_cp <- cost_complexity() %>% value_set(cp_vals) ## ----rpart-cp----------------------------------------------------------------- mtcars_cp <- cost_complexity() %>% value_set(log10(cp_vals)) mtcars_cp ## ----rpart-cp-vals------------------------------------------------------------ mtcars_cp %>% value_seq(2) # Sampling specific values is done with replacement mtcars_cp %>% value_sample(20) %>% table() ## ----custom-transform--------------------------------------------------------- trans_raise <- scales::trans_new( "raise", transform = function(x) 2^x , inverse = function(x) -log2(x) ) custom_cost <- cost(range = c(1, 10), trans = trans_raise) custom_cost ## ----custom-cost-------------------------------------------------------------- -log2(c(10, 1)) value_sample(custom_cost, 100) %>% range() ## ----wts---------------------------------------------------------------------- weight_func() ## ----wts-ex------------------------------------------------------------------- # redefine values weight_func() %>% value_set(c("rectangular", "triangular")) weight_func() %>% value_sample(3) # the sequence is returned in the order of the levels weight_func() %>% value_seq(3) ## ----unk---------------------------------------------------------------------- mtry() sample_size() num_terms() num_comp() # and so on ## ----finalize-mtry------------------------------------------------------------ finalize(mtry(), x = mtcars[, -1]) ## ----p-set-------------------------------------------------------------------- glmnet_set <- parameters(list(lambda = penalty(), alpha = mixture())) glmnet_set # can be updated too update(glmnet_set, alpha = mixture(c(.3, .6))) ## ----glm-reg------------------------------------------------------------------ grid_regular( mixture(), penalty(), levels = 3 # or c(3, 4), etc ) ## ----glm-rnd------------------------------------------------------------------ set.seed(1041) grid_random( mixture(), penalty(), size = 6 ) dials/inst/doc/dials.Rmd0000644000176200001440000001765614262004201014636 0ustar liggesusers--- title: "Working with Tuning Parameters" vignette: > %\VignetteEngine{knitr::rmarkdown} %\VignetteIndexEntry{Working with Tuning Parameters} output: knitr:::html_vignette: toc: yes --- ```{r setup, include = FALSE} knitr::opts_chunk$set( message = FALSE, digits = 3, collapse = TRUE, comment = "#>" ) options(digits = 3) library(dials) library(rpart) ``` ## Tuning Parameters Some statistical and machine learning models contain _tuning parameters_ (also known as _hyperparameters_), which are parameters that cannot be directly estimated by the model. An example would be the number of neighbors in a _K_-nearest neighbors model. To determine reasonable values of these elements, some indirect method is used such as resampling or profile likelihood. Search methods, such as genetic algorithms or Bayesian search can also be used to [determine good values](https://github.com/topepo/Optimization-Methods-for-Tuning-Predictive-Models). In any case, some information is needed to create a grid or to validate whether a candidate value is appropriate (e.g. the number of neighbors should be a positive integer). `dials` is designed to: * Create an easy to use framework for describing and querying tuning parameters. This can include getting sequences or random tuning values, validating current values, transforming parameters, and other tasks. * Standardize the names of different parameters. Different packages in R use different argument names for the same quantities. `dials` proposes some standardized names so that the user doesn't need to memorize the syntactical minutiae of every package. * Work with the other [tidymodels](https://www.tidymodels.org) packages for modeling and machine learning using [tidyverse](https://www.tidyverse.org/) principles. ## Parameter Objects Parameter objects contain information about possible values, ranges, types, and other aspects. They have two classes: the general `param` class and a more specific subclass related to the type of variable. Double and integer valued data have the subclass `quant_param` while character and logicals have `qual_param`. There are some common elements for each: * Labels are strings that describe the parameter (e.g. "Number of Components"). * Defaults are optional single values that can be set when one non-random value is requested. Otherwise, the information contained in parameter objects are different for different data types. ### Numeric Parameters An example of a numeric tuning parameter is the cost-complexity parameter of CART trees, otherwise known as $C_p$. A parameter object for $C_p$ can be created in `dials` using: ```{r cp} library(dials) cost_complexity() ``` Note that this parameter is handled in log units and the default range of values is between `10^-10` and `0.1`. The range of possible values can be returned and changed based on some utility functions. We'll use the pipe operator here: ```{r cp-range} library(dplyr) cost_complexity() %>% range_get() cost_complexity() %>% range_set(c(-5, 1)) # Or using the `range` argument # during creation cost_complexity(range = c(-5, 1)) ``` Values for this parameter can be obtained in a few different ways. To get a sequence of values that span the range: ```{r cp-seq} # Natural units: cost_complexity() %>% value_seq(n = 4) # Stay in the transformed space: cost_complexity() %>% value_seq(n = 4, original = FALSE) ``` Random values can be sampled too. A random uniform distribution is used (between the range values). Since this parameter has a transformation associated with it, the values are simulated in the transformed scale and then returned in the natural units (although the `original` argument can be used here): ```{r cp-sim} set.seed(5473) cost_complexity() %>% value_sample(n = 4) ``` For CART trees, there is a discrete set of values that exist for a given data set. It may be a good idea to assign these possible values to the object. We can get them by fitting an initial `rpart` model and then adding the values to the object. For `mtcars`, there are only three values: ```{r rpart, error=TRUE} library(rpart) cart_mod <- rpart(mpg ~ ., data = mtcars, control = rpart.control(cp = 0.000001)) cart_mod$cptable cp_vals <- cart_mod$cptable[, "CP"] # We should only keep values associated with at least one split: cp_vals <- cp_vals[ cart_mod$cptable[, "nsplit"] > 0 ] # Here the specific Cp values, on their natural scale, are added: mtcars_cp <- cost_complexity() %>% value_set(cp_vals) ``` The error occurs because the values are not in the transformed scale: ```{r rpart-cp} mtcars_cp <- cost_complexity() %>% value_set(log10(cp_vals)) mtcars_cp ``` Now, if a sequence or random sample is requested, it uses the set values: ```{r rpart-cp-vals} mtcars_cp %>% value_seq(2) # Sampling specific values is done with replacement mtcars_cp %>% value_sample(20) %>% table() ``` Any transformations from the `scales` package can be used with the numeric parameters, or a custom transformation generated with `scales::trans_new()`. ```{r custom-transform} trans_raise <- scales::trans_new( "raise", transform = function(x) 2^x , inverse = function(x) -log2(x) ) custom_cost <- cost(range = c(1, 10), trans = trans_raise) custom_cost ``` Note that if a transformation is used, the `range` argument specifies the parameter range _on the transformed scale_. For this version of `cost()`, parameter values are sampled between 1 and 10 and then transformed back to the original scale by the inverse `-log2()`. So on the original scale, the sampled values are between `-log2(10)` and `-log2(1)`. ```{r custom-cost} -log2(c(10, 1)) value_sample(custom_cost, 100) %>% range() ``` ### Discrete Parameters In the discrete case there is no notion of a range. The parameter objects are defined by their discrete values. For example, consider a parameter for the types of kernel functions that is used with distance functions: ```{r wts} weight_func() ``` The helper functions are analogues to the quantitative parameters: ```{r wts-ex} # redefine values weight_func() %>% value_set(c("rectangular", "triangular")) weight_func() %>% value_sample(3) # the sequence is returned in the order of the levels weight_func() %>% value_seq(3) ``` ## Creating Novel Parameters The package contains two constructors that can be used to create new quantitative and qualitative parameters, `new_quant_param()` and `new_qual_param()`. The [How to create a tuning parameter function](https://www.tidymodels.org/learn/develop/parameters/) article walks you through a detailed example. ## Unknown Values There are some cases where the range of parameter values are data dependent. For example, the upper bound on the number of neighbors cannot be known if the number of data points in the training set is not known. For that reason, some parameters have an _unknown_ placeholder: ```{r unk} mtry() sample_size() num_terms() num_comp() # and so on ``` These values must be initialized prior to generating parameter values. The `finalize()` methods can be used to help remove the unknowns: ```{r finalize-mtry} finalize(mtry(), x = mtcars[, -1]) ``` ## Parameter Sets These are collection of parameters used in a model, recipe, or other object. They can also be created manually and can have alternate identification fields: ```{r p-set} glmnet_set <- parameters(list(lambda = penalty(), alpha = mixture())) glmnet_set # can be updated too update(glmnet_set, alpha = mixture(c(.3, .6))) ``` These objects can be very helpful when creating tuning grids. ## Parameter Grids Sets or combinations of parameters can be created for use in grid search. `grid_regular()`, `grid_random()`, `grid_max_entropy()`, and `grid_latin_hypercube()` take any number of `param` objects or a parameter set. For example, for a glmnet model, a regular grid might be: ```{r glm-reg} grid_regular( mixture(), penalty(), levels = 3 # or c(3, 4), etc ) ``` and, similarly, a random grid is created using ```{r glm-rnd} set.seed(1041) grid_random( mixture(), penalty(), size = 6 ) ```