Plot: Plot

Description Details Usage Methods Plot method arguments See Also Examples

Description

Generates plots from History data.

Details

Usually not instantiated directly but invoked by calling the generic plot(h), where h is an History class instance.

Usage

1
   Plot <- Plot$new()

Methods

cumulative(history,...)

Plots cumulative regret or reward (depending on parameter regret=TRUE/FALSE) over time.

average(history,...)

Plots average regret or reward (depending on parameter regret=TRUE/FALSE) over time.

arms(history),...

Plot the percentage of simulations per time step each arm was chosen over time. If multiple agents have been run, plots only the first agent.

Plot method arguments

type

(character, "cumulative") Can be either "cumulative" (default), "average", or "arms". Sets the plot method when Plot() is called through R's generic plot() function. Methods are descrived in the Methods section above.

regret

(logical, TRUE) Plot policy regret (default, TRUE) or reward (FALSE)?

rate

(logical, TRUE) If rate is TRUE, the rate of regret or reward is plotted.

limit_agents

(list , NULL) Limit plotted agents to the agents in the list.

limit_context

(character vector , NULL) Only plots data where context feature name(s) in vector equal to one.

no_par

(logical, FALSE) If no_par is TRUE, Plot() does not set or adjust plotting parameters itself. This makes it possible to set custom plotting parameters through R's par() function.

legend

(logical, TRUE) Shows the legend when TRUE (default).

legend_title

(character , NULL) Sets a custom legend title.

legend_labels

(character list , NULL) Sets legend labels to custom values as specified in list.

legend_border

(logical , NULL) When TRUE, the legend is borderless.

legend_position

(character , "topleft") a single keyword from the list "bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center". This places the legend on the inside of the plot frame at the given location.

xlim

(c(integer,integer), NULL) Sets x-axis limits.

ylim

(c(integer,integer), NULL) Sets y-axis limits.

log

(character , "") A character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic.

use_colors

(logical, TRUE) If use_colors is FALSE, plots will be in grayscale. Otherwise, plots will make use of a color palette (default).

disp

(character, NULL) When disp (for "dispersion measure") is set to either 'var','sd' or 'ci', the variance, standard deviation, or 95% confidence interval will be added to the plot(s).

plot_only_disp

(logical, FALSE) When TRUE and disp is either 'var','sd' or 'ci', plot only dispersion measure.

traces

(logical , FALSE) Plot traces of independent simulations (default is FALSE).

traces_max

(integer , 100) The number of trace lines.

traces_alpha

(numeric , 0.3) Opacity of the trace lines. Default is 0.3 - that is, an opacity of 30%.

smooth

(logical , FALSE) Smooth the plot (default is FALSE)

interval

(integer, NULL) Plot only every t%%interval==0 data point.

cum_average

(logical , FALSE) Calculates moving average from cum_reward or cum_regret with step size interval.

color_step

(integer, 1) When > 1, the plot cycles through nr_agents/color_step colors.

lty_step

(integer, 1) When > 1, the plot cycles through nr_agents/lty_step line types.

lwd

(integer, 1) Line width.

xlab

(character, NULL) a title for the x axis

ylab

(character, NULL) a title for the y axis

trunc_over_agents

(logical , TRUE) Truncate the chart to the agent with the fewest time steps t.

trunc_per_agent

(logical , TRUE) Truncate every agent's plot to the number of time steps that have been fully simulated. That is, time steps for which the number of simulations equals the number defined in Simulator's simulations parameter.

See Also

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

Bandit subclass examples: BasicBernoulliBandit, ContextualLogitBandit, OfflineReplayEvaluatorBandit

Policy subclass examples: EpsilonGreedyPolicy, ContextualLinTSPolicy

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## Not run: 

bandit <- ContextualPrecachingBandit$new(weights = c(0.9, 0.1, 0.1))

agents <- list(Agent$new(RandomPolicy$new(), bandit),
               Agent$new(OraclePolicy$new(), bandit),
               Agent$new(ThompsonSamplingPolicy$new(1.0, 1.0), bandit),
               Agent$new(Exp3Policy$new(0.1), bandit),
               Agent$new(GittinsBrezziLaiPolicy$new(), bandit),
               Agent$new(UCB1Policy$new(), bandit))

history <- Simulator$new(agents, horizon = 100, simulations = 1000)$run()

par(mfrow = c(3, 2), mar = c(1, 4, 2, 1), cex=1.3)

plot(history, type = "cumulative", use_colors = FALSE, no_par = TRUE, legend_border = FALSE,
     limit_agents = c("GittinsBrezziLai", "UCB1","ThompsonSampling"))

plot(history, type = "cumulative", regret = FALSE, legend = FALSE,
     limit_agents = c("UCB1"), traces = TRUE, no_par = TRUE)

plot(history, type = "cumulative", regret = FALSE, rate = TRUE, disp = "sd",
     limit_agents = c("Exp3", "ThompsonSampling"),
     legend_position = "bottomright", no_par = TRUE)

plot(history, type = "cumulative", rate = TRUE, plot_only_disp = TRUE,
     disp = "var", smooth = TRUE, limit_agents = c("UCB1", "GittinsBrezziLai"),
    legend_position = "bottomleft", no_par = TRUE)

plot(history, type = "average", disp = "ci", regret = FALSE, interval = 10,
     smooth = TRUE, legend_position = "bottomright", no_par = TRUE, legend = FALSE)

plot(history, limit_agents = c("ThompsonSampling"), type = "arms",
     interval = 20, no_par = TRUE)


## End(Not run)

Nth-iteration-labs/contextual documentation built on July 28, 2020, 1:13 p.m.