Site Search:

covid-19 infected population

Problem 

Given the covid-19 infected population from 2/24 to 3/22, predict the infection population at 3/30.
For example, giving the following array
(https://coronavirus.1point3acres.com/en)
{53, 58, 60, 61, 67, 72, 94, 112, 134, 169, 240, 344, 460, 581, 757, 1047, 1292, 1717, 2250, 2978, 3686, 4654, 6105, 8669, 14094, 19585, 26867, 35228}
return the prediction for the next 7 days.

Solution

assume the death rate and recovery rate are marginal, so that we can ignore them for the purpose of prediction.
We can calculate the spreadRate for each day. For each day, the formula is spreadRate[i] = delta[i+1]/infected[i].
Once we have the array of spread rate. We can observe the numbers and make prediction.
If the numbers are random, we can get the average.
If the numbers are increasing, we can calculate the slope.
Finally we are able to make an educated guess for the infected population at 3/30.


import java.util.*;
class Solution {
  public double[] spreadRate(int[] infected) {
    int N = infected.length;
    double[] rates = new double[N];
    for(int i = 0; i <= N-2; i++) {
      rates[i] = (double)(infected[i+1] - infected[i])/((double)(infected[i]));
      System.out.print(String.format("%6.2f ",rates[i]*100));
    }
    System.out.println();
    return rates;
  }
  private int predict(int count, int days, double rate) {
    for(int i = 0; i < days; i++) {
      count = (int)(count * (1 + rate));
      System.out.print(count+" ");
    }
    System.out.println();
    return count;
  }
  public static void main(String...args) {
    int[] infected = new int[]{53, 58, 60, 61, 67, 72, 94, 112, 134, 169, 240, 344, 460, 581, 757, 1047, 1292, 1717, 2250, 2978, 3686, 4654, 6105, 8669, 14094, 19585, 26867, 35228};
    Solution pd = new Solution();
    double[] rates = pd.spreadRate(infected);
    double average = Arrays.stream(rates).summaryStatistics().getAverage();
    System.out.println(average);
    System.out.println(pd.predict(infected[infected.length-1], 30-22, average));
 
  }
}

The calculation need to iterate the infected array, the time cost is O(N). We need an array to store the spread rate, the space cost is O(N).