-
Notifications
You must be signed in to change notification settings - Fork 3
/
figure-aum-optimized.R
93 lines (90 loc) · 2.62 KB
/
figure-aum-optimized.R
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
source("packages.R")
result.list <- readRDS("figure-aum-optimized-data.rds")
iterations.tall <- melt(result.list$iterations, id="step.number")
iterations.tall[, Variable := ifelse(
variable=="min.errors", "label errors", toupper(variable))]
gg <- ggplot()+
geom_line(aes(
step.number, value),
data=iterations.tall)+
facet_grid(Variable ~ ., scales="free")+
ylab("")+
xlab("Iteration of gradient descent algorithm")
png("figure-aum-optimized-iterations.png", width=3, height=3, units="in", res=200)
print(gg)
dev.off()
two.it <- iterations.tall[step.number %in% range(step.number)]
two.it[, emph := ifelse(step.number==1, "initial", "optimized")]
emph <- gg+
geom_point(aes(
step.number, value, color=emph),
data=two.it)+
theme(legend.position = "none")
png("figure-aum-optimized-iterations-emph.png", width=3, height=3, units="in", res=200)
print(emph)
dev.off()
result.list$auc[, `:=`(x=c(0.25), y=c(0.75, 0.5))]
result.list$roc[, is.monotonic := c(NA, (diff(fp)<=0) & (diff(fn)>=0)), by=pred.name]
result.list$roc[, line.i := 1:.N, by=pred.name]
result.list$roc[, range(line.i), by=pred.name]
## same number of monotonic moves, makes sense because all the same
## error diffs but happening at different thresholds.
result.list$roc[, .(n.monotonic=sum(is.monotonic[-1])), by=pred.name]
ggplot()+
geom_path(aes(
FPR, TPR, color=pred.name),
data=result.list$roc)+
geom_point(aes(
FPR, TPR, color=pred.name),
data=result.list$roc[is.monotonic==FALSE])+
geom_text(aes(
FPR, TPR, color=pred.name, label=line.i),
hjust=1,vjust=1,
data=result.list$roc[is.monotonic==FALSE])+
geom_point(aes(
FPR, TPR, color=pred.name),
fill="white",
shape=21,
data=result.list$auc)+
geom_segment(aes(
x, y,
xend=FPR, yend=TPR,
color=pred.name),
data=result.list$auc)+
geom_label(aes(
x, y, color=pred.name,
label=sprintf(
"%s errors=%d auc=%.2f",
pred.name, errors, auc)),
size=3,
hjust=0,
data=result.list$auc)+
coord_equal()+
guides(color="none")
gg <- ggplot()+
geom_path(aes(
FPR, TPR, color=pred.name),
data=result.list$roc)+
geom_point(aes(
FPR, TPR, color=pred.name),
fill="white",
shape=21,
data=result.list$auc)+
geom_segment(aes(
x, y,
xend=FPR, yend=TPR,
color=pred.name),
data=result.list$auc)+
geom_label(aes(
x, y, color=pred.name,
label=sprintf(
"%s errors=%d auc=%.2f",
pred.name, errors, auc)),
size=3,
hjust=0,
data=result.list$auc)+
coord_equal()+
guides(color="none")
png("figure-aum-optimized.png", width=3, height=3, units="in", res=200)
print(gg)
dev.off()