View source: R/prtree_grid_expansion.R
| expand_sigma_grid | R Documentation |
Creates a grid of candidate \boldsymbol\sigma vectors for
use in pr_tree. The grid is generated from the feature standard
deviations of X, or using unit scales when X = NULL
expand_sigma_grid(X = NULL, n_feat = NULL, idx_train = NULL,
grid_size = 8, min_mult = 0, max_mult = 2, tiny_sigma = NULL,
verbose = TRUE)
X |
A numeric vector, matrix or data frame of predictor variables. If
|
n_feat |
Optional integer. Number of features. Required when |
idx_train |
Optional integer vector. Indices of observations to use for
computing feature standard deviations. If |
grid_size |
Integer. Number of candidate vectors to generate when
|
min_mult |
Numeric. Minimum multiplier for automatic grid generation. Default is 0. See ‘Details’ for how this defines the multiplier interval. Ignored when a custom grid is provided. |
max_mult |
Numeric. Maximum multiplier for automatic grid generation. Default is 2. Ignored when a custom grid is provided. |
tiny_sigma |
A single numeric value or |
verbose |
Logical. If |
When X is provided, the grid is based on the empirical standard
deviations of the features. If a standard deviation for a feature cannot be
computed (e.g., due to all missing values or a constant feature), it
defaults to 1.0 to ensure the grid generation proceeds without errors.
Automatic grid generation
The automatic grid is generated as follows:
For each feature j, the base values are the empirical standard deviations
\hat\sigma_j from the training data.
If grid_size = 1, the grid consists solely of these base values
\hat{\boldsymbol\sigma}.
If grid_size > 1, the grid is constructed using grid_size
multipliers equally spaced in the interval:
(min_mult, max_mult] when min_mult = 0 (excludes 0, includes max_mult).
[min_mult, max_mult] when min_mult > 0 (both inclusive).
Each multiplier m generates a candidate vector m \times \hat{\boldsymbol\sigma}.
If tiny_sigma is provided, it is added as an extra candidate (first
row) with \boldsymbol\sigma = \text{tiny\_sigma} \cdot
\boldsymbol{1}_p, where \boldsymbol{1}_p is a vector of ones of
length p (the number of features). This results in a final grid of
size grid_size + 1.
pr_tree_control for setting control parameters.
pr_tree_control_cv for cross-validation settings.
pr_tree for fitting a single tree.
pr_tree_cv for cross-validation.
# With actual data, default range (0, 2]
X <- matrix(runif(100 * 3, 0, 10), ncol = 3)
grid1 <- expand_sigma_grid(X, grid_size = 8)
# Custom range with min_mult > 0 (includes min_mult)
grid2 <- expand_sigma_grid(X, grid_size = 8, min_mult = 0.5, max_mult = 3)
# Without data (unit scales)
grid3 <- expand_sigma_grid(n_feat = 3, grid_size = 8)
# Only tiny sigma
grid4 <- expand_sigma_grid(n_feat = 3, grid_size = 0, tiny_sigma = 1e-20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.