Skip to content

Commit

Permalink
Thesis: ES1
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncstanton committed Jul 27, 2023
0 parents commit 2b4193f
Show file tree
Hide file tree
Showing 101 changed files with 17,377 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__pycache__/
/results/
/R/plots/
/R/pdfs/
/R/data/
/R/scratch/
/R/.RData
/R/.Rhistory
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Simon C Stanton

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
130 changes: 130 additions & 0 deletions R/ch-4-graphs-NBS-summary_multi-model.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
---
title: "ch 4 graphs"
author: "Simon C Stanton"
date: "2023-06-09"
output: html_document

params:
exp_id: 478692
sj_id: all # all
game: "" # All RGS
tournament_set: "Final Round"
model: "Multi-Model"
model_type: "_multi" # "_single"
#reward_upper_bound_game: 20000 # game-theoretic
#mc_upper_bound_game: 5000 # game-theoretic
#reward_upper_bound_game: 64000 # binary bandit
#mc_upper_bound_game: 16000 # binary bandit
#reward_upper_bound_game: 52000 # foundational RL, 1k
#mc_upper_bound_game: 13000 # foundational RL, 1k

#reward_upper_bound_rgs: 2880000 # game-theoretic
#mc_upper_bound_rgs: 720000 # game-theoretic
#reward_upper_bound_rgs: 9216000 # binary bandit
#mc_upper_bound_rgs: 2304000 # binary bandit
#reward_upper_bound_rgs: 7488000 # foundational RL, 1k
#mc_upper_bound_rgs: 1872000 # foundational RL, 1k
#reward_upper_bound_rgs: 74880000 # foundational RL, 10k
#mc_upper_bound_rgs: 18720000 # foundational RL, 10k
reward_upper_bound_rgs: 6336000 # Tourney 4, 1k
mc_upper_bound_rgs: 1584000 # Tourney 4, 1k

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dplyr)
library(ggrepel)
library(ggpubr)
library(stringr)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
```

## R Markdown


```{r, import-data, echo=FALSE, include=FALSE}
path_to_data = "~/results/observations/tournament/"
view_path = "/view/ep_o/view_"
file_suffix_pre = "_sj_"
#file_suffix_post = "_model_g111_trial_NBS_summary.csv"
file_suffix_post = "_models_trials_NBS_summary_total-RGS.csv"
filename = paste(path_to_data, params$exp_id, view_path, params$exp_id, file_suffix_pre, params$sj_id, file_suffix_post, sep="")
filename
df_data <- read.csv(file= filename, header=TRUE, check.names=FALSE)
df_data$Agent <- as.factor(df_data$Agent)
summary(df_data)
```

## Alter data and plot

```{r plot, echo=FALSE}
min_max_norm <- function(y, x) {
(x - min(x)) / (y - min(x))
}
#df_data$Reward_scaled = min_max_norm(params$reward_upper_bound_rgs, df_data$Reward)
#df_data$MC_scaled = min_max_norm(params$mc_upper_bound_rgs, df_data$MC)
df_data$Reward_scaled = df_data$Reward / params$reward_upper_bound_rgs
df_data$MC_scaled = df_data$MC / params$mc_upper_bound_rgs
z <- df_data$Agent
z2 <- str_pad(z, width = max(str_width(z)+2), side="both")
options(repr.plot.width = 8, repr.plot.height =6)
ggplot(df_data, aes(x=MC_scaled, y=Reward_scaled)) +
geom_point(color = "black", size = 1) +
expand_limits(x=c(0,1), y=c(0,1)) +
scale_y_continuous(breaks = seq(0, 1, by = .1)) +
scale_x_continuous(breaks = seq(0, 1, by = .1)) +
theme_bw() +
theme(panel.grid.major = element_line(color = "lightgrey", linewidth = 0.2, linetype = 1),
panel.grid.minor = element_line(color = "lightgrey", linewidth = 0.2, linetype = 3)) +
labs(x="Mutual Cooperation") +
labs(y="Reward") +
theme(
axis.title.x = element_text(margin = margin(t = 11), size=10, hjust=0.5),
axis.title.y = element_text(margin = margin(r = 11), size=10),
) +
geom_label_repel(aes(label = z2),
force=500,
size = 2.5, # 3.5
label.padding = .28,
label.size = .2,
label.r = .25,
min.segment.length = unit(0, 'lines'),
segment.size=.18,
arrow = arrow(length = unit(0, "line"), type = "open"),
max.overlaps = Inf,
nudge_x=0.5,
nudge_y=0.09,
) +
stat_cor(method="pearson", label.x = .845, label.y = 0, size=3) +
labs(title = paste(params$model, "Tournament Summary"),
subtitle = paste(params$tournament_set, "Algorithm Performance")
) +
theme(plot.title = element_text(hjust = 0.5, size = 12), # Center title position and size
plot.subtitle = element_text(hjust = 0.5, size=10), # Center subtitle
) +
annotate("text", x = 0.12, y = 0, label = paste("Model: ", params$game, " Exp_ID: ", params$exp_id, " 1k", sep=""), cex=3)
ggsave(path=".", filename=paste(params$exp_id, params$model_type, "-model-reward-mc.png", sep=""), bg='white', width=8, height=6 )
cor.test(df_data$MC_scaled, df_data$Reward_scaled)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
136 changes: 136 additions & 0 deletions R/ch-4-graphs-NBS-summary_single-model-Matches.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: "ch 4 graphs"
author: "Simon C Stanton"
date: "2023-06-09"
output: html_document

params:
exp_id: 398741
sj_id: 0 # all
game: "g111" # All RGS
tournament_set: "Final Round"
model: "Single-Model"
model_type: "_single" #
reward_upper_bound_game: 4000 # game-theoretic
mc_upper_bound_game: 1000 # game-theoretic
#reward_upper_bound_game: 64000 # binary bandit
#mc_upper_bound_game: 16000 # binary bandit
#reward_upper_bound_game: 52000 # foundational RL, 1k
#mc_upper_bound_game: 13000 # foundational RL, 1k
#reward_upper_bound_game: 520000 # foundational RL, 10k
#mc_upper_bound_game: 130000 # foundational RL, 10k
reward_upper_bound_rgs: 6336000 # Tourney 4, 1k
mc_upper_bound_rgs: 1584000 # Tourney 4, 1k

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(dplyr)
library(ggrepel)
library(ggpubr)
library(stringr)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
```

## R Markdown


```{r, import-data, echo=FALSE, include=FALSE}
path_to_data = "~/results/observations/tournament/"
view_path = "/view/ep_o/view_"
file_suffix_pre = "_sj_"
file_suffix_post = "_model_g111_trial_NBS.csv"
filename = paste(path_to_data, params$exp_id, view_path, params$exp_id, file_suffix_pre, params$sj_id, file_suffix_post, sep="")
filename
df_data <- read.csv(file= filename, header=TRUE, check.names=FALSE)
#df_data$Agent <- as.factor(df_data$Agent)
summary(df_data)
```

## Alter data and plot

```{r plot, echo=FALSE}
df_data$A0_Reward_proportion = df_data$R0 / params$reward_upper_bound_game
df_data$A1_Reward_proportion = df_data$R1 / params$reward_upper_bound_game
df_data$MC_proportion = df_data$MC / params$mc_upper_bound_game
z0 <- df_data$A0
z1 <- df_data$A1
df_data$z2 <- paste(z0, "&", z1) #str_pad(z, width = max(str_width(z)+2), side="both")
df_data$z2
df_data
```




```{r plot, echo=FALSE}
options(repr.plot.width = 8, repr.plot.height =6)
ggplot(df_data, aes(x=A0_Reward_proportion, y=A1_Reward_proportion, color=MC_proportion)) +
geom_point(color = "black", shape=1, aes(size=MC_proportion)) +
expand_limits(x=c(0,1), y=c(0,1)) +
scale_y_continuous(breaks = seq(0, 1, by = .25)) +
scale_x_continuous(breaks = seq(0, 1, by = .25)) +
theme_bw() +
theme(panel.grid.major = element_line(color = "lightgrey", linewidth = 0.2, linetype = 1),
panel.grid.minor = element_line(color = "lightgrey", linewidth = 0.2, linetype = 3)) +
labs(x="Agent Zero TR") +
labs(y="Agent One TR") +
theme(
axis.title.x = element_text(margin = margin(t = 11), size=10, hjust=0.5),
axis.title.y = element_text(margin = margin(r = 11), size=10),
) +
geom_label_repel(aes(label = z2),
size = 2.5, # 3.5
label.padding = .28,
label.size = .2,
label.r = .25,
min.segment.length = unit(0, 'lines'),
segment.size=.18,
arrow = arrow(length = unit(0, "line"), type = "open"),
max.overlaps = Inf,
nudge_x=-0.099,
nudge_y=0.014,
force=10
) +
labs(title = paste(params$model, "Tournament Summary"),
subtitle = paste(params$tournament_set, "Match Pairings"),
color="MC"
) +
theme(plot.title = element_text(hjust = 0.5, size = 12), # Center title position and size
plot.subtitle = element_text(hjust = 0.5, size=10), # Center subtitle
) +
guides(color = FALSE) +
guides(size=guide_legend(title="MC")) +
theme(legend.title.align=0.5) +
annotate("text", x = 0.12, y = 0, label = paste("Model: ", params$game, " Exp_ID: ", params$exp_id, " 1k", sep=""), cex=3)
#+
#scale_fill_discrete(name = "New Legend Title") #
ggsave(path=".", filename=paste(params$exp_id, params$model_type, "-model", "_sj_", params$sj_id, "_", params$game, "_match-pairings.png", sep=""), bg='white', width=8, height=6 )
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.



Loading

0 comments on commit 2b4193f

Please sign in to comment.