| compute_pu_scores | R Documentation |
This function calculates a continuous importance score
(ensemble_score) for each planning unit by combining two sources
of information: (1) a rarity-weighted aggregation of feature values, and
(2) how consistently each planning unit is selected across one or more
solutions.
The relative influence of these components is controlled by
alpha_freq. When multiple solutions are provided, selection
consistency reflects how often each planning unit is selected across the
portfolio. When a single solution is provided, it reflects whether the
planning unit is selected or not. If no solution columns are present, the
score is based entirely on the rarity-weighted feature component.
Optionally, locked_in planning units can be forced to rank above
all others.
compute_pu_scores(
s,
feature_mat,
feature_weights = NULL,
alpha_freq = 0.25,
freq_gamma = 1.5,
lock_mode = c("top", "none"),
winsor_p = NULL,
cost_col = NULL,
cost_beta = 1
)
s |
An |
feature_mat |
A numeric matrix or data frame with one row per planning unit and one column per feature (e.g. proportion of each feature in each PU). |
feature_weights |
Optional named numeric vector of user weights
for the features. Names must match |
alpha_freq |
Numeric in |
freq_gamma |
Numeric exponent applied to selection consistency
(after percentile ranking) to emphasize planning units that are selected
in many solutions ( |
lock_mode |
Character, either |
winsor_p |
Optional numeric in |
cost_col |
Optional name of a numeric column in |
cost_beta |
Numeric exponent applied to costs when |
The same sf object s with two new numeric columns:
selection_consistency and ensemble_score.
# Minimal sf with 3 planning units + two solution columns
s <- sf::st_as_sf(
data.frame(
x = c(0, 1, 2),
y = c(0, 0, 0),
solution_1 = c(1, 0, 1),
solution_2 = c(1, 1, 0),
locked_in = c(FALSE, TRUE, FALSE)
),
coords = c("x", "y"), crs = 4326
)
# Feature matrix must match nrow(s)
feature_mat <- data.frame(
f1 = c(0.2, 0.0, 0.8),
f2 = c(0.0, 0.5, 0.1)
)
s2 <- compute_pu_scores(
s, feature_mat,
alpha_freq = 0.25,
lock_mode = "top"
)
s2[, c("selection_consistency", "ensemble_score", "locked_in")]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.