-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplot_figuer.R
172 lines (145 loc) · 5.16 KB
/
plot_figuer.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
plot_the_figure <- function(x, y1, y2, xlab = '', network_name = '', notes = ''){
# xlab = 'p_cc: Probability of Core Connectivity'
# xlab = 'Average Degree (Connectivity)_'
# notes = 'at z=7'
plot(x, y1, pch=4, ylim=c(0,1),
ylab = 'Probability and Extent of Contagion',
xlab = xlab)
points(x, y2, pch=16)
maintitle = paste('Probability and Extent of Contagion for', network_name)
subtitle = paste(notes)
title(main=maintitle,
sub=subtitle)
}
file_name = 'results_sbm_3.csv'
average_degree = 3
# the csv file need changed with add comma
data = read.csv(file_name, header =FALSE)
x = seq(get_low_bound_cc(average_degree), get_up_bound_cc(average_degree), 0.0005)
plot_the_figure(x, as.numeric(data$V1),as.numeric(data$V2),
xlab = 'p_cc: Probability of Core Connectivity',
network_name = 'SBM Network', notes = 'at z=3')
# the final ER
file_name = 'FINAL_ER.csv'
x = seq(0,10.1,0.2)
data = read.csv(file_name, header = FALSE)
y1 = as.numeric(data$V1)
y2 = as.numeric(data$V2)
xtick = seq(0,10,1)
plot(x, y1, pch=4, ylim=c(0,1.03),
ylab = 'Probability and Extent of Contagion',
xlab = 'Average Degree (Connectivity)', xaxt = "n")
axis(side = 1, at = xtick, labels=xtick )
grid()
points(x, y2, pch=16)
arrows(0.8,1.02,7,1.02,code=3,length = 0.25, angle = 10)
text(4,1.04,"Contagion Window")
abline(v=0.8,lty=2)
abline(v=7,lty=2)
legend(8.5,1.1,c("Contagion\nProbability\n", "Contagion\nExtent"), pch=c(4,16),bty="n")
title(main='Probability and Extent of Contagion for ER Network',
sub='Randomly Chose One Bank Bankrupt')
# the final ER as line
# plot Biggest
file_name = 'FINAL_ER.csv'
x = seq(0,10.1,0.2)
data = read.csv(file_name, header = FALSE)
y1 = as.numeric(data$V1)
y2 = as.numeric(data$V2)
xtick = seq(0,10,1)
#y1 line for probability
#y2 dashlien for extent
plot(x, y1, type="l", lty=1, ylim=c(0,1.03),
ylab = 'Probability and Extent of Contagion',
xlab = 'Average Degree (Connectivity)', xaxt = "n")
axis(side = 1, at = xtick, labels=xtick )
grid()
points(x, y2, type="l", lty=2)
second_file_name = "results_er_biggest.csv"
second_data = read.csv(second_file_name, header = FALSE)
prob = as.numeric(second_data$V1)
exte = as.numeric(second_data$V2)
points(x, prob, pch=4)
points(x, exte, pch=16)
arrows(0.6,1.02,7.8,1.02,code=3,length = 0.25, angle = 10)
text(4.5,1.04,"Contagion Window")
abline(v=0.8,lty=2)
abline(v=7,lty=2)
legend(8.2,1,c("Contagion\nProbability\n", "Contagion\nExtent"), pch=c(4,16), lty=c(1,2),bty="n")
title(main='Probability and Extent of Contagion for ER Network',
sub='The Bank with the Biggest Connectivity Bankrupt')
# the final ER as line
# plot TARGET
file_name = 'FINAL_ER.csv'
x = seq(0,10.1,0.2)
data = read.csv(file_name, header = FALSE)
y1 = as.numeric(data$V1)
y2 = as.numeric(data$V2)
xtick = seq(0,10,1)
#y1 line for probability
#y2 dashlien for extent
plot(x, y1, type="l", lty=1, ylim=c(0,1.03),
ylab = 'Probability and Extent of Contagion',
xlab = 'Average Degree (Connectivity)', xaxt = "n")
axis(side = 1, at = xtick, labels=xtick )
grid()
points(x, y2, type="l", lty=2)
second_file_name = "results_er_target_0.1.csv"
second_data = read.csv(second_file_name, header = FALSE)
prob = as.numeric(second_data$V1)
exte = as.numeric(second_data$V2)
points(x, prob, pch=4)
points(x, exte, pch=16)
arrows(1,0.4,5,0.4,code=3,length = 0.25, angle = 10)
text(3,0.425,"Contagion Window")
abline(v=0.8,lty=2)
abline(v=7,lty=2)
legend(8.2,1,c("Contagion\nProbability\n", "Contagion\nExtent"), pch=c(4,16), lty=c(1,2),bty="n")
title(main='Probability and Extent of Contagion for ER Network',
sub='The Bank with the Target Policy')
# SBM
plot_sbm <- function(average_degree = 2){
file_name = paste("results_sbm_",average_degree,".csv", sep='')
up = round(get_low_bound_cc(average_degree),3)
down = round(get_up_bound_cc(average_degree),3)
x = seq(up, down, 0.0005)
xtick = seq(up, down, 0.001)
data = read.csv(file_name, header = FALSE)
y1 = as.numeric(data$V1)
y2 = as.numeric(data$V2)
plot(x, y1, pch=4, ylim=c(0,1.0),
ylab='',
xlab = 'p_cc', xaxt = "n",
main=paste("Average Degree: ",average_degree ))
axis(side = 1, at = xtick, labels= xtick)
grid()
points(x, y2, pch=16)
}
par(mfrow=c(2,3))
for (i in 2:7){
plot_sbm(i)
}
mtext(expression(bold("SBM Networks Simulation on Different Average Degrees")), side = 3, line = 0, outer = T)
# SBM cc=cp
plot_sbm <- function(average_degree = 2){
file_name = paste("results_sbm_f_",average_degree,".csv", sep='')
down = round(get_up_bound_pp(average_degree),3)
x = seq(0, down, 0.0005)
xtick = seq(0, down, 0.001)
data = read.csv(file_name, header = FALSE)
y1 = as.numeric(data$V1)
y2 = as.numeric(data$V2)
plot(x, y1, pch=4, ylim=c(0,1.0),
ylab='',
xlab = 'p_pp', xaxt = "n",
main=paste("Average Degree: ",average_degree ))
axis(side = 1, at = xtick, labels= xtick)
grid()
points(x, y2, pch=16)
}
par(mfrow=c(2,3))
mtext(expression(bold("SBM Networks Simulation on Different Average Degrees")), side = 3, line = 0)
for (i in 2:7){
plot_sbm(i)
}
mtext(expression(bold("SBM Networks Simulation on Different Average Degrees")), side = 3, line = 0, outer =T)