Validate and communicateLesson 57 of 76 · 7 min

Push the boundaries deliberately

Check invariants, extreme inputs and physical constraints before trusting an estimate.

An invariant is a relationship that should hold throughout the calculation, such as a probability lying between zero and one or a stock ledger never creating negative served demand. Extreme inputs can expose errors a typical case does not reach.

Test an inventory allocation rule with zero stock, zero demand and a demand far above stock. Served units must lie between zero and demand. Served plus unmet demand must equal demand. These accounting identities hold independently of any distribution used to generate demand.

Also test whether input units and supports are compatible with the model. An assertion that a sampled number is positive does not justify clipping an inappropriate generator. Stop and revise an invalid input or model rather than quietly transforming evidence until tests pass.

Conserve demand at the boundaries
  1. Demand and stock
    D≥0,S≥0D\ge0,\quad S\ge0
  2. Serve what is possible
    served=min⁡(D,S)\text{served}=\min(D,S)
  3. Check both ledgers
    served+unmet=D\text{served}+\text{unmet}=D
Reference illustration. The source also requires remaining stock to be nonnegative. These invariants hold at zero demand, zero stock and extreme demand; they test arithmetic independently of distribution fit.

Which is stronger evidence for a ledger than merely getting a positive average?

Write a prediction (optional)

Seeded teaching simulation

Select Run Python below with the code unchanged.

Tools
About Python ↗

The code is editable. Press Ctrl+Enter or ⌘+Enter to run Python from the editor.

Published example output

This result comes from the original Python. Your runs appear above. Build environment ↗

stock: 0 served: [0 0 0 0] unmet: [   0    1   10 1000]
stock: 5 served: [0 1 5 5] unmet: [  0   0   5 995]
stock: 100 served: [  0   1  10 100] unmet: [  0   0   0 900]
Ledger invariants passed for extreme cases.

Read the first result

The ledger checks every listed trial. A mean can hide both positive and negative errors that cancel.

Try an edit

Replace served = np.minimum(demand, stock) with served = demand. Select Run Python again. Read the execution error. Which ledger condition fails when the model serves more than it has in stock? Open Tools, select Restore example and run once more to confirm Ledger invariants passed for extreme cases.

Back to the Python editor

Scope. These invariants verify an allocation rule, not the empirical suitability of a demand forecast.

Try a fresh case

A model produces negative durations. What is the useful first response?

Choose an answer
Need a hint?
Hint 1

Check whether the invalid result was generated or calculated.

Hint 2

State the revised assumption if you change the model.

Your notes