Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-303

Croston One-Step Update

Problem

Perform one Croston update step for intermittent demand. If demand is zero, return [size, interval] unchanged. If size is None, initialize the pair with [demand, gap]. Otherwise return the alpha-smoothed pair [alpha * demand + (1 - alpha) * size, alpha * gap + (1 - alpha) * interval].

Hint

Zero demand updates neither the demand size nor the inter-arrival interval.

Test cases

case 1
in: [4,2,5,2,0.5]
expected: [4.5,2]
case 2
in: [4,2,0,3,0.5]
expected: [4,2]
case 3
in: [null,null,6,3,0.5]
expected: [6,3]
case 4
in: [0,0,8,4,0.25]
expected: [2,1]
Starter codePython
def croston_update(size, interval, demand, gap, alpha):
    # Your code here
    pass

4 test cases · run your code against them in the editor