Skip to content

Commit

Permalink
bug fix counterfactuals: rank_nondom needs negative fitness values fo…
Browse files Browse the repository at this point in the history
…r minimization
  • Loading branch information
dandls committed Nov 24, 2022
1 parent 8d9b231 commit 2274420
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/Counterfactuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Counterfactuals = R6::R6Class("Counterfactuals",
if (any(c("no_nondom", "frac_nondom", "hypervolume") %in% measures)) {
res = self$evaluate()[, c("dist_target", "dist_x_interest", "no_changed", "dist_train")]
if (any(c("no_nondom", "frac_nondom") %in% measures)) {
idnondom = miesmuschel::rank_nondominated(as.matrix(res))$fronts == 1
idnondom = miesmuschel::rank_nondominated(-as.matrix(res))$fronts == 1
if ("no_nondom" %in% measures) evals$no_nondom = sum(idnondom)
if ("frac_nondom" %in% measures) evals$frac_nondom = sum(idnondom)/nrow(res)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Counterfactuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ test_that("evaluate and evaluate_set returns correct results", {
expect_true(cf_evalset$no_nondom < nrow(cf$data))
expect_identical(
cf_evalset$no_nondom,
sum(miesmuschel::rank_nondominated(as.matrix(cf_eval[,c("dist_x_interest", "dist_target", "no_changed", "dist_train")]))$fronts == 1)
sum(miesmuschel::rank_nondominated(-as.matrix(cf_eval[,c("dist_x_interest", "dist_target", "no_changed", "dist_train")]))$fronts == 1)
)
expect_identical(cf_evalset$frac_nondom, cf_evalset$no_nondom/nrow(cf$data))

Expand Down

0 comments on commit 2274420

Please sign in to comment.