Created
June 2, 2015 00:27
-
-
Save rasmusab/5475efcab3c9b0708d38 to your computer and use it in GitHub Desktop.
Creates some plots from the model fits created by this script: https://gist.github.com/rasmusab/b29bb53cfc3fe25f3f80
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(ggplot2) | |
library(plyr) | |
n_games <- readRDS("n_games.Rdata") | |
n_positions <- readRDS("n_positions.Rdata") | |
fullmoves_white <- readRDS("fullmoves_white.Rdata") | |
fits <- readRDS("chess_fits.Rdata") | |
fit <- fits$fit | |
fit <- fit | |
fit_bishop <- fits$fit_bishops | |
fit_over_moves <- fits$fit_over_moves | |
fit_df <- data.frame(name = c("White's Advantage", "Pawn", "Knight", "Bishop", "Rook", "Queen"), | |
value = fit, | |
image = c("☆","♟", "♞", "♝","♜","♛")) | |
fit_df$name <- factor(fit_df$name, levels = as.character(fit_df$name[order(fit_df$value)])) | |
fit_bishop_df <- data.frame( | |
name = c("White's Advantage", "Pawn", "Knight", "Bishop", "Bishop pair","Rook", "Queen"), | |
value = fit_bishop, | |
image = c("☆","♟", "♞", "♝", "♝♥♝","♜","♛")) | |
fit_bishop_df$name <- factor(fit_bishop_df$name, | |
levels = as.character(fit_bishop_df$name[order(fit_bishop_df$value)])) | |
fit_over_moves_df <- ldply(seq_len(length(fit_over_moves)), function(i) { | |
data.frame( | |
name = c("White's Advantage", "Pawn", "Knight", "Bishop", "Bishop pair","Rook", "Queen"), | |
value = fit_over_moves[[i]], | |
image = c("☆","♟", "♞", "♝", "♝♥♝","♜","♛"), | |
moves = paste((i - 1) * 10, "-", i * 10)) | |
}) | |
fit_over_moves_df$name <- factor(fit_over_moves_df$name, | |
levels = c("White's Advantage", "Pawn", "Knight", "Bishop", "Bishop pair","Rook", "Queen")) | |
fit_over_moves_df_rel_pawn <- ldply(seq_len(length(fit_over_moves)), function(i) { | |
data.frame( | |
name = c("White's Advantage", "Pawn", "Knight", "Bishop", "Bishop pair","Rook", "Queen"), | |
value = fit_over_moves[[i]] / fit_over_moves[[i]][2], | |
image = c("☆","♟", "♞", "♝", "♝♥♝","♜","♛"), | |
moves = paste((i - 1) * 10, "-", i * 10)) | |
}) | |
fit_over_moves_df_rel_pawn$name <- factor(fit_over_moves_df_rel_pawn$name, | |
levels = c("White's Advantage", "Pawn", "Knight", "Bishop", "Bishop pair","Rook", "Queen")) | |
qplot(name, value, data = fit_df, geom=c("text"), label = image, | |
main = "Predictive piece value (in log-odds)", | |
size = I(10), ylim=c(0, NA), xlab="", ylab='Piece "value"') + coord_flip() | |
qplot(name, value / fit_df$value[fit_df$name == "Pawn"], data = fit_df, geom=c("text"), label = image, | |
main = "Predictive piece value with pawn fixed to 1.0", | |
size = I(10), ylim=c(0, NA), xlab="", ylab='Piece "value"') + coord_flip() | |
qplot(name, value / fit_bishop_df$value[fit_bishop_df$name == "Pawn"], data = fit_bishop_df, geom=c("text"), label = image, | |
main = "Predictive piece value including bishop pair", | |
size = I(10), ylim=c(0, NA), xlab="", ylab='Piece "value"') + coord_flip() | |
qplot(name, value / fit_bishop_df$value[fit_bishop_df$name == "Knight"] * 3, | |
data = fit_bishop_df, geom=c("text"), label = image, | |
main = "Predictive piece value with knight fixed to 3.0", | |
size = I(10), xlab="", ylab='Piece "value"') + | |
coord_flip() + scale_y_continuous(breaks = c(0, 1, 3, 5, 9), limits = c(0, 9)) | |
old_par <- par(mar = c(4.2, 3.5, 2.5, 0.5)) | |
hist(fullmoves_white, col = "darkgreen", border = "darkgreen", | |
breaks = 0:101, yaxt = "n", ylab = "", main = "% of games playing after x full moves", xlab = "No. full moves") | |
axis(2, seq(0, n_games, length.out = 6), labels = paste0(seq(0, 100, 20), "%"), las = 1) | |
par(old_par) | |
qplot(moves, value, size = I(6),geom=c("text"), label=image, group = name, color = name, ylab = "Piece value (in log-odds)", | |
main = "Predictive piece value as the game progresses", xlab = "Full moves",data=fit_over_moves_df) + | |
geom_line(linewidth = 1) + theme(legend.position="none") | |
qplot(name, value , color = name,data = fit_over_moves_df[ fit_over_moves_df$moves == "0 - 10",], geom=c("text"), label = image, | |
main = "Predictive piece value moves 1-10 (in log-odds)", | |
size = I(10), ylim=c(-0.28, 0.28), xlab="", ylab='Piece "value"') + coord_flip() + theme(legend.position="none") | |
qplot(moves, value,size = I(6),geom=c("text"), label=image, group = name, color = name, ylab = "Piece value relative to pawn", xlab = "Full moves", main = "Predictive piece value as the game progresses", | |
data=fit_over_moves_df_rel_pawn[ fit_over_moves_df_rel_pawn$moves != "0 - 10",]) + geom_line(linewidth = 1) + theme(legend.position="none") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment