All problems
Hierarchical Forecast Coherence
Problem
Check that a hierarchy reconciles: return True when abs(aggregate - sum(children)) <= tol.
This is the coherence condition that bottom-up reconciliation guarantees by construction.
Hint
The tolerance absorbs floating-point rounding from earlier steps.
Test cases
case 1
in: [10,[3,4,3],1e-9]
expected: true
case 2
in: [10,[3,4,4],0.5]
expected: false
case 3
in: [0,[],1e-9]
expected: true
case 4
in: [5.5,[1.1,2.2,2.2],0.000001]
expected: true
Starter codePython
def hierarchical_forecast_coherence(aggregate, children, tol):
# Your code here
pass4 test cases · run your code against them in the editor