100 Exercises / Mathematical modeling / Mathematical Modeling 100 Exercises
Using Probability to Evaluate Demand Fluctuations and Equipment Failures
Model demand and equipment failures with probability distributions. Compare stockout risk, expected loss, and CVaR over a common horizon in Python.
Modeling Uncertainty and Risk for Critical Replacement Parts: No.061–No.070
Using fictional industrial replacement parts and heat treatment equipment, we model demand, lead time, yield, and failure time as random variables. We use expected values and standard deviations to describe variation, then calculate prediction intervals, stockout and failure probabilities, and expected losses. These measures help us compare inventory levels and maintenance intervals.
About this material These notebooks were adapted from corporate training delivered by Surikobo or its representative, Hiroshi Wayama, and published with the participating companies’ permission. All data is fictional and does not describe actual companies or factories.
Introduction: Practical Challenges in Manufacturing Covered in This Article
For replacement parts manufacturers, shortages due to surging demand and sudden failures of heat treatment equipment are affecting delivery times. Planning based solely on average demand and mean interval of failure may be efficient under normal conditions, but losses when fluctuations overlap cannot be accounted for.
We use 365 days of demand for three products and a fictional equipment-lifetime model to compare average outcomes with losses in adverse cases.
Common situations on site
- Inventory is determined solely by average demand, without monitoring demand variation.
- Treat options with the same expected profit as equal and do not compare the size of the loss.
- Mechanically applying the same normal distribution to quantity, delivery time, and yield
- Presenting sales forecasts as a single numerical value and not submitting forecast ranges to management meetings
- Failure probability and loss during failure are managed separately.
- Only the option with the highest expected value is selected, without checking tolerance for the worst-case scenario.
Why is this issue so difficult to judge?
Uncertainty refers to “values not being fixed,” while risk is “uncertain results leading to operational losses.” It is necessary to compare failures with low probability but significant impact against frequent but minor demand fluctuations using the same criteria.
We examine distributions, upper quantiles, loss probabilities, expected losses, and average losses in the worst cases.
Exercises in this article
| No. | Theme | judgment |
|---|---|---|
| 061 | random variable | How to express demand, delivery dates, and yield |
| 062 | expected value | How to compare average results |
| 063 | Variance and Standard Deviation | How to measure variation |
| 064 | distribution selection | What kind of distribution should match the workload? |
| 065 | Demand distribution | How to express lead time demand |
| 066 | Sales forecast range | How to show upper and lower sales limits |
| 067 | Stockout Probability | What is the risk of stockouts per inventory level? |
| 068 | failure probability | What is the probability of failure during the maintenance interval? |
| 069 | expected loss | How to integrate probability and impact |
| 070 | Decision-making | How to balance expected outcomes against downside risk |
Preparing the Python environment
Run the cells from top to bottom in Jupyter Notebook. [IN: n] marks an input and [OUT: n] its corresponding output. Environment details show the original execution example; version and OS strings will differ on your machine.
No external data is used. Fix random number seeds and simulate them using NumPy, pandas, SciPy, and matplotlib.
Show environment setup
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
import platform, sys
import matplotlib, matplotlib.pyplot as plt
from matplotlib import font_manager
import numpy as np, pandas as pd, scipy
from scipy import stats
from IPython.display import display
SEED = 42
rng = np.random.default_rng(SEED)
fonts = {f.name for f in font_manager.fontManager.ttflist}
plot_font = next(
(f for f in ["Hiragino Sans", "Yu Gothic", "Noto Sans CJK JP"] if f in fonts),
"sans-serif",
)
plt.rcParams["font.family"] = plot_font
plt.rcParams["axes.unicode_minus"] = False
print(
f"Python {sys.version.split()[0]} / NumPy {np.__version__} / pandas {pd.__version__} / SciPy {scipy.__version__}"
)
print(
f"matplotlib {matplotlib.__version__} / font {plot_font} / seed {SEED} / {platform.platform()}"
)
# Show full text in table cells instead of truncating long descriptions.
pd.set_option("display.max_colwidth", None)
Python 3.13.1 / NumPy 2.5.1 / pandas 3.0.3 / SciPy 1.18.0
matplotlib 3.11.0 / font Hiragino Sans / seed 42 / macOS-26.3-arm64-arm-64bit-Mach-O
Fictional data
It generates the 365-day demand for products A, B, and C from a negative binomial distribution. Average demand and variance vary by product, and multipliers for days of the week and season are added. The equipment lifespan is based on a Weibull distribution with a shape parameter of 2.2 and a scale of 420 days.
Show fictional-data setup
# These data-generation settings are teaching assumptions, not estimates from a real factory.
dates = pd.date_range("2025-01-01", periods=365, freq="D")
specs = pd.DataFrame(
{
"product": ["A", "B", "C"],
"mean_demand": [95, 58, 28],
"dispersion": [18, 10, 5],
"price": [5200, 8400, 14500],
"unit_margin": [1800, 3100, 5600],
"shortage_loss": [3500, 6000, 12000],
"lead_days": [5, 8, 12],
}
)
rows = []
for i, date in enumerate(dates):
factor = (0.48 if date.day_of_week >= 5 else 1.0) * (
1 + 0.14 * np.sin(2 * np.pi * (i - 50) / 365)
)
for s in specs.itertuples(index=False):
mu = max(1, s.mean_demand * factor)
k = s.dispersion
p = k / (k + mu)
rows.append(
{
"date": date,
"product": s.product,
"demand": rng.negative_binomial(k, p),
"expected": mu,
}
)
demand = pd.DataFrame(rows).merge(specs, on="product")
print(f"Demand records: {len(demand):,} rows (365 days × 3 products)")
display(demand.head(9).style.format({"expected": "{:.1f}", "price": "¥{:,.0f}"}))
Demand records: 1,095 rows (365 days × 3 products)
| date | product | demand | expected | mean_demand | dispersion | price | unit_margin | shortage_loss | lead_days | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2025-01-01 00:00:00 | A | 101 | 84.9 | 95 | 18 | ¥5,200 | 1800 | 3500 | 5 |
| 1 | 2025-01-01 00:00:00 | B | 18 | 51.8 | 58 | 10 | ¥8,400 | 3100 | 6000 | 8 |
| 2 | 2025-01-01 00:00:00 | C | 37 | 25.0 | 28 | 5 | ¥14,500 | 5600 | 12000 | 12 |
| 3 | 2025-01-02 00:00:00 | A | 95 | 85.1 | 95 | 18 | ¥5,200 | 1800 | 3500 | 5 |
| 4 | 2025-01-02 00:00:00 | B | 72 | 51.9 | 58 | 10 | ¥8,400 | 3100 | 6000 | 8 |
| 5 | 2025-01-02 00:00:00 | C | 45 | 25.1 | 28 | 5 | ¥14,500 | 5600 | 12000 | 12 |
| 6 | 2025-01-03 00:00:00 | A | 83 | 85.2 | 95 | 18 | ¥5,200 | 1800 | 3500 | 5 |
| 7 | 2025-01-03 00:00:00 | B | 88 | 52.0 | 58 | 10 | ¥8,400 | 3100 | 6000 | 8 |
| 8 | 2025-01-03 00:00:00 | C | 23 | 25.1 | 28 | 5 | ¥14,500 | 5600 | 12000 | 12 |
summary = demand.groupby("product", as_index=False).agg(
average_need=("demand", "mean"),
standard_deviation=("demand", "std"),
smallest=("demand", "min"),
largest=("demand", "max"),
)
display(
summary.style.format({"average_need": "{:.1f}", "standard_deviation": "{:.1f}"})
)
fig, axes = plt.subplots(1, 2, figsize=(11, 4.2))
for p, g in demand.groupby("product"):
axes[0].plot(g["date"], g["demand"].rolling(14).mean(), label=p)
axes[0].set_title("14-day moving average of demand by product")
axes[0].set_xlabel("Date")
axes[0].set_ylabel("Demand (units/day)")
axes[0].grid(True, alpha=0.3)
axes[0].legend()
axes[1].boxplot(
[g["demand"] for _, g in demand.groupby("product")], tick_labels=["A", "B", "C"]
)
axes[1].set_title("Daily Demand Distribution by Product")
axes[1].set_xlabel("Products")
axes[1].set_ylabel("Demand (units/day)")
axes[1].grid(True, axis="y", alpha=0.3)
plt.tight_layout()
plt.show()
| product | average_need | standard_deviation | smallest | largest | |
|---|---|---|---|---|---|
| 0 | A | 82.4 | 32.5 | 25 | 184 |
| 1 | B | 48.9 | 23.5 | 10 | 153 |
| 2 | C | 23.7 | 13.9 | 1 | 77 |
No.061: Expressing Uncertainty as a Random Variable
Practical context
Expressing demand, lead time, yield, and lifespan as random variables rather than fixed values allows you to handle multiple outcomes and likelihood of occurrence.
Modeling approach
is used as a random variable, and the demand , delivery , and yield are represented as distributions. First define each variable’s unit and allowable range.
Check with Python
samples = pd.DataFrame(
{
"daily demand": rng.negative_binomial(12, 12 / (12 + 80), 10000),
"lead time": np.maximum(1, rng.normal(8, 1.5, 10000)),
"yield rate": rng.beta(98, 2, 10000),
}
)
display(samples.describe(percentiles=[0.05, 0.5, 0.95]).T.style.format("{:.2f}"))
fig, axes = plt.subplots(1, 3, figsize=(12, 3.7))
for ax, col, color in zip(axes, samples.columns, ["#2c7fb8", "#756bb1", "#2ca25f"]):
ax.hist(samples[col], bins=25, color=color, edgecolor="white")
ax.set_title(col + "Probability distribution")
ax.set_xlabel(col)
ax.set_ylabel("Frequency")
ax.grid(True, axis="y", alpha=0.3)
plt.tight_layout()
plt.show()
| count | mean | std | min | 5% | 50% | 95% | max | |
|---|---|---|---|---|---|---|---|---|
| daily demand | 10000.00 | 80.02 | 24.70 | 13.00 | 43.00 | 77.00 | 124.00 | 224.00 |
| lead time | 10000.00 | 7.98 | 1.49 | 2.14 | 5.53 | 7.98 | 10.48 | 14.28 |
| yield rate | 10000.00 | 0.98 | 0.01 | 0.88 | 0.95 | 0.98 | 1.00 | 1.00 |
Interpreting the results
Demand is a non-negative integer, delivery time is a positive continuous value, and yield is 0–1. Choosing a distribution that fits the workload range is the premise for realistic simulation.
No.062: Expressing Average Results Using Expected Values
Practical context
You can compare the average profit for each production volume candidate. However, you cannot determine the range of losses based solely on expected values.
Modeling approach
For a discrete random variable, . The Monte Carlo calculation estimates profit as margin on fulfilled demand minus unsold-stock costs and shortage losses.
Check with Python
d_sim = rng.choice(demand.query("product=='A'")["demand"], size=30000, replace=True)
plans = []
for q in [60, 80, 100, 120, 140]:
sold = np.minimum(q, d_sim)
leftover = np.maximum(q - d_sim, 0)
shortage = np.maximum(d_sim - q, 0)
profit = sold * 1800 - leftover * 250 - shortage * 3500
plans.append(
{
"Production volume": q,
"expected benefit": profit.mean(),
"probability of loss": (profit < 0).mean(),
"5%point": np.quantile(profit, 0.05),
}
)
ev = pd.DataFrame(plans)
display(
ev.style.format(
{
"expected benefit": "¥{:,.0f}",
"probability of loss": "{:.1%}",
"5%point": "¥{:,.0f}",
}
)
)
fig, ax = plt.subplots()
ax.plot(ev["Production volume"], ev["expected benefit"], marker="o")
ax.set_title("Production volume and expected profit")
ax.set_xlabel("Production quantity (units/day)")
ax.set_ylabel("Expected profit (JPY/day)")
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
| Production volume | expected benefit | probability of loss | 5%point | |
|---|---|---|---|---|
| 0 | 60 | ¥4,188 | 39.9% | ¥-154,500 |
| 1 | 80 | ¥67,665 | 12.0% | ¥-48,500 |
| 2 | 100 | ¥108,383 | 2.3% | ¥32,400 |
| 3 | 120 | ¥126,173 | 0.3% | ¥35,600 |
| 4 | 140 | ¥129,515 | 0.0% | ¥32,650 |
Interpreting the results
The plan with the highest expected profit is generally advantageous, but also check the 5th percentile and loss probability. Your choice depends on your financial capacity and the importance of your customers.
No.063: Expressing Variance with Variance and Standard Deviation
Practical context
Even if average demand is the same, products with larger standard deviations require safety stock and capacity margins.
Modeling approach
,. Scale is adjusted with a coefficient of variation .
Check with Python
variability = (
demand.groupby("product")["demand"].agg(["mean", "var", "std"]).reset_index()
)
variability["CV"] = variability["std"] / variability["mean"]
display(
variability.style.format(
{"mean": "{:.1f}", "var": "{:.1f}", "std": "{:.1f}", "CV": "{:.2f}"}
)
)
fig, ax = plt.subplots()
ax.bar(variability["product"], variability["CV"], color="#fdae6b")
ax.set_title("Demand coefficient of variation by product")
ax.set_xlabel("Products")
ax.set_ylabel("coefficient of variation CV")
ax.grid(True, axis="y", alpha=0.3)
plt.tight_layout()
plt.show()
| product | mean | var | std | CV | |
|---|---|---|---|---|---|
| 0 | A | 82.4 | 1057.0 | 32.5 | 0.39 |
| 1 | B | 48.9 | 552.5 | 23.5 | 0.48 |
| 2 | C | 23.7 | 192.7 | 13.9 | 0.59 |
Interpreting the results
Standard deviation is in units of the original quantity, variance is the square of the quantity, and CV is dimensionless. CV is useful for comparing different demand scales.
No.064: Selecting a Probability Distribution That Fits Business Data
Practical context
The range and generation process differ depending on the quantity, duration, ratio, and lifespan. Incorrect selection of distribution leads to negative demand and yields exceeding 100%.
Modeling approach
For case count, candidates are Poisson and negative binomial; for positive time, gamma and log-normal; for ratio, beta; and for lifespan, Weibull. Choose based on mean and variance, histogram, and business knowledge.
Check with Python
dist_check = demand.groupby("product")["demand"].agg(["mean", "var"]).reset_index()
dist_check["mean ratio of variance"] = dist_check["var"] / dist_check["mean"]
dist_check["Candidate"] = np.where(
dist_check["mean ratio of variance"] > 1.3,
"Negative binomial distribution",
"Poisson distribution",
)
display(
dist_check.style.format(
{"mean": "{:.1f}", "var": "{:.1f}", "mean ratio of variance": "{:.2f}"}
)
)
fig, ax = plt.subplots()
ax.bar(dist_check["product"], dist_check["mean ratio of variance"], color="#9ecae1")
ax.axhline(1, color="black", linestyle="--", label="Poisson Guidelines")
ax.set_title("Demand variance-to-mean ratio")
ax.set_xlabel("Products")
ax.set_ylabel("Variance / mean")
ax.grid(True, axis="y", alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
| product | mean | var | mean ratio of variance | Candidate | |
|---|---|---|---|---|---|
| 0 | A | 82.4 | 1057.0 | 12.84 | Negative binomial distribution |
| 1 | B | 48.9 | 552.5 | 11.30 | Negative binomial distribution |
| 2 | C | 23.7 | 192.7 | 8.13 | Negative binomial distribution |
Interpreting the results
The pooled demand variance exceeds its mean. However, varying means across weekdays and seasons can also increase this ratio. The threshold of 1.3 in the code is a teaching heuristic. Compare observations under similar weekday and seasonal conditions before choosing a distribution.
No.065: Expressing Demand as a Probability Distribution
Practical context
By creating a distribution of lead time demand, you can determine order points based on quantiles rather than averages.
Modeling approach
Simulate lead-time demand by resampling historical daily demand, then calculate its mean, 95th percentile, and 99th percentile.
Check with Python
a_hist = demand.query("product=='A'")["demand"].to_numpy()
lead = 5
lead_demand = rng.choice(a_hist, size=(30000, lead), replace=True).sum(axis=1)
lead_kpi = pd.DataFrame(
{
"average": [lead_demand.mean()],
"standard_deviation": [lead_demand.std()],
"95%point": [np.quantile(lead_demand, 0.95)],
"99%point": [np.quantile(lead_demand, 0.99)],
}
)
display(lead_kpi.style.format("{:.0f} units"))
fig, ax = plt.subplots()
ax.hist(lead_demand, bins=35, color="#2c7fb8", edgecolor="white")
ax.axvline(
np.quantile(lead_demand, 0.95), color="#de2d26", linestyle="--", label="95%point"
)
ax.set_title("Product A: five-day demand distribution")
ax.set_xlabel("Five-day demand (units)")
ax.set_ylabel("Frequency")
ax.grid(True, axis="y", alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
| average | standard_deviation | 95%point | 99%point | |
|---|---|---|---|---|
| 0 | 411 units | 72 units | 532 units | 583 units |
Interpreting the results
Stock equal to mean demand does not necessarily imply a 50% stockout probability; that interpretation applies near the median. Independent resampling from all observed days discards weekday order, seasonality, and serial dependence. Use the quantile corresponding to the target stockout probability as a candidate reorder point.
No.066: Modeling Sales Forecast Ranges
Practical context
Prediction ranges that include uncertainty in demand, price, and yield help assess cash and capacity requirements.
Modeling approach
Use Monte Carlo simulation of monthly sales to estimate the median and 80% and 95% prediction intervals.
Check with Python
n = 40000
monthly_demand = rng.choice(a_hist, size=(n, 30), replace=True).sum(axis=1)
price = rng.normal(5200, 120, n)
yield_rate = rng.beta(98, 2, n)
capacity = 3000
revenue = price * np.minimum(monthly_demand, capacity * yield_rate)
qs = np.quantile(revenue, [0.025, 0.1, 0.5, 0.9, 0.975])
interval = pd.DataFrame(
{"indicator": ["2.5%", "10%", "median", "90%", "97.5%"], "Monthly Sales": qs}
)
display(interval.style.format({"Monthly Sales": "¥{:,.0f}"}))
fig, ax = plt.subplots()
ax.hist(revenue / 1e6, bins=35, color="#74c476", edgecolor="white")
ax.axvspan(
qs[0] / 1e6, qs[-1] / 1e6, color="#fdae6b", alpha=0.25, label="95%Predicted Section"
)
ax.set_title("Predicted distribution of monthly sales")
ax.set_xlabel("Monthly Sales (million yen)")
ax.set_ylabel("Frequency")
ax.grid(True, axis="y", alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
print(f"95% prediction interval: ¥{qs[0]:,.0f}–¥{qs[-1]:,.0f}")
| indicator | Monthly Sales | |
|---|---|---|
| 0 | 2.5% | ¥10,969,947 |
| 1 | 10% | ¥11,602,134 |
| 2 | median | ¥12,838,050 |
| 3 | 90% | ¥14,095,645 |
| 4 | 97.5% | ¥14,773,267 |
95% prediction interval: ¥10,969,947–¥14,773,267
Interpreting the results
The forecast range includes not only demand but also uncertainties in price and yield. Use the lower limit for cash flow and the upper limit for capacity planning.
No.067: Expressing Out-of-Stock Risk in Probabilistic Terms
Practical context
By showing the probability of out-of-stock during lead time at each inventory level, you can explain the trade-off between inventory and service.
Modeling approach
is estimated through simulation.
Check with Python
stock_levels = np.arange(300, 801, 50)
risk = pd.DataFrame(
{
"Inventory": stock_levels,
"Stockout Probability": [np.mean(lead_demand > s) for s in stock_levels],
}
)
display(risk.style.format({"Stockout Probability": "{:.1%}"}))
fig, ax = plt.subplots()
ax.plot(
risk["Inventory"], risk["Stockout Probability"] * 100, marker="o", color="#de2d26"
)
ax.axhline(5, color="black", linestyle="--", label="5%Objective")
ax.set_title("Product A: stock and five-day stockout probability")
ax.set_xlabel("Available Stock (units)")
ax.set_ylabel("Stockout probability (%)")
ax.grid(True, alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
target_stock = risk.loc[risk["Stockout Probability"] <= 0.05, "Inventory"].min()
print(
f"Smallest tested stock level with stockout probability at most 5%: {target_stock:.0f} units"
)
| Inventory | Stockout Probability | |
|---|---|---|
| 0 | 300 | 93.9% |
| 1 | 350 | 79.6% |
| 2 | 400 | 55.2% |
| 3 | 450 | 29.4% |
| 4 | 500 | 11.4% |
| 5 | 550 | 2.9% |
| 6 | 600 | 0.6% |
| 7 | 650 | 0.1% |
| 8 | 700 | 0.0% |
| 9 | 750 | 0.0% |
| 10 | 800 | 0.0% |
Smallest tested stock level with stockout probability at most 5%: 550 units
Interpreting the results
Increasing inventory lowers stockout probability. The improvement from one additional unit depends on the demand distribution and current stock level; it does not necessarily diminish throughout the range. Choose inventory using both the target stockout probability and holding cost.
No.068: Expressing Failure Risk in Probabilities
Practical context
Expressing equipment lifespan as a probability distribution allows for quantifying the probability of failure before the next maintenance.
Modeling approach
For lifetime measured from new, the Weibull failure probability is . When , the hazard rate increases with age. The following comparison assumes maintenance restores the equipment to an as-new condition. For equipment already aged , failure probability over the next days is .
Check with Python
beta, eta = 2.2, 420
days = np.arange(30, 601, 30)
failure_prob = 1 - np.exp(-((days / eta) ** beta))
failure = pd.DataFrame(
{
"maintenance interval_days": days,
"Probability of failure within the period": failure_prob,
}
)
display(
failure.iloc[::2].style.format(
{"Probability of failure within the period": "{:.1%}"}
)
)
fig, ax = plt.subplots()
ax.plot(days, failure_prob * 100, marker="o", color="#756bb1")
ax.axhline(10, color="black", linestyle="--", label="10%guideline")
ax.set_title("Maintenance intervals and failure probability within the period")
ax.set_xlabel("Maintenance interval (days)")
ax.set_ylabel("Failure probability (%)")
ax.grid(True, alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
limit = failure.loc[
failure["Probability of failure within the period"] <= 0.10,
"maintenance interval_days",
].max()
print(f"Longest tested interval with failure probability at most 10%: {limit} days")
| maintenance interval_days | Probability of failure within the period | |
|---|---|---|
| 0 | 30 | 0.3% |
| 2 | 90 | 3.3% |
| 4 | 150 | 9.9% |
| 6 | 210 | 19.6% |
| 8 | 270 | 31.5% |
| 10 | 330 | 44.5% |
| 12 | 390 | 57.2% |
| 14 | 450 | 68.8% |
| 16 | 510 | 78.4% |
| 18 | 570 | 85.9% |
Longest tested interval with failure probability at most 10%: 150 days
Interpreting the results
The longer the maintenance interval, the higher the probability of failure. Update the parameters by equipment group using observed failures and replacement histories, and compare them with preventive replacement costs.
No.069: Using Expected Loss to Assess Risk
Practical context
By multiplying the probability of occurrence by the impact amount, different types of risks can be prioritized on a common monetary scale.
Modeling approach
. For rare, severe events, also examine maximum losses and business-continuity requirements.
Check with Python
risks = pd.DataFrame(
{
"Risks": [
"PartsAmissing_item",
"Sudden equipment failure",
"Quality leakage",
"emergency transport",
],
"Probability of occurrence": [0.08, 0.12, 0.015, 0.20],
"Impact amount": [3_500_000, 18_000_000, 45_000_000, 1_200_000],
}
)
risks["expected loss"] = risks["Probability of occurrence"] * risks["Impact amount"]
risks = risks.sort_values("expected loss", ascending=False)
display(
risks.style.format(
{
"Probability of occurrence": "{:.1%}",
"Impact amount": "¥{:,.0f}",
"expected loss": "¥{:,.0f}",
}
)
)
fig, ax = plt.subplots()
ax.barh(risks["Risks"][::-1], risks["expected loss"][::-1] / 1e6, color="#fdae6b")
ax.set_title("Expected Loss by Manufacturing Risk")
ax.set_xlabel("Expected loss (million JPY / evaluation period)")
ax.set_ylabel("Risk Events")
ax.grid(True, axis="x", alpha=0.3)
plt.tight_layout()
plt.show()
| Risks | Probability of occurrence | Impact amount | expected loss | |
|---|---|---|---|---|
| 1 | Sudden equipment failure | 12.0% | ¥18,000,000 | ¥2,160,000 |
| 2 | Quality leakage | 1.5% | ¥45,000,000 | ¥675,000 |
| 0 | PartsAmissing_item | 8.0% | ¥3,500,000 | ¥280,000 |
| 3 | emergency transport | 20.0% | ¥1,200,000 | ¥240,000 |
Interpreting the results
You can compare high-probability/medium losses and low-probability/massive losses in the same table. Unacceptable risks such as defective products reaching customers are treated as constraints regardless of expected loss ranking.
No.070: Organizing Decisions Considering Uncertainty
Practical context
The policy with the lowest expected cost may differ from the one with the smallest losses in adverse cases. Compare both average losses and tail risk.
Modeling approach
Use the same 360-day horizon for all policies. Sum stockout losses over five-day demand cycles, failure losses over maintenance cycles, and policy costs for 360 days. This simplified model replenishes stock to its target at each demand-cycle start and restores equipment to as-new condition at each maintenance-cycle start. Each maintenance cycle has at most one failure, and failures do not alter demand. Compare mean loss, the 95th percentile, and the mean of the worst 5% of trials (CVaR95).
Check with Python
decisions = []
n = 30000
horizon_days = 360
cycle_days = 5
# Shared demand draws make policies comparable over the same 360-day horizon.
cycle_demand = rng.choice(
a_hist, size=(n, horizon_days // cycle_days, cycle_days), replace=True
).sum(axis=2)
failure_uniforms = rng.random((n, 3))
for name, stock, interval, annual_cost in [
("Low cost", 450, 360, 1_200_000),
("Balance", 550, 240, 2_100_000),
("High reliability", 650, 150, 3_400_000),
]:
shortage = np.maximum(cycle_demand - stock, 0).sum(axis=1) * 3500
# Each maintenance cycle starts as new and allows at most one failure.
full_cycles, remainder = divmod(horizon_days, interval)
durations = [interval] * full_cycles + ([remainder] if remainder else [])
failure_probabilities = 1 - np.exp(-((np.array(durations) / eta) ** beta))
failure_count = (failure_uniforms[:, : len(durations)] < failure_probabilities).sum(
axis=1
)
failure_loss = failure_count * 18_000_000
total = annual_cost + shortage + failure_loss
q95 = np.quantile(total, 0.95)
# Average exactly the worst 5%, including only the required number of ties.
tail_count = n // 20
cvar = np.sort(total)[-tail_count:].mean()
decisions.append(
{
"policy": name,
"Expected Total Loss": total.mean(),
"95%point": q95,
"CVaR95": cvar,
"P(loss > JPY 5 million)": np.mean(total > 5_000_000),
}
)
decision = pd.DataFrame(decisions)
display(
decision.style.format(
{
"Expected Total Loss": "¥{:,.0f}",
"95%point": "¥{:,.0f}",
"CVaR95": "¥{:,.0f}",
"P(loss > JPY 5 million)": "{:.1%}",
}
)
)
fig, ax = plt.subplots()
x = np.arange(3)
ax.bar(
x - 0.18, decision["Expected Total Loss"] / 1e6, 0.36, label="Expected Total Loss"
)
ax.bar(x + 0.18, decision["CVaR95"] / 1e6, 0.36, label="CVaR95")
ax.set_xticks(x, decision["policy"])
ax.set_title("Average Loss and Tail Risk by Policy")
ax.set_xlabel("decision-making policy")
ax.set_ylabel("Loss (million yen / 360 days)")
ax.grid(True, axis="y", alpha=0.3)
ax.legend()
plt.tight_layout()
plt.show()
best = decision.loc[decision["Expected Total Loss"].idxmin()]
print(
f"Minimum expected total loss: {best['policy']} / ¥{best['Expected Total Loss']:,.0f}"
)
| policy | Expected Total Loss | 95%point | CVaR95 | P(loss > JPY 5 million) | |
|---|---|---|---|---|---|
| 0 | Low cost | ¥13,944,103 | ¥23,963,500 | ¥24,472,276 | 69.6% |
| 1 | Balance | ¥7,993,414 | ¥20,572,500 | ¥25,921,246 | 30.0% |
| 2 | High reliability | ¥7,200,311 | ¥21,400,000 | ¥25,470,929 | 20.0% |
Minimum expected total loss: High reliability / ¥7,200,311
Interpreting the results
Under these assumptions, the high-reliability policy minimizes mean loss, while the low-cost policy minimizes CVaR95. The model allows at most one failure over 360 days for the low-cost policy, but one per maintenance cycle for the others; this assumption affects the ranking. Review post-failure recovery, acceptable losses, and customer and safety requirements before selecting a policy.
Practical lessons
- Expressing uncertain workloads as random variables that fit the value range
- Include the expected value and standard deviation and quantile points together
- The distribution is chosen from the process of generating the business and the average variance.
- Forecasts are shown not as individual points, but as intervals
- Connecting stockouts and breakdowns to inventory and maintenance using probabilities
- Integrate probability and impact into expected loss
- Use CVaR and constraints for low-frequency massive losses
- Policies are evaluated based on both average outcomes and deterioration tolerance
Preparing for practical use
1. Determine the Scope and Unit of Uncertainty
Define demand, delivery time, yield, failure, and price without confusing them.
2. Keeping a history of out-of-stock, malfunctions, and maintenance
It records not only normal data but also right-censored lifetimes, delays, lost orders, and impact amounts.
3. Testing the distribution assumption
We check and regularly update histograms, quantiles, fit levels, and process knowledge.
4. Agree on loss parameters
Gross profit, stoppages, emergency transportation, customer impact, safety, and legal matters are organized by the relevant departments.
5. Conduct backtesting and stress tests
Stress-test policies under demand surges, supply stoppages, and repeated failures.
6. Set decision-making rules
Decide which of the approval criteria should be expected value, service level, maximum allowable loss, or CVaR.
Conclusion
No.061–070 represent demand, sales, stockouts, and failures as probability distributions, and link expected value, standard deviation, forecast interval, expected loss, and CVaR to decision-making. Rather than eliminating uncertainty, it is important to visualize the range of results and the size of losses, and compare inventory and maintenance options.
Support for businesses
At Surikobo, we support probabilistic models for demand, delivery time, and yield, stockout/failure risks, predictive intervals, Monte Carlo simulations, and inventory and maintenance decisions that consider risks.
📩 Contact Us: www.surikobo.co.jp/contact Please feel free to consult us first.