cost_fun: Cost function

Description Usage Arguments Value

View source: R/cost-fun.R

Description

Defines a cost function to be used in seq_opt(). A cost function defines the penalty for a given state transitions. If multiple cost functions are provided to seq_opt() then costs are computed for each cost function and summed to produce the final cost.

Usage

1
2
cost_fun(f, context_sensitive, vectorised = FALSE, symmetric = NA,
  has_reverse = FALSE)

Arguments

f

Function defining the cost function. If context_sensitive = TRUE, this function should take two arguments, the first corresponding to the previous state, and the second corresponding to the new state. If context_sensitive = FALSE, this function should take one argument corresponding to the new state.

context_sensitive

(Logical scalar) Whether the function is affected by the identity of the previous state. If FALSE, this means the cost function only depends on the identity of the new state.

vectorised

(Logical scalar) Whether or not f is vectorised. If f is vectorised, it should take as its first input a list of potential previous states, with its second input being the new state, as before. It should then return a numeric vector corresponding to the transition cost associated with each potential previous state.

symmetric

(Logical scalar) Whether f is symmetric, meaning that it returns the same result when transitioning forwards or backwards between two states.

has_reverse

(Logical scalar) If reverse == TRUE, the cost function f should have an optional argument reverse which defaults to FALSE, which when set to TRUE instructs the cost function to compute the transition cost "backwards", as if proceeding from the continuation to the context.

Value

An object of class cost_fun, to be combined into a list and passed to seq_opt().


pmcharrison/seqopt documentation built on May 22, 2019, 6:35 p.m.