This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
plots.Rmd
516 lines (408 loc) · 21.9 KB
/
plots.Rmd
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
---
title: "plots"
author: "K. Enevoldsen & P. Waade"
date: "12/10/2018"
output: html_document
editor_options:
chunk_output_type: console
---
#Setup
```{r setup, include=FALSE}
# !diagnostics off
#^the above argument prevents the mulitple 'unknown column' warnings (harmless warnings)
knitr::opts_chunk$set(echo = TRUE)
#devtools::install_github("thomasp85/patchwork")
pacman::p_load(pacman, plyr, tidyverse, raster, reshape2, knitr, brms, boot, rethinking, groupdata2, patchwork, RColorBrewer, Hmisc)
p_load(gmodels)
```
#add ID
```{r add_ID}
add_ID <- function(result_df, add_op = F){
#DESCRIPTION
#INPUT
#OUTPUT
n_rounds <- max(result_df$round_nr)
n_players <- nrow(result_df)/n_rounds
result_df$ID <- as.numeric( #as. numeric since sapply returns a matrix
sapply(seq(1, n_players, by = 2), #creating a list of the first agent in each pair (jumping by two since it is a pair)
function(x) rep(c(x, x+1), n_rounds))) #creating ID for each pair equal to x and x+1 and repeating for each round
if (add_op){
result_df$op <- sapply(seq(nrow(result_df)),
function(x)
str_split(result_df$pair[x], " / ")[[1]][str_split(result_df$pair[x], " / ")[[1]] != result_df$player[x]])
}
return(result_df)
}
```
#heatmap
```{r heatmap}
#create a compete matrix
quick_heatmap <- function(result_df, return_plot_df = F){
#DESCRIPTION
#INPUT
#OUTPUT
tmp_list <- NULL; i = 1
for (c_pair in unique(result_df$pair)){ #loop through all the pairs
p_subset <- subset(result_df, pair == c_pair)
#Player 1
player <- p_subset$player[1]
op <- p_subset$player[2]
points <- sum(p_subset$points[seq(1, nrow(p_subset), by = 2)]) #calculate points
tmp_list[[i]] <- data_frame(player = player, op = op, points = points) #save the variables
#Player 2
player <- p_subset$player[2]
op <- p_subset$player[1]
points <- sum(p_subset$points[seq(2, nrow(p_subset), by = 2)]) #calculate points
tmp_list[[i+1]] <- data_frame(player = player, op = op, points = points) #save the variables
i = i + 2
}
i
tmp_df <- tmp_list %>% bind_rows() #save the variables
unique(tmp_df$player)
p <- ggplot(tmp_df, aes(player, op)) +
geom_tile(aes(fill = points), colour = "white") +
scale_fill_gradient(name = "Points", low = "lightsteelblue1", high = "steelblue") +
theme_classic() + labs(x = "Player 1", y = "Player 2")
if (return_plot_df){
return(list(plot = p, plot_df = tmp_df))
} else{
return(p)
}
}
```
#P(k) plot
```{r quick_p_k_plot}
quick_p_k_plot <- function(result_df, ID, blue = T){
p_k_v <- c()
hidden_states <- result_df$hidden_states[result_df$ID == ID]
for (i in 1:length(hidden_states)){
p_k_v <- c(p_k_v, hidden_states[[i]]$own_hidden_states$p_k)
}
level <- length(p_k_v)/length(hidden_states)
plot_df <- data_frame(round = seq(length(hidden_states)))
for (i in 1:level){
plot_df[,i+1] <- p_k_v[seq(i, length(p_k_v), by= level)]
colnames(plot_df)[i+1] <- paste("P(", i-1, ")", sep = "")
}
plot_df1 <- melt(plot_df , id.vars = 'round', variable.name = "level")
p <- ggplot(plot_df1, aes(round, value, color = level)) + geom_line() + labs(x = "Round", y = "P(k)") + guides(color=guide_legend(title=" "))
if (blue){ #add color palette
p <- p + scale_color_brewer(palette="Blues", direction = -1) + theme_linedraw()
}
return(p)
}
```
#p_k again (repeated simulations)
```{r}
#repeated sims.
p_k_rep_sim <- function(d, agent, examined_level = "\\d"){
#examined level can be regex - i.e "\\d" gets all levels
d <- subset(d, player == agent)
tmp <- lapply(d$hidden_states, function(x) as_tibble(t(c(x$own_hidden_states$p_k)))) %>% bind_rows()
colnames(tmp) <- paste("P(",(seq(length(colnames(tmp)))-1), ")", sep = "")
d <- bind_cols(d, tmp)
d <- dplyr::select(d, round_nr, sim, colnames(tmp))
dp <- reshape2::melt(d, id.vars = c("round_nr", "sim"),value.name = "prop" )
dp <- filter(dp, grepl(examined_level, variable)) #remove everything beside the chosen values
dp <- dp %>% group_by(round_nr, variable) %>% mutate(mean_p = mean(prop)) %>% merge(., dp)
ggplot(dp, aes(round_nr, prop)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) + geom_line(aes(round_nr, mean_p), size = 0.3) + labs(x = "Round", y = "P(k)") + theme_light() + facet_wrap(~variable)
}
```
#Win % plot
```{r quick_pwon_plot}
quick_pwon_plot <- function(d, agent){
d <- dplyr::select(d, -c(hidden_states))
#create a commulative sum and percentage won
d <- d %>%
group_by(sim, player) %>%
mutate(cumsum = cumsum(points), p_won = ((round_nr + cumsum(points))/2)/round_nr)
dp <- subset(d, player == agent)
dp <- dp %>% group_by(round_nr) %>% summarise(m_p_won = mean(p_won)) %>% merge(., dp)
ggplot(dp, aes(round_nr, p_won)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, m_p_won), size = 0.3) + labs(x = "Round", y = "Win %") + theme_linedraw() + geom_hline(yintercept = 0.5, color = "firebrick") + coord_cartesian(ylim = c(0.3, 0.8))
}
```
#0-ToM plot
```{r}
#fixing sim
oToM_plot <- function(d){
d <- subset(d1, player == "0-ToM")
d$mean_p <- sapply(d$hidden_states, function(x) x$own_hidden_states$mean_basic)
d$variance <- sapply(d$hidden_states, function(x) x$own_hidden_states$variance_basic)
dp <- d %>%
group_by(round_nr) %>%
summarise(m_m = mean(inv.logit(mean_p)), m_v = mean(exp(variance)) ) %>%
merge(., d) %>%
mutate(mean_p = inv.logit(mean_p), variance = exp(variance))
#mean
p_mean <- ggplot(dp, aes(round_nr, mean_p)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue",
fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, m_m)) + theme_light() +
labs(title = "", y = "Mean for probability estimation", x = "Round")
#variance
p_var <- ggplot(dp, aes(round_nr, variance)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue",
fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, m_v)) + theme_light() +
labs(title = "", y = "Variance for probability estimation", x = "Round")
return(list(p_mean, p_var))
}
```
#plotting all the things
```{r}
load(file = "result_df_1.rda")
d <- result_df
load(file = "result_df_2.rda")
result_df$sim <- result_df$sim + 25
d <- rbind(d, result_df)
load(file = "result_df_3.rda")
result_df$sim <- result_df$sim + 50
d <- rbind(d, result_df)
load(file = "result_df_4.rda")
result_df$sim <- result_df$sim + 75
d <- rbind(d, result_df)
rm(result_df)
unique(d$sim)
sump <- d %>% group_by(sim, pair, player) %>% summarise(points = sum(points), total_rounds = n())
#the following command extract the op from the pair by only choosing the agent in the pair which is not the agent (notice that the result are transposed so that the op. is in the same order as players)
sump$op <- t(str_split(sump$pair, pattern = " / ", simplify = T))[t(str_split(sump$pair, pattern = " / ", simplify = T) != sump$player)]
p_df <- sump %>% mutate(p_won = ((total_rounds + points)/2)/total_rounds) %>% group_by(pair, player, op) %>% summarise(mean_pwon = mean(p_won), sd_p_won = sd(p_won), ci_lower = ci(p_won)[2], ci_upper = ci(p_won)[3])
#all
heat1_all <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
p_df <- p_df %>% filter(!(player %in% c("WSLS", "RB")) & !(op %in% c("WSLS", "RB")))
#ToM's
heat2_all <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
#doing it with only 30 trials
sump <- d %>% filter(round_nr < 31) %>% group_by(sim, pair, player) %>% summarise(points = sum(points), total_rounds = n())
sump$op <- t(str_split(sump$pair, pattern = " / ", simplify = T))[t(str_split(sump$pair, pattern = " / ", simplify = T) != sump$player)]
head(d)
p_df <- sump %>% mutate(p_won = ((total_rounds + points)/2)/total_rounds) %>% group_by(pair, player, op) %>% summarise(mean_pwon = mean(p_won), sd_p_won = sd(p_won), ci_lower = ci(p_won)[2], ci_upper = ci(p_won)[3], n = n())
#with only 30 trials
heat1_30 <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
p_df <- p_df %>% filter(!(player %in% c("WSLS", "RB")) & !(op %in% c("WSLS", "RB")))
#with only 30 trials - ToMs
heat2_30 <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
unique(d$pair)
d1 <- filter(d, pair == "0-ToM / 1-ToM")
pwon1v0 <- quick_pwon_plot(d = d1, agent = "1-ToM")
d1 <- filter(d, pair == "1-ToM / 2-ToM")
pwon2v1 <- quick_pwon_plot(d = d1, agent = "2-ToM")
d1 <- filter(d, pair == "2-ToM / 4-ToM")
pwon4v2 <- quick_pwon_plot(d = d1, agent = "4-ToM")
d1 <- filter(d, pair == "4-ToM / 5-ToM")
pwon5v4 <- quick_pwon_plot(d = d1, agent = "5-ToM")
d1 <- filter(d, pair == "RB / 0-ToM")
plots <- oToM_plot(d = d1)
otom_mean <- plots[[1]]
otom_var <- plots[[2]]
d1 <- filter(d, pair == "0-ToM / 1-ToM")
plots <- oToM_plot(d = d1)
otom_mean_v1 <- plots[[1]]
otom_var_v1 <- plots[[2]]
d1 <- filter(d, pair == "1-ToM / 2-ToM")
p_k2v1 <- p_k_rep_sim(d = d1, agent = "2-ToM")
d1 <- filter(d, pair == "2-ToM / 5-ToM")
p_k5v2 <- p_k_rep_sim(d = d1, agent = "5-ToM")
d1 <- filter(d, pair == "2-ToM / 3-ToM")
p_k3v2 <- p_k_rep_sim(d = d1, agent = "3-ToM")
d1 <- filter(d, pair == "0-ToM / 2-ToM")
p_k2v0 <- p_k_rep_sim(d = d1, agent = "2-ToM")
d1 <- filter(d, pair == "0-ToM / 3-ToM")
p_k3v0 <- p_k_rep_sim(d = d1, agent = "3-ToM")
#all all the plots
plot_list <- c("heat1_all", "heat2_all","heat1_30", "heat2_30", "pwon1v0", "pwon2v1", "pwon4v2", "pwon5v4", "otom_mean", "otom_var", "p_k2v1", "p_k5v2", "p_k3v2")
plot_list <- c("heat1_all", "heat2_30")
plot_list <- c("p_k2v0", "p_k3v0")
i = "heat1_all"
for (i in plot_list){
assign("tmpplot", eval(parse(text = i)))
filename <- paste(i, ".png", sep = "")
if (i == "p_k5v2"){
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 30, height = 20, units = "cm")
} else if (grepl("heat",i)){
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 30, height = 30, units = "cm")
} else {
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 20, height = 20, units = "cm")
}
}
```
#extracting parameters
```{r}
d1 <- d %>% filter(pair == "4-ToM / 5-ToM", player == "4-ToM")
tmp <- lapply(d1$hidden_states, function(x) as_tibble(t(c( x$own_hidden_states$param_mean)))) %>% bind_rows()
colnames(tmp) <- paste("mean_", seq(2), sep = "")
d1 <- bind_cols(d1, tmp)
d1 <- d1 %>% group_by(round_nr) %>% summarise(mean_1_m = mean(mean_1), mean_2_m = mean(mean_2)) %>% merge(.,d1)
mu_1_2v1 <- ggplot(d1, aes(round_nr, mean_1)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_1_m), size = 0.3) + theme_light() + labs(x= "Trial", y = "Volatility estimate")
mu_2_2v1 <- ggplot(d1, aes(round_nr, mean_2)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_2_m), size = 0.3)+ theme_light() + labs(x= "Trial", y = "Tempature estimate")
ggsave(filename = "mu_1_2v1.png", plot = mu_1_2v1, path = "plots", width = 20, height = 20, units = "cm")
ggsave(filename = "mu_2_2v1.png", plot = mu_2_2v1, path = "plots", width = 20, height = 20, units = "cm")
d1 <- d %>% filter(pair == "0-ToM / 1-ToM", player == "1-ToM")
tmp <- lapply(d1$hidden_states, function(x) as_tibble(t(c( x$own_hidden_states$param_mean)))) %>% bind_rows()
colnames(tmp) <- paste("mean_", seq(2), sep = "")
d1 <- bind_cols(d1, tmp)
d1 <- d1 %>% group_by(round_nr) %>% summarise(mean_1_m = mean(mean_1), mean_2_m = mean(mean_2)) %>% merge(.,d1)
mu_1_1v0 <- ggplot(d1, aes(round_nr, mean_1)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_1_m), size = 0.3) + theme_light() + labs(x= "Trial", y = "Volatility estimate")
mu_2_1v0 <- ggplot(d1, aes(round_nr, mean_2)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_2_m), size = 0.3)+ theme_light() + labs(x= "Trial", y = "Tempature estimate")
ggsave(filename = "mu_1_1v0.png", plot = mu_1_1v0, path = "plots", width = 20, height = 20, units = "cm")
ggsave(filename = "mu_2_1v0.png", plot = mu_2_1v0, path = "plots", width = 20, height = 20, units = "cm")
```
#plotting all the things - Accurate priors
```{r}
load(file = "result_df_selfsim_1.rda")
d <- result_df
load(file = "result_df_selfsim_2.rda")
result_df$sim <- result_df$sim + 25
d <- rbind(d, result_df)
sump <- d %>% group_by(sim, pair, player) %>% summarise(points = sum(points), total_rounds = n())
#the following command extract the op from the pair by only choosing the agent in the pair which is not the agent (notice that the result are transposed so that the op. is in the same order as players)
sump$op <- t(str_split(sump$pair, pattern = " / ", simplify = T))[t(str_split(sump$pair, pattern = " / ", simplify = T) != sump$player)]
p_df <- sump %>% mutate(p_won = ((total_rounds + points)/2)/total_rounds) %>% group_by(pair, player, op) %>% summarise(mean_pwon = mean(p_won), sd_p_won = sd(p_won), ci_lower = ci(p_won)[2], ci_upper = ci(p_won)[3])
# #all
# heat1_all <- ggplot(p_df, aes(player, op)) +
# geom_tile(aes(fill = mean_pwon), colour = "white") +
# scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
# geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
# theme_classic() + labs(x = "Player 1", y = "Player 2")
#
# p_df <- p_df %>% filter(!(player %in% c("WSLS", "RB")) & !(op %in% c("WSLS", "RB")))
#
# #ToM's
# heat2_all <- ggplot(p_df, aes(player, op)) +
# geom_tile(aes(fill = mean_pwon), colour = "white") +
# scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
# geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
# theme_classic() + labs(x = "Player 1", y = "Player 2")
#
#doing it with only 30 trials
sump <- d %>% filter(round_nr < 31) %>% group_by(sim, pair, player) %>% summarise(points = sum(points), total_rounds = n())
sump$op <- t(str_split(sump$pair, pattern = " / ", simplify = T))[t(str_split(sump$pair, pattern = " / ", simplify = T) != sump$player)]
p_df <- sump %>% mutate(p_won = ((total_rounds + points)/2)/total_rounds) %>% group_by(pair, player, op) %>% summarise(mean_pwon = mean(p_won), sd_p_won = sd(p_won), ci_lower = ci(p_won)[2], ci_upper = ci(p_won)[3])
#with only 30 trials
heat1_30 <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
p_df <- p_df %>% filter(!(player %in% c("WSLS", "RB")) & !(op %in% c("WSLS", "RB")))
#with only 30 trials - ToMs
heat2_30 <- ggplot(p_df, aes(player, op)) +
geom_tile(aes(fill = mean_pwon), colour = "white") +
scale_fill_gradient(name = "Win %", low = "lightsteelblue1", high = "steelblue") +
geom_text(aes(label = paste(round(mean_pwon, 2)," (", round(ci_lower, 2), ", ", round(ci_upper, 2), ")", sep = "") )) +
theme_classic() + labs(x = "Player 1", y = "Player 2")
#
# unique(d$pair)
# d1 <- filter(d, pair == "0-ToM / 1-ToM")
# pwon1v0 <- quick_pwon_plot(d = d1, agent = "1-ToM")
# d1 <- filter(d, pair == "1-ToM / 2-ToM")
# pwon2v1 <- quick_pwon_plot(d = d1, agent = "2-ToM")
# d1 <- filter(d, pair == "2-ToM / 4-ToM")
# pwon4v2 <- quick_pwon_plot(d = d1, agent = "4-ToM")
# d1 <- filter(d, pair == "4-ToM / 5-ToM")
# pwon5v4 <- quick_pwon_plot(d = d1, agent = "5-ToM")
# d1 <- filter(d, pair == "RB / 0-ToM")
# plots <- oToM_plot(d = d1)
# otom_mean <- plots[[1]]
# otom_var <- plots[[2]]
#
# d1 <- filter(d, pair == "1-ToM / 2-ToM")
# p_k2v1 <- p_k_rep_sim(d = d1, agent = "2-ToM")
#
# d1 <- filter(d, pair == "2-ToM / 5-ToM")
# p_k5v2 <- p_k_rep_sim(d = d1, agent = "5-ToM")
#
# d1 <- filter(d, pair == "2-ToM / 3-ToM")
# p_k3v2 <- p_k_rep_sim(d = d1, agent = "3-ToM")
#all all the plots
plot_list <- c("heat1_all", "heat2_all","heat1_30", "heat2_30", "pwon1v0", "pwon2v1", "pwon4v2", "pwon5v4", "otom_mean", "otom_var", "p_k2v1", "p_k5v2", "p_k3v2")
plot_list <- c("heat1_30", "heat2_30")
for (i in plot_list){
assign("tmpplot", eval(parse(text = i)))
filename <- paste(i, "selfsim.png", sep = "")
if (i == "p_k5v2"){
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 30, height = 20, units = "cm")
} else if (grepl("heat",i)){
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 30, height = 30, units = "cm")
} else {
ggsave(filename = filename, plot = tmpplot, path = "plots", width = 20, height = 20, units = "cm")
}
}
```
#extracting parameters - selfim
```{r}
d1 <- d %>% filter(pair == "0-ToM / 1-ToM", player == "1-ToM")
tmp <- lapply(d1$hidden_states, function(x) as_tibble(t(c( x$own_hidden_states$param_mean)))) %>% bind_rows()
colnames(tmp) <- paste("mean_", seq(2), sep = "")
d1 <- bind_cols(d1, tmp)
d1 <- d1 %>% group_by(round_nr) %>% summarise(mean_1_m = mean(mean_1), mean_2_m = mean(mean_2)) %>% merge(.,d1)
mu_1_1v0_selfsim = ggplot(d1, aes(round_nr, mean_1)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_1_m), size = 0.3) + theme_light() + labs(x="Trial", y="Volatility estimate")
mu_2_1v0_selfsim = ggplot(d1, aes(round_nr, mean_2)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_2_m), size = 0.3) + theme_light() + labs(x="Trial", y="Temperature estimate")
d1 <- d %>% filter(pair == "1-ToM / 2-ToM", player == "2-ToM")
tmp <- lapply(d1$hidden_states, function(x) as_tibble(t(c( x$own_hidden_states$param_mean)))) %>% bind_rows()
colnames(tmp) <- paste("mean_", seq(2), sep = "")
d1 <- bind_cols(d1, tmp)
d1 <- d1 %>% group_by(round_nr) %>% summarise(mean_1_m = mean(mean_1), mean_2_m = mean(mean_2)) %>% merge(.,d1)
mu_1_2v1_selfsim = ggplot(d1, aes(round_nr, mean_1)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_1_m), size = 0.3) + theme_light() + labs(x="Trial", y="Volatility estimate")
mu_2_2v1_selfsim = ggplot(d1, aes(round_nr, mean_2)) +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.25, fill = "steelblue") +
stat_summary(fun.data=mean_cl_boot, geom="ribbon", alpha = 0.30, fill = "steelblue", fun.args = list(conf.int = .5)) +
geom_line(aes(round_nr, mean_2_m), size = 0.3) + theme_light() + labs(x="Trial", y="Temperature estimate")
ggsave(filename = "mu_1_1v0_selfsim.png", plot = mu_1_1v0_selfsim, path = "plots", width = 20, height = 20, units = "cm")
ggsave(filename = "mu_2_1v0_selfsim.png", plot = mu_2_1v0_selfsim, path = "plots", width = 20, height = 20, units = "cm")
ggsave(filename = "mu_1_2v1_selfsim.png", plot = mu_1_1v0_selfsim, path = "plots", width = 20, height = 20, units = "cm")
ggsave(filename = "mu_2_2v1_selfsim.png", plot = mu_2_1v0_selfsim, path = "plots", width = 20, height = 20, units = "cm")
```
```{r}
tmpplot <- quick_pwon_plot(result_df, agent = "0-ToM")
ggsave(filename = "RBvotom_lowB.png", plot = tmpplot, path = "plots", width = 20, height = 20, units = "cm")
d_save <- d
beepr::beep(5)
```
# tjek SD på heatmap
#lav heatmap om til percentage won
#omregn på prop på 0 tom'en