Skip to content

Instantly share code, notes, and snippets.

@bwedding
Last active July 3, 2020 03:28
Show Gist options
  • Save bwedding/7c60652fcfa1c166cd1a1035adfc5b2e to your computer and use it in GitHub Desktop.
Save bwedding/7c60652fcfa1c166cd1a1035adfc5b2e to your computer and use it in GitHub Desktop.
Prediction of COVID Infection in Texas based on real data
#include <vector>
#include <iostream>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;
const int NumDays = 45;
const int PopulationTexas = 30000000;
const double InfectedPct = 0.046; // % infected
const int StartingNumberOfInfected = PopulationTexas * InfectedPct;
const double FinalInfectedPopulation = 0.15;
const double DailyInfectionRateIncrease = (FinalInfectedPopulation - InfectedPct) / NumDays;
struct DailyTestResults
{
double Positive;
int NumTests;
};
int GetRandomNum()
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, PopulationTexas-1);
return dis(gen);
}
void IncreaseInfectionRate(vector<bool> &Population)
{
int NewInfected = (double)Population.size() * DailyInfectionRateIncrease;
for (int i = 0; i < NewInfected; i++)
{
// Note: There is a small possibility of marking an infected person infected
// but shouldn't hurt the final results when dealing with such large numbers
Population[GetRandomNum()] = true;
}
}
int main()
{
// https://www.khou.com/article/news/health/coronavirus/a-closer-look-at-covid-19-testing-numbers-in-texas/285-2483e965-0baf-4228-8bd9-0ad309b9f1f6
// Actual tests conducted 5/16 to 7/1
const vector<DailyTestResults> DailyTests =
{
{ 0.0483, 23708 }, { 0.0497, 22004 }, { 0.0447, 24725 }, { 0.047, 26966 }, { 0.0543, 23450 },
{ 0.0551, 21838 }, { 0.0539, 21868 }, { 0.0487, 22186 }, { 0.0515, 20198 }, { 0.0427, 22218 },
{ 0.0433, 21756 }, { 0.049, 21871 }, { 0.0456, 23687 }, { 0.0544, 23482 }, { 0.054, 23570 },
{ 0.0662, 21585 }, { 0.0626, 23620 }, { 0.0603, 24043 }, { 0.0644, 23537 }, { 0.08, 20021 },
{ 0.0711, 21469 }, { 0.0666, 23019 }, { 0.0692, 22046 }, { 0.0685, 23966 }, { 0.0705, 23626 },
{ 0.0722, 23863 }, { 0.0611, 29139 }, { 0.0662, 27778 }, { 0.0671, 28727 }, { 0.0694, 29793 },
{ 0.075, 28774 }, { 0.0853, 28137 }, { 0.0894, 29011 }, { 0.088, 32885 }, { 0.0951, 33464 },
{ 0.0964, 35550 }, { 0.1042, 37231 }, { 0.1176, 35943 }, { 0.1173, 39060 }, { 0.1323, 37061 },
{ 0.1431, 35577 }, { 0.1374, 38597 }, { 0.1402, 38856 }, { 0.1358, 41670 }, { 0.1332, 45209 }
};
vector<bool> Population(PopulationTexas, false);
// Initialize infected population
int Infected = Population.size() * InfectedPct;
for (int i = 0; i < Infected; i++)
{
Population[GetRandomNum()] = true;
}
int Day = 1;
int i = 0;
for (auto& test : DailyTests)
{
int Positives = 0;
// Run daily tests
for (int i = 0; i < test.NumTests; i++)
{
if (Population[GetRandomNum()]) // Infected
Positives++;
}
double PositivityRate = (double)Positives / (double)test.NumTests;
cout << std::fixed << std::showpoint << std::setprecision(2);
cout << "Day " << Day++ << " Found " << PositivityRate * 100.0
<< "%\tActual: " << test.Positive * 100.0 << "%\n";
IncreaseInfectionRate(Population);
}
int totalSick = 0;
for (int i = 0; i < Population.size(); i++)
{
if (Population[i])
totalSick++;
}
cout << std::fixed << std::showpoint << std::setprecision(4);
cout << "Found: " << found << "\n";
cout << "Total Infected is " << totalSick << "\nWhich is a percentage of: " << (double)totalSick / (double)PopulationTexas << "\n";
cout << "The daily infection increase is about " << DailyInfectionRateIncrease
<< "%\nWhich means daily infections are about " << PopulationTexas * DailyInfectionRateIncrease << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment