-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotLearning.jl
More file actions
143 lines (125 loc) · 5.09 KB
/
Copy pathplotLearning.jl
File metadata and controls
143 lines (125 loc) · 5.09 KB
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
# Generates figures summarizing performance collected by simLearning.
#
# Call the script as
#
# plotLearning.jl configfile model N [α]
#
# where conf/configfile.ini is the configuation file, model is the learning model,
# and N is the input dimensionality. α is the optional learning rate (only required
# for certain models). To function generates the figure and writes it to
#
# figs/learning_configfile_model_N.pdf
import Cairo, Fontconfig
using StatsBase, Gadfly
include("common.jl")
include("models.jl")
# plot settings
const meantheme = Theme(default_color="black")
const t = Theme()
const uppctl = 0.75
const lopctl = 0.25
# parse command line arguments
function parseargs()
length(ARGS) ∈ (3, 4) || error("Expected three or four parameters")
conffile = ARGS[1]
modelname = ARGS[2]
N = parse(Int64, ARGS[3])
α = length(ARGS) > 3 ? parse(Float64, ARGS[4]) : nothing
return conffile, modelname, N, α
end
function readconf(conffile)
conf = ConfParse("conf/$(conffile).ini")
parse_conf!(conf)
task = createtask(conf)
return task
end
conffile, modelname, N, α = parseargs()
if requiresα(modelname) && α == nothing
error("Model $(modelname) requires learning rate parameter")
end
task = readconf(conffile)
maxperf = taskmaxperf(task)
randperf = taskrandperf(task)
const basefilename = requiresα(modelname) ?
"learning_$(conffile)_$(modelname)_$(N)_$(@sprintf("%.2f", α))" :
"learning_$(conffile)_$(modelname)_$(N)"
# read and process data
datafile = "data/$(basefilename)"
df = readcompressedtable(datafile)
println("Computing statistics")
df[:corr] = df[:choice] .== Int64.(sign.(df[:μ]))
df[:Ifrac] = df[:modelI] ./ df[:trueI]
df[:relperf] = (df[:Eperf] .- randperf) / (maxperf-randperf)
dftrials = by(df, :trial,
df -> DataFrame(
pc = mean(df[:corr]),
t = mean(df[:t]),
tmed = quantile(df[:t], 0.5),
tup = quantile(df[:t], uppctl),
tlo = quantile(df[:t], lopctl),
perf = (taskperf(task, mean(df[:corr]), mean(df[:t])) .- randperf) / (maxperf-randperf),
avgpc = mean(df[:EPC]),
avgpcmed = quantile(df[:EPC], 0.5),
avgpcup = quantile(df[:EPC], uppctl),
avgpclo = quantile(df[:EPC], lopctl),
avgt = mean(df[:EDT]),
avgtmed = quantile(df[:EDT], 0.5),
avgtup = quantile(df[:EDT], uppctl),
avgtlo = quantile(df[:EDT], lopctl),
avgperf = mean(df[:relperf]),
avgperfmed = quantile(df[:relperf], 0.5),
avgperfup = quantile(df[:relperf], uppctl),
avgperflo = quantile(df[:relperf], lopctl),
Ifrac = mean(df[:Ifrac]),
Ifracmed = quantile(df[:Ifrac], 0.5),
Ifracup = quantile(df[:Ifrac], uppctl),
Ifraclo = quantile(df[:Ifrac], lopctl),
angerr = mean(df[:angerr]),
angerrmed = quantile(df[:angerr], 0.5),
angerrup = quantile(df[:angerr], uppctl),
angerrlo = quantile(df[:angerr], lopctl),
))
# plot results
println("Generating plots")
ppc = plot(dftrials, x="trial", y="pc", Geom.line,
Guide.xlabel("trial"), Guide.ylabel("p(corr)"),
Coord.cartesian(ymin=0.4, ymax=1), meantheme)
pepc = plot(dftrials,
layer(x="trial", y="avgpc", Geom.line, meantheme),
layer(x="trial", y="avgpcmed", ymin="avgpclo", ymax="avgpcup",
Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("<p(corr)>"),
Coord.cartesian(ymin=0.4, ymax=1), t)
pdt = plot(dftrials,
layer(x="trial", y="t", Geom.line, meantheme),
layer(x="trial", y="tmed", ymin="tlo", ymax="tup", Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("dt"), Coord.cartesian(ymin=0), t)
pedt = plot(dftrials,
layer(x="trial", y="avgt", Geom.line, meantheme),
layer(x="trial", y="avgtmed", ymin="avgtlo", ymax="avgtup",
Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("<dt>"), Coord.cartesian(ymin=0), t)
pperf = plot(dftrials, x="trial", y="perf", Geom.line,
Guide.xlabel("trial"), Guide.ylabel("frac rew rate"),
Coord.cartesian(ymin=0.0, ymax=1.1), meantheme)
peperf = plot(dftrials,
layer(x="trial", y="avgperf", Geom.line, meantheme),
layer(x="trial", y="avgperfmed", ymin="avgperflo", ymax="avgperfup",
Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("<frac rew rate>"),
Coord.cartesian(ymin=0.0, ymax=1.1), t)
pangerr = plot(dftrials,
layer(x="trial", y="angerr", Geom.line, meantheme),
layer(x="trial", y="angerrmed", ymin="angerrlo", ymax="angerrup",
Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("angular error"), Coord.cartesian(ymin=0.0), t)
pIfrac = plot(dftrials,
layer(x="trial", y="Ifrac", Geom.line, meantheme),
layer(x="trial", y="Ifracmed", ymin="Ifraclo", ymax="Ifracup",
Geom.line, Geom.ribbon),
Guide.xlabel("trial"), Guide.ylabel("frac Fisher info"),
Coord.cartesian(ymin=0.0, ymax=1.1), t)
p = gridstack(Union{Plot,Gadfly.Compose.Context}[ppc pepc; pdt pedt; pperf peperf; pangerr pIfrac])
plotfile = "figs/$(basefilename).pdf"
println("Writing plot to $plotfile")
draw(PDF(plotfile, 8.5inch, 11inch), p)