Skip to contents

reduce_weighted_vote() makes a reducer for ensemble() that adds up the weights of the modules behind each value and returns the output with the largest total. Without weights, every vote counts 1.

Usage

reduce_weighted_vote(field = NULL)

Arguments

field

The output field to vote on. With NULL, the first field.

Value

A function function(outputs, weights = NULL) for the reduce_fn argument of ensemble().

Details

Values are compared as strings. Ties go to the value that sorts first alphabetically. The reducer returns the whole output of the first module that gave the winning value.

Examples

vote <- reduce_weighted_vote(field = "sentiment")
outputs <- list(
  list(sentiment = "positive"),
  list(sentiment = "negative"),
  list(sentiment = "positive")
)
vote(outputs)
#> $sentiment
#> [1] "positive"
#> 

# The second module is trusted more than the other two together
vote(outputs, weights = c(0.4, 0.9, 0.4))
#> $sentiment
#> [1] "negative"
#>