Skip to content

Commit

Permalink
add borda score
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Aug 7, 2024
1 parent 0d9eccf commit 87d68d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
10 changes: 9 additions & 1 deletion R/EnsembleFSResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,26 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
#' The weights used are equal to the performance scores of each voter/model (or the inverse scores if the measure is minimized).
#' The un-weighted methods use same weights for all voters (equal to 1).
#'
#' Note that some methods output a feature ranking instead of a score per feature.
#' Therefore we also calculate **Borda's score**:
#' \eqn{s_{borda} = (p-i)/(p-1)}, where \eqn{p} is the total number of features, and \eqn{i} is the feature ranking.
#' So the best feature gets a borda score of \eqn{1} and the worst-ranked feature a borda score of \eqn{0}.
#' This score is method-agnostic, i.e. it can be used to compare the feature rankings across different methods.
#'
#' The following methods are currently supported:
#'
#' - `"av"|"av_weighted"` (approval voting) selects the candidates that have the highest approval score, i.e. the features that appear the most often.
#' This is the default feature ranking method.
#' - `"sav"|"sav_weighted"` (satisfaction approval voting) selects the candidates that have a higher satisfaction score,in proportion to the size of the voters approval sets.
#' - `"sav"|"sav_weighted"` (satisfaction approval voting) selects the candidates that have a higher satisfaction score, in proportion to the size of the voters approval sets.
#' Voters who approve more candidates contribute a lesser score to the individual approved candidates.
#'
#' @param method (`character(1)`)\cr
#' The method to calculate the feature ranking.
#'
#' @return A [data.table::data.table] listing all the features, ordered by decreasing scores (depends on the `"method"`).
#' An extra column `"norm_score"` is produced for methods for which the original scores (i.e. approval counts in the case of approval voting) can be normalized and interpreted as **selection probabilities**, see Meinshausen et al. (2010).
#' The `"borda_score"` column is always included to incorporate feature ranking methods that don't output per-feature scores but only rankings.
#'
feature_ranking = function(method = "av") {
assert_choice(method, choices = c("av", "av_weighted", "sav", "sav_weighted"))

Expand Down
6 changes: 4 additions & 2 deletions R/voting_methods.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# some collection of voting methods for feature ranking

# Parameters:
# @param voters list of feature vectors (best features, each a subset of "candidates")
# @param candidates vector with ALL features
# @param weights vector of weights, 1-1 correspondence with voters
# @return data.table with 4 columns: features (mandatory), score, norm_score, borda_score (mandatory). Always features are ordered with decreasing `score` (or descreasing
# `borda_score` if a method returns only a ranking).

approval_voting = function(voters, candidates, weights) {
# faster R version in case of equal weights
Expand Down Expand Up @@ -31,10 +32,11 @@ approval_voting = function(voters, candidates, weights) {
setorderv(res, cols = "score", order = -1)
}

res
res[, borda_score := (nrow(res) - .I) / (nrow(res) - 1)]
}

satisfaction_approval_voting = function(voters, candidates, weights) {
res = as.data.table(SAV_rcpp(voters, candidates, weights))
setorderv(res, cols = "score", order = -1)
res[, borda_score := (nrow(res) - .I) / (nrow(res) - 1)]
}
1 change: 0 additions & 1 deletion man/AutoFSelector.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion man/ensemble_fs_result.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87d68d4

Please sign in to comment.