-
Notifications
You must be signed in to change notification settings - Fork 1
/
unittest.jl
183 lines (137 loc) · 4.22 KB
/
unittest.jl
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
using DataArrays, DataFrames
using Match
using ParallelDataTransfer
using QuadGK
using Parameters #module
using Distributions
using StatsBase
using Base.Profile
include("parameters.jl")
include("PopStruct.jl")
include("functions.jl")
sigma1 = 0.4
ef1 = 0.4
P=InfluenzaParameters(
precaution_factorS = sigma1,
precaution_factorV = 0.0,
VaccineEfficacy = ef1,
GeneralCoverage = 1,
Prob_transmission = 0.079,
sim_time = 365,
grid_size_human = 10000
)
humans = Array{Human}(P.grid_size_human)
setup_human(humans)
setup_demographic(humans,P)
vaccination(humans,P)
Number_in_age_group = zeros(Int64,15)
Age_group_Matrix = Matrix{Int64}(15,P.grid_size_human)
for i = 1:P.grid_size_human
Age_group_Matrix[humans[i].contact_group,(Number_in_age_group[humans[i].contact_group]+1)] = humans[i].index
Number_in_age_group[humans[i].contact_group] += 1
end
########################
f = open(string("VaccineEffectiveness/VaccineEffec","$ef1",".dat"),"w")
for j = 1:15
A = find(x -> x.vaccinationStatus == 1 && x.contact_group == j,humans)
soma = 0.0
for k = A
soma += humans[k].vaccineEfficacy
end
soma = soma/length(A)
println(f,"$j $soma")
end
close(f)
end
#################
######erasing the age groups
for i=1:P.grid_size_human
humans[i].contact_group = 1
end
function test_humanage()
ag = map(x -> x.age, humans)
plot(x = ag, Geom.histogram)
a = find(x -> x.gender == FEMALE, humans)
ag = zeros(Int64, length(a))
for i=1:length(a)
ag[i] = humans[a[i]].agegroup
end
ag = map(x -> x.agegroup, humans)
# ag = map(x -> x.age, humans)
plot(x = ag, Geom.histogram)
find(x -> x.age >= 15, humans)
find(x -> x.age >= 15 && x.gender == MALE, humans)
find(x -> x.age >= 15 && x.gender == FEMALE, humans)
end
#### Testing LogNormal
d = LogNormal(1,sqrt(0.4356))
d1 = Vector{Float64}(3000)
for i = 1:length(d1)
d1[i] = min(15,rand(d))
end
writedlm("testeLogNormal.dat",d1)
##Contact distribution
X = Matrix{Float64}(15,15)
X[1,:] = ContactMatrix[1,:]
for i = 2:15
for j = 1:15
X[i,j] = ContactMatrix[i,j]-ContactMatrix[i-1,j]
end
end
writedlm("MatrixContact2.dat",X)
########
NB = N_Binomial()
ContactMatrix = ContactMatrixFunc()
ContactMatrix2 = ContactMatrixFunc2()
for i=1:P.grid_size_human
humans[i].daily_contacts = rand(NB[humans[i].contact_group])
end
@profile finding_contact(humans,1,ContactMatrix)
## to do
## if there is a protection level, the
function myfunc()
A = rand(200, 200, 400)
maximum(A)
end
#############################################################
#### Testing Frailty indexx, vaccine coverage etc
FrIndex = Matrix{Float64}(length(humans),2)
for i = 1:length(humans)
rd = rand()
MaxFra,MinFra = FrailtyIndex(humans[i])
FrIndex[i,2] = rd*(MaxFra-MinFra)+MinFra
FrIndex[i,1] = humans[i].age
end
writedlm("Frailty.dat",FrIndex)
for i = 1:length(humans)
FrIndex[i,2] = humans[i].vaccineEfficacy
FrIndex[i,1] = humans[i].age
end
writedlm("VaccineEffic.dat",FrIndex)
for i = 1:length(humans)
FrIndex[i,2] = humans[i].Coverage
FrIndex[i,1] = humans[i].age
end
writedlm("VaccineCov.dat",FrIndex)
find(x -> x.age <= 64 && x.age >= 50, humans)
find(x -> x.age <= 64 && x.age >= 50 && x.vaccinationStatus == 1, humans)
###############################################################33
######################### Testing number of daily contacts
TestMatrix = zeros(Int64,15,15)
NB = N_Binomial()
ContactMatrix = ContactMatrixFunc()
for t = 1:P.sim_time
for i=1:P.grid_size_human
humans[i].daily_contacts = rand(NB[humans[i].contact_group])
for j=1:humans[i].daily_contacts
r =finding_contact2(humans,i,ContactMatrix,Age_group_Matrix,Number_in_age_group)# rand(1:P.grid_size_human)#
TestMatrix[humans[i].contact_group,humans[r].contact_group]+=1
end
end
end
TestMatrix2 = zeros(Float64,15,15)
for i = 1:15
TestMatrix2[:,i] = TestMatrix[:,i]/Number_in_age_group[i]
end
TestMatrix2 = TestMatrix2/P.sim_time
writedlm("DailyContactsP10000.dat",TestMatrix2)