Prescriptive Analytics & Decision Intelligence
Overview / Module 6 / Day 55
Module 6 · Optimization under Uncertainty · Day 55 of 80

Mini-project: VSS and EVPI

Day 53's stochastic program earned more than the plan for an average week. Is it worth building stochastic models in general, or only sometimes? And what would a perfect forecast be worth? Two numbers answer these questions:

▶
Video for Day 55 coming soon

In this lesson

Today's 5-hour plan

LessonProjectBreakCommit
0:00–0:30
55.1 The brief
0:30–1:30
55.2 Four numbers
1:30–1:45
Break
1:45–2:45
55.3 When does the stochastic model pay?; 55.4 December
2:45–3:30
55.5 What is a better forecast worth?
3:30–3:45
Break
3:45–4:45
55.6 The memo
4:45–5:00
Commit with Git + checklist
  • The value of the stochastic solution (VSS): what the stochastic model adds over planning for the average.
  • The expected value of perfect information (EVPI): what knowing the future would add.

Today's mini-project computes both for the bakery and finds out when they are large.

55.1 The brief

The bakery's planning team asks two questions. Should we keep using the stochastic model, or is planning for the average week good enough? And the forecasting team wants budget for a better forecast: what is it worth?

Four numbers, all expected weekly profit:

NumberMeaning
EVThe plan for the average week, as promised by its own model
EEVThat plan's expected profit when real weeks vary (fixed first stage, recourse in each scenario)
RPThe stochastic program's expected profit (Day 53)
WSWait-and-see: a plan made knowing each week in advance (Day 53's planted bug, used on purpose)

VSS=RP−EEV,EVPI=WS−RP\text{VSS} = \text{RP} - \text{EEV}, \qquad \text{EVPI} = \text{WS} - \text{RP}

For a maximization, EEV≤RP≤WS\text{EEV} \le \text{RP} \le \text{WS} always holds. A stochastic plan is never worse than the average-week plan, and foresight never hurts. Create day55/values.py:

"""Day 55 mini-project: what is modelling uncertainty worth (VSS), and what would perfect information be worth (EVPI)?

Import it:  from values import scale_demand, four_numbers
"""
import pyomo.environ as pyo

from bakery import solve
from two_stage import build_two_stage


def scale_demand(demand, cap, k):
    """Stretch every scenario's error by k: demand = forecast x (1 + k (ratio - 1)). k = 0.5 is a forecast with half
    the error, k = 2 twice the error."""
    return {(p, w): cap[p] * max(0.0, 1 + k * (v / cap[p] - 1)) for (p, w), v in demand.items()}


def four_numbers(d, econ, st, demand, weeks):
    """EV: the plan for the average week; EEV: that plan's expected profit when weeks vary; RP: the stochastic
    program's expected profit; WS: wait-and-see, a plan made knowing each week in advance.
    VSS = RP - EEV (what the stochastic model adds), EVPI = WS - RP (what perfect forecasts would add)."""
    n = len(weeks)
    mean = {(p, 0): sum(demand[p, w] for w in range(n)) / n for p in d["products"]}
    ev = build_two_stage(d, econ, st, mean, ["average"])
    solve(ev)
    plan = {p: max(0.0, pyo.value(ev.x[p])) for p in ev.P}
    out = {"EV": pyo.value(ev.expected_profit)}
    for name, kw in [("EEV", {"plan": plan}), ("RP", {}), ("WS", {"anticipate": True})]:
        m = build_two_stage(d, econ, st, demand, weeks, **kw)
        solve(m)
        out[name] = pyo.value(m.expected_profit)
    out["VSS"], out["EVPI"] = out["RP"] - out["EEV"], out["WS"] - out["RP"]
    return out

55.2 Four numbers

# ---------- 55.2 Four numbers ----------
print("--- four numbers")
base = four_numbers(d, econ, st, demand, weeks)
for k in ("EV", "EEV", "RP", "WS", "VSS", "EVPI"):
    print(f"{k:>5}: ${base[k]:>12,.2f}")
print(f"VSS is {base['VSS'] / base['RP']:.2%} of profit (${base['VSS'] * 52:,.0f} a year); "
      f"EVPI {base['EVPI'] / base['RP']:.2%} (${base['EVPI'] * 52:,.0f} a year)")
--- four numbers
   EV: $  113,816.84
  EEV: $  111,661.74
   RP: $  112,600.11
   WS: $  113,648.14
  VSS: $      938.37
 EVPI: $    1,048.03
VSS is 0.83% of profit ($48,795 a year); EVPI 0.93% ($54,498 a year)
  • EV promises $113,817, more than even perfect foresight delivers: planning for the average week is overconfident about what it will earn.
  • Its plan really earns $111,662 (EEV), $2,155 less than promised. The stochastic plan earns $938 more: VSS ≈ $49,000 a year.
  • Perfect forecasts would add another $1,048 a week: EVPI ≈ $54,000 a year. That is the ceiling on what any forecasting project could deliver for this decision.

55.3 When does the stochastic model pay?

Stretch the forecast errors (×0.5 to ×2) and give the bakery more or less flexibility (0, 40 or 80 top-up oven hours):

# ---------- 55.3 When does the stochastic model pay? ----------
print("--- uncertainty and flexibility")
rows = []
for k in (0.5, 1.0, 1.5, 2.0):
    for hours in (0, 40, 80):
        r = four_numbers(d, econ, {**st, "topup_oven_hours": hours}, scale_demand(demand, d["cap"], k), weeks)
        rows.append((k, hours, round(r["RP"], 2), round(r["VSS"], 2), round(r["EVPI"], 2)))
grid = pd.DataFrame(rows, columns=["error_scale", "topup_hours", "RP", "VSS", "EVPI"])
print(grid.to_string(index=False))
--- uncertainty and flexibility
 error_scale  topup_hours        RP     VSS    EVPI
         0.5            0 107688.73  434.46  653.84
         0.5           40 113225.19  479.79  530.83
         0.5           80 117259.38  856.77  184.23
         1.0            0 106972.86  843.91 1243.38
         1.0           40 112600.11  938.37 1048.03
         1.0           80 116829.54 1449.49  500.09
         1.5            0 106219.36 1216.43 1698.62
         1.5           40 111915.25 1367.95 1416.79
         1.5           80 116282.07 1957.54  732.95
         2.0            0 105442.78 1565.86 2126.95
         2.0           40 111209.93 1794.59 1758.16
         2.0           80 115674.21 2422.17  990.95
  • VSS grows with uncertainty: $480 a week with half today's errors, $1,795 with twice the errors (40 h). If the future is nearly certain, the average is a fine plan.
  • VSS grows with flexibility, too: more top-up hours give the stochastic plan more ways to use what it knows about the spread. A plan with a second chance needs to know the odds to use it well.
  • EVPI falls with flexibility: with 80 top-up hours, perfect information is worth $500 instead of $1,048. Flexibility and information are substitutes: a bakery that can react doesn't need to know in advance.

55.4 December

# ---------- 55.4 December ----------
print("--- december")
dd, de, ds, ddem, dweeks = load_two_stage(con, december_only=True)
dec = four_numbers(dd, de, ds, ddem, dweeks)
print(", ".join(f"{k} ${dec[k]:,.2f}" for k in ("EEV", "RP", "WS", "VSS", "EVPI")))
--- december
EEV $108,757.11, RP $113,773.36, WS $114,863.36, VSS $5,016.24, EVPI $1,090.00

In December's weeks, VSS is $5,016 a week, five times the annual average. December's errors are large and one-sided (demand above forecast), and the average-week plan misses that. In December the stochastic model is not a refinement; it is the plan.

55.5 What is a better forecast worth?

EVPI is a ceiling. A real forecasting project halves the errors at best. Its value is the stochastic plan's profit with smaller errors, against today's:

# ---------- 55.5 What is a better forecast worth? ----------
print("--- better forecasts")
rp = grid.set_index(["error_scale", "topup_hours"]).RP
for k in (0.5, 1.5, 2.0):
    print(f"forecast errors x{k}: the stochastic plan earns ${rp[k, 40] - rp[1.0, 40]:+,.2f} a week against today's errors")

# the yule logs (Day 51): one product, no second chance
hist = con.sql("SELECT forecast_logs, demand_logs FROM yule_log_history").df()
e = dict(con.sql("SELECT * FROM yule_log_economics").fetchall())
salvage = e["boxing_day_price"] * e["boxing_day_sell_share"]
ratios = (hist.demand_logs / hist.forecast_logs).to_numpy()
fc = con.sql("SELECT sum(forecast_logs) FROM yule_log_forecast").fetchall()[0][0] / 40      # an average store


def profit(q, dem):
    sold = np.minimum(q, dem)
    return e["price"] * sold - e["cost"] * q + salvage * (q - sold)


dem = fc * ratios
q_star = q_empirical(dem, critical_ratio(e["price"], e["cost"], salvage))
eev, rp_y, ws = profit(fc, dem).mean(), profit(q_star, dem).mean(), profit(dem, dem).mean()
print(f"yule logs, an average store (forecast {fc:.1f}): ordering the forecast ${eev:,.2f}, newsvendor ${rp_y:,.2f}, "
      f"perfect information ${ws:,.2f} -> VSS ${rp_y - eev:,.2f} ({(rp_y - eev) / rp_y:.1%}), "
      f"EVPI ${ws - rp_y:,.2f} ({(ws - rp_y) / rp_y:.1%})")
--- better forecasts
forecast errors x0.5: the stochastic plan earns $+625.08 a week against today's errors
forecast errors x1.5: the stochastic plan earns $-684.86 a week against today's errors
forecast errors x2.0: the stochastic plan earns $-1,390.18 a week against today's errors
yule logs, an average store (forecast 48.0): ordering the forecast $866.73, newsvendor $949.50, perfect information $1,013.32 -> VSS $82.78 (8.7%), EVPI $63.81 (6.7%)
  • Halving the forecast errors is worth about $625 a week, $32,500 a year, for the bakery plan alone. Worse forecasts cost about as much.
  • For the yule logs (one product, no second chance), VSS is 8.7% of the profit and EVPI 6.7%. Without recourse, the stochastic model (here, the newsvendor) matters far more in relative terms.

55.6 The memo

A model memo

To: bakery planning and the forecasting team. Re: what modelling uncertainty and better forecasts are worth.

"Keep the stochastic plan. Planning for the average week promises $113,800 a week but earns $111,700. The stochastic plan earns $112,600: about $49,000 a year more. In December it earns $5,000 a week more, so it must be used for the holiday weeks above all.

A better forecast has a value we can now state. Perfect forecasts would be worth at most $54,000 a year to the bakery plan. Halving today's forecast errors would be worth about $32,500 a year. That is the budget ceiling for a forecasting project aimed at this decision; other decisions it improves would add to it.

Flexibility is an alternative to forecasting. Doubling the mid-week top-up from 40 to 80 oven hours would raise profit by about $4,200 a week and cut the value of perfect forecasts in half. Compare the cost of that capacity with the cost of better forecasts before choosing."

Commit

git add .
git commit -m "Day 55: VSS and EVPI mini-project"
git push

Day 55 checklist

  • I can compute EV, EEV, RP and WS, and from them VSS and EVPI.
  • I know that planning for the average is overconfident, and by how much here.
  • I can show how VSS and EVPI change with uncertainty and with flexibility.
  • I can put a value on a better forecast, and know that EVPI is its ceiling.
  • I can tell a team when a stochastic model is worth the trouble.