The function step_pd_degree()
creates a specification of a
recipe step that will separate data sets of persistent pairs by homological
degree. The input and output must be list-columns.
step_pd_degree(
recipe,
...,
role = "persistence diagram",
trained = FALSE,
hom_degrees = NULL,
columns = NULL,
keep_original_cols = FALSE,
skip = FALSE,
id = rand_id("pd_degree")
)
A recipe object. The step will be added to the sequence of operations for this recipe.
One or more selector functions to choose variables for this step.
See selections()
for more details.
For model terms created by this step, what analysis role should they be assigned? By default, the new columns created by this step from the original variables will be used as predictors in a model.
A logical to indicate if the quantities for preprocessing have been estimated.
Integer vector of homological degrees.
A character string of the selected variable names. This field
is a placeholder and will be populated once prep()
is used.
A logical to keep the original variables in the
output. Defaults to FALSE
.
A logical. Should the step be skipped when the recipe is baked by
bake()
? While all operations are baked when prep()
is run, some
operations may not be able to be conducted on new data (e.g. processing the
outcome variable(s)). Care should be taken when using skip = TRUE
as it
may affect the computations for subsequent operations.
A character string that is unique to this step to identify it.
An updated version of recipe
with the new step added to the
sequence of any existing operations.
The hom_degrees
argument sets the homological degrees for which to
return new list-columns. If not NULL
(the default), it is intersected
with the degrees found in any specified columns of the training data;
otherwise all found degrees are used. This parameter cannot be tuned.
Other topological feature extraction via persistent homology:
step_pd_point_cloud()
,
step_pd_raster()
dat <- data.frame(
roads = I(list(eurodist, UScitiesD * 1.6)),
topos = I(list(volcano, 255 - volcano))
)
ph_rec <- recipe(~ ., data = dat) %>%
step_pd_point_cloud(roads, keep_original_cols = FALSE) %>%
step_pd_raster(topos, keep_original_cols = FALSE) %>%
step_pd_degree(roads_pd, topos_pd)
ph_prep <- prep(ph_rec, training = dat)
(ph_res <- bake(ph_prep, dat))
#> # A tibble: 2 × 4
#> roads_pd_0 roads_pd_1 topos_pd_0 topos_pd_1
#> <list> <list> <list> <list>
#> 1 <PHom [20 × 3]> <PHom [3 × 3]> <PHom [13 × 3]> <PHom [5 × 3]>
#> 2 <PHom [9 × 3]> <PHom [1 × 3]> <PHom [7 × 3]> <PHom [1 × 3]>
tidy(ph_rec, number = 3)
#> # A tibble: 2 × 3
#> terms value id
#> <chr> <dbl> <chr>
#> 1 roads_pd NA pd_degree_xb20B
#> 2 topos_pd NA pd_degree_xb20B
tidy(ph_prep, number = 3)
#> # A tibble: 2 × 3
#> terms value id
#> <chr> <dbl> <chr>
#> 1 roads_pd NA pd_degree_xb20B
#> 2 topos_pd NA pd_degree_xb20B
with_degs <- recipe(~ ., data = dat) %>%
step_pd_point_cloud(roads, keep_original_cols = FALSE) %>%
step_pd_raster(topos, keep_original_cols = FALSE) %>%
step_pd_degree(roads_pd, topos_pd, hom_degrees = c(1, 2))
with_degs <- prep(with_degs, training = dat)
bake(with_degs, dat)
#> # A tibble: 2 × 2
#> roads_pd_1 topos_pd_1
#> <list> <list>
#> 1 <PHom [3 × 3]> <PHom [5 × 3]>
#> 2 <PHom [1 × 3]> <PHom [1 × 3]>