| func_epsilon | R Documentation |
\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}
func_epsilon(shown, rownum, params, ...)
shown |
Which options shown in this trial. |
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.
|
An int, either 0 or 1, indicating exploration or
exploitation on the current trial.
func_epsilon <- function(
shown,
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 <- as.integer(stats::runif(1) < epsilon)
# Epsilon-Decreasing:
} else if (rownum > threshold && model == "decreasing") {
prob_explore <- 1 / (1 + epsilon * rownum)
try <- as.integer(stats::runif(1) < prob_explore)
}
return(try)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.