Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

82 multi criteria weighting run number bug fix #83

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading