Chapter 26 — Assignment Project: Predictive Maintenance for a Pump Fleet
Overview¶
A water utility runs 40 pumps. Each pump is healthy, then degrading, then failing, and its sensors report every hour a vibration level and a bearing temperature. Maintenance logs give the true state of 10 pumps; the other 30 have only their sensor readings. The utility wants to know, every hour, how each pump is doing, to be warned before it fails, and to estimate how long it has left.
| Part | Task | Points |
|---|---|---|
| A | A supervised HMM: filtering, smoothing and one-moment classification | 20 |
| B | Learning from the unlabelled pumps with Baum–Welch | 25 |
| C | An early-warning alarm | 20 |
| D | Remaining useful life | 20 |
| E | Recommendation | 15 |
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
STATES = ['healthy', 'degrading', 'failing']
def _fleet():
"""The simulator: treat it as unknown (use only the data it returns)."""
A = np.array([[0.995, 0.005, 0.0], [0.0, 0.985, 0.015], [0.0, 0.0, 1.0]])
mean = np.array([[1.0, 60.0], [1.25, 61.5], [1.8, 65.0]]); sd = np.array([[0.35, 2.5], [0.40, 2.5], [0.50, 3.0]])
rng = np.random.default_rng(26); pumps = []
for _ in range(40):
z = [0]
while not (z[-1] == 2 and z.count(2) >= 24): # a failing pump is stopped after 24 hours
z.append(rng.choice(3, p=A[z[-1]]))
z = np.array(z); pumps.append((z, rng.normal(mean[z], sd[z])))
return pumps
PUMPS = _fleet()
LABELLED, UNLABELLED = PUMPS[:10], PUMPS[10:]
TRAIN_L, TEST_L = LABELLED[:5], LABELLED[5:]
print(f'{len(PUMPS)} pumps; hours recorded: {sum(len(z) for z, _ in PUMPS)}; hours before failing: mean {np.mean([np.argmax(z == 2) for z, _ in PUMPS]):.0f}, from {min(np.argmax(z == 2) for z, _ in PUMPS)} to {max(np.argmax(z == 2) for z, _ in PUMPS)}')
print('first pump, first 5 hours (vibration, temperature):\n', np.round(PUMPS[0][1][:5], 2))Part A — A Supervised HMM (20 points)¶
From the 5 pumps of
TRAIN_L, learn an HMM by counting: initial distribution, transition matrix (pseudo-count 0.1), and for each state the mean and standard deviation of each sensor (Gaussian emissions, the two sensors independent given the state).On the 5 pumps of
TEST_L, report the accuracy of: (a) classifying each hour from its own readings alone (Gaussian Bayes with the state frequencies as prior); (b) filtering; (c) smoothing. Plot, for one test pump, the true state and the filtered and smoothed .
# Your code hereYour comments:
Part B — Learning from the Unlabelled Pumps (25 points)¶
Most pumps have no logs. Implement Baum–Welch for this Gaussian HMM (the M-step re-estimates the means and standard deviations as averages weighted by the smoothed state probabilities) and learn from the 30 pumps of UNLABELLED alone, from two starts:
a random start (random means within the range of the readings, any transition matrix);
an informed start: states ordered by severity (means increasing with the state), a left-to-right transition matrix (a pump never gets better).
Compare the two results with the supervised model of Part A: the learned parameters, the log-likelihood of TEST_L, and the smoothing accuracy on TEST_L (match the learned states to the true ones by their mean vibration).
# Your code hereYour comparison:
Part C — An Early-Warning Alarm (20 points)¶
An alarm can only use the past: it is raised at the first hour when the filtered exceeds a threshold. Using the supervised model, on all 10 labelled pumps:
For thresholds 0.3, 0.5, 0.7 and 0.9, report the number of false alarms (raised before the pump is failing) and, for the pumps that fail, the average delay between the true start of failing and the alarm.
The utility wants the alarm before failure: repeat with an alarm on . What is the average warning time before failure, and how many pumps raise it while still healthy?
# Your code hereYour answer:
Part D — Remaining Useful Life (20 points)¶
For a pump not yet failing, the expected number of hours until it enters failing follows from the transition matrix: with the transitions among {healthy, degrading}, the vector of expected hitting times is . Given a belief over the two states (filtered, renormalised without failing), the estimate is .
Compute from the supervised model. Interpret its two numbers.
For every hour before failure of the labelled pumps, estimate the remaining useful life, and compare with the truth: mean absolute error, overall and by true state. Compare with the naive estimate “the average remaining life over all hours”.
# Your code hereYour answer:
Part E — Recommendation (15 points)¶
Write half a page to the utility: which model should run on the pumps (supervised, learned without labels, or both), which alarm and threshold, and how much warning they can expect. What should they log from now on to improve it? Support each point with your numbers.
Grading Rubric¶
| Criterion | Excellent | Adequate | Insufficient |
|---|---|---|---|
| A (20) | correct model; three accuracies; the plot read | accuracies only | missing |
| B (25) | Baum–Welch from both starts; parameters, likelihood and accuracy compared and explained | one start | missing |
| C (20) | the trade-off between false alarms and delay, for both alarms | one alarm | missing |
| D (20) | hitting times interpreted; errors by state, against the naive estimate | overall error only | missing |
| E (15) | a recommendation grounded in the numbers | generic | missing |