GoldenBatchDeviationEvents¤
Scores how far a batch's trajectory of one signal (reactor temperature, pH, torque) deviates from a golden reference batch: the largest pointwise deviation, the area between the curves, or a dynamic-time-warping shape distance; overall or per recipe phase.
ts_shape.events.development.golden_batch · Engineering guide · API reference
Example¤
import pandas as pd
import ts_shape
from ts_shape.events.development.golden_batch import GoldenBatchDeviationEvents
def batch(n, drift, seed): # one batch: temperature plus its phase signal
return pd.concat([
ts_shape.make_timeseries(["reactor2:jacket_temp"], n_points=n, freq="1min", drift=drift, seed=seed),
ts_shape.make_id_signal("reactor2:phase", ["HEAT_UP", "HOLD", "COOL_DOWN"], hold=n // 3, freq="1min"),
], ignore_index=True)
golden, new = batch(240, 40.0, 1), batch(300, 46.0, 2)
gb = GoldenBatchDeviationEvents(golden, "reactor2:jacket_temp", n_resample=256)
result = gb.compare(new, mode="dtw", dtw_band_frac=0.1)
print(result[["mode", "deviation_score", "max_abs_residual", "batch_time_at_max"]])
phases = gb.phase_breakdown(new, new, phase_uuid="reactor2:phase")
Methods¤
| Method | Returns |
|---|---|
compare(batch_df, mode='pointwise', dtw_band_frac=0.1) |
one row: start, end, mode, deviation_score, max_abs_residual, batch_time_at_max |
phase_breakdown(batch_df, phase_df, phase_uuid) |
one row per phase occurrence: phase, start, end, deviation_score, max_abs_residual |
Notes¤
- The constructor's DataFrame holds the golden batch; it raises
ValueErrorwithout samples ofsignal_uuid. Both batches are mapped to batch time 0 to 1 and interpolated onton_resamplepoints (at least 4), so batches of different length are comparable.batch_time_at_maxis on that scale (0.5 = halfway). - Scores, all in signal units:
pointwiseis the largest absolute residual;areathe integral of the absolute residual over batch time (the mean absolute deviation);dtwthe DTW distance within a Sakoe-Chiba band ofdtw_band_frac×n_resamplepoints, divided by the warping-path length. phase_breakdownreads phase names fromvalue_stringofphase_uuidinphase_df(often the same frame asbatch_df). A phase spanning the fraction [a, b] of the batch is compared with the fraction [a, b] of the golden batch, scored with the area method. This assumes the phase sequence and relative phase lengths are the same in both batches.