@@ -24,93 +24,6 @@ convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
2424 res
2525}
2626
27- # ------------------------------------------------------------------------------
28- # min_grid generic - put here so that the generic shows up first in the man file
29-
30- # ' Determine the minimum set of model fits
31- # '
32- # ' `min_grid` determines exactly what models should be fit in order to
33- # ' evaluate the entire set of tuning parameter combinations. This is for
34- # ' internal use only and the API may change in the near future.
35- # ' @param x A model specification.
36- # ' @param grid A tibble with tuning parameter combinations.
37- # ' @param ... Not currently used.
38- # ' @return A tibble with the minimum tuning parameters to fit and an additional
39- # ' list column with the parameter combinations used for prediction.
40- # ' @keywords internal
41- # ' @export
42- min_grid <- function (x , grid , ... ) {
43- # x is a `model_spec` object from parsnip
44- # grid is a tibble of tuning parameter values with names
45- # matching the parameter names.
46- UseMethod(" min_grid" )
47- }
48-
49- # As an example, if we fit a boosted tree model and tune over
50- # trees = 1:20 and min_n = c(20, 30)
51- # we should only have to fit two models:
52- #
53- # trees = 20 & min_n = 20
54- # trees = 20 & min_n = 30
55- #
56- # The logic related to how this "mini grid" gets made is model-specific.
57- #
58- # To get the full set of predictions, we need to know, for each of these two
59- # models, what values of num_terms to give to the multi_predict() function.
60- #
61- # The current idea is to have a list column of the extra models for prediction.
62- # For the example above:
63- #
64- # # A tibble: 2 x 3
65- # trees min_n .submodels
66- # <dbl> <dbl> <list>
67- # 1 20 20 <named list [1]>
68- # 2 20 30 <named list [1]>
69- #
70- # and the .submodels would both be
71- #
72- # list(trees = 1:19)
73- #
74- # There are a lot of other things to consider in future versions like grids
75- # where there are multiple columns with the same name (maybe the results of
76- # a recipe) and so on.
77-
78- # ------------------------------------------------------------------------------
79- # helper functions
80-
81- # Template for model results that do no have the sub-model feature
82- blank_submodels <- function (grid ) {
83- grid %> %
84- dplyr :: mutate(.submodels = map(1 : nrow(grid ), ~ list ()))
85- }
86-
87- get_fixed_args <- function (info ) {
88- # Get non-sub-model columns to iterate over
89- fixed_args <- info $ name [! info $ has_submodel ]
90- }
91-
92- get_submodel_info <- function (spec , grid ) {
93- param_info <-
94- get_from_env(paste0(class(spec )[1 ], " _args" )) %> %
95- dplyr :: filter(engine == spec $ engine ) %> %
96- dplyr :: select(name = parsnip , has_submodel )
97-
98- # In case a recipe or other activity has grid parameter columns,
99- # add those to the results
100- grid_names <- names(grid )
101- is_mod_param <- grid_names %in% param_info $ name
102- if (any(! is_mod_param )) {
103- param_info <-
104- param_info %> %
105- dplyr :: bind_rows(
106- tibble :: tibble(name = grid_names [! is_mod_param ],
107- has_submodel = FALSE )
108- )
109- }
110- param_info %> % dplyr :: filter(name %in% grid_names )
111- }
112-
113-
11427# ------------------------------------------------------------------------------
11528# nocov
11629
0 commit comments