diff options
author | Ta180m | 2020-04-30 12:19:22 -0500 |
---|---|---|
committer | Ta180m | 2020-04-30 12:19:22 -0500 |
commit | e7527775e2d87ec127b69617bff4dd396f10a2e9 (patch) | |
tree | 35040e0bd1d80ee5deeebbbd9667fd9320e966af | |
parent | 0799b67093c48157aa742c21658339d84333f2f3 (diff) |
Finally got ESIR and SEIR to work
-rw-r--r-- | COVID-19-ESIR.png | bin | 0 -> 40520 bytes | |||
-rw-r--r-- | COVID-19-SEIR.png | bin | 0 -> 39490 bytes | |||
-rw-r--r-- | README.md | 56 | ||||
-rw-r--r-- | SARS-ESIR.png | bin | 0 -> 40906 bytes | |||
-rw-r--r-- | SARS-SEIR.png | bin | 0 -> 35105 bytes | |||
-rw-r--r-- | out/COVID-19-ESIR-data.csv | 4 | ||||
-rw-r--r-- | out/COVID-19-ESIR-prediction.csv | 78 | ||||
-rw-r--r-- | out/COVID-19-SEIR-data.csv | 5 | ||||
-rw-r--r-- | out/COVID-19-SEIR-prediction.csv | 78 | ||||
-rw-r--r-- | out/SARS-ESIR-data.csv | 4 | ||||
-rw-r--r-- | out/SARS-ESIR-prediction.csv | 77 | ||||
-rw-r--r-- | out/SARS-SEIR-data.csv | 5 | ||||
-rw-r--r-- | out/SARS-SEIR-prediction.csv | 77 | ||||
-rw-r--r-- | solver2.py | 20 |
14 files changed, 394 insertions, 10 deletions
diff --git a/COVID-19-ESIR.png b/COVID-19-ESIR.png Binary files differnew file mode 100644 index 0000000..5b2d708 --- /dev/null +++ b/COVID-19-ESIR.png diff --git a/COVID-19-SEIR.png b/COVID-19-SEIR.png Binary files differnew file mode 100644 index 0000000..d44ed9d --- /dev/null +++ b/COVID-19-SEIR.png @@ -1,3 +1,59 @@ # Infectious-Disease-Modeling Original code by [JasonXu314](https://github.com/JasonXu314/covid-19-project/) and [Lewuathe](https://github.com/Lewuathe/COVID19-SIR) + +For SARS in Hong Kong use +`./solver2.py --country=Hong_Kong --popcountry=20000 --initial=1000 --disease=SARS --start=4/10/03` + +For COVID-19 in the US use +`./solver2.py --popcountry=3000000 --initial=100` + + +## Usage +``` +usage: solver2.py [-h] [--mode {SIR,Linear,ESIR,SEIR}] + [--data [{Actual,S,I,R,E} [{Actual,S,I,R,E} ...]]] + [--folder FOLDER] [--disease DISEASE] [--out OUT] + [--start START] [--end END] [--incubation INCUBATION_PERIOD] + [--predict PREDICTION_RANGE] [--country COUNTRY] + [--popcountry POPCOUNTRY] [--popmodel POPMODEL] + [--initial INITIAL] + +optional arguments: + -h, --help show this help message and exit + --mode {SIR,Linear,ESIR,SEIR}, -m {SIR,Linear,ESIR,SEIR} + change the mode of the model (SIR, Linear, ESIR, + SEIR); default: SIR + --data [{Actual,S,I,R,E} [{Actual,S,I,R,E} ...]], -d [{Actual,S,I,R,E} [{Actual,S,I,R,E} ...]] + change the type of data to present in the graph + (Actual, S, I, R, E); default: Actual S I R + --folder FOLDER, -f FOLDER + the folder in which to find the data files; defaults + to looking in the data folder + --disease DISEASE, -D DISEASE + the disease to model; defaults to COVID-19 + --out OUT, -o OUT the name of the graph and csv files; defaults to the + name of the disease + --start START, -s START + the date where the data starts (defaults to the start + date of COVID-19 (1/22/20)) + --end END, -e END the date where the data stops (defaults to whereever + the input data ends) + --incubation INCUBATION_PERIOD, -i INCUBATION_PERIOD + the incubation period of the disease (only applicable + if using SIRE model; ignored otherwise); none by + default + --predict PREDICTION_RANGE, -p PREDICTION_RANGE + the number of days to predict the course of the + disease (defaults to None, meaning the model will not + predict beyond the given data) + --country COUNTRY, -c COUNTRY + the country that is being modeled (defaults to US) + --popcountry POPCOUNTRY, -pc POPCOUNTRY + the population of the country (defaults to US + population) + --popmodel POPMODEL, -pm POPMODEL + the population of the model (defaults to 10000) + --initial INITIAL, -I INITIAL + initial infected people (defaults to 1) +```
\ No newline at end of file diff --git a/SARS-ESIR.png b/SARS-ESIR.png Binary files differnew file mode 100644 index 0000000..b334cb1 --- /dev/null +++ b/SARS-ESIR.png diff --git a/SARS-SEIR.png b/SARS-SEIR.png Binary files differnew file mode 100644 index 0000000..b0187aa --- /dev/null +++ b/SARS-SEIR.png diff --git a/out/COVID-19-ESIR-data.csv b/out/COVID-19-ESIR-data.csv new file mode 100644 index 0000000..e16f0d7 --- /dev/null +++ b/out/COVID-19-ESIR-data.csv @@ -0,0 +1,4 @@ +Beta: 0.11506079905613333 +Gamma: 0.004485002592721715 +Mu: 1e-08 +R0: 25.654509698111923
\ No newline at end of file diff --git a/out/COVID-19-ESIR-prediction.csv b/out/COVID-19-ESIR-prediction.csv new file mode 100644 index 0000000..15ad69e --- /dev/null +++ b/out/COVID-19-ESIR-prediction.csv @@ -0,0 +1,78 @@ +,Actual,S,I,R +1/22/20,0.0033333333333333335,9999.666666666666,0.33333333333333337,0.0 +1/23/20,0.0033333333333333335,9999.626113386881,0.37230581397620527,0.0015807991430292917 +1/24/20,0.006666666666666667,9999.58081926442,0.4158343279178975,0.0033464076627307353 +1/25/20,0.006666666666666667,9999.530230241262,0.46445133279667583,0.005318425940276048 +1/26/20,0.016666666666666666,9999.47370935019,0.5187689595900552,0.007521690219182955 +1/27/20,0.016666666666666666,9999.410195932789,0.5798064388452426,0.009997628365004882 +1/28/20,0.016666666666666666,9999.339138100348,0.6480941545637604,0.012767745089180731 +1/29/20,0.016666666666666666,9999.260059689912,0.7240897547339856,0.01585055535425662 +1/30/20,0.016666666666666666,9999.172252932163,0.8084734505330113,0.019273617303852183 +1/31/20,0.023333333333333334,9999.074778451411,0.902148016326647,0.023073532262660536 +2/1/20,0.02666666666666667,9998.966465265594,1.0062387896694178,0.0272959447364483 +2/2/20,0.02666666666666667,9998.845910786284,1.122093671304566,0.03199554241205561 +2/3/20,0.03666666666666667,9998.711480818678,1.251283125164049,0.03723605615739605 +2/4/20,0.03666666666666667,9998.56130956161,1.3956001783685417,0.043090260021456786 +2/5/20,0.03666666666666667,9998.393299607538,1.5570604212274348,0.0496399712342984 +2/6/20,0.03666666666666667,9998.205121942554,1.737902007238834,0.056976050207055 +2/7/20,0.03666666666666667,9997.994215946379,1.9405856530895627,0.06519840053193422 +2/8/20,0.03666666666666667,9997.757789392363,2.1677946386551605,0.07441596898221718 +2/9/20,0.03666666666666667,9997.492818447488,2.4224348069998825,0.08474674551225844 +2/10/20,0.03666666666666667,9997.196047672365,2.7076345643767,0.09631776325748614 +2/11/20,0.04,9996.863990021238,3.0267448802273016,0.1092650985344019 +2/12/20,0.04,9996.492926841978,3.38333928718209,0.12373387084058081 +2/13/20,0.043333333333333335,9996.078907876084,3.781213881060188,0.13987824285467146 +2/14/20,0.043333333333333335,9995.617751258695,4.224387320869431,0.157861420436396 +2/15/20,0.043333333333333335,9995.100289480084,4.721661948385379,0.17804857153125916 +2/16/20,0.043333333333333335,9994.516819794286,5.282354253776822,0.20082595193720937 +2/17/20,0.043333333333333335,9993.866243817323,5.907527234907954,0.2262289477694925 +2/18/20,0.043333333333333335,9993.145311395869,6.600310380400788,0.25437822373033286 +2/19/20,0.043333333333333335,9992.348460820938,7.366052973091157,0.2854862059703617 +2/20/20,0.043333333333333335,9991.467818827883,8.212324090028714,0.3198570820886177 +2/21/20,0.05,9990.493200596391,9.14891260247693,0.35788680113254645 +2/22/20,0.05,9989.41210975049,10.187827175913094,0.4000630735980009 +2/23/20,0.05,9988.209738358544,11.343296270028326,0.44696537142924114 +2/24/20,0.05,9986.868966933253,12.631768138727548,0.49926492801893446 +2/25/20,0.05,9985.370364431663,14.071910830129516,0.5577247382081553 +2/26/20,0.05,9983.692188255147,15.684612186566797,0.6231995582863851 +2/27/20,0.05333333333333334,9981.810384249424,17.492979844585772,0.6966359059915124 +2/28/20,0.05333333333333334,9979.698586704544,19.522341234946662,0.7790720605098338 +2/29/20,0.08,9977.3281183549,21.800243582623494,0.8716380624760518 +3/1/20,0.1,9974.667990379223,24.356453906804106,0.9755557139732771 +3/2/20,0.17666666666666667,9971.684902400577,27.222959020890176,1.0921385785330266 +3/3/20,0.24333333333333335,9968.343242486368,30.43396553249719,1.222791981135226 +3/4/20,0.3466666666666667,9964.605087148337,34.02589984345444,1.369013008208206 +3/5/20,0.5733333333333334,9960.430201342566,38.03740814980507,1.5323905076287054 +3/6/20,0.7233333333333334,9955.776038469472,42.50935644180602,1.7146050887218716 +3/7/20,1.12,9950.59774037381,47.48483050392804,1.9174291222612567 +3/8/20,1.5,9944.844563782051,53.01250683519244,2.1429293827570484 +3/9/20,1.7133333333333334,9938.429109001789,59.17581074493476,2.3950802532771633 +3/10/20,2.3600000000000003,9931.28410971237,66.03953431726215,2.676355970369462 +3/11/20,3.6833333333333336,9923.337492154149,73.673190586763,2.9893172590894515 +3/12/20,5.19,9914.501469396979,82.16127704189319,3.3372535611291965 +3/13/20,7.156666666666667,9904.672541340207,91.60327562497613,3.724183034817316 +3/14/20,9.523333333333333,9893.731494712678,102.1136527322028,4.15485255511899 +3/15/20,9.726666666666667,9881.543403072734,113.82185921363165,4.634737713635952 +3/16/20,14.356666666666667,9867.957626808206,126.87233037318875,5.170042818606493 +3/17/20,20.32,9852.807813136427,141.42448596866763,5.767700894905462 +3/18/20,29.576666666666668,9835.911896104228,157.65273021172933,6.435373684044263 +3/19/20,46.980000000000004,9817.072096587928,175.74645176790264,7.181451644170861 +3/20/20,64.67666666666668,9796.074922293348,195.91002375658354,8.015053950069769 +3/21/20,85.75,9772.691167755802,218.36280375103587,8.946028493162066 +3/22/20,112.11333333333334,9746.675914340105,243.33913377839076,9.984951881505387 +3/23/20,145.54333333333335,9717.76853024056,271.088340319647,11.143129439793915 +3/24/20,179.12,9685.692670480972,301.8747343096709,12.432595209358398 +3/25/20,219.26000000000002,9650.156276914639,335.9776111371963,13.866111948166141 +3/26/20,279.4533333333334,9610.854601775942,373.6880684074213,15.457329816637479 +3/27/20,338.8566666666667,9567.476342716238,415.2991688314755,17.224488452287385 +3/28/20,404.9266666666667,9519.552038843865,461.26051676003846,19.18744439609663 +3/29/20,469.6966666666667,9466.572446747607,512.0603658715773,21.367187380816706 +3/30/20,539.4566666666667,9408.027732312834,568.1854772150563,23.786790472111093 +3/31/20,627.24,9343.40747072151,630.121119209935,26.47141006855526 +4/1/20,711.2066666666667,9272.200646452193,698.3510676461705,29.448285901636666 +4/2/20,812.0533333333334,9193.895653280031,773.3576056842154,32.74674103575474 +4/3/20,918.6066666666667,9107.98029427676,855.621523855019,36.39818186822094 +4/4/20,1029.4833333333333,9013.941781810714,945.6221200600273,40.43609812925864 +4/5/20,1123.5500000000002,8911.266737546815,1043.8371995711823,44.89606288200328 +4/6/20,1222.2,8799.441192446577,1150.7430750309222,49.81573252250221 +4/7/20,1320.7366666666667,8677.950586768104,1266.8145664521824,55.23484677971486 diff --git a/out/COVID-19-SEIR-data.csv b/out/COVID-19-SEIR-data.csv new file mode 100644 index 0000000..98e5f69 --- /dev/null +++ b/out/COVID-19-SEIR-data.csv @@ -0,0 +1,5 @@ +Beta: 0.11054937398441604 +Gamma: 1e-08 +Mu: 1e-08 +Sigma: 0.0009697697322082875 +R0: 5527411.7020644825
\ No newline at end of file diff --git a/out/COVID-19-SEIR-prediction.csv b/out/COVID-19-SEIR-prediction.csv new file mode 100644 index 0000000..216cf0d --- /dev/null +++ b/out/COVID-19-SEIR-prediction.csv @@ -0,0 +1,78 @@ +,Actual,S,I,R +1/22/20,0.0033333333333333335,9999.666666666666,0.33333333333333337,0.0 +1/23/20,0.0033333333333333335,9999.627703932636,0.3722960708871821,-7.047500503241619e-09 +1/24/20,0.006666666666666667,9999.584187413606,0.41581259384888014,-1.49152950354593e-08 +1/25/20,0.006666666666666667,9999.535585180327,0.464414831515325,-2.3699210398033534e-08 +1/26/20,0.016666666666666666,9999.481297402239,0.5187026144994259,-3.350731144359509e-08 +1/27/20,0.016666666666666666,9999.420271502591,0.5797285196504275,-4.452958089143598e-08 +1/28/20,0.016666666666666666,9999.35189874109,0.648101287311564,-5.6875709818881055e-08 +1/29/20,0.016666666666666666,9999.275787997143,0.7242120381115329,-7.061590659430941e-08 +1/30/20,0.016666666666666666,9999.191314730966,0.808685311894688,-8.586249552376956e-08 +1/31/20,0.023333333333333334,9999.09762098357,0.9023790677210395,-1.0276991685097948e-07 +2/1/20,0.02666666666666667,9998.99361537678,1.0063846838662542,-1.2153472675732646e-07 +2/2/20,0.02666666666666667,9998.877973113224,1.1220269578216555,-1.4239559736186735e-07 +2/3/20,0.03666666666666667,9998.749135976333,1.2508641062942234,-1.6563331672132827e-07 +2/4/20,0.03666666666666667,9998.605312330348,1.3946877652065937,-1.9157078883010485e-07 +2/5/20,0.03666666666666667,9998.444477120309,1.5555229896970593,-2.205730336202621e-07 +2/6/20,0.03666666666666667,9998.264371872068,1.7356282541195687,-2.5304718696153445e-07 +2/7/20,0.03666666666666667,9998.062504692276,1.9374954520437282,-2.8944250066132573e-07 +2/8/20,0.03666666666666667,9997.836150268393,2.1638498962547996,-3.302503424647093e-07 +2/9/20,0.03666666666666667,9997.582349868684,2.4176503187537017,-3.760041960544277e-07 +2/10/20,0.03666666666666667,9997.29791134222,2.702088870757009,-4.272796610508932e-07 +2/11/20,0.04,9996.979409118876,3.020591122696953,-4.846944530121872e-07 +2/12/20,0.04,9996.623184209333,3.3768160642214227,-5.489084034340606e-07 +2/13/20,0.043333333333333335,9996.225344205073,3.7746561041939612,-6.206234597499338e-07 +2/14/20,0.043333333333333335,9995.781763278394,4.21823707069377,-7.005836853308967e-07 +2/15/20,0.043333333333333335,9995.2878763168,4.71212407662139,-7.89614001491647e-07 +2/16/20,0.043333333333333335,9994.729673252885,5.270327190678028,-8.903154346461404e-07 +2/17/20,0.043333333333333335,9994.101593223397,5.898407276621259,-1.003694924017184e-06 +2/18/20,0.043333333333333335,9993.402844646575,6.597155916258238,-1.1298515769493453e-06 +2/19/20,0.043333333333333335,9992.630113810632,7.369886821656041,-1.2693480407207008e-06 +2/20/20,0.043333333333333335,9991.777564873753,8.222435835141674,-1.4232105025428344e-06 +2/21/20,0.05,9990.836839864092,9.163160929302064,-1.592928689560839e-06 +2/22/20,0.05,9989.797058679776,10.202942206984064,-1.780455868853314e-06 +2/23/20,0.05,9988.644819088899,11.355181901294454,-1.9882088474323683e-06 +2/24/20,0.05,9987.364196729528,12.635804375599937,-2.2190679722436185e-06 +2/25/20,0.05,9985.936745109704,14.063256123527145,-2.476377130166188e-06 +2/26/20,0.05,9984.341495607432,15.658505768962627,-2.7639437480127095e-06 +2/27/20,0.05333333333333334,9982.554957470695,17.445044066052862,-3.0860387925293243e-06 +2/28/20,0.05333333333333334,9980.55111781744,19.448883899204265,-3.4473967703956814e-06 +2/29/20,0.08,9978.30144163559,21.698560283083154,-3.8532157282249365e-06 +3/1/20,0.1,9975.774871783038,24.22513036261579,-4.309157252563754e-06 +3/2/20,0.17666666666666667,9972.937828987646,27.06217341298835,-4.821346469892306e-06 +3/3/20,0.24333333333333335,9969.754211847247,30.24579083964694,-5.396372046624275e-06 +3/4/20,0.3466666666666667,9966.185396829644,33.81460617829759,-6.0412861891068505e-06 +3/5/20,0.5733333333333334,9962.190238272617,37.80976509490626,-6.763604643620727e-06 +3/6/20,0.7233333333333334,9957.725068383907,42.27493538569881,-7.571306696380109e-06 +3/7/20,1.12,9952.743697241232,47.25630697716109,-8.472835173532714e-06 +3/8/20,1.5,9947.197412792282,52.80259192603878,-9.477096441159757e-06 +3/9/20,1.7133333333333334,9941.034980854713,58.96502441933756,-1.0593460405275972e-05 +3/10/20,2.3600000000000003,9934.18467876412,65.81532712971975,-1.183852492577203e-05 +3/11/20,3.6833333333333336,9926.555298283798,73.44470830443369,-1.3233477649315049e-05 +3/12/20,5.19,9918.079803623716,81.92020373762848,-1.4786587842158435e-05 +3/13/20,7.156666666666667,9908.673492617427,91.32651560183623,-1.6510067880203516e-05 +3/14/20,9.523333333333333,9898.232818699395,101.7671904708687,-1.842053697925139e-05 +3/15/20,9.726666666666667,9886.635390904994,113.3646193198174,-2.0539021195002944e-05 +3/16/20,14.356666666666667,9873.739973870519,126.26003752505356,-2.2890953423058815e-05 +3/17/20,20.32,9859.38648783317,140.61352486422825,-2.5506173398919426e-05 +3/18/20,29.576666666666668,9843.396008631062,156.6040055162721,-2.8418927697984978e-05 +3/19/20,46.980000000000004,9825.570767703222,174.42924806139555,-3.1667869735555426e-05 +3/20/20,64.67666666666668,9805.694152089593,194.30586548108883,-3.52960597668305e-05 +3/21/20,85.75,9783.530704431025,216.4693151581218,-3.935096488690971e-05 +3/22/20,112.11333333333334,9758.826122969287,241.17389887654403,-4.3884459030792356e-05 +3/23/20,145.54333333333335,9731.307261547056,268.69276282168505,-4.895282297337746e-05 +3/24/20,179.12,9700.682129607925,299.3178975801538,-5.461674432946389e-05 +3/25/20,219.26000000000002,9666.639892196396,333.3601381398392,-6.094131755375021e-05 +3/26/20,279.4533333333334,9628.850869957887,371.14916388990974,-6.79960439408348e-05 +3/27/20,338.8566666666667,9586.966539138728,413.0334986208137,-7.585483162521576e-05 +3/28/20,404.9266666666667,9540.61953158616,459.38051052427915,-8.459599558129106e-05 +3/29/20,469.6966666666667,9489.423634748338,510.57641219331373,-9.430225762335835e-05 +3/30/20,539.4566666666667,9432.973791674332,567.0262606222051,-0.00010506074640561513 +3/31/20,627.24,9370.837885356395,629.1621728661532,-0.00011696683699850675 +4/1/20,711.2066666666667,9302.453787425597,697.5462773648485,-0.00013016277267359017 +4/2/20,812.0533333333334,9227.237783759485,772.7622883097854,-0.0001447873339664349 +4/3/20,918.6066666666667,9144.626035134926,855.3740449945691,-0.0001609821841327032 +4/4/20,1029.4833333333333,9054.062771173381,945.9373178735826,-0.00017889981322058814 +4/5/20,1123.5500000000002,8955.000290340902,1044.9998085619877,-0.0001987035380708135 +4/6/20,1222.2,8846.898959948136,1153.1011498357243,-0.00022056750231663365 +4/7/20,1320.7366666666667,8729.227216150326,1270.772905631511,-0.0002446766763838338 diff --git a/out/SARS-ESIR-data.csv b/out/SARS-ESIR-data.csv new file mode 100644 index 0000000..3ec411f --- /dev/null +++ b/out/SARS-ESIR-data.csv @@ -0,0 +1,4 @@ +Beta: 0.2367418297398915 +Gamma: 0.08679182290949222 +Mu: 0.10967338538708958 +R0: 1.205006381498899
\ No newline at end of file diff --git a/out/SARS-ESIR-prediction.csv b/out/SARS-ESIR-prediction.csv new file mode 100644 index 0000000..53f7c9b --- /dev/null +++ b/out/SARS-ESIR-prediction.csv @@ -0,0 +1,77 @@ +,Actual,S,I,R +4/10/03,499.0,9500.0,500.0,0.0 +4/11/03,529.5,9444.227075391838,514.0807218021808,41.692202805979804 +4/12/03,554.0,9391.905808241256,527.8835492084675,80.21064255027629 +4/14/03,595.0,9342.737831622848,541.4072053704581,115.85496300669492 +4/15/03,616.0,9296.461524712588,554.6500653009963,148.88840998641558 +4/16/03,634.0,9252.833038871782,567.6114509240942,179.55551020412332 +4/17/03,648.5,9211.626297647057,580.2916310749339,208.0820712780086 +4/18/03,679.0,9172.632996770366,592.6918214998664,234.67518172976713 +4/19/03,679.0,9135.662331729156,604.8142120510969,259.52345621974825 +4/21/03,701.0,9100.538906279773,616.661803432948,282.7992902872789 +4/22/03,717.0,9067.13469857277,628.2339699615961,304.63133146563365 +4/23/03,729.0,9035.339039006762,639.5295862771557,325.1313747160836 +4/24/03,744.0,9005.045849005795,650.5484116967016,344.4057392975029 +4/25/03,755.0,8976.153641019362,661.2910902142701,362.55526876636844 +4/26/03,763.5,8948.565518522382,671.7591505008583,379.6753309767601 +4/28/03,778.5,8922.189176015216,681.9550059044246,395.85581808036096 +4/29/03,786.0,8896.936899023654,691.8819544498883,411.18114652645676 +4/30/03,794.5,8872.725564098935,701.5441788391297,425.73025706193647 +5/1/03,800.0,8849.478888723479,710.9463510728079,439.5747602037145 +5/2/03,805.5,8827.14745312997,720.090062772033,452.76248409799797 +5/3/03,810.5,8805.695796844215,728.9755008085773,465.32870234720815 +5/5/03,818.5,8785.088747242953,737.603489787653,477.3077629693951 +5/6/03,823.0,8765.291327948718,745.9754989197179,488.73317313156366 +5/7/03,827.0,8746.268758829852,754.0936420204754,499.6375991496741 +5/8/03,830.5,8727.986456000484,761.9606775108748,510.0528664886416 +5/9/03,833.5,8710.410031820553,769.5800084171109,520.0099597623364 +5/10/03,837.0,8693.505294895791,776.9556823706242,529.5390227335843 +5/12/03,841.5,8677.238250077733,784.0923916081009,538.6693583141655 +5/13/03,844.5,8661.57509846371,790.9954729714727,547.4294285648159 +5/14/03,849.0,8646.482237396856,797.6709079079174,555.8468546952263 +5/15/03,851.5,8631.927789194468,804.1249923666973,563.947218438836 +5/16/03,853.0,8617.900552990895,810.3602263578307,571.7392206512744 +5/17/03,855.0,8604.389661478894,816.3794458484228,579.2308926726835 +5/19/03,857.0,8591.38120322021,822.186326607322,586.4324701724694 +5/20/03,859.0,8578.86118446475,827.7847315642418,593.3540839710073 +5/21/03,859.5,8566.815529150595,833.1787108097622,600.0057600396423 +5/22/03,861.0,8555.230078903982,838.3725015953288,606.3974195006882 +5/23/03,862.0,8544.090593039318,843.3705283332534,612.5388786274285 +5/24/03,862.0,8533.38274855917,848.1774025967143,618.4398488441157 +5/26/03,863.0,8523.092140154273,852.7979231197548,624.1099367259716 +5/27/03,864.0,8513.204280203528,857.2370757972849,629.5586439991877 +5/28/03,865.0,8503.704598773995,861.5000336850803,634.7953675409241 +5/29/03,866.0,8494.578443620907,865.5921569997828,639.8293993793109 +5/30/03,868.0,8485.811080187654,869.5189931189004,644.6699266934471 +5/31/03,869.5,8477.387691605792,873.2862765808067,649.3260318134012 +6/2/03,873.0,8469.293378695049,876.8999290847415,653.8066922202106 +6/3/03,873.5,8461.514710595857,880.3657431994991,658.1195462046451 +6/4/03,874.0,8454.059819074075,883.6850464724492,662.2551344534753 +6/5/03,874.0,8446.921131132256,886.8619225328471,666.2169463348977 +6/6/03,875.0,8440.083849838937,889.9018399182116,670.0143102428513 +6/9/03,876.5,8433.533919320269,892.8100859584927,673.6559947212374 +6/10/03,877.0,8427.258024760009,895.5917667760718,677.1502084639196 +6/11/03,877.0,8421.243592399516,898.2518072857611,680.5046003147232 +6/12/03,877.5,8415.47878953776,900.7949511948042,683.7262592674355 +6/13/03,877.5,8409.952524531318,903.2257610028759,686.8217144658064 +6/16/03,877.5,8404.654446794371,905.5486180020819,689.7969352035472 +6/17/03,877.5,8399.57494679871,907.7677222769591,692.6573309243319 +6/18/03,877.5,8394.705156073727,909.8870927044758,695.4077512217959 +6/19/03,877.5,8390.03694720643,911.9105669540312,698.0524858395376 +6/20/03,877.5,8385.56293384143,913.8418014874555,700.5952646711165 +6/23/03,877.5,8381.276470680936,915.6842715590107,703.0392577600547 +6/24/03,877.5,8377.171653484775,917.441271215389,705.3870752998363 +6/25/03,877.5,8373.24331907038,919.1159132957147,707.6407676339073 +6/26/03,877.5,8369.487045312782,920.7111294315423,709.8018252556759 +6/27/03,877.5,8365.89915114463,922.2296700468584,711.8711788085125 +6/30/03,877.5,8362.476696556172,923.67410435808,713.8491990857493 +7/1/03,877.5,8359.217482595266,925.0468203740556,715.7356970306806 +7/2/03,877.5,8356.120051367374,926.3500248960648,717.529923736563 +7/3/03,877.5,8353.183686035569,927.5857435178184,719.230570446615 +7/4/03,877.5,8350.408410820526,928.755820625458,720.8357685540174 +7/7/03,877.5,8347.783048558855,929.8641820396883,722.3527694014589 +7/8/03,877.5,8345.282144812525,930.9172920980251,723.8005630894507 +7/9/03,877.5,8342.899946870173,931.9177326215087,725.1823205083202 +7/10/03,877.5,8340.631421707416,932.8678948596776,726.5006834329073 +7/11/03,877.5,8338.471712715169,933.7700836254672,727.7582036593645 +8/7/03,877.5,8336.416139699633,934.6265172952101,728.9573430051577 diff --git a/out/SARS-SEIR-data.csv b/out/SARS-SEIR-data.csv new file mode 100644 index 0000000..face094 --- /dev/null +++ b/out/SARS-SEIR-data.csv @@ -0,0 +1,5 @@ +Beta: 0.01082548864886504 +Gamma: 1e-08 +Mu: 1e-08 +Sigma: 0.0010246938312194157 +R0: 541269.1501908005
\ No newline at end of file diff --git a/out/SARS-SEIR-prediction.csv b/out/SARS-SEIR-prediction.csv new file mode 100644 index 0000000..fb009fd --- /dev/null +++ b/out/SARS-SEIR-prediction.csv @@ -0,0 +1,77 @@ +,Actual,S,I,R +4/10/03,499.0,9500.0,500.0,0.0 +4/11/03,529.5,9494.832776379075,505.16722864414726,-1.0049017893654477e-05 +4/12/03,554.0,9489.615021231453,510.38498886174114,-2.0196708490327354e-05 +4/14/03,595.0,9484.346299922172,515.6537152881966,-3.044403329478051e-05 +4/15/03,616.0,9479.026175635721,520.9738447394818,-4.07919681313532e-05 +4/16/03,634.0,9473.654208751632,526.3458168365376,-5.124149936138442e-05 +4/17/03,648.5,9468.229956265563,531.7700745841634,-6.179360882997584e-05 +4/18/03,679.0,9462.752972916978,537.247063243363,-7.244928711449601e-05 +4/19/03,679.0,9457.222811208285,542.7772303122033,-8.320953379882134e-05 +4/21/03,701.0,9451.639021404832,548.3610255258131,-9.407535747333604e-05 +4/22/03,717.0,9446.001151534903,553.9989008563845,-0.00010504777573493214 +4/23/03,729.0,9440.30874738973,559.6913105131715,-0.00011612781518700943 +4/24/03,744.0,9434.561352523486,565.4387109424914,-0.00012731651143947555 +4/25/03,755.0,9428.758508253284,571.2415608277236,-0.0001386149091087459 +4/26/03,763.5,9422.899753659178,577.1003210893101,-0.00015002406181774378 +4/28/03,778.5,9416.984625584166,583.0154548847557,-0.0001615450321959002 +4/29/03,786.0,9411.012658634185,588.9874276086279,-0.00017317889187915396 +4/30/03,794.5,9404.983385178115,595.0167068925563,-0.00018492672150995177 +5/1/03,800.0,9398.896335347777,601.1037626052337,-0.0001967896107372481 +5/2/03,805.5,9392.751037037935,607.249066852415,-0.00020876865821650522 +5/3/03,810.5,9386.547015906293,613.4530939769181,-0.00022086497160969318 +5/5/03,818.5,9380.283795373496,619.7163205586231,-0.0002330796675852899 +5/6/03,823.0,9373.960896623134,626.039225414473,-0.000245413871818281 +5/7/03,827.0,9367.577838601735,632.4222895984733,-0.00025786871899016007 +5/8/03,830.5,9361.134138018771,638.865996401692,-0.00027044535278892835 +5/9/03,833.5,9354.629309346652,645.3708313522598,-0.000283144925909095 +5/10/03,837.0,9348.062864820737,651.93728221537,-0.00029596860005167694 +5/12/03,841.5,9341.434314439317,658.5658389932785,-0.0003089175459241988 +5/13/03,844.5,9334.743165963633,665.2569939253037,-0.00032199294324069313 +5/14/03,849.0,9327.988924917861,672.0112414878266,-0.0003351959807217004 +5/15/03,851.5,9321.171094589126,678.8290783942911,-0.00034852785609426867 +5/16/03,853.0,9314.289176027485,685.711003595203,-0.00036198977609195373 +5/17/03,855.0,9307.342668079065,692.6575182450104,-0.00037558295647366943 +5/19/03,857.0,9300.331096358257,699.669096729908,-0.0003893086386532089 +5/20/03,859.0,9293.253974616735,706.746225298807,-0.00040316806803868246 +5/21/03,859.5,9286.110787611027,713.8894191957595,-0.00041716248377624443 +5/22/03,861.0,9278.90101970139,721.0991940611004,-0.0004312931348895171 +5/23/03,862.0,9271.6241548518,728.3760659314465,-0.0004455612802795907 +5/24/03,862.0,9264.279676629953,735.7205512396977,-0.00045996818872502313 +5/26/03,863.0,9256.86706820727,743.1331668150356,-0.0004745151388818404 +5/27/03,864.0,9249.385812358894,750.6144298829247,-0.0004892034192835363 +5/28/03,865.0,9241.83539146369,758.1648580651118,-0.0005040343283410723 +5/29/03,866.0,9234.215287504241,765.7849693796263,-0.0005190091743428781 +5/30/03,868.0,9226.52498206686,773.47528224078,-0.0005341292754548511 +5/31/03,869.5,9218.763956341574,781.2363154591667,-0.0005493959597203565 +6/2/03,873.0,9210.931691122136,789.0685882416632,-0.0005648105650602276 +6/3/03,873.5,9203.027666806023,796.9726201914284,-0.0005803744392727652 +6/4/03,874.0,9195.05136339443,804.9489313079039,-0.0005960889400337384 +6/5/03,874.0,9187.002260492278,812.9980419868135,-0.0006119554348963837 +6/6/03,875.0,9178.879837308206,821.1204730201633,-0.0006279753012914061 +6/9/03,876.5,9170.68357265458,829.3167455962424,-0.0006441499265269778 +6/10/03,877.0,9162.41294494748,837.5873812996218,-0.0006604807077887393 +6/11/03,877.0,9154.067432206719,845.932902111155,-0.000676969052139799 +6/12/03,877.5,9145.646512055824,854.3538304079781,-0.000693616376520733 +6/13/03,877.5,9137.14966172205,862.8506889635098,-0.000710424107749585 +6/16/03,877.5,9128.576358036364,871.4240009474506,-0.0007273936825218674 +6/17/03,877.5,9119.926077433467,880.0742899257843,-0.0007445265474105596 +6/18/03,877.5,9111.198295951777,888.8020798607764,-0.0007618241588661093 +6/19/03,877.5,9102.392489233433,897.6078951109752,-0.0007792879832164324 +6/20/03,877.5,9093.508132524295,906.4922604312112,-0.0007969194966669115 +6/23/03,877.5,9084.544700673952,915.4557009725976,-0.0008147201853003983 +6/24/03,877.5,9075.501668135706,924.4987422825302,-0.0008326915450772123 +6/25/03,877.5,9066.378508966589,933.6219103046864,-0.0008508350818351401 +6/26/03,877.5,9057.174696827351,942.8257313790269,-0.0008691523112894365 +6/27/03,877.5,9047.88970498246,952.1107322417946,-0.0008876447590328244 +6/30/03,877.5,9038.523006300118,961.4774400255145,-0.0009063139605354945 +7/1/03,877.5,9029.074073252237,970.9263822589945,-0.0009251614611451053 +7/2/03,877.5,9019.542377914458,980.4580868673245,-0.0009441888160867831 +7/3/03,877.5,9009.927391966141,990.0730821718771,-0.000963397590463122 +7/4/03,877.5,9000.228586690371,999.7718968903075,-0.0009827893592541843 +7/7/03,877.5,8990.445432973953,1009.5550601365533,-0.0010023657073175002 +7/8/03,877.5,8980.577401307413,1019.4231014208335,-0.0010221282293880673 +7/9/03,877.5,8970.623961785,1029.3765506496513,-0.0010420785300783515 +7/10/03,877.5,8960.58458410469,1039.4159381257912,-0.001062218223878286 +7/11/03,877.5,8950.458737568173,1049.5417945483198,-0.0010825489351552733 +8/7/03,877.5,8940.245891080865,1059.7546510125874,-0.0011030722981541815 @@ -23,7 +23,7 @@ parser.add_argument('--predict', '-p', dest = 'prediction_range', default = None parser.add_argument('--country', '-c', dest = 'country', default = 'US', help = 'the country that is being modeled (defaults to US)') parser.add_argument('--popcountry', '-pc', dest = 'popcountry', default = '3328200000', help = 'the population of the country (defaults to US population)') parser.add_argument('--popmodel', '-pm', dest = 'popmodel', default = '10000', help = 'the population of the model (defaults to 10000)') -parser.add_argument('--initial', '-I', dest = 'initial', default = '1', help = 'initial infected people (defaults to 1') +parser.add_argument('--initial', '-I', dest = 'initial', default = '1', help = 'initial infected people (defaults to 1)') args = parser.parse_args() # Running a model for a million population is quite hard, so here we've reduced the population and modified the actual stats to match @@ -131,7 +131,7 @@ class Learner(object): extended_actual = np.concatenate((data.values.flatten(), [0] * (size - len(data.values)))) if args.mode == 'SEIR': - result = solve_ivp(model, [0, size], [S_0,I_0,R_0, E_0], t_eval=np.arange(0, size, 1)) + result = solve_ivp(model, [0, size], [S_0,I_0,R_0,E_0], t_eval=np.arange(0, size, 1)) else: result = solve_ivp(model, [0, size], [S_0,I_0,R_0], t_eval=np.arange(0, size, 1), vectorized=True) @@ -193,18 +193,18 @@ class Learner(object): with open(f'out/{args.disease}-{args.mode}-data.csv', 'w+') as file: file.write(f'Beta: {beta}\nGamma: {gamma}\nMu: {mu}\nR0: {beta/(gamma + mu)}') elif args.mode == 'SEIR': - exposed_data = self.load_exposed(self.country) + # exposed_data = self.load_exposed(self.country) optimal = minimize( loss_seir, - [0.001, 0.001], - args=(confirmed_data, recovered_data, exposed_data), + [0.001, 0.001, 0.001, 0.001], + args=(confirmed_data, recovered_data), method='L-BFGS-B', bounds=[(0.00000001, 0.4), (0.00000001, 0.4), (0.00000001, 0.4), (0.00000001, 0.4)] ) beta, gamma, mu, sigma = optimal.x print(f'Beta: {beta}, Gamma: {gamma}, Mu: {mu}, Sigma: {sigma} R0: {(beta * sigma)/((mu + gamma) * (mu + sigma))}') - new_index, extended_actual, prediction = self.predict(confirmed_data, beta = beta, gamma = gamma, mu = mu) + new_index, extended_actual, prediction = self.predict(confirmed_data, beta = beta, gamma = gamma, mu = mu, sigma = sigma) print(f'Predicted I: {prediction.y[1][-1] * int(args.popmodel)}, Actual I: {extended_actual[-1] * correction_factor}') df = compose_df(prediction, extended_actual, correction_factor, new_index) with open(f'out/{args.disease}-{args.mode}-data.csv', 'w+') as file: @@ -280,7 +280,7 @@ def loss_esir(point, confirmed, recovered): sol_rec = np.sqrt(np.mean((solution.y[2] - (recovered.values * correction_factor/int(args.popmodel)))**2)) return sol_inf * 0.5 + sol_rec * 0.5 -def loss_seir(point, confirmed, recovered, exposed): +def loss_seir(point, confirmed, recovered): size = len(confirmed) beta, gamma, mu, sigma = point def model(t, y): @@ -289,11 +289,11 @@ def loss_seir(point, confirmed, recovered, exposed): R = y[2] E = y[3] return [mu - beta * S * I - mu * S, beta * S * I - sigma * E - mu * E, sigma * E * I - gamma * I - mu * I, gamma * I - mu * R] - solution = solve_ivp(model, [0, size], [S_0,E_0,I_0,R_0], t_eval=np.arange(0, size, 1), vectorized=True) + solution = solve_ivp(model, [0, size], [S_0,I_0,R_0,E_0], t_eval=np.arange(0, size, 1), vectorized=True) sol_inf = np.sqrt(np.mean((solution.y[1] - (confirmed.values.flatten() * correction_factor/int(args.popmodel)))**2)) sol_rec = np.sqrt(np.mean((solution.y[2] - (recovered.values * correction_factor/int(args.popmodel)))**2)) - sol_exp = np.sqrt(np.mean((solution.y[3] - (exposed.values * correction_factor/int(args.popmodel)))**2)) - return sol_inf/3 + sol_rec/3 + sol_exp/3 + # sol_exp = np.sqrt(np.mean((solution.y[3] - (exposed.values * correction_factor/int(args.popmodel)))**2)) + return sol_inf * 0.5 + sol_rec * 0.5 my_learner = Learner(args.country) my_learner.train() |