-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_nonmonotonic.R
130 lines (97 loc) · 6.72 KB
/
plot_nonmonotonic.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
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
library(ggplot2)
library(plyr)
library(RColorBrewer)
library(reshape2)
setwd("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopicData")
files <- list.files()
data <- data.frame()
for (file in files) {
tmp <- read.table(file, sep=";", header=T)
tmp$cls <- "rf"
data <- rbind(data, tmp)
}
data$metric <- gsub("_mean", "", data$metric)
data$ratio <- paste(data$c_miss, data$c_action, sep=":")
base_size <- 36
line_size <- 1
point_size <- 4
data <- subset(data, dataset != "bpic2018")
data <- subset(data, dataset != "uwv")
data$method <- as.character(data$method)
data$dataset <- as.character(data$dataset)
#data$method[data$method=="single_threshold"] <- "Single Alarm"
data$dataset[data$dataset=="uwv_all"] <- "uwv"
data$dataset[data$dataset=="traffic_fines_1"] <- "traffic_fines"
data$ratio <- as.factor(data$ratio)
data$ratio_com <- as.factor(data$c_com)
data <- subset(data, cls=="rf")
print(subset(data,method=="perfect_prediction"))
head(data)
dt_min_prefix <- subset(data, metric=="cost_avg" & method=="min_prefix")
dt_prefix <- subset(data, metric=="cost_avg" & method=="prefix_threshold")
dt_single <- subset(data, metric=="cost_avg" & method=="single_threshold")
dt_merged <- merge(dt_min_prefix, dt_single, by=c("dataset", "c_miss", "c_action", "c_postpone", "c_com", "early_type", "cls", "ratio"), suffixes=c("_min_prefix", "_single"))
dt_merged$benefit_min_prefix <- dt_merged$value_min_prefix/dt_merged$value_single
dt_merged2 <- merge(dt_prefix, dt_single, by=c("dataset", "c_miss", "c_action", "c_postpone", "c_com", "early_type", "cls", "ratio"), suffixes=c("_prefix", "_single"))
dt_merged2$benefit_prefix <-dt_merged2$value_prefix/dt_merged2$value_single
dt_merged2$benefit_fixed <- ifelse(dt_merged2$value_single > dt_merged2$value_prefix,1.0,0.0)
print(min(dt_merged2$benefit_prefix))
dt_merged2$benefit_fixed <- ifelse(dt_merged2$value_single < dt_merged2$value_prefix,-1.0,dt_merged2$benefit_fixed)
ggplot(dt_merged2, aes(x=benefit_prefix)) +
geom_histogram(color="black", fill="white",binwidth = 0.01) + facet_wrap(dataset ~ early_type, ncol=3) + xlab("Ratio baseline divided by two thresholds system") +
theme(text = element_text(size=25))
ggsave("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopic/result_histogram_single_vs_prefix.pdf", width = 18, height = 16)
ggplot(dt_merged, aes(x=benefit_min_prefix)) +
geom_histogram(color="black", fill="white",binwidth = 0.01) + facet_wrap(dataset ~ early_type, ncol=3)
ggsave("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopic/result_histogram_single_vs_minprefix.pdf", width = 18, height = 16)
vec_traffic_linear <- subset(dt_merged2, dataset=="traffic_fines" & early_type=="linear" & benefit_prefix)
print("traffic_fines_single:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="traffic_fines" & early_type=="const")
print("traffic_fines_const:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="traffic_fines" & early_type=="nonmonotonic")
print("traffic_fines_nonmonotonic:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_cancelled" & early_type=="linear")
print("bpic2017_cancelled_linear:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_cancelled" & early_type=="const")
print("bpic2017_cancelled_const:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_cancelled" & early_type=="nonmonotonic")
print("bpic2017_cancelled_nonmonotonic:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_refused" & early_type=="linear")
print("bpic2017_refused_single:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_refused" & early_type=="const")
print("bpic2017_refused_const:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
vec_traffic_linear <- subset(dt_merged2, dataset=="bpic2017_refused" & early_type=="nonmonotonic")
print("bpic2017_refused_nonmonotonic:")
print(max(vec_traffic_linear$benefit_prefix))
print(min(vec_traffic_linear$benefit_prefix))
dt_merged2$benefit_prefix <- ifelse(dt_merged2$benefit_prefix < 0.9,0.9,dt_merged2$benefit_prefix)
dt_merged2$benefit_prefix <- ifelse(dt_merged2$benefit_prefix > 1.1,1.1,dt_merged2$benefit_prefix)
#print(dt_merged)
ggplot(subset(dt_merged, cls=="rf"), aes(factor(ratio_com_single), factor(ratio))) + geom_tile(aes(fill = benefit_min_prefix), colour = "black") +
theme_bw(base_size=base_size) + scale_fill_gradientn(colours=c("green","white","red"),breaks=c(0.9,1.0,1.1), limits=c(0.0,1.1),name="Correlation \n coefficient") +
xlab("c_com") + ylab("c_out : c_in") + theme(axis.text.x = element_text(size=20)) + facet_wrap(dataset ~ early_type, ncol=3)
ggsave("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopic/result_heatmap_single_vs_minprefix.pdf", width = 20, height = 13)
ggplot(subset(dt_merged2, cls=="rf"), aes(factor(ratio_com_single), factor(ratio))) + geom_tile(aes(fill = benefit_prefix), colour = "black") +
theme_bw(base_size=base_size) + scale_fill_gradientn(colours=c("green4","green3","green2","green1","white","red1","red2","red3","red4"),breaks=c(0.9,1.0,1.1), limits=c(0.9,1.1), name="Ratio \n", labels=c(expression(phantom(x) <=0.9),"1.0",expression(phantom(x) >= 1.1)) ) +
xlab("c_com") + ylab("c_out : c_in") + theme(axis.text.x = element_text(size=20)) + facet_wrap(dataset ~ early_type, ncol=3)
ggsave("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopic/result_heatmap_ratio_single_vs_prefix.pdf", width = 20, height = 13)
ggplot(subset(dt_merged2, cls=="rf"), aes(factor(ratio_com_single), factor(ratio))) + geom_tile(aes(fill = benefit_fixed), colour = "black") +
theme_bw(base_size=base_size) + scale_fill_gradientn(colours=c("red","white","green"),breaks=c(-0.8,0.0,0.8), limits=c(-1.0,1.0),name="Best System",labels=c("Single Threshold","Tie","Two Thresholds")) +
xlab("c_com") + ylab("c_out : c_in") + theme(axis.text.x = element_text(size=20)) + facet_wrap(dataset ~ early_type, ncol=3)
ggsave("/Users/stephanf/Dropbox/Dokumente/Masterstudium/Masterthesis/testresults/NonMyopic/result_heatmap_single_vs_prefix_fixed.pdf", width = 20, height = 13)