Max Projection

Remix this to get started with Julia

1.0
.

Here we try to calculate the "Max Projection" using the following assumotions

  1. The peak day is day 56

  2. The gradient (of daily growth) at the peak is -0.0031

  3. The value of daily growth at peak is exactly 1.000000000000000000000000

  4. The gradient is fixed at peak and remains constant for the next 24 days

  5. After 24 days, the gradient is halved

  6. The number of cases on peak day is 511

const peakday = 56.0
const gradient = -0.0031
const dailygrowth_atpeak = 1.0
0.8s
1.0
function growth_rate(d)
    if d <= peakday + 24.0
        return dailygrowth_atpeak + (d - peakday) * gradient
    else
        return growth_rate(peakday + 24.0) + (d - (peakday + 24)) * (gradient/2.0)
    end
end
0.8s
growth_rate (generic function with 1 method)

The Max Projection on peakday is 511

The Max Projection on day d is the growth rate on that day times the Max Projection of the day before

function max_projection(d)
    if d <= peakday
        return 511.0
    end
    if d > peakday
        return growth_rate(d) * max_projection(d-1.0)
    end
end
0.5s
max_projection (generic function with 1 method)

Create a floating point array starting at 56 and ending at 105

days = Float64.(collect(56:105))
1.2s
50-element Array{Float64,1}: 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 ⋮ 97.0 98.0 99.0 100.0 101.0 102.0 103.0 104.0 105.0

Applying the function max_projection to a vector of floating point values then rounding it

maxpro = round.(  max_projection.(days)  )
0.6s
50-element Array{Float64,1}: 511.0 509.0 506.0 502.0 495.0 488.0 479.0 468.0 457.0 444.0 ⋮ 41.0 37.0 33.0 29.0 26.0 23.0 21.0 18.0 16.0

Finally we obtain our array of "day,max projection value"

[ (days[k],maxpro[k]) for k=1:105-56+1 ]
1.1s
50-element Array{Tuple{Float64,Float64},1}: (56.0, 511.0) (57.0, 509.0) (58.0, 506.0) (59.0, 502.0) (60.0, 495.0) (61.0, 488.0) (62.0, 479.0) (63.0, 468.0) (64.0, 457.0) (65.0, 444.0) ⋮ (97.0, 41.0) (98.0, 37.0) (99.0, 33.0) (100.0, 29.0) (101.0, 26.0) (102.0, 23.0) (103.0, 21.0) (104.0, 18.0) (105.0, 16.0)
Shift+Enter to run
Runtimes (1)