Learn R Programming

multiRL (version 0.2.3)

func_epsilon: Function: \(\epsilon\)–first, Greedy, Decreasing

Description

\(\epsilon–first\):

$$ P(x) = \begin{cases} i \le \text{threshold}, & x=1 \\ i > \text{threshold}, & x=0 \end{cases} $$

\(\epsilon–greedy\):

$$ P(x) = \begin{cases} \epsilon, & x=1 \\ 1-\epsilon, & x=0 \end{cases} $$

\(\epsilon–decreasing\):

$$ P(x) = \begin{cases} \frac{1}{1+\epsilon \cdot i}, & x=1 \\ \frac{\epsilon \cdot i}{1+\epsilon \cdot i}, & x=0 \end{cases} $$

Usage

func_epsilon(rownum, params, ...)

Value

An int, either 0 or 1, indicating exploration or exploitation on the current trial.

Arguments

rownum

The trial number

params

Parameters used by the model’s internal functions, see params

...

It currently contains the following information; additional information may be added in future package versions.

  • idinfo:

    • subid

    • block

    • trial

  • exinfo: contains information whose column names are specified by the user.

    • Frame

    • RT

    • NetWorth

    • ...

  • behave: includes the following:

    • action: the behavior performed by the human in the given trial.

    • latent: the object updated by the agent in the given trial.

    • simulation: the actual behavior performed by the agent.

Body

func_epsilon <- function(
    rownum,
    params,
    ...
){

list2env(list(...), envir = environment()) # If you need extra information(...) # Column names may be lost(C++), indexes are recommended # e.g. # Trial <- idinfo[3] # Frame <- exinfo[1] # Action <- behave[1] epsilon <- params[["epsilon"]] threshold <- params[["threshold"]] # Determine the model currently in use based on which parameters are free. if (is.na(epsilon) && threshold > 0) { model <- "first" } else if (!(is.na(epsilon)) && threshold == 0) { model <- "decreasing" } else if (!(is.na(epsilon)) && threshold == 1) { model <- "greedy" } else { stop("Unknown Model! Plase modify your learning rate function") } set.seed(rownum) # Epsilon-First: if (rownum <= threshold) { try <- 1 } else if (rownum > threshold && model == "first") { try <- 0 # Epsilon-Greedy: } else if (rownum > threshold && model == "greedy"){ try <- sample( c(1, 0), prob = c(epsilon, 1 - epsilon), size = 1 ) # Epsilon-Decreasing: } else if (rownum > threshold && model == "decreasing") { try <- sample( c(1, 0), prob = c( 1 / (1 + epsilon * rownum), epsilon * rownum / (1 + epsilon * rownum) ), size = 1 ) } return(try) }