Site Search:

covid-19 spread rate prediction with a simple java program

/*
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.

assume the death rate and recovery rate are marginal.
spreadRate, delta, spreadRate[i] = delta[i+1]/infected[i]

random, average.
        increasing, slope
        formular.
*/
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));
    
  }
}