Commit b05f72b
Make decayEffect a continuous function of sample timestamp (#33)
* Make decayEffect a continuous function of sample timestamp
Reformulates decayEffect using a closed-form quadratic in time-since-sample
rather than accumulating step-by-step from the floored simulation boundary.
This makes the effect value at any future absolute timestamp independent of
which delta-sized simulation bucket the sample's startDate falls into.
For samples aligned to delta boundaries the two formulations are
mathematically identical. For unaligned samples (the common case with real
CGM streams) the new formulation removes a small discontinuity that the
old code exhibited at bucket boundaries.
Adds LoopMathTests covering continuity across a delta boundary. Existing
fixture-calibrated tests are re-pinned to the new values; per-prediction
drift is on the order of 0.1 mg/dL.
Ports the LoopMath change from LoopKit/LoopKit#556 by Moti Nisenson-Ken to
the LoopAlgorithm package, where decayEffect now lives.
* Space to kick off tests
---------
Co-authored-by: Pete Schwamb <pete@pete-mbp-eth.maplect.net>1 parent bd1a879 commit b05f72b
6 files changed
Lines changed: 152 additions & 98 deletions
File tree
- Sources/LoopAlgorithm
- Tests/LoopAlgorithmTests
- Fixtures
- Mocks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
199 | 206 | | |
200 | 207 | | |
201 | | - | |
202 | | - | |
| 208 | + | |
203 | 209 | | |
204 | 210 | | |
205 | | - | |
| 211 | + | |
| 212 | + | |
206 | 213 | | |
207 | | - | |
208 | 214 | | |
209 | 215 | | |
210 | 216 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
0 commit comments