ceo-mof 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ceo_mof-0.2.0/PKG-INFO +204 -0
- ceo_mof-0.2.0/README.md +185 -0
- ceo_mof-0.2.0/ceo_mof/__init__.py +2 -0
- ceo_mof-0.2.0/ceo_mof/__main__.py +5 -0
- ceo_mof-0.2.0/ceo_mof/checks.py +288 -0
- ceo_mof-0.2.0/ceo_mof/cli.py +76 -0
- ceo_mof-0.2.0/ceo_mof/data.py +48 -0
- ceo_mof-0.2.0/ceo_mof/evaluate.py +37 -0
- ceo_mof-0.2.0/ceo_mof/experiment.py +290 -0
- ceo_mof-0.2.0/ceo_mof/features.py +98 -0
- ceo_mof-0.2.0/ceo_mof/mof.py +54 -0
- ceo_mof-0.2.0/ceo_mof/mow_ecg.py +165 -0
- ceo_mof-0.2.0/ceo_mof/notebook_ref.py +48 -0
- ceo_mof-0.2.0/ceo_mof/reference/MOW_ECG_v5.ipynb +11264 -0
- ceo_mof-0.2.0/ceo_mof/reference/r1_previous_grid.csv +3841 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/PKG-INFO +204 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/SOURCES.txt +22 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/dependency_links.txt +1 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/entry_points.txt +2 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/requires.txt +11 -0
- ceo_mof-0.2.0/ceo_mof.egg-info/top_level.txt +1 -0
- ceo_mof-0.2.0/pyproject.toml +34 -0
- ceo_mof-0.2.0/setup.cfg +4 -0
- ceo_mof-0.2.0/tests/test_core.py +64 -0
ceo_mof-0.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ceo-mof
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MOW-ECG R-peak detection with expanding-statistics context features (CEO-MOF experiment)
|
|
5
|
+
Author-email: Vitchawong Laohabutr <vitchawong@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: numpy>=1.22
|
|
10
|
+
Requires-Dist: scipy>=1.9
|
|
11
|
+
Requires-Dist: pandas>=1.4
|
|
12
|
+
Requires-Dist: wfdb>=4.1
|
|
13
|
+
Requires-Dist: neurokit2>=0.2
|
|
14
|
+
Requires-Dist: joblib>=1.3
|
|
15
|
+
Requires-Dist: numba>=0.56
|
|
16
|
+
Requires-Dist: pymof>=0.7
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
19
|
+
|
|
20
|
+
# CEO-MOF with expanding statistics
|
|
21
|
+
|
|
22
|
+
Code for the corrected CEO-MOF experiment (design report: *"CEO-MOF With Expanding
|
|
23
|
+
Statistics: Corrected Experiment Design"*). It adds **expanding-statistics context**
|
|
24
|
+
to MOW-ECG's MOF input and measures R-peak detection on MIT-BIH.
|
|
25
|
+
|
|
26
|
+
- MOW-ECG itself is a faithful port of **`MOW_ECG_v5.ipynb`** (R-peak path). Your
|
|
27
|
+
notebook ships inside the package (`ceo_mof/reference/`) and `verify` runs it
|
|
28
|
+
**unchanged with the real pymof** to prove the port gives identical R-peaks.
|
|
29
|
+
- Only the MOF input changes between rungs. Preprocessing, windows, candidate
|
|
30
|
+
search, filtering, merging and evaluation are the same for every rung.
|
|
31
|
+
- Every context feature at time *i* uses only samples 0..*i* (checked).
|
|
32
|
+
|
|
33
|
+
## Install
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
cd ceo-mof-expanding
|
|
37
|
+
pip install . # or: pip install -e . (editable, for development)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Python 3.9+. Installs numpy, scipy, pandas, wfdb, neurokit2, joblib, numba, pymof.
|
|
41
|
+
This also gives the command `ceo-mof` (same as `python -m ceo_mof`).
|
|
42
|
+
|
|
43
|
+
## Run it: five steps
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# 1. data (about 100 MB; skip if you already have the mitdb folder)
|
|
47
|
+
ceo-mof download --data-dir mitdb
|
|
48
|
+
|
|
49
|
+
# 2. verify the pipeline is MOW-ECG (~3-5 min)
|
|
50
|
+
ceo-mof verify --data-dir mitdb
|
|
51
|
+
|
|
52
|
+
# 3. pre-run checks on the 6 quick records (~3-5 min)
|
|
53
|
+
ceo-mof check --data-dir mitdb
|
|
54
|
+
|
|
55
|
+
# -> read results_expanding/checks/prerun_checks_zerophase_MLII.txt before step 4
|
|
56
|
+
|
|
57
|
+
# 4. the experiment: 11 rungs x 48 records x 80 settings (~45 min on 12 workers)
|
|
58
|
+
ceo-mof run --data-dir mitdb --records all --workers 12
|
|
59
|
+
|
|
60
|
+
# 5. (optional) rebuild the report from saved results
|
|
61
|
+
ceo-mof report --data-dir mitdb
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
PowerShell is the same. The results folder is `results_expanding/` (change with `--out`).
|
|
65
|
+
Everything is cached per record, so an interrupted `run` resumes where it stopped.
|
|
66
|
+
|
|
67
|
+
## The rungs
|
|
68
|
+
|
|
69
|
+
| Rung | Features (all scaled per window with robust z, except R1) | Question |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| R1 | amplitude x (unscaled, = MOW-ECG) | baseline |
|
|
72
|
+
| T | x, position in window (0 to 1) | control: what does a pure time marker do? |
|
|
73
|
+
| A1 | x, μ⁽⁰⁾ | does the signal's usual level so far help? |
|
|
74
|
+
| A2 | x, μ⁽⁰⁾, σ⁽⁰⁾ | + its usual spread |
|
|
75
|
+
| A3 | x, μ⁽⁰⁾, σ⁽⁰⁾, skewness | + the lean of its history |
|
|
76
|
+
| A4 | x, μ⁽⁰⁾, σ⁽⁰⁾, skewness, kurtosis | + spikiness of its history |
|
|
77
|
+
| B1 | x, μ⁽¹⁾, σ⁽¹⁾ | history of slopes (1st difference) |
|
|
78
|
+
| B2 | x, μ⁽²⁾, σ⁽²⁾ | history of curvature (2nd difference) |
|
|
79
|
+
| B3 | x, μ⁽³⁾, σ⁽³⁾ | history of the 3rd difference |
|
|
80
|
+
| B123 | x + all six of B1-B3 | all orders together |
|
|
81
|
+
| AB1 | x, μ⁽⁰⁾, σ⁽⁰⁾, μ⁽¹⁾, σ⁽¹⁾ | closest to Yin Jiang's vector (without time index) |
|
|
82
|
+
|
|
83
|
+
Definitions (`ceo_mof/features.py`):
|
|
84
|
+
- Backward differences: Δx_i = x_i − x_{i−1}, Δ²x_i = x_i − 2x_{i−1} + x_{i−2}, Δ³x_i = x_i − 3x_{i−1} + 3x_{i−2} − x_{i−3}.
|
|
85
|
+
The difference values are **never** given to MOF.
|
|
86
|
+
- μ⁽ʳ⁾_i, σ⁽ʳ⁾_i: expanding mean and population SD of Δʳx over positions r..i (Eqs. 5–6); 0 for i < r.
|
|
87
|
+
- Skewness, kurtosis: standardized central moments of x over 0..i (kurtosis non-excess, normal = 3); 0 where SD = 0.
|
|
88
|
+
- Computed in one streaming pass (Welford/Pébay update), numerically stable over 650,000 samples.
|
|
89
|
+
- The expansion starts at the **beginning of the record** (open question 1 in the design report).
|
|
90
|
+
- Scaling: robust z per window and per column, `(v − median) / (1.4826·MAD)`, no additive
|
|
91
|
+
constant; a column with MAD = 0 in a window is set to 0.
|
|
92
|
+
|
|
93
|
+
Everything else is MOW-ECG: MLII lead, full 30-min records, raw ADC values; zero-phase
|
|
94
|
+
Butterworth 0.5 Hz + 50 Hz powerline filter; 3 s windows every 2 s; candidate search
|
|
95
|
+
and RR filter from `approx_peaks_v5` / `filter_false_positives_rr_outlier_v5`; merge from
|
|
96
|
+
`overlapping_window_MOF_PQRST_v5`; ±50 ms greedy matching on beat annotations only.
|
|
97
|
+
|
|
98
|
+
## What `verify` proves
|
|
99
|
+
|
|
100
|
+
1. **MOF**: the vectorised MOF equals pymof (max difference 0) on random data with ties
|
|
101
|
+
(1, 3 and 8 features) and on real windows, for R1 and for multi-feature rungs.
|
|
102
|
+
2. **Port = your notebook**: runs `overlapping_window_MOF_PQRST_v5` from the shipped
|
|
103
|
+
notebook with the real pymof and compares R-peaks at IRP 0.6 / MRI 0.3 (the notebook's
|
|
104
|
+
hard-coded values). Default record 100; add more with `--notebook-records 100,203`
|
|
105
|
+
(about 1 min each).
|
|
106
|
+
3. **R1 = the earlier experiments**: TP/FP/FN at all 80 IRP/MRI settings against the R1
|
|
107
|
+
results of the earlier ladder runs (`ceo_mof/reference/r1_previous_grid.csv`).
|
|
108
|
+
This confirms your data, library versions, lead and beat set match the earlier runs.
|
|
109
|
+
|
|
110
|
+
Tested while building this package on record 100: all three PASS (2272 peaks, TP 2186,
|
|
111
|
+
FP 86, FN 87; all 80 settings identical).
|
|
112
|
+
|
|
113
|
+
## What `check` reports (the five pre-run checks)
|
|
114
|
+
|
|
115
|
+
| # | Check | Pass when |
|
|
116
|
+
|---|---|---|
|
|
117
|
+
| 1 | Causality: features from samples 0..i only = features at i from the full record (20 random i) | bit-equal |
|
|
118
|
+
| 2 | Formulas vs numpy/scipy at 10 positions | relative difference < 1e-8 |
|
|
119
|
+
| 3 | Baseline: amplitude through the scaled path vs R1 | same scores (or same detections on all 80 settings) |
|
|
120
|
+
| 4 | Spread: within-window MAD and range of every feature, unscaled, next to amplitude | report only |
|
|
121
|
+
| 5 | Time link: median \|Spearman\| between each scaled feature and its position in the window, all windows / first 5 min / rest | report only |
|
|
122
|
+
|
|
123
|
+
It also states whether the preprocessing filter uses future samples. (It does: NeuroKit's
|
|
124
|
+
Butterworth uses `sosfiltfilt` and the powerline filter uses `filtfilt`.)
|
|
125
|
+
|
|
126
|
+
On record 100, checks 4–5 already showed the risk in the design report: inside a 3 s
|
|
127
|
+
window the expanding features vary by 1e-4 of amplitude or less, and several SD features
|
|
128
|
+
follow the time position (|Spearman| 0.3–0.5). Rung T is there to tell this apart from
|
|
129
|
+
real history information.
|
|
130
|
+
|
|
131
|
+
## Outputs (`results_expanding/`)
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
checks/verify_zerophase_MLII.txt verification
|
|
135
|
+
checks/prerun_checks_zerophase_MLII.txt pre-run checks (+ spread_*.csv, time_link_*.csv)
|
|
136
|
+
report/zerophase_MLII/report.txt the results, ready to paste into the report
|
|
137
|
+
report/zerophase_MLII/
|
|
138
|
+
totals_global_{thesis,aami}.csv Se/PPV/DER/F1 per rung at 0.6/0.3
|
|
139
|
+
totals_bestglobal_{thesis,aami}.csv ... at each rung's own best setting
|
|
140
|
+
per_record_F1_*.csv F1 per record
|
|
141
|
+
wilcoxon_thesis.csv paired tests (bar: p < 0.005)
|
|
142
|
+
focus_records_F1_*.csv 117, 124, 108, 200, 203, 219, 220, 221
|
|
143
|
+
early_vs_rest_F1_thesis.csv first 5 minutes vs the rest
|
|
144
|
+
grid_all_records.csv TP/FP/FN for every record, rung, setting
|
|
145
|
+
scores/, grid/, split/ per-record cache (safe to delete; resumes)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`report.txt` matches the empty tables in the design report's Results section.
|
|
149
|
+
|
|
150
|
+
## Options
|
|
151
|
+
|
|
152
|
+
| Option | Default | Meaning |
|
|
153
|
+
|---|---|---|
|
|
154
|
+
| `--records` | quick (verify/check), all (run) | `quick`, `all`, or `100,203,...` |
|
|
155
|
+
| `--rungs` | all 11 | e.g. `R1,T,A2,B1` |
|
|
156
|
+
| `--workers` | CPU count − 1 | parallel records |
|
|
157
|
+
| `--filter` | `zerophase` | `causal` = forward-only filters (a true data-stream variant; changes R1 too) |
|
|
158
|
+
| `--lead` | `MLII` | or a channel number such as `0` (the notebook uses channel 0; only 114 differs) |
|
|
159
|
+
| `--out` | `results_expanding` | output folder |
|
|
160
|
+
| `--notebook-records` | `100` | records for the notebook comparison in `verify` |
|
|
161
|
+
|
|
162
|
+
## Runtime
|
|
163
|
+
|
|
164
|
+
- MOF for all 11 rungs: about 0.63 s per window, 903 windows per record, so about
|
|
165
|
+
10 minutes per record per core. The 80-setting grid adds about 45 s per record.
|
|
166
|
+
- 48 records: about 45 minutes on 12 workers; about 4–5 hours on Colab's 2 cores.
|
|
167
|
+
- Memory: about 150 MB per worker.
|
|
168
|
+
|
|
169
|
+
## Colab
|
|
170
|
+
|
|
171
|
+
Open `run_in_colab.ipynb`. It installs the package, downloads MIT-BIH, and writes results
|
|
172
|
+
to Google Drive so a disconnect doesn't lose finished records.
|
|
173
|
+
|
|
174
|
+
## Tests
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
pip install pytest
|
|
178
|
+
pytest -q tests
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Six fast tests on synthetic data: MOF vs pymof with ties, Eq. 4 differences, expanding
|
|
182
|
+
formulas and causality, scaling with a constant column, port vs notebook, and matching.
|
|
183
|
+
|
|
184
|
+
## How the code is organised
|
|
185
|
+
|
|
186
|
+
| File | Contents |
|
|
187
|
+
|---|---|
|
|
188
|
+
| `ceo_mof/mow_ecg.py` | MOW-ECG port: `preprocess`, `windows`, `find_candidates`, `filter_candidates`, `mow_ecg_from_scores`, `mow_ecg` |
|
|
189
|
+
| `ceo_mof/mof.py` | vectorised MOF, bit-identical to pymof |
|
|
190
|
+
| `ceo_mof/features.py` | backward differences, expanding moments, window position, scaling |
|
|
191
|
+
| `ceo_mof/experiment.py` | rungs, scoring, caching, 80-setting grid, parallel run, summaries, report |
|
|
192
|
+
| `ceo_mof/checks.py` | `verify` and `check` |
|
|
193
|
+
| `ceo_mof/notebook_ref.py` | runs your notebook's v5 cells as the reference |
|
|
194
|
+
| `ceo_mof/evaluate.py` | ±50 ms matching (as in the notebook), Se/PPV/DER/F1 |
|
|
195
|
+
| `ceo_mof/data.py` | MIT-BIH loading, record lists, exclusion sets |
|
|
196
|
+
|
|
197
|
+
### Differences from the notebook (none change the R-peaks; `verify` checks this)
|
|
198
|
+
|
|
199
|
+
- IRP and MRI are parameters (the notebook hard-codes 0.6 s and 0.3 s).
|
|
200
|
+
- The notebook's CLCCP/CLCVP/SOD signals and P/Q/S/T detection are not computed: they
|
|
201
|
+
do not affect R-peaks.
|
|
202
|
+
- No print statements or global variables.
|
|
203
|
+
- MOF scores are computed by the vectorised MOF and passed in, instead of calling pymof
|
|
204
|
+
inside the window loop.
|
ceo_mof-0.2.0/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# CEO-MOF with expanding statistics
|
|
2
|
+
|
|
3
|
+
Code for the corrected CEO-MOF experiment (design report: *"CEO-MOF With Expanding
|
|
4
|
+
Statistics: Corrected Experiment Design"*). It adds **expanding-statistics context**
|
|
5
|
+
to MOW-ECG's MOF input and measures R-peak detection on MIT-BIH.
|
|
6
|
+
|
|
7
|
+
- MOW-ECG itself is a faithful port of **`MOW_ECG_v5.ipynb`** (R-peak path). Your
|
|
8
|
+
notebook ships inside the package (`ceo_mof/reference/`) and `verify` runs it
|
|
9
|
+
**unchanged with the real pymof** to prove the port gives identical R-peaks.
|
|
10
|
+
- Only the MOF input changes between rungs. Preprocessing, windows, candidate
|
|
11
|
+
search, filtering, merging and evaluation are the same for every rung.
|
|
12
|
+
- Every context feature at time *i* uses only samples 0..*i* (checked).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
cd ceo-mof-expanding
|
|
18
|
+
pip install . # or: pip install -e . (editable, for development)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Python 3.9+. Installs numpy, scipy, pandas, wfdb, neurokit2, joblib, numba, pymof.
|
|
22
|
+
This also gives the command `ceo-mof` (same as `python -m ceo_mof`).
|
|
23
|
+
|
|
24
|
+
## Run it: five steps
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# 1. data (about 100 MB; skip if you already have the mitdb folder)
|
|
28
|
+
ceo-mof download --data-dir mitdb
|
|
29
|
+
|
|
30
|
+
# 2. verify the pipeline is MOW-ECG (~3-5 min)
|
|
31
|
+
ceo-mof verify --data-dir mitdb
|
|
32
|
+
|
|
33
|
+
# 3. pre-run checks on the 6 quick records (~3-5 min)
|
|
34
|
+
ceo-mof check --data-dir mitdb
|
|
35
|
+
|
|
36
|
+
# -> read results_expanding/checks/prerun_checks_zerophase_MLII.txt before step 4
|
|
37
|
+
|
|
38
|
+
# 4. the experiment: 11 rungs x 48 records x 80 settings (~45 min on 12 workers)
|
|
39
|
+
ceo-mof run --data-dir mitdb --records all --workers 12
|
|
40
|
+
|
|
41
|
+
# 5. (optional) rebuild the report from saved results
|
|
42
|
+
ceo-mof report --data-dir mitdb
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
PowerShell is the same. The results folder is `results_expanding/` (change with `--out`).
|
|
46
|
+
Everything is cached per record, so an interrupted `run` resumes where it stopped.
|
|
47
|
+
|
|
48
|
+
## The rungs
|
|
49
|
+
|
|
50
|
+
| Rung | Features (all scaled per window with robust z, except R1) | Question |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| R1 | amplitude x (unscaled, = MOW-ECG) | baseline |
|
|
53
|
+
| T | x, position in window (0 to 1) | control: what does a pure time marker do? |
|
|
54
|
+
| A1 | x, μ⁽⁰⁾ | does the signal's usual level so far help? |
|
|
55
|
+
| A2 | x, μ⁽⁰⁾, σ⁽⁰⁾ | + its usual spread |
|
|
56
|
+
| A3 | x, μ⁽⁰⁾, σ⁽⁰⁾, skewness | + the lean of its history |
|
|
57
|
+
| A4 | x, μ⁽⁰⁾, σ⁽⁰⁾, skewness, kurtosis | + spikiness of its history |
|
|
58
|
+
| B1 | x, μ⁽¹⁾, σ⁽¹⁾ | history of slopes (1st difference) |
|
|
59
|
+
| B2 | x, μ⁽²⁾, σ⁽²⁾ | history of curvature (2nd difference) |
|
|
60
|
+
| B3 | x, μ⁽³⁾, σ⁽³⁾ | history of the 3rd difference |
|
|
61
|
+
| B123 | x + all six of B1-B3 | all orders together |
|
|
62
|
+
| AB1 | x, μ⁽⁰⁾, σ⁽⁰⁾, μ⁽¹⁾, σ⁽¹⁾ | closest to Yin Jiang's vector (without time index) |
|
|
63
|
+
|
|
64
|
+
Definitions (`ceo_mof/features.py`):
|
|
65
|
+
- Backward differences: Δx_i = x_i − x_{i−1}, Δ²x_i = x_i − 2x_{i−1} + x_{i−2}, Δ³x_i = x_i − 3x_{i−1} + 3x_{i−2} − x_{i−3}.
|
|
66
|
+
The difference values are **never** given to MOF.
|
|
67
|
+
- μ⁽ʳ⁾_i, σ⁽ʳ⁾_i: expanding mean and population SD of Δʳx over positions r..i (Eqs. 5–6); 0 for i < r.
|
|
68
|
+
- Skewness, kurtosis: standardized central moments of x over 0..i (kurtosis non-excess, normal = 3); 0 where SD = 0.
|
|
69
|
+
- Computed in one streaming pass (Welford/Pébay update), numerically stable over 650,000 samples.
|
|
70
|
+
- The expansion starts at the **beginning of the record** (open question 1 in the design report).
|
|
71
|
+
- Scaling: robust z per window and per column, `(v − median) / (1.4826·MAD)`, no additive
|
|
72
|
+
constant; a column with MAD = 0 in a window is set to 0.
|
|
73
|
+
|
|
74
|
+
Everything else is MOW-ECG: MLII lead, full 30-min records, raw ADC values; zero-phase
|
|
75
|
+
Butterworth 0.5 Hz + 50 Hz powerline filter; 3 s windows every 2 s; candidate search
|
|
76
|
+
and RR filter from `approx_peaks_v5` / `filter_false_positives_rr_outlier_v5`; merge from
|
|
77
|
+
`overlapping_window_MOF_PQRST_v5`; ±50 ms greedy matching on beat annotations only.
|
|
78
|
+
|
|
79
|
+
## What `verify` proves
|
|
80
|
+
|
|
81
|
+
1. **MOF**: the vectorised MOF equals pymof (max difference 0) on random data with ties
|
|
82
|
+
(1, 3 and 8 features) and on real windows, for R1 and for multi-feature rungs.
|
|
83
|
+
2. **Port = your notebook**: runs `overlapping_window_MOF_PQRST_v5` from the shipped
|
|
84
|
+
notebook with the real pymof and compares R-peaks at IRP 0.6 / MRI 0.3 (the notebook's
|
|
85
|
+
hard-coded values). Default record 100; add more with `--notebook-records 100,203`
|
|
86
|
+
(about 1 min each).
|
|
87
|
+
3. **R1 = the earlier experiments**: TP/FP/FN at all 80 IRP/MRI settings against the R1
|
|
88
|
+
results of the earlier ladder runs (`ceo_mof/reference/r1_previous_grid.csv`).
|
|
89
|
+
This confirms your data, library versions, lead and beat set match the earlier runs.
|
|
90
|
+
|
|
91
|
+
Tested while building this package on record 100: all three PASS (2272 peaks, TP 2186,
|
|
92
|
+
FP 86, FN 87; all 80 settings identical).
|
|
93
|
+
|
|
94
|
+
## What `check` reports (the five pre-run checks)
|
|
95
|
+
|
|
96
|
+
| # | Check | Pass when |
|
|
97
|
+
|---|---|---|
|
|
98
|
+
| 1 | Causality: features from samples 0..i only = features at i from the full record (20 random i) | bit-equal |
|
|
99
|
+
| 2 | Formulas vs numpy/scipy at 10 positions | relative difference < 1e-8 |
|
|
100
|
+
| 3 | Baseline: amplitude through the scaled path vs R1 | same scores (or same detections on all 80 settings) |
|
|
101
|
+
| 4 | Spread: within-window MAD and range of every feature, unscaled, next to amplitude | report only |
|
|
102
|
+
| 5 | Time link: median \|Spearman\| between each scaled feature and its position in the window, all windows / first 5 min / rest | report only |
|
|
103
|
+
|
|
104
|
+
It also states whether the preprocessing filter uses future samples. (It does: NeuroKit's
|
|
105
|
+
Butterworth uses `sosfiltfilt` and the powerline filter uses `filtfilt`.)
|
|
106
|
+
|
|
107
|
+
On record 100, checks 4–5 already showed the risk in the design report: inside a 3 s
|
|
108
|
+
window the expanding features vary by 1e-4 of amplitude or less, and several SD features
|
|
109
|
+
follow the time position (|Spearman| 0.3–0.5). Rung T is there to tell this apart from
|
|
110
|
+
real history information.
|
|
111
|
+
|
|
112
|
+
## Outputs (`results_expanding/`)
|
|
113
|
+
|
|
114
|
+
```
|
|
115
|
+
checks/verify_zerophase_MLII.txt verification
|
|
116
|
+
checks/prerun_checks_zerophase_MLII.txt pre-run checks (+ spread_*.csv, time_link_*.csv)
|
|
117
|
+
report/zerophase_MLII/report.txt the results, ready to paste into the report
|
|
118
|
+
report/zerophase_MLII/
|
|
119
|
+
totals_global_{thesis,aami}.csv Se/PPV/DER/F1 per rung at 0.6/0.3
|
|
120
|
+
totals_bestglobal_{thesis,aami}.csv ... at each rung's own best setting
|
|
121
|
+
per_record_F1_*.csv F1 per record
|
|
122
|
+
wilcoxon_thesis.csv paired tests (bar: p < 0.005)
|
|
123
|
+
focus_records_F1_*.csv 117, 124, 108, 200, 203, 219, 220, 221
|
|
124
|
+
early_vs_rest_F1_thesis.csv first 5 minutes vs the rest
|
|
125
|
+
grid_all_records.csv TP/FP/FN for every record, rung, setting
|
|
126
|
+
scores/, grid/, split/ per-record cache (safe to delete; resumes)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`report.txt` matches the empty tables in the design report's Results section.
|
|
130
|
+
|
|
131
|
+
## Options
|
|
132
|
+
|
|
133
|
+
| Option | Default | Meaning |
|
|
134
|
+
|---|---|---|
|
|
135
|
+
| `--records` | quick (verify/check), all (run) | `quick`, `all`, or `100,203,...` |
|
|
136
|
+
| `--rungs` | all 11 | e.g. `R1,T,A2,B1` |
|
|
137
|
+
| `--workers` | CPU count − 1 | parallel records |
|
|
138
|
+
| `--filter` | `zerophase` | `causal` = forward-only filters (a true data-stream variant; changes R1 too) |
|
|
139
|
+
| `--lead` | `MLII` | or a channel number such as `0` (the notebook uses channel 0; only 114 differs) |
|
|
140
|
+
| `--out` | `results_expanding` | output folder |
|
|
141
|
+
| `--notebook-records` | `100` | records for the notebook comparison in `verify` |
|
|
142
|
+
|
|
143
|
+
## Runtime
|
|
144
|
+
|
|
145
|
+
- MOF for all 11 rungs: about 0.63 s per window, 903 windows per record, so about
|
|
146
|
+
10 minutes per record per core. The 80-setting grid adds about 45 s per record.
|
|
147
|
+
- 48 records: about 45 minutes on 12 workers; about 4–5 hours on Colab's 2 cores.
|
|
148
|
+
- Memory: about 150 MB per worker.
|
|
149
|
+
|
|
150
|
+
## Colab
|
|
151
|
+
|
|
152
|
+
Open `run_in_colab.ipynb`. It installs the package, downloads MIT-BIH, and writes results
|
|
153
|
+
to Google Drive so a disconnect doesn't lose finished records.
|
|
154
|
+
|
|
155
|
+
## Tests
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pip install pytest
|
|
159
|
+
pytest -q tests
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Six fast tests on synthetic data: MOF vs pymof with ties, Eq. 4 differences, expanding
|
|
163
|
+
formulas and causality, scaling with a constant column, port vs notebook, and matching.
|
|
164
|
+
|
|
165
|
+
## How the code is organised
|
|
166
|
+
|
|
167
|
+
| File | Contents |
|
|
168
|
+
|---|---|
|
|
169
|
+
| `ceo_mof/mow_ecg.py` | MOW-ECG port: `preprocess`, `windows`, `find_candidates`, `filter_candidates`, `mow_ecg_from_scores`, `mow_ecg` |
|
|
170
|
+
| `ceo_mof/mof.py` | vectorised MOF, bit-identical to pymof |
|
|
171
|
+
| `ceo_mof/features.py` | backward differences, expanding moments, window position, scaling |
|
|
172
|
+
| `ceo_mof/experiment.py` | rungs, scoring, caching, 80-setting grid, parallel run, summaries, report |
|
|
173
|
+
| `ceo_mof/checks.py` | `verify` and `check` |
|
|
174
|
+
| `ceo_mof/notebook_ref.py` | runs your notebook's v5 cells as the reference |
|
|
175
|
+
| `ceo_mof/evaluate.py` | ±50 ms matching (as in the notebook), Se/PPV/DER/F1 |
|
|
176
|
+
| `ceo_mof/data.py` | MIT-BIH loading, record lists, exclusion sets |
|
|
177
|
+
|
|
178
|
+
### Differences from the notebook (none change the R-peaks; `verify` checks this)
|
|
179
|
+
|
|
180
|
+
- IRP and MRI are parameters (the notebook hard-codes 0.6 s and 0.3 s).
|
|
181
|
+
- The notebook's CLCCP/CLCVP/SOD signals and P/Q/S/T detection are not computed: they
|
|
182
|
+
do not affect R-peaks.
|
|
183
|
+
- No print statements or global variables.
|
|
184
|
+
- MOF scores are computed by the vectorised MOF and passed in, instead of calling pymof
|
|
185
|
+
inside the window loop.
|