This repository was archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntbk_asresults_reinforce.Rmd
More file actions
179 lines (157 loc) · 7.3 KB
/
Copy pathntbk_asresults_reinforce.Rmd
File metadata and controls
179 lines (157 loc) · 7.3 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
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
---
title: "Algorithm Selection Model Performance"
output:
html_document:
df_print: paged
toc: yes
---
## Description
Comparison of algorithm selection model performance between _pairwise random forest regression_ and REINFORCE.
```{r results='hide', message=FALSE, warning=FALSE}
library(tidyr)
library(magrittr)
library(dplyr)
library(ggplot2)
library(ggthemes)
library(grid)
library(scales)
library(aslib)
library(llama)
library(randomForest)
library(parallelMap)
source('reinforce.R')
```
```{r load_dataset}
dataset_hard <- ExtractHardInstancesGRAPHS2015()
```
## Model Training
```{r train_prfr}
if (!file.exists("model_regr_hard.rds")) {
parallelStartSocket(4)
parallelLibrary("llama", "mlr")
start_time <- Sys.time()
system.time(model_regr_hard <- regressionPairs(makeLearner("regr.randomForest"), dataset_hard))
end_time <- Sys.time()
saveRDS(model_regr_hard, "model_regr_hard.rds")
cat("Training started at", format(start_time, "%X"), "and ended at", format(end_time, "%X"), "\n")
end_time - start_time
} else {
model_regr_hard <- readRDS("model_regr_hard.rds")
cat("Loaded model_regr_hard from disk.\n")
}
```
```{r train_reinforce}
if (!file.exists("model_reinforce.rds")) {
start_time <- Sys.time()
system.time(model_reinforce <- REINFORCE_AS(dataset_hard, EPOCHS = 30, NUM_BATCHES = 64, DROPOUT_PROB = 0.5, TB_ROOTFOLDER = paste(getwd(), "test_asresults"), OUTFILE = "test_reinforce.txt"))
end_time <- Sys.time()
saveRDS(model_reinforce, "model_reinforce.rds")
cat("Training started at", format(start_time, "%X"), "and ended at", format(end_time, "%X"), "\n")
end_time - start_time
} else {
model_reinforce <- readRDS("model_reinforce.rds")
cat("Loaded model_reinforce from disk.\n")
}
```
## Algorithm selection results
```{r as_results}
resvbs = data.frame(model = "Virtual best solver",
mean.misclassification.penalty = mean(misclassificationPenalties(dataset_hard, vbs)),
solved = sum(successes(dataset_hard, vbs)),
mean.performance = mean(parscores(dataset_hard, vbs, factor = 1)),
median.performance = median(parscores(dataset_hard, vbs, factor = 1)))
ressb = data.frame(model = "Single best solver",
mean.misclassification.penalty = mean(misclassificationPenalties(dataset_hard, singleBest)),
solved = sum(successes(dataset_hard, singleBest)),
mean.performance = mean(parscores(dataset_hard, singleBest, factor = 1)),
median.performance = median(parscores(dataset_hard, singleBest, factor = 1)))
resrp = data.frame(model = "Pairwise random forest regression",
mean.misclassification.penalty = mean(misclassificationPenalties(dataset_hard, model_regr_hard)),
solved = sum(successes(dataset_hard, model_regr_hard)),
mean.performance = mean(parscores(dataset_hard, model_regr_hard, factor = 1)),
median.performance = median(parscores(dataset_hard, model_regr_hard, factor = 1)))
resrl = data.frame(model = "REINFORCE",
mean.misclassification.penalty = mean(misclassificationPenalties(dataset_hard, model_reinforce)),
solved = sum(successes(dataset_hard, model_reinforce)),
mean.performance = mean(parscores(dataset_hard, model_reinforce, factor = 1)),
median.performance = median(parscores(dataset_hard, model_reinforce, factor = 1)))
rbind(resvbs, resrp, ressb, resrl)
```
## Cumulative Density Function Plots
### Using original runtime values
The plot below shows the number of problems solved by each model for a given time duration.
```{r cdf_plot}
runtimes <- data.frame(PRFR = parscores(dataset_hard, model_regr_hard, factor = 1),
REINFORCE = parscores(dataset_hard, model_reinforce, factor = 1),
VBS = parscores(dataset_hard, vbs, factor = 1),
SBS = parscores(dataset_hard, singleBest, factor = 1))
runtimes_long <- gather(runtimes, model, time, PRFR:SBS)
cdfplot = ggplot(runtimes_long, aes(x = time, col = model)) +
stat_ecdf() +
scale_linetype_manual(values=c(3,1), guide = FALSE) +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x, n = 10),
labels = trans_format("log10", math_format(10^.x)),
limits = c(1, (1e8)-1)) +
coord_cartesian(xlim = c(1, (1e8)-1),
ylim = c(0,1)) +
ylab("fraction of instances solved") + xlab("runtime [ms]") +
annotation_logticks(sides = "b") +
theme_tufte(base_family='Times', base_size = 14) +
guides(col = guide_legend(ncol = 2, keyheight = .8)) +
theme(legend.justification=c(1,0), legend.position=c(1,0.7), aspect.ratio = 0.6, axis.line = element_line(colour="black"), panel.grid = element_line(), panel.grid.major = element_line(colour="lightgray"))
cdfplot_zoom = ggplot(runtimes_long, aes(x = time, col = model)) +
stat_ecdf() +
scale_linetype_manual(values=c(3,1), guide = FALSE) +
scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x, n = 3),
labels = trans_format("log10", math_format(10^.x)),
limits = c(1, (1e8)-1)) +
coord_cartesian(xlim = c(1e7, (1e8)-1),
ylim = c(.963,1)) +
annotation_logticks(sides = "b") +
theme_tufte(base_family='Times', base_size = 14) +
theme(legend.position="none",
axis.title.x=element_blank(), axis.title.y=element_blank(),
panel.background = element_rect(fill='white', colour = "white"),
axis.line = element_line(colour="black"),
panel.grid = element_line(),
panel.grid.major = element_line(colour="lightgray"))
vp = viewport(width = 0.57, height = 0.41, x = 0.71, y = 0.41)
print(cdfplot)
print(cdfplot_zoom, vp = vp)
```
```{r quantiles}
summary(runtimes)
```
### Using log-scaled runtime values
```{r log_cdf_plot}
runtimes_logscaled <- runtimes_long %>%
mutate(time = replace(time, time == 0, 1)) %>%
mutate(time = log10(time))
cdfplot_log <- ggplot(runtimes_logscaled, aes(x = time, col = model)) +
stat_ecdf() +
ylab("fraction of instances solved") + xlab("log(runtime)") +
theme_tufte(base_family='Times', base_size = 14) +
guides(col = guide_legend(ncol = 2, keyheight = .8)) +
theme(legend.justification=c(1,0), legend.position=c(1,0.6), aspect.ratio = 0.6, axis.line = element_line(colour="black"), panel.grid = element_line(), panel.grid.major = element_line(colour="lightgray"))
cdfplot_log_zoom <- ggplot(runtimes_logscaled, aes(x = time, col = model)) +
stat_ecdf() +
coord_cartesian(xlim = c(4, 8), ylim = c(.75,1)) +
theme_tufte(base_family='Times', base_size = 14) +
theme(legend.position="none",
axis.title.x=element_blank(), axis.title.y=element_blank(),
panel.background = element_rect(fill='white', colour = "white"),
axis.line = element_line(colour="black"),
panel.grid = element_line(),
panel.grid.major = element_line(colour="lightgray"))
vp = viewport(width = 0.55, height = 0.41, x = 0.72, y = 0.39)
print(cdfplot_log)
print(cdfplot_log_zoom, vp = vp)
```
```{r log_quantiles}
runtimes_logscaled_wide <- runtimes_logscaled %>%
mutate(ID = rep(c(1:2336),4)) %>%
spread(model, time)
summary(runtimes_logscaled_wide[,2:5])
```
## Source code
[Source Rmd file](https://github.com/kvrigor/oraqle-dev/blob/master/project/ntbk_asresults_reinforce.Rmd)