Digital Twin with Python (VTR UGE 21), day 3 of 5
Prof. Dr. Utku Kose, Süleyman Demirel University
Part A matches symptoms with faults of the data. Parts B and C repeat two methods of the lecture step by step, with sliders for their numbers: the Hampel test against the mean test, and least squares by Gauss-Newton steps. Part D fits the thermal model to synthetic readings in the browser by hand and shows the sum of squared errors and the three ratios that the data determine. Part E repeats the Kalman filter over eight readings step by step, also with sliders, and Part F computes one step of a Kalman filter by hand. In Parts B, C and E every intermediate value is rounded, and the next step continues with the rounded value, as in a calculation by hand. Part G cleans two minutes of heart-rate readings from a run by hand, with one window of the Hampel filter.
Match each symptom with the fault of the data that causes it.
Back to the lecture: Spikes, gaps and drift, where the text continues after the box of this part.
The worked example of the lecture: seven readings with the value under test in the middle. The Hampel test compares its distance from the median with a limit built from the median absolute deviation (MAD), and the classical test compares its distance from the mean with a limit built from the standard deviation. The sliders set the value under test, a second value of the window and the factor of both limits, 3 in the lecture.
Back to the lecture: Spikes, gaps and drift. The lecture continues there with Section 2 of the Colab notebook: Open it from the next orange box.
Least squares with one parameter, solved by Gauss-Newton steps as in the lecture. Four readings follow the heating of the pack at 40 A with the fan off, and the model is \(\hat{y}(t; \theta)\)\({} = 36 + 31.73\,(1 - e^{-t/\theta})\), whose only parameter is the time constant \(\theta\) in seconds. Each round computes the model values and the residuals, the change of the model values when \(\theta\) grows by \(h = 100\) s, and the step. As in the optimiser of SciPy, a trust region limits every step: It may change \(\theta\) by at most half of its value. The sliders set the true time constant behind the readings, the noise added to them and the starting guess of the fit.
Back to the lecture: Calibration. The lecture continues there with Section 3 of the Colab notebook: Open it from the next orange box.
The dots are noisy temperature measurements of the pack over ninety minutes. Fit the model by hand with the four parameter sliders and watch the sum of squared errors, the sum of the squared differences between the dots and the curve. The four parameters are the internal resistance R0, the heat capacity m cp, the cooling conductance hA0 without the fan and the additional conductance hA1 at full fan. The noise alone leaves a sum of about 65, so no setting can go much lower. Then press Scale all four by 1.5: The curve does not move. Switch the experiment to fan never on and try to find the value of hA1.
The sliders move along the four parameters. The readout of the three ratios shows what the data actually determine: Equal ratios give an identical curve, whatever the four values are.
Back to the lecture: A hidden symmetry. The lecture continues there with Section 4 of the Colab notebook: Open it from the next orange box.
The scalar filter of the lecture on eight readings of a pack that warms by 0.05 °C per step, from 41.00 to 41.35 °C. The belief starts at 40.00 °C with the variance \(P_0 = 1\), a very uncertain guess. Each step predicts with the model, a rise of 0.05 °C, and corrects with the reading. The first reading has no prediction before it. The sliders set the process noise variance \(Q\) and the standard deviation of the sensor noise that the filter assumes, \(R = \sigma^2\). The gain is rounded to four decimals and the belief to three.
Back to the lecture: A Kalman filter instead of overwriting, where the text continues after the box of this part.
The model predicts 40.0 C with a variance of 0.5. The sensor reads 41.5 C with a noise variance of 0.25. The Kalman gain is the prior variance divided by the sum of the prior and the noise variances.
Back to the lecture: A Kalman filter instead of overwriting. The lecture continues there with Section 7 of the Colab notebook: Open it from the next orange box.
Two minutes of a run, one reading every 5 seconds. Three readings are missing, and some readings are spikes from the cadence of the steps. Click every reading that you take for a spike, and click it again to take the mark back. Then test the reading at 35 seconds by hand with the Hampel filter. Its window of seven readings holds 148, 151, 149, 196, 150, 152 and 147 beats per minute (bpm). Compute the median, the MAD and the limit 3 × 1.4826 × MAD, and compare your marks with the filter.
Back to the lecture: Your asset. The lecture continues there with Section 8 of the Colab notebook: Open it from the next orange box.
Answer each question, rate your confidence and check the answer. Results stay in this browser.
Write a short answer to each question. The text is saved in this browser and is included when you export the learning log.