當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


R dials finalize 用於最終確定數據特定參數範圍的函數


這些函數采用參數對象,並根據數據集和簡單的啟發式修改 ranges 的未知部分。

用法

finalize(object, ...)

# S3 method for list
finalize(object, x, force = TRUE, ...)

# S3 method for param
finalize(object, x, force = TRUE, ...)

# S3 method for parameters
finalize(object, x, force = TRUE, ...)

# S3 method for logical
finalize(object, x, force = TRUE, ...)

# S3 method for default
finalize(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), ...)

參數

object

一個 param 對象或 param 對象列表。

...

傳遞給底層參數終結器函數的其他參數。例如,對於 get_rbf_range() ,點將傳遞到 kernlab::sigest()

x

預測數據。在某些情況下(見下文),這應該隻包括數字數據。

force

單個邏輯表明即使參數對象完整,它仍然應該更新範圍嗎?

log_vals

邏輯:範圍應該設置在 log10 刻度上嗎?

frac

用於上限的數據分數的雙精度值。對於 get_n_frac_range()get_batch_sizes() ,需要兩個小數值的向量。

seed

用於控製計算隨機性的整數。

更新的 param 對象或更新的 param 對象列表,具體取決於 object 中提供的內容。

細節

finalize() 運行 param 對象 ( object$finalize ) 中包含的嵌入式終結器函數並返回更新後的版本。終結函數是 get_*() 幫助程序之一。

get_*() 輔助函數設計為與管道一起使用並就地更新參數對象。

get_p()get_log_p() 將範圍的上限值設置為數據中的列數(分別在自然尺度和 log10 尺度上)。

get_n()get_n_frac() 將上限值設置為數據中的行數或總行數的一部分。

get_rbf_range() 根據 kernlab::sigest() 中定義的啟發式設置兩個邊界。它要求 x 中的所有列都是數字。

例子

library(dplyr)
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union
car_pred <- select(mtcars, -mpg)

# Needs an upper bound
mtry()
#> # Randomly Selected Predictors (quantitative)
#> Range: [1, ?]
finalize(mtry(), car_pred)
#> # Randomly Selected Predictors (quantitative)
#> Range: [1, 10]

# Nothing to do here since no unknowns
penalty()
#> Amount of Regularization (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-10, 0]
finalize(penalty(), car_pred)
#> Amount of Regularization (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-10, 0]

library(kernlab)
#> 
#> Attaching package: ‘kernlab’
#> The following object is masked from ‘package:scales’:
#> 
#>     alpha
library(tibble)
library(purrr)
#> 
#> Attaching package: ‘purrr’
#> The following object is masked from ‘package:kernlab’:
#> 
#>     cross
#> The following object is masked from ‘package:scales’:
#> 
#>     discard

params <-
  tribble(
    ~parameter, ~object,
    "mtry", mtry(),
    "num_terms", num_terms(),
    "rbf_sigma", rbf_sigma()
  )
params
#> # A tibble: 3 × 2
#>   parameter object     
#>   <chr>     <list>     
#> 1 mtry      <nparam[?]>
#> 2 num_terms <nparam[?]>
#> 3 rbf_sigma <nparam[+]>

# 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
#> # A tibble: 3 × 2
#>   parameter object     
#>   <chr>     <list>     
#> 1 mtry      <nparam[+]>
#> 2 num_terms <nparam[+]>
#> 3 rbf_sigma <nparam[+]>

params %>%
  dplyr::filter(parameter == "rbf_sigma") %>%
  pull(object)
#> [[1]]
#> Radial Basis Function sigma (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-10, 0]
#> 
complete_params %>%
  dplyr::filter(parameter == "rbf_sigma") %>%
  pull(object)
#> [[1]]
#> Radial Basis Function sigma (quantitative)
#> Transformer: log-10 [1e-100, Inf]
#> Range (transformed scale): [-1.6, -0.933]
#> 
源代碼:R/finalize.R

相關用法


注:本文由純淨天空篩選整理自Max Kuhn等大神的英文原創作品 Functions to finalize data-specific parameter ranges。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。