Skip to content

Commit

Permalink
Merge pull request #83 from JGCRI/82-multi_criteria_weighting-run_num…
Browse files Browse the repository at this point in the history
…ber-bug-fix

82 multi criteria weighting run number bug fix
  • Loading branch information
jk-brown authored Apr 17, 2024
2 parents 495e95c + 1894492 commit 0d3185b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ Suggests:
testthat (>= 3.0.0)
Remotes:
github::JGCRI/hector
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
VignetteBuilder: knitr
11 changes: 7 additions & 4 deletions R/multi_criteria_weighting.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#'
#' @examples
#' # Data frames representing scored ensemble using different scoring criterion
#' score_df1 <- data.frame(weights = c(0.8, 0.6, 0.9))
#' score_df2 <- data.frame(weights = c(0.7, 0.5, 0.8))
#' score_df3 <- data.frame(weights = c(0.9, 0.8, 0.7))
#' score_df1 <- data.frame(run_number = c(1, 2, 3), weights = c(0.8, 0.6, 0.9))
#' score_df2 <- data.frame(run_number = c(1, 2, 3), weights = c(0.7, 0.5, 0.8))
#' score_df3 <- data.frame(run_number = c(1, 2, 3), weights = c(0.9, 0.8, 0.7))
#'
#' # List of score data frames
#' scores_list <- list(score_df1, score_df2, score_df3)
Expand Down Expand Up @@ -60,9 +60,12 @@ multi_criteria_weighting <- function(scores_list, criterion_weights = NULL) {
# normalize the combined weights to sum to 1
normalized_combined_scores <- combined_scores / sum(combined_scores)

# extract run_numbers from one of the data frames in scores_list
run_numbers <- scores_list[[1]]$run_number

# return a df with run number and normalized multi-criteria weights
return(data.frame(
run_number = 1:length(normalized_combined_scores),
run_number = run_numbers,
mc_weight = normalized_combined_scores
))
}
6 changes: 3 additions & 3 deletions man/multi_criteria_weighting.Rd

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

9 changes: 6 additions & 3 deletions tests/testthat/test-multi_criterion_weighting.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Sample data
score_df1 <- data.frame(weights = c(0.6, 0.4))
score_df2 <- data.frame(weights = c(0.5, 0.5))
score_df3 <- data.frame(weights = c(0.9, 0.1))
score_df1 <- data.frame(run_number = c(1, 2),
weights = c(0.6, 0.4))
score_df2 <- data.frame(run_number = c(1, 2),
weights = c(0.5, 0.5))
score_df3 <- data.frame(run_number = c(1, 2),
weights = c(0.9, 0.1))

# Sample lists
L1 <- list()
Expand Down

0 comments on commit 0d3185b

Please sign in to comment.