-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot.R
279 lines (242 loc) · 14.4 KB
/
plot.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
setwd("~/ChangjiangGou/Workflows/code/result")
library(ggplot2)
library(reshape2)
library(tikzDevice)
library(plyr)
#for visulasiation of the result
#-------------------Expected Period to Pbound,------------------------------
#-------------_____________---------------____________________-------------_____________
rm(list=ls())
str1<-"disc"
#str1<-"cont"
resultfile<-paste("result_norm_5p_",str1,"_pt5.txt",sep = "")
result<-read.table(resultfile,header = TRUE)
result<-result[1:1638000,]
result$Heuristics<-revalue(result$Heuristics,c(BestE="BestEnergy",DupAll="DuplicateAll",MaxS="MaxSpeed"))
result$ExpectedP<-as.numeric(as.character(result$ExpectedP))
result$ActualProba<-as.numeric(as.character(result$ActualProba))
result.summary<-ddply(result,c("K","Heuristics"),summarise,minEP=min(ExpectedP),
ExpectedPeriod=mean(ExpectedP),maxEP=max(ExpectedP),
minPro=min(ActualProba),ActualProbability=mean(ActualProba),
maxPro=max(ActualProba)
)
temp<-ddply(result,"K",summarise,avaPT=mean(Pbound),maxPT=max(Pbound),minPT=min(Pbound))
result.summary<-merge(result.summary,temp)
temp<-ddply(result,"K",summarise,avaProbaT=mean(ProbaT))
result.summary<-merge(result.summary,temp)
#display.brewer.all()
#colors()
hues = seq(15, 375, length = length(levels(result.summary$Heuristics)) + 1)
hcl(h = hues, l = 65, c = 100)[1:length(levels(result.summary$Heuristics))]
levels(result.summary$Heuristics)
cb_palette <- c(BestEnergy="#F8766D", BestTrade="#C49A00", Closer="#53B400",
DuplicateAll="#00C094", Failure="#00B6EB", MaxSpeed="#A58AFF",
Threshold="#FB61D7")#,"009E73")
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/EP_",str1,"_5p.tex",sep = "")
#tikz(outputfigure,width = 6,height = 6)
ggplot(result.summary,aes(x=K,y=ExpectedPeriod,colour=Heuristics))+
geom_ribbon(aes(ymin=minEP, ymax=maxEP,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_ribbon(aes(ymin=minPT,ymax=maxPT),linetype="dotted",colour="black",alpha=0.1)+
geom_line(aes(y=avaPT),colour="black",linetype="dotted",size=1.5)+
coord_cartesian(y=c(0,60))+
labs(colour="Heuristics",x="kappa",y="Expected Period")+
scale_colour_manual(values = cb_palette)+
theme(legend.position=c(0.98,0.13),legend.justification = c(1,0))+
theme(legend.background = element_rect(colour = "black"),legend.title = element_text(size = 18),
legend.text = element_text(size=16))+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/EP_cont_5p.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
dev.off()
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/AP_",str1,"_5p.tex",sep="")
#tikz(outputfigure,width = 6,height = 6)
ggplot(result.summary,aes(x=K,y=ActualProbability,colour=Heuristics))+
geom_ribbon(aes(ymin=minPro, ymax=maxPro,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_line(aes(y=avaProbaT),colour="black",linetype="dotted",size=1.5)+
#theme(axis.line = element_line(colour="black"))+
coord_cartesian(y=c(0,0.1))+
#coord_cartesian(y=c(0,0.3))+
labs(colour="Heuristics",linetype="Target/Expected",x="kappa",y="Probability of exceeding the period bound")+
scale_colour_manual(values = cb_palette)+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/AP_cont_5p.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
dev.off()
result$Energy<-as.numeric(as.character(result$Energy))
energy.wide<-dcast(result,Tree_name+NPRatio+K~Heuristics,value.var = "Energy")
energy.wide$BestTrade<-energy.wide$BestTrade/energy.wide$BestEnergy
energy.wide$Closer<-energy.wide$Closer/energy.wide$BestEnergy
energy.wide$DuplicateAll<-energy.wide$DuplicateAll/energy.wide$BestEnergy
energy.wide$MaxSpeed<-energy.wide$MaxSpeed/energy.wide$BestEnergy
energy.wide$Threshold<-energy.wide$Threshold/energy.wide$BestEnergy
energy.long<-melt(energy.wide,id.vars=c("Tree_name","K","NPRatio"),variable.name="Heuristics",value.name = "NEnergy")
energy.long<-energy.long[!energy.long$Heuristics=="BestEnergy",]
energy.summary<-ddply(energy.long,c("K","Heuristics"),summarise,minE=min(NEnergy),
E=mean(NEnergy),maxE=max(NEnergy))
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/E_",str1,"_5p.tex",sep = "")
#tikz(outputfigure,width = 6,height = 6)
#ytitle<-expression(paste("Energy cost normalised to ",bold(BestEnergy)))
ggplot(energy.summary,aes(x=K,y=E,colour=Heuristics))+
geom_line(size=1.5)+
coord_cartesian(y=c(0,45))+#215.4228 for MaxSpeed
labs(colour="Heuristics",x="kappa",y="Energy cost normalised to \\textbf{BestEnergy}")+
scale_colour_manual(values = cb_palette)+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/E_cont_5p.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
dev.off()
#------------------------expected period with different chains' size----------------------------------
rm(list=ls())
str1<-"disc"
#str1<-"cont"
p<-512
resultfile<-paste("result_",str1,"_manyNPratios.txt",sep = "")
result<-read.table(resultfile,header = TRUE)
result<-result[1:1800000,]
result<-result[result$Energy!=-1,]
result$Heuristics<-revalue(result$Heuristics,c(BestE="BestEnergy",DupAll="DuplicateAll",MaxS="MaxSpeed"))
result$Energy<-as.numeric(as.character(result$Energy))
#result$Energy<-result$Energy/(p*result$NPRatio)
energy.wide<-dcast(result,Tree_name+NPRatio+K~Heuristics,value.var = "Energy")
energy.wide$BestEnergy<-as.numeric(energy.wide$BestEnergy)
energy.wide$BestTrade<-as.numeric(energy.wide$BestTrade)
energy.wide$Closer<-as.numeric(energy.wide$Closer)
energy.wide$DuplicateAll<-as.numeric(energy.wide$DuplicateAll)
energy.wide$MaxSpeed<-as.numeric(energy.wide$MaxSpeed)
energy.wide$Threshold<-as.numeric(energy.wide$Threshold)
energy.wide$BestTrade<-energy.wide$BestTrade/energy.wide$BestEnergy
energy.wide$Closer<-energy.wide$Closer/energy.wide$BestEnergy
energy.wide$DuplicateAll<-energy.wide$DuplicateAll/energy.wide$BestEnergy
energy.wide$MaxSpeed<-energy.wide$MaxSpeed/energy.wide$BestEnergy
energy.wide$Threshold<-energy.wide$Threshold/energy.wide$BestEnergy
energy.long<-melt(energy.wide,id.vars=c("Tree_name","K","NPRatio"),variable.name="Heuristics",value.name = "NEnergy")
energy.long<-subset(energy.long,Heuristics!="BestEnergy")
p<-512
energy.summary<-ddply(energy.long,c("NPRatio","Heuristics"),summarise,minE=min(NEnergy),
E=mean(NEnergy),maxE=max(NEnergy))
#mean(energy.long$NEnergy[which(energy.long$Heuristics=="MaxSpeed")]) #maxspeed is 215
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/E_",str1,"_4k.tex",sep = "")
#outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/E_",str1,"_4k_eachnode.tex",sep = "")
#tikz(outputfigure,width = 6,height = 6)
#ytitle<-expression(paste("Mean energy cost\n(normalised to",bold(BestEnergy),")"))
ggplot(energy.summary,aes(x=NPRatio,y=E,colour=Heuristics))+
geom_ribbon(aes(ymin=minE, ymax=maxE,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
#coord_cartesian(y=c(0,7))+
coord_cartesian(y=c(5,25))+
scale_colour_manual(values = cb_palette)+
#guides(colour=FALSE)+
labs(colour="Heuristics",x="Ratio of node to core",y="Energy cost normalized to \\textbf{BestEnergy}")+
#labs(colour="Heuristics",x="Ratio of node to core",y="Mean node's energy cost\n(normalized to \\textbf{BestEnergy})")+
theme(legend.position=c(0.98,0.4),legend.justification = c(1,0))+
theme(legend.background = element_rect(colour = "black"),legend.title = element_text(size = 18),
legend.text = element_text(size=16))+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/E_cont_4k.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
result$ExpectedP<-as.numeric(as.character(result$ExpectedP))
result$ActualProba<-as.numeric(as.character(result$ActualProba))
Period.summary<-ddply(result,c("NPRatio","Heuristics"),summarise,minEP=min(ExpectedP),EP=mean(ExpectedP),maxEP=max(ExpectedP))
Proba.summary<-ddply(result,c("NPRatio","Heuristics"),summarise,minPt=min(ActualProba),Pt=mean(ActualProba),maxPt=max(ActualProba))
temp<-ddply(result,"NPRatio",summarise,avaP=mean(Pbound),maxPd=max(Pbound),minPd=min(Pbound))
Period.summary<-merge(Period.summary,temp)
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/EP_NP_",str1,".tex",sep = "")
#tikz(outputfigure,width = 6,height = 6)
ggplot(Period.summary,aes(x=NPRatio,y=EP,colour=Heuristics))+
geom_ribbon(aes(ymin=minEP, ymax=maxEP,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_ribbon(aes(ymin=minPd,ymax=maxPd),linetype="dotted",colour="black",alpha=0.1)+
geom_line(aes(y=avaP),colour="black",linetype="dotted",size=1.5)+
scale_colour_manual(values = cb_palette)+
labs(colour="Heuristics",x="Ratio of node to core",y="Expected Period")+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/EP_NP_cont.pdf", width=9, height=6, units="in",dpi=300)#a4 21*29.7
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/AP_NP_",str1,".tex",sep = "")
#tikz(outputfigure,width = 6,height = 6)
ggplot(Proba.summary,aes(x=NPRatio,y=Pt,colour=Heuristics))+
geom_ribbon(aes(ymin=minPt, ymax=maxPt,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_line(aes(y=0.05),colour="black",linetype="dotted")+
coord_cartesian(y=c(0,0.075))+#BestEnergy is always 1
scale_colour_manual(values = cb_palette)+
labs(colour="Heuristics",x="Ratio of node to core",y="Probability of exceeding the period bound")+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Thesis/Year2/fig/AP_NP_cont.pdf", width=9, height=6, units="in",dpi=300)#a4 21*29.7
#------------------------------------------on real apps----------------------------
rm(list=ls())
str1<-"disc"
#str1<-"cont"
resultfile<-paste("result_real_",str1,".txt",sep = "")
result<-read.table(resultfile,header = TRUE)
result<-result[1:4368,]
result$Heuristics<-revalue(result$Heuristics,c(BestE="BestEnergy",DupAll="DuplicateAll",MaxS="MaxSpeed"))
result$ExpectedP<-as.numeric(as.character(result$ExpectedP))
result$ActualProba<-as.numeric(as.character(result$ActualProba))
result.summary<-ddply(result,c("K","Heuristics"),summarise,minEP=min(ExpectedP),
ExpectedPeriod=mean(ExpectedP),maxEP=max(ExpectedP),
minPro=min(ActualProba),ActualProbability=mean(ActualProba),
maxPro=max(ActualProba)
)
temp<-ddply(result,"K",summarise,avaPT=mean(Pbound),maxPT=max(Pbound),minPT=min(Pbound))
result.summary<-merge(result.summary,temp)
temp<-ddply(result,"K",summarise,avaProbaT=mean(ProbaT))
result.summary<-merge(result.summary,temp)
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/EP_real_",str1,".tex",sep="")
#tikz(outputfigure,width = 6,height = 6)
ggplot(result.summary,aes(x=K,y=ExpectedPeriod,colour=Heuristics))+
#geom_ribbon(aes(ymin=minPT,ymax=maxPT,colour="Period bound"),alpha=0.1)+
#geom_ribbon(aes(ymin=minEP, ymax=maxEP,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_line(aes(y=avaPT),colour="black",linetype="dotted",size=1.5)+
scale_colour_manual(values = cb_palette)+
labs(colour="Heuristics",x="kappa",y="Expected Period")+
#theme(legend.position=c(0.98,0.13),legend.justification = c(1,0))#+
#guides(colour=FALSE)+
theme(legend.position=c(0.4,0.6),legend.justification = c(1,0))+
theme(legend.background = element_rect(colour = "black"),legend.title = element_text(size = 18),
legend.text = element_text(size=16))+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Workflows/ExpectedP_disc_realapps.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/AP_real_",str1,".tex",sep="")
#tikz(outputfigure,width = 6,height = 6)
ggplot(result.summary,aes(x=K,y=ActualProbability,colour=Heuristics))+
geom_ribbon(aes(ymin=minPro, ymax=maxPro,colour=Heuristics),alpha=0.1)+
geom_line(size=1.5)+
geom_line(aes(y=avaProbaT),colour="black",linetype="dotted",size=1.5)+
#coord_cartesian(ylim = c(0,0.03))+#BestEnergy is always 1
coord_cartesian(ylim = c(0,0.16))+#BestEnergy is always 1
scale_colour_manual(values = cb_palette)+
labs(colour="Heuristics",linetype="Target/Expected",x="kappa",y="Probability of exceeding the period bound")+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Workflows/Probability_disc_realapps.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7
result$Energy<-as.numeric(as.character(result$Energy))
energy.wide<-dcast(result,Tree_name+NPRatio+K~Heuristics,value.var = "Energy")
energy.wide$BestTrade<-energy.wide$BestTrade/energy.wide$BestEnergy
energy.wide$Closer<-energy.wide$Closer/energy.wide$BestEnergy
energy.wide$DuplicateAll<-energy.wide$DuplicateAll/energy.wide$BestEnergy
energy.wide$MaxSpeed<-energy.wide$MaxSpeed/energy.wide$BestEnergy
energy.wide$Threshold<-energy.wide$Threshold/energy.wide$BestEnergy
energy.long<-melt(energy.wide,id.vars=c("Tree_name","K","NPRatio"),variable.name="Heuristics",value.name = "NEnergy")
energy.long<-energy.long[!energy.long$Heuristics=="BestEnergy",]
energy.summary<-ddply(energy.long,c("K","Heuristics"),summarise,minE=min(NEnergy),
E=mean(NEnergy),maxE=max(NEnergy))
#mean(energy.long$NEnergy[which(energy.long$Heuristics=="MaxSpeed")]) #MaxSpeed is 254.0781
outputfigure<-paste("/Users/changjiang/ChangjiangGou/Workflows/E_real_",str1,".tex",sep="")
#tikz(outputfigure,width = 6,height = 6)
ggplot(energy.summary,aes(x=K,y=E,colour=Heuristics))+
geom_line(size=1.5)+
coord_cartesian(y=c(0,45))+#MaxSpeed is 254.0781
scale_colour_manual(values = cb_palette)+
labs(colour="Heuristics",x="kappa",y="Energy cost normalized to \\textbf{BestEnergy}")+
guides(colour=FALSE)+
theme(axis.title = element_text(size = 20),axis.text = element_text(size = 20))
dev.off()
#ggsave("/Users/changjiang/ChangjiangGou/Workflows/E_disc_realapps.pdf", width=9,height = 6,units = "in",dpi=300)#a4 21*29.7