Skip to contents

Returns closures for value and gradient evaluation of a score at any parameter vector theta, using analytic or finite-difference derivatives.

Usage

score_diff_path(
  score,
  data,
  ctx = NULL,
  method = c("auto", "analytic", "fd"),
  fd_step = NULL,
  fd_scheme = NULL
)

Arguments

score

A ustat_score.

data

Data object passed to score evaluators.

ctx

Optional context from score_setup(). If NULL, one is created via score_setup().

method

One of c("auto", "analytic", "fd") for gradients.

fd_step

Optional finite-difference step override.

fd_scheme

Optional finite-difference scheme override.

Value

A list with closures:

  • value(idxs, theta, rng = NULL) for one subset;

  • value_batch(subs, theta, rng = NULL) for many subsets;

  • grad(idxs, theta, rng = NULL) for one-subset gradients;

  • grad_batch(subs, theta, rng = NULL) for batch gradients;

  • meta with derivative settings.

Examples

sc <- new_score(
  name = "affine_order1",
  order = 1L,
  eval_param = function(idxs, data, theta, ctx, rng) {
    theta[1] * data[idxs] + theta[2]
  }
)
path <- score_diff_path(sc, data = c(1, 2, 4), method = "fd")
path$value(2L, theta = c(0.5, 1))
#> [1] 2
path$grad(2L, theta = c(0.5, 1))
#> [1] 2 1