diff --git a/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv b/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv deleted file mode 100644 index 012df22ce2a8dfa6be17cab0943ad1ecd8cbc175..0000000000000000000000000000000000000000 --- a/IntervalsModel/network-data/POLYMOD/AALfreqdist.csv +++ /dev/null @@ -1,19 +0,0 @@ -,Age_in,Age_out,location,0,1,2 -0,Y,Y,workschool,0.77870480731029,0.19355052310952192,0.027744669580188053 -1,Y,Y,rest,0.37273777435502503,0.33153638814016173,0.29572583750481324 -2,Y,M,workschool,0.4884488448844885,0.3536067892503536,0.15794436586515795 -3,Y,M,rest,0.2386593470095348,0.25874024848309735,0.5026004045073678 -4,Y,O,workschool,0.35185185185185186,0.2037037037037037,0.4444444444444444 -5,Y,O,rest,0.1974025974025974,0.34545454545454546,0.45714285714285713 -6,M,Y,workschool,0.49799839871897517,0.31571924206031493,0.1862823592207099 -7,M,Y,rest,0.25687518887881533,0.26624357812027805,0.4768812330009066 -8,M,M,workschool,0.4924376199616123,0.2583493282149712,0.24921305182341652 -9,M,M,rest,0.1579316799251287,0.25869599126501325,0.583372328809858 -10,M,O,workschool,0.40144927536231884,0.2246376811594203,0.3739130434782608 -11,M,O,rest,0.19285274183610598,0.30560690080098585,0.5015403573629083 -12,O,Y,workschool,0.6153846153846154,0.21794871794871795,0.16666666666666669 -13,O,Y,rest,0.2197452229299363,0.28343949044585987,0.4968152866242038 -14,O,M,workschool,0.28994082840236685,0.28994082840236685,0.42011834319526625 -15,O,M,rest,0.14428482198625858,0.27920049968769517,0.5765146783260462 -16,O,O,workschool,0.2,0.2545454545454545,0.5454545454545455 -17,O,O,rest,0.1589895988112927,0.35066864784546803,0.4903417533432392 diff --git a/IntervalsModel/network-data/POLYMOD/Duration-priors.py b/IntervalsModel/network-data/POLYMOD/Duration-priors.py index 1add443532078af5a0dffebd85db7dc73c53940e..5630a580ca2deb8fdda9f187236e876cdcdc9615 100644 --- a/IntervalsModel/network-data/POLYMOD/Duration-priors.py +++ b/IntervalsModel/network-data/POLYMOD/Duration-priors.py @@ -6,9 +6,6 @@ Created on 2021-03-11 Uses this POLYMOD duration data to deduce priors on the poisson random variables controlling individual contact durations -Determines the fraction of interactions which are daily, 3x/week or singular - in the ABM. Daily are those with frequency_mult =1, 3x/week are 2 and - singular are 3-5. @author: mark """ diff --git a/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py b/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py index 065beeded43597477a33413c628ea2e96b3ce934..b6bb77f8a7f4870266576851d0929f97cbfd7b47 100644 --- a/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py +++ b/IntervalsModel/network-data/POLYMOD/Frequency-distribution.py @@ -3,9 +3,10 @@ """ Created on 2021-03-24 -Determines the fraction of interactions which are daily, 3x/week or singular - in the ABM. Daily are those with frequency_mult =1, 3x/week are 2 and - singular are 3-5. +Determines the mixing matrices for locales_nohh for each frequency bin: + - 'daily' = key 1 + - '3xweekly' = key 2 + - 'justonce' = keys 3-5 @@ -13,7 +14,9 @@ Determines the fraction of interactions which are daily, 3x/week or singular """ import numpy as np import pandas as pd +import itertools from itertools import product +import csv # Read the cleaned survey as a dataframe Contact = pd.read_csv("AALContact_data.csv") @@ -28,7 +31,6 @@ ContAAL = {} columns = ['part_id', 'cont_id', 'age_source', 'age_target', 'duration_multi', 'frequency_multi'] for x,y,z in list(product(Ages,Ages,Locales)): - #x,y,z = symage[0], symage[1], loc C = Contact[Contact['cnt_'+z] == True][Contact['age_source']==x][Contact['age_target']==y] ContAAL[(x,y,z)] = C[columns].copy(deep=True) @@ -36,7 +38,6 @@ for x,y,z in list(product(Ages,Ages,Locales)): freqdistAAL={} locales_nohh = ['workschool', 'rest'] for x,y, z in list(product(Ages, Ages, locales_nohh)): - #x, y, z = symage[0],symage[1],loc C = ContAAL[(x,y,z)] tot = len(C) freqfull = np.full(5,0.) @@ -46,10 +47,41 @@ for x,y, z in list(product(Ages, Ages, locales_nohh)): freqdistAAL[(x,y,z)] = [freqfull[0], freqfull[1], np.sum(freqfull[2:])] +# Import Prem mixing matrices by locales_nohh +Prem = {} +with open('../Prem/wsMixing.csv', newline='') as csvfile: + Prem['workschool'] = np.array(list(csv.reader(csvfile))[1:], dtype='f') +with open('../Prem/restMixing.csv', newline='') as csvfile: + Prem['rest'] = np.array(list(csv.reader(csvfile))[1:], dtype='f') + +# Initialize mixing matrices and reindexers for age and freq bins +Mixing={} +freqbins = ['daily', '3xweekly', 'justonce'] +for loc, fbins in list(product(locales_nohh, freqbins)): + Mixing[(loc, fbins)] = np.full((3,3), 0.) +age_swap={'Y':0, 'M':1, 'O': 2} +freq_swap={'daily':0, '3xweekly':1, 'justonce':2} + +# Subdivide mixing matrices by localces_nohh and frequency +for x,y, z, fbins in list(product(Ages, Ages, locales_nohh, freqbins)): + i = age_swap[x] + j = age_swap[y] + rescale = freqdistAAL[(x,y,z)][freq_swap[fbins]] + Mixing[(z, fbins)][i][j] = rescale*Prem[z][i][j] + +# Function which flattens an array to a list +def Flatten(A): + return list(itertools.chain.from_iterable(A)) + +# Flatten the mixing subdivided mixing matrices +flat_mixing = {} +for loc, fbins in list(product(locales_nohh, freqbins)): + flat_mixing[(loc,fbins)] = Flatten(Mixing[(loc,fbins)]) + # Save them to csv -df = pd.DataFrame(list(freqdistAAL.items()), columns=['col1','col2']) +df = pd.DataFrame(list(flat_mixing.items()), columns=['col1','col2']) dfkeys = pd.DataFrame([pd.Series(x) for x in df.col1]) -dfkeys.columns = ["Age_in", "Age_out", "location"] +dfkeys.columns = ["location", "frequency"] dfvals = pd.DataFrame([pd.Series(x) for x in df.col2]) dfout = dfkeys.join(dfvals) -dfout.to_csv("AALfreqdist.csv") \ No newline at end of file +dfout.to_csv("mixing_loc-freq.csv") \ No newline at end of file diff --git a/IntervalsModel/network-data/POLYMOD/mixing_loc-freq.csv b/IntervalsModel/network-data/POLYMOD/mixing_loc-freq.csv new file mode 100644 index 0000000000000000000000000000000000000000..e45f1f98ab15cd1629bd0c4411de9f46ff52afd9 --- /dev/null +++ b/IntervalsModel/network-data/POLYMOD/mixing_loc-freq.csv @@ -0,0 +1,7 @@ +,location,frequency,0,1,2,3,4,5,6,7,8 +0,workschool,daily,3.1964647992527766,1.2547184122670996,0.006237831139178188,0.48589087391586855,2.4905386632966904,0.008553753347824449,0.0011922432682835138,0.002093297586440158,0.00442679226398468 +1,workschool,3xweekly,0.7944954598823015,0.9083386189192323,0.0036113759226821087,0.3080433568287634,1.3066202996559655,0.004786396277663501,0.0004222528241837445,0.002093297586440158,0.00563409924507141 +2,workschool,justonce,0.1138876488849416,0.40572458311725706,0.007879365649488237,0.1817533922793549,1.2604129250173148,0.007967033804110858,0.0003228992184934517,0.0030331454823928823,0.012073069810867311 +3,rest,daily,1.0168944716132233,0.3299602444066508,0.04073636423457753,0.2925992588436326,0.5125821543230763,0.15144660611690303,0.05819329875669662,0.10602850831351676,0.10606175483955847 +4,rest,3xweekly,0.904489814110522,0.3577232431793653,0.07128863741051067,0.303270525930871,0.8396222251306884,0.23999206592327127,0.07506092158472462,0.20517204855472723,0.23393059945921307 +5,rest,justonce,0.8067923080567723,0.694873904534345,0.09433684349060058,0.5432019181826497,1.8933898836230174,0.3938579468982718,0.13156745805861844,0.4236550353825799,0.327106346701442