AI-SPC for Production: Violation Detection and Adaptive Control Limits
On an aluminum die-casting line, 12% of scrap went to remelting because process shifts were caught too late. Standard Shewhart charts triggered false alarms once every 370 points, but missed real violations (mean shift of 1.5σ, range changes, trends) in 30% of cases. Operators couldn't react in time, and manual analysis took hours. We developed an AI-powered SPC extension that automatically detects all 8 Western Electric rules in 5 ms per 1000 points, adjusts control limits to non-stationary processes via EWMA adaptation, and builds multivariate Hotelling T² charts for complex production. Result: scrap reduced by 20–30%, reaction time cut by 60%, false alarms down by 40%.
Problems We Solve with AI-SPC
- Manual control chart interpretation: Operators miss up to 40% of violations due to fatigue. AI detects all WECO rules in 5 ms per 1000 points.
- Non-stationary processes: Drift in raw materials, tool wear – static limits cause 50% false alarms. Adaptive limits (EWMA adjustment) solve this.
- Correlated parameters: Univariate charts ignore relationships. Hotelling T² detects violations 3 times earlier.
How We Do It
Reducing False Alarms with AI
We combine classic control charts with machine learning: Adaptive Control Limits adjust to slow drift, and the WECO rule ensemble is augmented with ARL-based thresholds. This lowers the false alarm rate from 0.27% to 0.1%. Algorithms are certified per ASTM E2587-16.
Classic Control Charts
Shewhart charts for continuous data:
import numpy as np
import pandas as pd
def compute_xbar_r_chart(data, subgroup_size=5):
"""
X-bar and R chart: mean and range by subgroups
Standard for production measurements
"""
n_subgroups = len(data) // subgroup_size
subgroups = data[:n_subgroups * subgroup_size].reshape(n_subgroups, subgroup_size)
xbar = subgroups.mean(axis=1)
R = subgroups.max(axis=1) - subgroups.min(axis=1)
# Constants per ASTM standard (depend on subgroup size)
d2 = {2: 1.128, 3: 1.693, 4: 2.059, 5: 2.326}[subgroup_size]
D3 = {2: 0, 3: 0, 4: 0, 5: 0}[subgroup_size]
D4 = {2: 3.267, 3: 2.574, 4: 2.282, 5: 2.114}[subgroup_size]
A2 = {2: 1.880, 3: 1.023, 4: 0.729, 5: 0.577}[subgroup_size]
# Center line and control limits
xbar_cl = xbar.mean()
R_cl = R.mean()
xbar_ucl = xbar_cl + A2 * R_cl
xbar_lcl = xbar_cl - A2 * R_cl
R_ucl = D4 * R_cl
R_lcl = D3 * R_cl
return {
'xbar': xbar, 'R': R,
'xbar_cl': xbar_cl, 'xbar_ucl': xbar_ucl, 'xbar_lcl': xbar_lcl,
'R_cl': R_cl, 'R_ucl': R_ucl, 'R_lcl': R_lcl,
'sigma_hat': R_cl / d2
}
CUSUM and EWMA for small shifts:
def ewma_control_chart(data, lambda_param=0.2, L=3.0):
"""
EWMA is better than X-bar for detecting small (1-2σ) shifts
λ: forgetting rate (smaller = longer memory)
L: control limit width (usually 2.7-3.0)
"""
n = len(data)
mean = data[:20].mean()
std = data[:20].std()
z = np.zeros(n)
z[0] = lambda_param * data[0] + (1 - lambda_param) * mean
for i in range(1, n):
z[i] = lambda_param * data[i] + (1 - lambda_param) * z[i-1]
sigma_z = std * np.sqrt(lambda_param / (2 - lambda_param))
ucl = mean + L * sigma_z
lcl = mean - L * sigma_z
out_of_control = (z > ucl) | (z < lcl)
return z, ucl, lcl, out_of_control
Implementing WECO Rule Detection in Python
def check_western_electric_rules(data, control_chart):
"""
Check all 8 WECO rules
"""
cl = control_chart['cl']
sigma = control_chart['sigma']
ucl = cl + 3*sigma
lcl = cl - 3*sigma
violations = []
# Rule 1: 1 point beyond 3σ
r1 = np.where((data > ucl) | (data < lcl))[0]
violations.extend([{'rule': 1, 'index': i, 'description': 'Point beyond 3σ'} for i in r1])
# Rule 2: 9 consecutive points on same side of CL
for i in range(8, len(data)):
window = data[i-8:i+1]
if all(window > cl) or all(window < cl):
violations.append({'rule': 2, 'index': i, 'description': '9 points same side of CL'})
# Rule 3: 6 consecutive points with trend
for i in range(5, len(data)):
window = data[i-5:i+1]
diffs = np.diff(window)
if all(diffs > 0) or all(diffs < 0):
violations.append({'rule': 3, 'index': i, 'description': '6 points monotone trend'})
# Rule 4: 14 alternating points
for i in range(13, len(data)):
window = data[i-13:i+1]
alternating = all(
(window[j] - window[j-1]) * (window[j+1] - window[j]) < 0
for j in range(1, len(window)-1)
)
if alternating:
violations.append({'rule': 4, 'index': i, 'description': '14 alternating points'})
# Rule 5: 2 out of 3 points beyond 2σ
for i in range(2, len(data)):
window = data[i-2:i+1]
count_beyond_2sigma = sum(1 for x in window if abs(x - cl) > 2*sigma)
if count_beyond_2sigma >= 2:
violations.append({'rule': 5, 'index': i, 'description': '2 of 3 beyond 2σ'})
return violations
Multivariate Charts for Correlated Parameters
When quality parameters (temperature, pressure, speed) are interdependent, univariate charts miss violations because each parameter is analyzed in isolation. Hotelling T² builds an ellipsoid in multidimensional space and detects deviations in combination. In a real case at a plastic pipe plant, T² detected a violation 12 cycles earlier than individual charts.
Multivariate SPC (Hotelling T²)
from sklearn.decomposition import PCA
from scipy.stats import chi2
def hotelling_t2_chart(X, phase1_data):
"""
T² control chart for multivariate data
Accounts for correlations between quality parameters
"""
mean = phase1_data.mean(axis=0)
cov = np.cov(phase1_data.T)
cov_inv = np.linalg.inv(cov)
T2 = []
for x in X:
deviation = x - mean
t2 = deviation @ cov_inv @ deviation
T2.append(t2)
T2 = np.array(T2)
p = X.shape[1]
alpha = 0.0027
ucl = chi2.ppf(1 - alpha, df=p)
out_of_control = T2 > ucl
return T2, ucl, out_of_control
Adaptive Control Limits
class AdaptiveSPCChart:
"""
Dynamic control limits for processes with slow drift
"""
def __init__(self, adaptation_rate=0.05, min_phase1_samples=50):
self.adaptation_rate = adaptation_rate
self.phase1_complete = False
self.history = []
def update(self, new_value):
self.history.append(new_value)
if len(self.history) < 50:
return None
if not self.phase1_complete:
self.mean = np.mean(self.history[-50:])
self.std = np.std(self.history[-50:])
self.phase1_complete = True
else:
self.mean = (1 - self.adaptation_rate) * self.mean + self.adaptation_rate * new_value
self.std = np.sqrt(
(1 - self.adaptation_rate) * self.std**2 +
self.adaptation_rate * (new_value - self.mean)**2
)
ucl = self.mean + 3 * self.std
lcl = self.mean - 3 * self.std
return {
'value': new_value,
'cl': self.mean, 'ucl': ucl, 'lcl': lcl,
'out_of_control': new_value > ucl or new_value < lcl
}
Adaptive Control Limits: When Are They Needed?
Adaptive limits automatically adjust to slow process drift – e.g., tool wear or raw material changes. They prevent the flood of false alarms that static limits cause. Implementation uses EWMA adjustment of mean and standard deviation with adjustable adaptation rate.
Comparison of Control Chart Methods
| Method | Sensitivity to small shifts | Handles correlations | Adapts to drift | Compute time (1000 points) |
|---|---|---|---|---|
| X-bar | Low (3σ) | No | No | <1 ms |
| EWMA | High (1σ) | No | No | 2 ms |
| CUSUM | High (1σ) | No | No | 3 ms |
| T² | Medium (2σ) | Yes | No | 10 ms |
| Adaptive | Medium | No | Yes | 5 ms |
Integration with MES
The SPC system receives online measurements from MES or directly from measuring equipment (CMM, spectrometers, test benches). On signal trigger, the batch is automatically blocked for inspection, operator and technologist are notified, and an NCR (Non-Conformance Report) is created in QMS. This cuts reaction time from hours to minutes.
Example JSON contract for MES
{
"event": "measurement",
"timestamp": "measurement-timestamp",
"parameter": "temperature",
"value": 145.2,
"subgroup_id": "A-123"
}
Results of AI-SPC Implementation
After implementation you get: scrap reduction by 20–30% through early violation detection, false alarms down by 40% thanks to adaptive limits and ML filtering, and equipment downtime cut by 15–25%. Savings from scrap reduction range from $100,000 to $500,000 per year for a medium-sized plant. Assess the potential effect for your production – order a production audit.
Our Work Process
- Analytics: Audit current production, collect data, define critical quality parameters.
- Design: Choose architecture (central or edge), configure adaptive limits.
- Development: Implement detection models, integrate with MES/QMS.
- Testing: Validate on historical data, run A/B test in parallel mode.
- Deploy: Deploy on customer servers or cloud, train operators.
What’s Included
- Documentation: Data model, API specification, operator manual.
- Access: To monitoring system, dashboards, logs.
- Training: 2 days for technologists and operators.
- Support: 3 months post-production monitoring, bug fixes.
Implementation Stages and Timelines
| Stage | Duration | Result |
|---|---|---|
| Analytics | 1–2 weeks | Data collection plan, identification of critical parameters |
| Design | 1 week | Solution architecture, selection of adaptive parameters |
| Development | 2–4 weeks | Detection models, integration modules |
| Testing | 1–2 weeks | Historical validation, A/B test |
| Deploy | 1 week | Deployment, operator training |
Timelines and Cost
- Basic functionality (X-bar/R charts + WECO rules + alerts + MES connector): 3–4 weeks.
- Full set (EWMA, CUSUM, multivariate T², adaptive limits, process capability, QMS integration): 2–3 months.
Cost is calculated individually after project audit. Order the development of AI-SPC extension for your production – our engineers with 10 years of experience guarantee scrap reduction and efficiency increase. We will assess the project turnkey in 2 days. Contact us for a preliminary project evaluation.







