Bandit {contextual}R Documentation

Bandit: Superclass

Description

Parent or superclass of all {contextual} Bandit subclasses.

Details

In {contextual}, Bandits are responsible for the generation of (either synthetic or offline) contexts and rewards.

On initialisation, a Bandit subclass has to define the number of arms self$k and the number of contextual feature dimensions self$d.

For each t = {1, ..., T} a Bandit then generates a list containing current context in d x k dimensional matrix context$X, the number of arms in context$k and the number of features in context$d.

Note: in context-free scenario's, context$X can be omitted.

contextual diagram: get context

On receiving the index of a Policy-chosen arm through action$choice, Bandit is expected to return a named list containing at least reward$reward and, where computable, reward$optimal.

contextual diagram: get context

Usage

  bandit <- Bandit$new()

Methods

new()

generates and instantializes a new Bandit instance.

get_context(t)

argument:

  • t: integer, time step t.

returns a named list containing the current d x k dimensional matrix context$X, the number of arms context$k and the number of features context$d.

get_reward(t, context, action)

arguments:

  • t: integer, time step t.

  • context: list, containing the current context$X (d x k context matrix), context$k (number of arms) and context$d (number of context features) (as set by bandit).

  • action: list, containing action$choice (as set by policy).

returns a named list containing reward$reward and, where computable, reward$optimal (used by "oracle" policies and to calculate regret).

post_initialization()

Is called after a Simulator has cloned the Bandit instance number_of_simulations times. Do sim level random generation here.

generate_bandit_data(n)

Is called after cloning the Bandit instance number_of_simulations times. Differentiates itself from post_initialization() in that it is called after the optional arm-multiplier option is applied in Simulator, and in that it is possible to set the length of the to be generated data with the function's n parameter.

See Also

Core contextual classes: Bandit, Policy, Simulator, Agent, History, Plot

Bandit subclass examples: BasicBernoulliBandit, ContextualLogitBandit, OfflineReplayEvaluatorBandit

Policy subclass examples: EpsilonGreedyPolicy, ContextualLinTSPolicy


[Package contextual version 0.9.8.4 Index]