Skip to content

Commit

Permalink
add phragmen's rule in efs
Browse files Browse the repository at this point in the history
  • Loading branch information
bblodfon committed Aug 23, 2024
1 parent 6b7fb03 commit 60065f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/EnsembleFSResult.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
#' Voters who approve more candidates contribute a lesser score to the individual approved candidates.
#' - `"seq_pav"|"seq_pav_weighted"` (sequential proportional approval voting) sequentially builds a committee by iteratively selecting the candidate that maximizes the PAV score when added, ensuring proportional representation.
#' The **PAV score** (Proportional Approval Voting score) is a metric that calculates the weighted sum of harmonic numbers corresponding to the number of elected candidates supported by each voter, reflecting the overall satisfaction of voters in a committee selection process.
#' - `"seq_phragmen"|"seq_phragmen_weighted"` (sequential Phragmen's rule) distributes "loads" equally among voters for each candidate added to the committee.
#' The rule iteratively selects the candidate that results in the smallest increase in voter load.
#' This approach is suitable for scenarios where a balanced representation is desired, as it seeks to evenly distribute the "burden" of representation among all voters.
#'
#' @param method (`character(1)`)\cr
#' The method to calculate the feature ranking.
Expand All @@ -156,7 +159,8 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
#'
feature_ranking = function(method = "av", committee_size = NULL) {
assert_choice(method, choices = c("av", "av_weighted", "sav", "sav_weighted",
"seq_pav", "seq_pav_weighted"))
"seq_pav", "seq_pav_weighted", "seq_phragmen",
"seq_phragmen_weighted"))
assert_int(committee_size, lower = 1, null.ok = TRUE)

# cached results
Expand Down Expand Up @@ -189,6 +193,8 @@ EnsembleFSResult = R6Class("EnsembleFSResult",
res = satisfaction_approval_voting(voters, candidates, weights)
} else if (startsWith(method, "seq_pav")) {
res = seq_proportional_approval_voting(voters, candidates, weights, committee_size)
} else if (startsWith(method, "seq_phragmen")) {
res = seq_phragmen_rule(voters, candidates, weights, committee_size)
}

private$.feature_ranking[[method]] = res
Expand Down
11 changes: 11 additions & 0 deletions R/voting_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ seq_proportional_approval_voting = function(voters, candidates, weights, committ
add_borda_score(res)
}

seq_phragmen_rule = function(voters, candidates, weights, committee_size = NULL) {
if (is.null(committee_size)) {
committee_size = length(candidates)
}

# returns ranked features from best to worst (up to committee_size)
res = as.data.table(seq_PAV_rcpp(voters, candidates, weights, committee_size))

add_borda_score(res)
}

# add normalized borda scores
add_borda_score = function(dt) {
borda_score = NULL # silence data.table note: "no visible global binding"
Expand Down
3 changes: 3 additions & 0 deletions 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 60065f9

Please sign in to comment.