Skip to contents

Construct a rank-weight spec

Usage

new_rank_weight(name, eval = NULL, eval_batch = NULL, setup = NULL)

Arguments

name

Character scalar.

eval

Optional function (ranks, ctx) -> numeric(n).

eval_batch

Optional function (rank_matrix, ctx) -> numeric(n x m).

setup

Optional function to build context. At the top level, weights_matrix() passes any supplied ctx through to the rank-weight evaluator, but it does not automatically call setup() for you.

Value

A validated rank_weight specification.

Examples

rw <- new_rank_weight(
  name = "inv_rank",
  eval = function(ranks, ctx = NULL) {
    w <- 1 / as.numeric(ranks)
    w / sum(w)
  }
)
is_rank_weight(rw)
#> [1] TRUE