Created
December 30, 2015 04:13
-
-
Save brycemcd/e31465ac0cf7953a060f to your computer and use it in GitHub Desktop.
Reads in the output file of a monte carlo simulation for an epsilon-Greedy bandit algorithm implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("dplyr") | |
library("tidyr") | |
library("ggplot2") | |
epsilonGreedySanityCheck <- read.csv("~/Desktop/epsilonGreedySanityCheck.txt", header=FALSE) | |
names(epsilonGreedySanityCheck) <- c("testRun", | |
"iterationNum", | |
"epsilon", | |
"nArms", | |
"exploreOrExploit", | |
"chosenIndex", | |
"iterationRandomNumber") | |
epsilonGreedySanityCheck$testRun <- as.factor(epsilonGreedySanityCheck$testRun) | |
epsilonGreedySanityCheck$iterationNum <- as.factor(epsilonGreedySanityCheck$iterationNum) | |
check <- epsilonGreedySanityCheck %>% | |
group_by(testRun) %>% | |
filter( testRun == 0) | |
#mutate(randomMoreThanEpsilon = ifelse(iterationRandomNumber > epsilon, as.factor("yes"), as.factor("no"))) | |
#summarize(cntRandom = count(randomMoreThanEpsilon)) | |
check %>% head() | |
basegraph <- ggplot(data = epsilonGreedySanityCheck) + theme_bw() | |
basegraph + geom_histogram(aes(x=iterationRandomNumber, fill=testRun), alpha=0.9) + | |
labs(title = "# of times random number was chosen to explore or exploit") | |
exploreOrExplotPercent <- epsilonGreedySanityCheck %>% | |
group_by(testRun, exploreOrExploit) %>% | |
summarize(cnt = n()) %>% | |
spread(exploreOrExploit, cnt) %>% | |
mutate(ratio = (explore / (explore + exploit))) | |
exploreOrExplotPercent | |
testRunIterations <- epsilonGreedySanityCheck %>% | |
group_by(testRun) %>% | |
summarize(meanEps = mean(epsilon), | |
maxEps = max(epsilon)) %>% | |
select(testRun, meanEps, maxEps) | |
testRunIterations | |
# gut check does the calculated epsilon = epsilon given to the program? | |
gutCheck <- inner_join(exploreOrExplotPercent, testRunIterations, by="testRun") %>% | |
mutate(epsDiff = (meanEps - ratio)) | |
# 7 = epsDiff | |
diffs <- as.vector(t(gutCheck[, 7])) | |
diffs | |
sum(diffs) | |
mean(diffs) | |
median(diffs) | |
# is the chosen index random? | |
chosenIndexCheck <- epsilonGreedySanityCheck %>% | |
filter(exploreOrExploit == "explore") %>% | |
group_by(testRun, chosenIndex) %>% | |
summarize(idxCnt = n()) %>% | |
ungroup() | |
chosenIndexCheck | |
ggplot(data=chosenIndexCheck) + | |
geom_bar(aes(x=chosenIndex, y=idxCnt), stat="identity") + | |
facet_wrap(~ testRun) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment