Révision | 25efd5dac9a6ae0aa4cd8cc4260b23ca11d6619a (tree) |
---|---|
l'heure | 2010-04-22 01:19:02 |
Auteur | lorenzo |
Commiter | lorenzo |
Now the code can also define the number of susceptible individuals as the
number of individuals in the seed's CC (instead of simply the number of
individuals entering the museum after the seed). The code is still being
developed, hence be careful!
@@ -4,6 +4,12 @@ | ||
4 | 4 | import numpy as n |
5 | 5 | import sys |
6 | 6 | import string |
7 | +import igraph as ig | |
8 | + | |
9 | +def array_to_dict_iter(array): | |
10 | + for row in array: | |
11 | + yield dict(source=row[0], target=row[1]) | |
12 | + | |
7 | 13 | |
8 | 14 | |
9 | 15 |
@@ -23,6 +29,8 @@ | ||
23 | 29 | def time_infection(data_no_loops, infected): |
24 | 30 | before_and_after=\ |
25 | 31 | network_after_infection_introduction(infected,data_no_loops) |
32 | + | |
33 | + seed=infected | |
26 | 34 | |
27 | 35 | net_infected=before_and_after[0] |
28 | 36 |
@@ -30,6 +38,22 @@ | ||
30 | 38 | #number of people the seed can infect (not the number of visitors since |
31 | 39 | #the seed cannot infect a priori those who left before he entered) |
32 | 40 | |
41 | + g = ig.Graph.DictList(vertices=None, edges=array_to_dict_iter(net_infected[:,1:3])) | |
42 | + | |
43 | + g=g.simplify() | |
44 | + clustering=g.clusters() | |
45 | + c_sizes=s.asarray(clustering.sizes()) | |
46 | + | |
47 | + name_list=g.vs["name"] | |
48 | + | |
49 | + name_list=s.asarray(name_list) | |
50 | + | |
51 | + sel=s.where(name_list==seed)[0] | |
52 | + seed_membership=clustering.membership[sel] | |
53 | + | |
54 | + susceptible_improved=c_sizes[seed_membership] | |
55 | + | |
56 | + | |
33 | 57 | infected_list_overall=s.zeros(0).astype("int64") |
34 | 58 | infected_times_overall=s.zeros(0).astype("int64") |
35 | 59 |
@@ -93,7 +117,7 @@ | ||
93 | 117 | cumulative_new_infected[i]=len(set_infected) |
94 | 118 | |
95 | 119 | return [infected_list_overall,infected_times_overall,\ |
96 | - cumulative_new_infected, time_unique, susceptible] | |
120 | + cumulative_new_infected, time_unique, susceptible,susceptible_improved ] | |
97 | 121 | |
98 | 122 | |
99 | 123 |
@@ -250,6 +274,7 @@ | ||
250 | 274 | |
251 | 275 | total_infected_distr=s.zeros(len(visitor_list)).astype("int64") |
252 | 276 | total_susceptible_distr=s.zeros(len(visitor_list)).astype("int64") |
277 | + total_susceptible_distr_improved=s.zeros(len(visitor_list)).astype("int64") | |
253 | 278 | |
254 | 279 | |
255 | 280 | for visitor_iter in xrange(len(visitor_list)): |
@@ -268,10 +293,11 @@ | ||
268 | 293 | |
269 | 294 | total_infected_distr[visitor_iter]=count_infections[-1] |
270 | 295 | total_susceptible_distr[visitor_iter]=dynamic_infection[4] |
296 | + total_susceptible_distr_improved[visitor_iter]=dynamic_infection[5] | |
271 | 297 | |
272 | 298 | |
273 | 299 | |
274 | - return [total_infected_distr.astype("int64"),len(visitor_list)*s.ones(len(visitor_list)).astype("int64"),total_susceptible_distr.astype("int64")] | |
300 | + return [total_infected_distr.astype("int64"),len(visitor_list)*s.ones(len(visitor_list)).astype("int64"),total_susceptible_distr.astype("int64"),total_susceptible_distr_improved.astype("int64")] | |
275 | 301 | |
276 | 302 | |
277 | 303 | def iterate_calculation_number_infected_on_time_periods(period_list,data_laundry): |
@@ -279,6 +305,7 @@ | ||
279 | 305 | number_infected_overall=s.zeros(0).astype("int64") |
280 | 306 | number_non_isolated_overall=s.zeros(0).astype("int64") |
281 | 307 | number_susceptible_overall=s.zeros(0).astype("int64") |
308 | + number_susceptible_overall_improved=s.zeros(0).astype("int64") | |
282 | 309 | |
283 | 310 | #change period_list into an array of strings |
284 | 311 |
@@ -305,10 +332,11 @@ | ||
305 | 332 | number_non_isolated_overall=s.hstack((number_non_isolated_overall,number_non_isolated_and_infected[1])) |
306 | 333 | |
307 | 334 | number_susceptible_overall=s.hstack((number_susceptible_overall,number_non_isolated_and_infected[2])) |
335 | + number_susceptible_overall_improved=s.hstack((number_susceptible_overall_improved,number_non_isolated_and_infected[3])) | |
308 | 336 | |
309 | 337 | |
310 | 338 | return [number_infected_overall,number_non_isolated_overall,\ |
311 | - number_susceptible_overall] | |
339 | + number_susceptible_overall, number_susceptible_overall_improved] | |
312 | 340 | |
313 | 341 | |
314 | 342 |
@@ -356,12 +384,13 @@ | ||
356 | 384 | |
357 | 385 | period_list=n.loadtxt('periods_with_min_number_visitors.dat').astype('int64') |
358 | 386 | |
359 | -data_laundry=0 | |
387 | +data_laundry=1 | |
360 | 388 | number_and_number_infected=iterate_calculation_number_infected_on_time_periods(period_list,data_laundry) |
361 | 389 | |
362 | 390 | n.savetxt("number_distr_infected_overall.dat", number_and_number_infected[0], fmt="%d") |
363 | 391 | n.savetxt("number_distr_non_isolated_overall.dat", number_and_number_infected[1], fmt="%d") |
364 | 392 | n.savetxt("number_distr_susceptible_overall.dat", number_and_number_infected[2], fmt="%d") |
393 | +n.savetxt("number_distr_susceptible_overall_improved.dat", number_and_number_infected[3], fmt="%d") | |
365 | 394 | |
366 | 395 | |
367 | 396 |