library(StratTourn)
library(xtable)
library(ggplot2)
library(reshape2)
library(googleVis)
setwd("D:/libraries/StratTourn")


tourn = load.tournament("Tourn_Noisy_PD_20140721_202445.Rdata")
# Data for each match
md = tourn$dt
md = add.other.var(md,c("strat","u"))
md$delta.u = md$u - md$other.u
# Names of all strategies
strats = unique(md$strat)

# Data for each round
file = "D:/libraries/StratTourn/Tourn_Noisy_PD_20140721_202445_rs.csv"
rd = fread(file)
rd = as.tbl(as.data.frame(rd))
rd = add.other.var(rd,c("strat","u"))

rd = mutate(group_by(rd,match.id,i),
  choose.C = (a == "C")*1,
  choose.D = (a == "D")*1,
  other.D.prev = (obs.j == "D")*1,
  other.D.prev2 = is.true(obs.j == "D" & lag(obs.j) == "D")*1,
  other.d.dist75 = 0.75^distance.to.previous.event(other.D.prev),
  own.D.cum = cumsum(obs.i=="D"),
  other.D.cum = cumsum(obs.j=="D"),
  other.D.cum1 = (other.D.cum>=1)*1,
  other.D.cum2 = (other.D.cum>=2)*1,
  net.nice = other.D.cum - own.D.cum,
  net.nice1 = (net.nice>=1)*1,
  net.nice2 = (net.nice>=2)*1,
  error.D.i = lag(err.D.i, default=FALSE)*1,
  error.D.j = lag(err.D.j, default=FALSE)*1,
  error.D.i.cum = cumsum(error.D.i),
  error.D.j.cum = cumsum(error.D.j),
  num.err = error.D.i.cum+error.D.j.cum,
  diff.err = abs(error.D.i.cum-error.D.j.cum),
  error.D.i.once = (cumsum(error.D.i)>0)*1,
  error.D.j.once = (cumsum(error.D.j)>0)*1
)

# Names of all strategies
strats = unique(rd$strat)

# Perhaps select a subset of strategies
used.strats = strats
ard = rd

if (!identical(used.strats,strats)) {
  rows = rd$strat %in% used.strats & rd$other.strat %in% used.strats
  rd = ard[rows,]
}
max.time = 50
d = select(rd, match.id, strat, other.strat, t, i, u, other.u)
d$pair = paste0(d$strat," vs ", d$other.strat)

td = summarise(group_by(d, pair, t), strat1=strat[1], strat2=other.strat[1], u1=mean(u), u2 = mean(other.u))
td = as.data.frame(td)
td = filter(td, t<=max.time)
td = arrange(td, t, pair)
td$date = as.Date(paste0(td$t,"-01-01"))
p = gvisMotionChart(td, idvar = "pair", timevar = "date", xvar = "u1",
  yvar = "u2", colorvar = "strat1", sizevar = "", 
  options = list())

plot(p)


skranz/StratTourn documentation built on May 30, 2019, 2:02 a.m.