Skip to content

Commit

Permalink
Minor reproducibility update
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ulash committed Jul 29, 2020
1 parent 2dc61a6 commit 2eb4122
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
17 changes: 0 additions & 17 deletions 1_offline_ranking.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,4 @@ for(i in 1:length(deltas)){
p <- plots[[1]] + plots[[2]] + plots[[3]] + plots[[4]] + plots[[5]] + plots[[6]] + plot_layout(guides = "collect") & theme(legend.position = "bottom")
ggsave(paste0(f[[1]],"_offline.pdf"), p, device="pdf", width=10, height=7)

#pdf(paste0("offline_",f[[1]],".pdf"))

#layout(matrix(c(1,2,3,4,5,6,7,7,7), ncol=3, byrow=TRUE), heights=c(3, 3, 1))
#par(oma=c(4,4,2,2), las=1)
##par(cex=1.05)
#for(hist in histories){
# plot(hist, type="cumulative", no_par = TRUE, disp="ci", legend=FALSE, use_colors=TRUE, trunc_per_agent = FALSE, xlab = "", ylab = "")
#}
#par(cex=1.05)
#mtext("Time step", 1, 3, outer=TRUE, las = 0)
#mtext("Cumulative regret", 2, 3, outer=TRUE, las = 0)
#par(mar=c(1,1,1,1))
#plot.new()
#legend(x="center", ncol=4,legend=c("UR","E-First","LiF", "TBL"), fill=c("#F8766D", "#7CAE00", "#00BFC4", "#C77CFF"), title="Legend")
#
#dev.off()
}

8 changes: 6 additions & 2 deletions bandit_continuum_offon.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ OnlineOfflineContinuumBandit <- R6::R6Class(
post_initialization = function() {
self$choice <- runif(self$horizon, min=0, max=1)
temp_data <- self$arm_function(self$choice)
self$S <- data.frame(self$choice, temp_data$data)
self$maxval <- temp_data$max
if(self$max_bool == TRUE){
self$S <- data.frame(self$choice, temp_data$data)
self$maxval <- temp_data$max
} else {
self$S <- data.frame(self$choice, temp_data)
}
self$S <- self$S[sample(nrow(self$S)),]
colnames(self$S) <- c('choice', 'reward')
},
Expand Down
37 changes: 19 additions & 18 deletions bandit_continuum_offon_kern.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,50 @@
OnlineOfflineContinuumBanditKernel <- R6::R6Class(
inherit = Bandit,
class = FALSE,
private = list(
S = NULL,
n = NULL
),
public = list(
class_name = "OnlineOfflineContinuumBanditKernel",
delta = NULL,
c1 = NULL,
c2 = NULL,
arm_function = NULL,
choice = NULL,
h = NULL,
kernel = NULL,
horizon = NULL,
initialize = function(FUN, horizon) {
max_bool = FALSE,
maxval = NULL,
S = NULL,
n = NULL,
initialize = function(FUN, max_bool, horizon) {
self$arm_function <- FUN
self$k <- 1
self$horizon <- horizon
self$h <- horizon^(-1/5)
self$kernel <- function(action_true, action_choice, bandwith){ 1/sqrt(2*pi)*exp(((action_choice - action_true) / bandwith)^2/2) }
self$max_bool <- max_bool
},
post_initialization = function() {
self$choice <- runif(self$horizon, min=0, max=1)
private$S <- data.frame(self$choice, self$arm_function(self$choice))
private$S <- private$S[sample(nrow(private$S)),]
colnames(private$S) <- c('choice', 'reward')
private$n <- 0
temp_data <- self$arm_function(self$choice)
if(self$max_bool == TRUE){
self$S <- data.frame(self$choice, temp_data$data)
self$maxval <- temp_data$max
} else {
self$S <- data.frame(self$choice, temp_data)
}
self$S <- self$S[sample(nrow(self$S)),]
colnames(self$S) <- c('choice', 'reward')
self$n <- 0
},
get_context = function(index) {
context <- list()
context$k <- self$k
context
},
get_reward = function(index, context, action) {
reward_at_index <- as.double(private$S$reward[[index]])
#kern_value <- self$kernel(action_true = private$S$choice[[index]], action_choice = action$choice, bandwith = self$h)
temp_u <- (action$choice - private$S$choice[[index]]) / self$h
reward_at_index <- as.double(self$S$reward[[index]])
temp_u <- (action$choice - self$S$choice[[index]]) / self$h
kern_value <- 1/sqrt(2*pi) * exp(-temp_u^2 / 2)
#inc(private$n) <- 1
#print(paste0("Kernel value: ", kern_value, "action choice: ", action$choice, "true action: ", private$S$choice[[index]], "divy: ", temp_u))
reward <- list(
reward = (kern_value * reward_at_index),
optimal_reward = self$c2
optimal_reward = ifelse(self$max_bool, self$maxval, NA)
)
}
)
Expand Down

0 comments on commit 2eb4122

Please sign in to comment.