sensor-modeling 0.2.0__py3-none-any.whl

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.
Files changed (114) hide show
  1. sensor_modeling/__init__.py +45 -0
  2. sensor_modeling/alerts/__init__.py +26 -0
  3. sensor_modeling/alerts/alert.py +532 -0
  4. sensor_modeling/analysis/__init__.py +43 -0
  5. sensor_modeling/analysis/_frame.py +19 -0
  6. sensor_modeling/analysis/behavioral_analysis.py +57 -0
  7. sensor_modeling/analysis/behavioral_metrics.py +66 -0
  8. sensor_modeling/analysis/comparison.py +164 -0
  9. sensor_modeling/analysis/dependency_network.py +408 -0
  10. sensor_modeling/analysis/granger_causality.py +314 -0
  11. sensor_modeling/analysis/pipeline.py +168 -0
  12. sensor_modeling/analysis/reporting.py +109 -0
  13. sensor_modeling/baseline/__init__.py +30 -0
  14. sensor_modeling/baseline/adaptive.py +520 -0
  15. sensor_modeling/baseline/features.py +224 -0
  16. sensor_modeling/change_point/__init__.py +13 -0
  17. sensor_modeling/change_point/_validation.py +31 -0
  18. sensor_modeling/change_point/adaptive_normalization.py +55 -0
  19. sensor_modeling/change_point/embedding_cpd.py +60 -0
  20. sensor_modeling/change_point/energy_efficient.py +57 -0
  21. sensor_modeling/change_point/genetic_optimization.py +65 -0
  22. sensor_modeling/cli.py +416 -0
  23. sensor_modeling/context/__init__.py +33 -0
  24. sensor_modeling/context/occupancy.py +529 -0
  25. sensor_modeling/data/__init__.py +5 -0
  26. sensor_modeling/data/loaders.py +146 -0
  27. sensor_modeling/data/preprocessing.py +83 -0
  28. sensor_modeling/data/synthetic.py +121 -0
  29. sensor_modeling/data/validation.py +81 -0
  30. sensor_modeling/evaluation/__init__.py +92 -0
  31. sensor_modeling/evaluation/ablation.py +303 -0
  32. sensor_modeling/evaluation/attribution.py +474 -0
  33. sensor_modeling/evaluation/detection.py +297 -0
  34. sensor_modeling/evaluation/metrics.py +541 -0
  35. sensor_modeling/evaluation/provenance.py +309 -0
  36. sensor_modeling/examples/__init__.py +1 -0
  37. sensor_modeling/examples/demos/__init__.py +1 -0
  38. sensor_modeling/examples/demos/ambient_pipeline_demo.py +418 -0
  39. sensor_modeling/examples/demos/bernoulli_ar_demo.py +356 -0
  40. sensor_modeling/examples/demos/cpd_ar_demo.py +25 -0
  41. sensor_modeling/examples/demos/cpd_benchmark.py +42 -0
  42. sensor_modeling/examples/demos/hmm_granger_demo.py +30 -0
  43. sensor_modeling/examples/demos/nhpp_pelt_demo.py +80 -0
  44. sensor_modeling/examples/tutorials/__init__.py +1 -0
  45. sensor_modeling/fusion/__init__.py +46 -0
  46. sensor_modeling/fusion/defaults.py +296 -0
  47. sensor_modeling/fusion/emissions.py +339 -0
  48. sensor_modeling/fusion/estimate.py +375 -0
  49. sensor_modeling/fusion/filter.py +323 -0
  50. sensor_modeling/health/__init__.py +31 -0
  51. sensor_modeling/health/monitor.py +590 -0
  52. sensor_modeling/health/status.py +74 -0
  53. sensor_modeling/hmm/__init__.py +15 -0
  54. sensor_modeling/hmm/adaptive_hmm.py +22 -0
  55. sensor_modeling/hmm/base.py +134 -0
  56. sensor_modeling/hmm/circadian_hmm.py +22 -0
  57. sensor_modeling/hmm/heterogeneous_hmm.py +22 -0
  58. sensor_modeling/hmm/hierarchical_hmm.py +35 -0
  59. sensor_modeling/hmm/scaled_dirichlet_hmm.py +23 -0
  60. sensor_modeling/interop/__init__.py +57 -0
  61. sensor_modeling/interop/fhir.py +418 -0
  62. sensor_modeling/interop/privacy.py +308 -0
  63. sensor_modeling/models/__init__.py +12 -0
  64. sensor_modeling/models/bernoulli_ar/__init__.py +6 -0
  65. sensor_modeling/models/bernoulli_ar/base_model.py +569 -0
  66. sensor_modeling/models/bernoulli_ar/multivariate_model.py +411 -0
  67. sensor_modeling/models/change_point_detection/__init__.py +10 -0
  68. sensor_modeling/models/change_point_detection/deep.py +65 -0
  69. sensor_modeling/models/change_point_detection/pelt.py +159 -0
  70. sensor_modeling/models/nhpp_pelt/__init__.py +5 -0
  71. sensor_modeling/models/nhpp_pelt/bspline.py +96 -0
  72. sensor_modeling/models/nhpp_pelt/cli.py +243 -0
  73. sensor_modeling/models/nhpp_pelt/diagnostics.py +234 -0
  74. sensor_modeling/models/nhpp_pelt/io.py +58 -0
  75. sensor_modeling/models/nhpp_pelt/model.py +408 -0
  76. sensor_modeling/models/nhpp_pelt/optimizer.py +142 -0
  77. sensor_modeling/models/nhpp_pelt/plotting.py +218 -0
  78. sensor_modeling/models/nhpp_pelt/quad.py +72 -0
  79. sensor_modeling/models/nhpp_pelt/regularization.py +121 -0
  80. sensor_modeling/models/nhpp_pelt/utils.py +174 -0
  81. sensor_modeling/observations/__init__.py +59 -0
  82. sensor_modeling/observations/adapters.py +195 -0
  83. sensor_modeling/observations/ingest.py +269 -0
  84. sensor_modeling/observations/observation.py +270 -0
  85. sensor_modeling/observations/registry.py +262 -0
  86. sensor_modeling/observations/stream.py +342 -0
  87. sensor_modeling/observations/types.py +107 -0
  88. sensor_modeling/observations/units.py +117 -0
  89. sensor_modeling/online/__init__.py +36 -0
  90. sensor_modeling/online/benchmarks.py +242 -0
  91. sensor_modeling/online/pipeline.py +485 -0
  92. sensor_modeling/simulation/__init__.py +54 -0
  93. sensor_modeling/simulation/faults.py +191 -0
  94. sensor_modeling/simulation/household.py +862 -0
  95. sensor_modeling/states/__init__.py +23 -0
  96. sensor_modeling/states/markov.py +105 -0
  97. sensor_modeling/states/ontology.py +238 -0
  98. sensor_modeling/utils/__init__.py +41 -0
  99. sensor_modeling/utils/data_io.py +199 -0
  100. sensor_modeling/utils/logging_config.py +10 -0
  101. sensor_modeling/utils/missing.py +188 -0
  102. sensor_modeling/utils/plotting.py +98 -0
  103. sensor_modeling/utils/validation.py +117 -0
  104. sensor_modeling/visualization/__init__.py +3 -0
  105. sensor_modeling/visualization/clinical.py +67 -0
  106. sensor_modeling/visualization/interactive.py +208 -0
  107. sensor_modeling/visualization/research.py +60 -0
  108. sensor_modeling/visualization/web_app.py +137 -0
  109. sensor_modeling-0.2.0.dist-info/METADATA +683 -0
  110. sensor_modeling-0.2.0.dist-info/RECORD +114 -0
  111. sensor_modeling-0.2.0.dist-info/WHEEL +5 -0
  112. sensor_modeling-0.2.0.dist-info/entry_points.txt +18 -0
  113. sensor_modeling-0.2.0.dist-info/licenses/LICENSE +21 -0
  114. sensor_modeling-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,683 @@
1
+ Metadata-Version: 2.4
2
+ Name: sensor-modeling
3
+ Version: 0.2.0
4
+ Summary: Interpretable, probabilistic, privacy-preserving multimodal ambient sensing for behavioural research
5
+ Author-email: Diogo Ribeiro <dfr@esmad.ipp.pt>
6
+ Maintainer-email: Diogo Ribeiro <dfr@esmad.ipp.pt>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/DiogoRibeiro7/behavioral-sensing-research
9
+ Project-URL: Documentation, https://sensor-modeling.readthedocs.io
10
+ Project-URL: Repository, https://github.com/DiogoRibeiro7/behavioral-sensing-research
11
+ Project-URL: Bug Tracker, https://github.com/DiogoRibeiro7/behavioral-sensing-research/issues
12
+ Project-URL: Feature Requests, https://github.com/DiogoRibeiro7/behavioral-sensing-research/discussions
13
+ Project-URL: Changelog, https://github.com/DiogoRibeiro7/behavioral-sensing-research/blob/main/CHANGELOG.md
14
+ Project-URL: Zenodo DOI, https://doi.org/10.5281/zenodo.17070041
15
+ Project-URL: Citation, https://github.com/DiogoRibeiro7/behavioral-sensing-research/blob/main/CITATION.cff
16
+ Project-URL: Research Papers, https://github.com/DiogoRibeiro7/behavioral-sensing-research/blob/main/paper.bib
17
+ Project-URL: Funding, https://github.com/sponsors/DiogoRibeiro7
18
+ Keywords: sensor-modeling,ambient-assisted-living,digital-health,smart-homes,time-series-analysis,change-point-detection,hidden-markov-models,behavioral-monitoring,activity-recognition,machine-learning,healthcare-technology,iot-sensors,elderly-care,assistive-technology,python
19
+ Classifier: Development Status :: 4 - Beta
20
+ Classifier: Intended Audience :: Science/Research
21
+ Classifier: Intended Audience :: Healthcare Industry
22
+ Classifier: Intended Audience :: Developers
23
+ Classifier: Intended Audience :: Education
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
26
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
27
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
+ Classifier: Topic :: Home Automation
29
+ Classifier: Topic :: System :: Monitoring
30
+ Classifier: Programming Language :: Python :: 3
31
+ Classifier: Programming Language :: Python :: 3.10
32
+ Classifier: Programming Language :: Python :: 3.11
33
+ Classifier: Programming Language :: Python :: 3.12
34
+ Classifier: Programming Language :: Python :: Implementation :: CPython
35
+ Classifier: Operating System :: OS Independent
36
+ Classifier: Operating System :: POSIX :: Linux
37
+ Classifier: Operating System :: Microsoft :: Windows
38
+ Classifier: Operating System :: MacOS
39
+ Classifier: Natural Language :: English
40
+ Classifier: Environment :: Console
41
+ Classifier: Environment :: Web Environment
42
+ Classifier: Framework :: Flask
43
+ Classifier: Framework :: Matplotlib
44
+ Classifier: Framework :: Jupyter
45
+ Requires-Python: <3.13,>=3.10
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: numpy>=1.21.0
49
+ Requires-Dist: pandas>=1.3.0
50
+ Requires-Dist: scipy>=1.7.0
51
+ Requires-Dist: scikit-learn>=1.0.0
52
+ Requires-Dist: matplotlib>=3.5.0
53
+ Requires-Dist: seaborn>=0.11.0
54
+ Requires-Dist: networkx>=2.6
55
+ Requires-Dist: h5py>=3.1.0
56
+ Requires-Dist: plotly>=5.0.0
57
+ Requires-Dist: bokeh>=2.4.0
58
+ Requires-Dist: flask>=2.0.0
59
+ Requires-Dist: click>=8.0.0
60
+ Requires-Dist: pyyaml>=6.0
61
+ Requires-Dist: tqdm>=4.60.0
62
+ Requires-Dist: joblib>=1.1.0
63
+ Provides-Extra: dev
64
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
65
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
66
+ Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
67
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == "dev"
68
+ Requires-Dist: hypothesis>=6.0.0; extra == "dev"
69
+ Requires-Dist: coverage[toml]>=7.0.0; extra == "dev"
70
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
71
+ Requires-Dist: black>=23.0.0; extra == "dev"
72
+ Requires-Dist: isort>=5.12.0; extra == "dev"
73
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
74
+ Requires-Dist: flake8-docstrings>=1.7.0; extra == "dev"
75
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
76
+ Requires-Dist: bandit>=1.7.0; extra == "dev"
77
+ Requires-Dist: safety>=2.0.0; extra == "dev"
78
+ Requires-Dist: radon>=6.0.1; extra == "dev"
79
+ Requires-Dist: build>=0.10.0; extra == "dev"
80
+ Requires-Dist: twine>=6.2.0; extra == "dev"
81
+ Requires-Dist: setuptools-scm>=7.0.0; extra == "dev"
82
+ Provides-Extra: docs
83
+ Requires-Dist: mkdocs>=1.6.0; extra == "docs"
84
+ Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
85
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
86
+ Requires-Dist: mkdocs-jupyter>=0.24.0; extra == "docs"
87
+ Requires-Dist: jupyterlab>=4.0.0; extra == "docs"
88
+ Requires-Dist: notebook>=7.0.0; extra == "docs"
89
+ Requires-Dist: ipykernel>=6.20.0; extra == "docs"
90
+ Provides-Extra: performance
91
+ Requires-Dist: numba>=0.58.0; extra == "performance"
92
+ Requires-Dist: cython>=3.0.0; extra == "performance"
93
+ Requires-Dist: bottleneck>=1.3.0; extra == "performance"
94
+ Requires-Dist: numexpr>=2.8.0; extra == "performance"
95
+ Provides-Extra: viz
96
+ Requires-Dist: plotly>=5.15.0; extra == "viz"
97
+ Requires-Dist: bokeh>=3.0.0; extra == "viz"
98
+ Requires-Dist: holoviews>=1.16.0; extra == "viz"
99
+ Requires-Dist: panel>=1.8.10; extra == "viz"
100
+ Requires-Dist: dash>=2.10.0; extra == "viz"
101
+ Requires-Dist: streamlit>=1.25.0; extra == "viz"
102
+ Provides-Extra: ml
103
+ Requires-Dist: tensorflow>=2.13.0; extra == "ml"
104
+ Requires-Dist: torch>=2.0.0; extra == "ml"
105
+ Requires-Dist: transformers>=4.30.0; extra == "ml"
106
+ Requires-Dist: xgboost>=1.7.0; extra == "ml"
107
+ Requires-Dist: lightgbm>=4.0.0; extra == "ml"
108
+ Requires-Dist: catboost>=1.2.0; extra == "ml"
109
+ Provides-Extra: clinical
110
+ Requires-Dist: fhir.resources>=7.0.0; extra == "clinical"
111
+ Requires-Dist: pydicom>=2.4.0; extra == "clinical"
112
+ Requires-Dist: nibabel>=5.0.0; extra == "clinical"
113
+ Requires-Dist: mne>=1.4.0; extra == "clinical"
114
+ Provides-Extra: all
115
+ Requires-Dist: sensor-modeling[clinical,dev,docs,ml,performance,viz]; extra == "all"
116
+ Dynamic: license-file
117
+
118
+ # Sensor Modeling Research Toolkit
119
+
120
+ A research-grade Python toolkit for **interpretable, probabilistic,
121
+ privacy-preserving** analysis of behavioural sensor data, and for multimodal
122
+ ambient sensing in ambient assisted living (AAL), digital health and smart-home
123
+ research.
124
+
125
+ It provides an end-to-end pipeline from heterogeneous sensor observations to
126
+ explained alerts, alongside an established modelling core of Bernoulli
127
+ autoregressive models, hidden Markov models, change-point detection and
128
+ non-homogeneous Poisson processes.
129
+
130
+ > **This is a research toolkit, not a medical device.** Nothing it produces is
131
+ > a diagnosis, and no claim of clinical effectiveness is made or supported.
132
+ > Every quantitative result quoted here comes from the bundled simulator and
133
+ > has **not** been validated against real sensor data.
134
+
135
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
136
+ [![Python Version](https://img.shields.io/badge/python-3.10--3.12-blue.svg)](https://www.python.org/downloads/)
137
+ [![CI](https://github.com/DiogoRibeiro7/behavioral-sensing-research/actions/workflows/ci.yml/badge.svg)](https://github.com/DiogoRibeiro7/behavioral-sensing-research/actions/workflows/ci.yml)
138
+ [![Documentation Status](https://readthedocs.org/projects/sensor-modeling/badge/?version=latest)](https://sensor-modeling.readthedocs.io/en/latest/?badge=latest)
139
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17070041.svg)](https://doi.org/10.5281/zenodo.17070041)
140
+ [![Version](https://img.shields.io/badge/version-0.2.0-informational.svg)](CHANGELOG.md)
141
+
142
+ ## 🎯 Overview
143
+
144
+ The **Sensor Modeling Research Toolkit** addresses the growing need for reproducible, interpretable analysis of behavioral sensor streams in smart environments. Unlike general-purpose machine learning libraries, this toolkit provides domain-specific implementations optimized for the unique characteristics of ambient sensor data: irregular sampling, frequent missingness, binary activations, and the need for transparent, clinically interpretable models.
145
+
146
+ ### Key Differentiators
147
+
148
+ - **Research-Grade Implementation**: Clean, documented, and tested implementations of established algorithms from recent literature
149
+ - **Unified Interface**: Consistent API across different modeling approaches for easy comparison and ensemble methods
150
+ - **Clinical Focus**: Visualization and reporting utilities designed for healthcare stakeholders and non-technical users
151
+ - **Lightweight Deployment**: Minimal dependencies and efficient implementations suitable for edge computing and real-time applications
152
+ - **Extensible Architecture**: Modular design allows researchers to easily add new algorithms and extend existing functionality
153
+
154
+ ## 🧭 Observation, state, change, alert
155
+
156
+ The platform keeps five kinds of thing strictly distinct, and most of its
157
+ design follows from refusing to collapse them:
158
+
159
+ | Kind | What it is | Example |
160
+ | --- | --- | --- |
161
+ | **Measured observation** | A sensor reported a value at an instant | The fridge contact closed at 08:14 |
162
+ | **Derived feature** | A value an upstream device computed, carrying its own confidence | The radar reports 2 tracked people |
163
+ | **Inferred state** | A posterior over what the resident was probably doing | `P(kitchen_activity) = 0.81` |
164
+ | **Behavioural change** | A shift against the resident's own history | Sleep has trended down for three weeks |
165
+ | **Alert** | A judgement that a person should look at something | An `attention` alert, with its caveats |
166
+
167
+ A sensor event is not a behaviour:
168
+
169
+ ```text
170
+ fridge opening != eating
171
+ tap activation != drinking
172
+ toilet event != confirmed toileting
173
+ chair activity != sedentary behaviour
174
+ door event != resident movement
175
+ missing observation != inactivity
176
+ ```
177
+
178
+ The state ontology therefore stops at `kitchen_activity` and makes no claim
179
+ about food intake. Two rules are enforced mechanically rather than by
180
+ convention:
181
+
182
+ - **A missing observation is missing evidence, never negative evidence.**
183
+ Sensor reliability enters the fusion likelihood as a tempering weight, so a
184
+ failed sensor contributes a flat likelihood and cannot look like a quiet
185
+ resident.
186
+ - **Ambient activity is not automatically the resident's.** Occupancy
187
+ estimation produces `P(activity was the resident's)`, which discounts
188
+ evidence while a visitor or carer may be present.
189
+
190
+ The system can also return `unknown`. Abstention is a first-class output, not
191
+ a failure.
192
+
193
+ ### Supported and unsupported claims
194
+
195
+ The distinction the platform is built to hold. The left column is what the
196
+ evidence supports; the right is what it does **not**, however tempting the
197
+ inference.
198
+
199
+ | Supported | Not supported |
200
+ | --- | --- |
201
+ | Evidence of kitchen activity | Food consumption |
202
+ | Evidence of bathroom activity | Confirmed toileting |
203
+ | Bed occupancy with sustained low movement | Clinically defined sleep, or a sleep disorder |
204
+ | A door was crossed | The resident left the house |
205
+ | A sustained change against the resident's own history | A cause, a prognosis, or a diagnosis |
206
+ | Reduced room-to-room transitions | Deterioration in mobility as a clinical finding |
207
+ | Sensor coverage has fallen | The resident has become less active |
208
+ | `P(resident generated this activity) = 0.5` | Identification of who did it |
209
+
210
+ Two of these deserve spelling out.
211
+
212
+ **`kitchen_activity` is not eating.** A fridge contact records a door opening.
213
+ Turning that into a meal requires evidence the sensor cannot supply, so the
214
+ ontology stops where the evidence stops.
215
+
216
+ **`sleeping` is not sleep.** It is bed occupancy accompanied by sustained low
217
+ movement. It has no relationship to polysomnography, and mapping it to a
218
+ clinical sleep concept is a further inferential step this platform does not
219
+ take.
220
+
221
+ ## 🏠 Multimodal ambient sensing pipeline
222
+
223
+ ```text
224
+ heterogeneous observations -> validation -> sensor health -> occupancy context
225
+ -> multimodal fusion -> behavioural state -> adaptive baseline
226
+ -> change detection -> restrained alerts -> evaluation
227
+ ```
228
+
229
+ | Package | Responsibility |
230
+ | --- | --- |
231
+ | `sensor_modeling.observations` | Canonical hardware-neutral observation model, sensor registry, boundary validation, clock-drift correction |
232
+ | `sensor_modeling.health` | Online per-sensor reliability, emitted as an evidence weight |
233
+ | `sensor_modeling.context` | Occupancy contexts and uncertainty-aware attribution, from anonymous evidence only |
234
+ | `sensor_modeling.states` / `sensor_modeling.fusion` | Continuous-time state ontology and the recursive multimodal filter |
235
+ | `sensor_modeling.baseline` | Adaptive, weekday-aware, non-stationary personal baselines |
236
+ | `sensor_modeling.alerts` | Restrained, explained alerting with deduplication and rate limiting |
237
+ | `sensor_modeling.simulation` | Synthetic households with controlled ground truth |
238
+ | `sensor_modeling.evaluation` | Problem-appropriate metrics and paired sensor-ablation studies |
239
+ | `sensor_modeling.online` | Incremental, snapshot-able orchestration |
240
+
241
+ ### Reproducible end-to-end example
242
+
243
+ ```bash
244
+ sensor-modeling demo --days 90 --seed 20240304 --step-minutes 10
245
+ ```
246
+
247
+ Simulates a household with a carer and visitors, injects a three-day bed-sensor
248
+ dropout and five days of wearable non-adherence, loses, duplicates, delays and
249
+ clock-skews the record, introduces a genuine change in sleep on a known day,
250
+ then runs the whole pipeline and reports what it did and did not recover —
251
+ including its own false-alert burden. Two runs produce identical numbers.
252
+
253
+ ### Sensor-ablation experiment
254
+
255
+ ```bash
256
+ sensor-modeling ablate --days 14 --seeds 11 22 33 44
257
+ ```
258
+
259
+ Every configuration is evaluated on identical simulated households, so the
260
+ comparison measures sensing rather than residents. On a four-seed sweep, adding
261
+ a person-bound wearable to six object sensors recovered most of the full
262
+ ten-sensor deployment's accuracy — the remaining gap is 0.012 balanced accuracy
263
+ (95% CI [+0.004, +0.020]), real but small — while removing the wearable cost
264
+ 0.173 (95% CI [+0.140, +0.201]). A five-sensor configuration was the *best
265
+ calibrated* of all despite lower accuracy, which an accuracy-only evaluation
266
+ would have hidden. See [`docs/evaluation.md`](docs/evaluation.md).
267
+
268
+ > These numbers describe behaviour on the bundled simulator under its default
269
+ > parameters. They are not estimates of field performance. Nothing here has
270
+ > been validated against real sensor data — see
271
+ > [`docs/limitations.md`](docs/limitations.md).
272
+
273
+ ## ✨ Features
274
+
275
+ ### 🔧 **Comprehensive Data Pipeline**
276
+
277
+ - **Multi-format Loaders**: Support for CSV, JSON, HDF5, and real-time streaming data
278
+ - **Robust Preprocessing**: Missing value imputation, outlier detection, temporal alignment, and data validation
279
+ - **Synthetic Data Generation**: Configurable simulation of sensor networks with ground truth for benchmarking
280
+ - **Quality Assessment**: Automated data quality reporting and sensor failure detection
281
+
282
+ ### 🧠 **Advanced Modeling Capabilities**
283
+
284
+ #### **Bernoulli Autoregressive Models**
285
+
286
+ - Implementation of Gillam et al. (2022) approach for activity prediction
287
+ - Automatic sensor selection using stepwise BIC optimization
288
+ - Seasonal pattern detection and multivariate extensions
289
+ - Uncertainty quantification through prediction intervals
290
+
291
+ #### **Hidden Markov Models (HMMs)**
292
+
293
+ - Hierarchical HMMs for multi-level activity modeling ([Asghari & Nazerfard, 2019](https://arxiv.org/abs/1903.04820))
294
+ - Scaled Dirichlet HMMs with variational inference
295
+ - Heterogeneous HMMs for multi-source data integration
296
+ - Adaptive HMMs incorporating personal experience
297
+ - Circadian HMMs for rhythm monitoring applications
298
+
299
+ #### **Change-Point Detection**
300
+
301
+ - Embedding-based real-time detection ([Dadi et al., 2021](https://doi.org/10.1016/j.eswa.2021.115217))
302
+ - Energy-efficient CPAM algorithm ([Cook et al., 2020](https://doi.org/10.3390/s20010310))
303
+ - Adaptive normalization for non-stationary data
304
+ - Genetic algorithm optimization for parameter tuning
305
+ - Univariate PELT-based segmentation with configurable penalty and L1/L2 costs
306
+
307
+ #### **Non-Homogeneous Poisson Processes (NHPP)**
308
+
309
+ - B-spline intensity estimation with PELT segmentation
310
+ - Automatic model selection via AIC/BIC
311
+ - P-spline regularization for smooth intensity curves
312
+ - Time-rescaling diagnostics for model validation
313
+ - Lewis-Shedler thinning for simulation and testing
314
+
315
+ ### 📊 **Advanced Analysis & Interpretation**
316
+
317
+ #### **Causal Analysis**
318
+
319
+ - Granger causality testing adapted for binary time series
320
+ - Sensor dependency network construction and analysis
321
+ - Community detection in sensor interaction graphs
322
+ - Critical sensor identification for system robustness
323
+
324
+ #### **Behavioral Metrics**
325
+
326
+ - Activity pattern recognition (peak/quiet hours, routine detection)
327
+ - Anomaly scoring using statistical and network-based approaches
328
+ - Trend detection with configurable temporal windows
329
+ - Health indicators derived from activity levels and variability
330
+
331
+ #### **Cross-Model Comparison**
332
+
333
+ - Standardized evaluation metrics across different modeling paradigms
334
+ - Statistical significance testing for model performance
335
+ - Automated hyperparameter sweeps and elbow plot generation
336
+ - Cross-validation frameworks adapted for time series data
337
+
338
+ ### 🎨 **Rich Visualization & Reporting**
339
+
340
+ #### **Interactive Dashboards**
341
+
342
+ - Real-time data exploration using Plotly and Bokeh
343
+ - Parameter tuning interfaces with immediate visual feedback
344
+ - Drill-down capabilities for detected changes and anomalies
345
+ - Export functionality for presentations and publications
346
+
347
+ #### **Clinical Visualizations**
348
+
349
+ - Patient-friendly activity summaries and trend monitors
350
+ - Alert generation based on configurable clinical thresholds
351
+ - Comparison against normative population statistics
352
+ - Minimal FHIR-style observation export for clinical workflow prototyping
353
+
354
+ #### **Research Tools**
355
+
356
+ - Publication-quality figures with customizable styling
357
+ - Model diagnostic plots (residuals, QQ plots, time-rescaling)
358
+ - Performance comparison visualizations across multiple models
359
+ - Statistical test result visualization and interpretation
360
+
361
+ ### 🌐 **Deployment & Integration**
362
+
363
+ #### **Command-Line Interface**
364
+
365
+ - Batch processing capabilities for large-scale experiments
366
+ - Configurable analysis pipelines with JSON/YAML configuration
367
+ - Automated report generation in multiple formats (LaTeX, HTML, minimal FHIR-style JSON)
368
+ - Integration with cluster computing environments
369
+
370
+ #### **Web Application**
371
+
372
+ - Lightweight Flask-based interface for non-technical users
373
+ - Secure file upload with authentication and validation
374
+ - Real-time analysis results and interactive visualizations
375
+ - RESTful API for integration with existing systems
376
+
377
+ ## 🚀 Installation
378
+
379
+ ```bash
380
+ # Basic installation
381
+ pip install -e .[dev]
382
+
383
+ # For development with all tools
384
+ pip install -e .[dev]
385
+ pre-commit install
386
+ ```
387
+
388
+ ## 📖 Quick Start
389
+
390
+ ### Basic Usage Example
391
+
392
+ ```python
393
+ from sensor_modeling.models import BernoulliAutoregressiveModel
394
+ from sensor_modeling.utils import simulate_sensor_data
395
+ import pandas as pd
396
+
397
+ # Load or simulate sensor data
398
+ data = simulate_sensor_data(n_days=30, n_sensors=4)
399
+ print(f"Generated {len(data.data)} 15-minute intervals")
400
+
401
+ # Fit Bernoulli autoregressive model
402
+ model = BernoulliAutoregressiveModel(
403
+ sensor_names=data.data.columns.tolist(),
404
+ target_sensor="sensor_0"
405
+ )
406
+ result = model.fit(data)
407
+
408
+ if result["convergence"]:
409
+ print(f"Model converged with BIC: {result['bic']:.2f}")
410
+ print(f"Selected sensors: {result['selected_sensors']}")
411
+
412
+ # Generate predictions
413
+ probabilities = model.predict_probabilities(data)
414
+ print(f"Predicted activation probabilities: {probabilities[:5]}")
415
+ ```
416
+
417
+ ### Advanced Multi-Model Analysis
418
+
419
+ ```python
420
+ from sensor_modeling.analysis import AnalysisPipeline
421
+ from sensor_modeling.models import BernoulliAutoregressiveModel
422
+ from sensor_modeling.hmm import HierarchicalHMM
423
+ from sensor_modeling.change_point import EmbeddingCPD
424
+
425
+ # Set up comprehensive analysis pipeline
426
+ pipeline = AnalysisPipeline()
427
+
428
+ # Run all available models
429
+ results = pipeline.run(data)
430
+
431
+ # Generate comprehensive reports
432
+ pipeline.generate_report(results, output_dir="analysis_output")
433
+ print("Analysis complete! Check analysis_output/ for results.")
434
+ ```
435
+
436
+ ### Causal Network Analysis
437
+
438
+ ```python
439
+ from sensor_modeling.analysis import SensorDependencyNetwork
440
+
441
+ # Build causal dependency network
442
+ network_builder = SensorDependencyNetwork(significance_level=0.05)
443
+ network = network_builder.build_network(data.data)
444
+
445
+ # Analyze network structure
446
+ stats = network_builder.get_network_statistics()
447
+ roles = network_builder.identify_sensor_roles()
448
+ critical = network_builder.find_critical_sensors()
449
+
450
+ print(f"Network has {stats['num_edges']} causal relationships")
451
+ print(f"Most critical sensor: {critical['most_critical']}")
452
+
453
+ # Visualize network
454
+ network_builder.plot_network()
455
+ ```
456
+
457
+ ### Command-Line Usage
458
+
459
+ ```bash
460
+ # Fit Bernoulli autoregressive model
461
+ sensor-modeling bernoulli-ar data/sensor_readings.csv kitchen_motion
462
+
463
+ # Run NHPP-PELT change-point detection
464
+ sensor-modeling nhpp-pelt data/sensor_readings.csv motion_sensor
465
+
466
+ # Get help on available options
467
+ sensor-modeling --help
468
+ ```
469
+
470
+ ## 🏗️ Architecture Overview
471
+
472
+ The toolkit is organized into four primary layers designed for modularity and extensibility:
473
+
474
+ ### Core Models (`sensor_modeling.models`)
475
+
476
+ - **Bernoulli Autoregressive**: Single and multivariate models for activity prediction
477
+ - **NHPP-PELT**: Non-homogeneous Poisson process with change-point segmentation
478
+ - **Change-Point Detection**: Multiple algorithms for detecting behavioral changes
479
+ - **Hidden Markov Models**: Various HMM variants for state-based modeling
480
+
481
+ ### Analysis Framework (`sensor_modeling.analysis`)
482
+
483
+ - **Preprocessing**: Data cleaning, validation, and feature engineering pipelines
484
+ - **Causal Analysis**: Granger causality testing and network analysis
485
+ - **Behavioral Metrics**: Activity pattern recognition and health indicators
486
+ - **Model Comparison**: Cross-validation and statistical testing frameworks
487
+
488
+ ### Visualization Suite (`sensor_modeling.visualization`)
489
+
490
+ - **Interactive**: Real-time dashboards and parameter tuning interfaces
491
+ - **Clinical**: Patient-friendly summaries and alert systems
492
+ - **Research**: Publication-quality plots and diagnostic visualizations
493
+ - **Web Application**: Browser-based interface for non-technical users
494
+
495
+ ### Utilities (`sensor_modeling.utils`)
496
+
497
+ - **Data I/O**: Multi-format loaders and synthetic data generation
498
+ - **Validation**: Model performance assessment and calibration testing
499
+ - **Plotting**: Specialized plotting functions for sensor data
500
+ - **Missing Data**: Robust handling of incomplete observations
501
+
502
+ ## 📈 Roadmap Progress
503
+
504
+ The high-level status table below summarizes current capabilities. See
505
+ [`ROADMAP.md`](ROADMAP.md) for release milestones, quality gates, and
506
+ longer-term priorities.
507
+
508
+ Feature | Status | Implementation
509
+ ----------------------------------- | ---------- | -----------------------------------------
510
+ **Bernoulli Autoregressive Models** | ✅ Complete | Single/multivariate, automatic selection
511
+ **Hidden Markov Models** | ✅ Complete | 5 variants with different emission models
512
+ **Change Point Detection** | 🟡 Partial | 4 algorithms, expanding to deep learning
513
+ **NHPP-PELT** | ✅ Complete | B-spline intensities, diagnostics
514
+ **Causal Network Analysis** | ✅ Complete | Granger tests, network metrics
515
+ **Missing Data Handling** | ✅ Complete | Gap-aware workflows plus reliability-tempered fusion
516
+ **Multimodal Fusion** | ✅ Complete | Continuous-time filter over asynchronous modalities
517
+ **Sensor Health Modelling** | ✅ Complete | Online reliability feeding the inference layer
518
+ **Occupancy & Attribution** | ✅ Complete | Probabilistic visitor/resident attribution
519
+ **Adaptive Baselines** | ✅ Complete | Robust, weekday-aware, non-stationary
520
+ **Sensor Ablation Studies** | ✅ Complete | Paired designs with effect sizes
521
+ **Deep Learning CPD** | 🔵 Planned | Transformer and CNN-based approaches
522
+ **Real-time Processing** | ✅ Complete | Incremental pipeline, bounded memory, snapshot/restore
523
+ **Clinical Integration** | 🟡 Partial | Minimal FHIR-style export, expanding toward validated HL7 profiles
524
+
525
+ ## 📚 Research Foundation
526
+
527
+ This toolkit implements and extends algorithms from recent peer-reviewed research:
528
+
529
+ ### Core Publications
530
+
531
+ - **Gillam et al. (2022)**: "Modeling and forecasting of at home activity in older adults using passive sensor technology" - _Computers in Biology and Medicine_
532
+ - **Asghari & Nazerfard (2019)**: "Online Human Activity Recognition Employing Hierarchical Hidden Markov Models" - _arXiv:1903.04820_
533
+ - **Dadi et al. (2021)**: "Embedding-based real-time change point detection" - _Expert Systems with Applications_
534
+ - **Cook et al. (2020)**: "Easing Power Consumption of Wearable Activity Monitoring with Change Point Detection" - _Sensors_
535
+
536
+ ### Additional References
537
+
538
+ The toolkit incorporates methodologies from 20+ research papers in ambient assisted living, change-point detection, and time series analysis. See [`paper.bib`](paper.bib) for complete references.
539
+
540
+ ## 🔬 Example Applications
541
+
542
+ ### Smart Home Monitoring
543
+
544
+ ```python
545
+ # Detect changes in daily routines
546
+ from sensor_modeling.change_point import EmbeddingCPD
547
+
548
+ cpd = EmbeddingCPD(window=7)
549
+ cpd.fit(daily_activity_data)
550
+ change_points = cpd.predict(plot=True)
551
+ print(f"Detected {len(change_points)} routine changes")
552
+ ```
553
+
554
+ ### Clinical Decision Support
555
+
556
+ ```python
557
+ # Generate clinical alerts
558
+ from sensor_modeling.visualization.clinical import clinical_alerts
559
+
560
+ thresholds = {
561
+ "bathroom_visits": 8, # per day
562
+ "sleep_duration": 4, # hours minimum
563
+ "activity_level": 0.1 # baseline activity
564
+ }
565
+
566
+ alerts = clinical_alerts(patient_data, thresholds)
567
+ active_alerts = [sensor for sensor, triggered in alerts.items() if triggered]
568
+ print(f"Active clinical alerts: {active_alerts}")
569
+ ```
570
+
571
+ ### Research Studies
572
+
573
+ ```python
574
+ # Cross-model comparison for publication
575
+ from sensor_modeling.analysis.comparison import cross_validate
576
+
577
+ models = {
578
+ "Bernoulli AR": BernoulliAutoregressiveModel(sensors, target),
579
+ "Hierarchical HMM": HierarchicalHMM(n_states=4),
580
+ "NHPP-PELT": NHPPPELT(NHPPConfig(n_basis=5))
581
+ }
582
+
583
+ cv_scores = cross_validate(models, dataset, n_splits=5)
584
+ print("Cross-validation results:", cv_scores)
585
+ ```
586
+
587
+ ## 🤝 Contributing
588
+
589
+ We welcome contributions from researchers and practitioners! The toolkit is designed to be easily extensible:
590
+
591
+ ### Getting Started
592
+
593
+ 1. **Fork the repository** and create your feature branch:
594
+
595
+ ```bash
596
+ git checkout -b feature/my-new-algorithm
597
+ ```
598
+
599
+ 2. **Install development dependencies**:
600
+
601
+ ```bash
602
+ pip install -e .[dev]
603
+ pre-commit install
604
+ ```
605
+
606
+ 3. **Add your implementation** following the existing patterns:
607
+
608
+ ```python
609
+ # Example: New change-point detector
610
+ from sensor_modeling.change_point.base import BaseCPD
611
+
612
+ class MyNewCPD(BaseCPD):
613
+ def fit(self, series):
614
+ # Your algorithm here
615
+ return self
616
+
617
+ def predict(self):
618
+ # Return change points
619
+ return self.change_points_
620
+ ```
621
+
622
+ 4. **Write tests and documentation**:
623
+
624
+ ```bash
625
+ pytest tests/test_my_new_algorithm.py
626
+ mkdocs build --strict
627
+ ```
628
+
629
+ 5. **Submit a pull request** with:
630
+
631
+ - Clear description of the algorithm and its benefits
632
+ - Tests demonstrating correctness and performance
633
+ - Documentation updates including usage examples
634
+ - Reference to relevant publications
635
+
636
+ ### Contribution Guidelines
637
+
638
+ - **Code Style**: Follow PEP 8, use type hints, write comprehensive docstrings
639
+ - **Testing**: Maintain >90% test coverage, include property-based tests for core algorithms
640
+ - **Documentation**: Update API docs and add tutorial notebooks for new features
641
+ - **Performance**: Include benchmarks for computationally intensive algorithms
642
+ - **Reproducibility**: Use fixed random seeds and provide example datasets
643
+
644
+ See <CONTRIBUTING.md> for detailed guidelines and our [Code of Conduct](CODE_OF_CONDUCT.md).
645
+ Maintainers should use [`RELEASE.md`](RELEASE.md) for the main-only release
646
+ checklist.
647
+
648
+ ## 📄 License
649
+
650
+ Distributed under the [MIT License](LICENSE). This allows for both academic and commercial use while maintaining attribution to the original authors.
651
+
652
+ ## 📞 Contact & Support
653
+
654
+ - **Primary Author**: Diogo Ribeiro (<dfr@esmad.ipp.pt>)
655
+ - **Institution**: ESMAD - Instituto Politécnico do Porto
656
+ - **Issues**: Use GitHub Issues for bug reports and feature requests
657
+ - **Discussions**: GitHub Discussions for questions and community support
658
+ - **Security**: Follow [`SECURITY.md`](SECURITY.md) for private vulnerability reports
659
+ - **Support**: See [`SUPPORT.md`](SUPPORT.md) for the right support channel
660
+
661
+ ## 📖 Documentation
662
+
663
+ - **Online Documentation**: [sensor-modeling.readthedocs.io](https://sensor-modeling.readthedocs.io)
664
+ - **API Reference**: Complete documentation of all classes and functions
665
+ - **Tutorials**: Step-by-step guides for common use cases
666
+ - **Examples**: Jupyter notebooks demonstrating advanced workflows
667
+
668
+ ## 🏆 Citation
669
+
670
+ If you use this software in your research, please cite it as:
671
+
672
+ ```bibtex
673
+ @software{ribeiro2025sensor,
674
+ title={Sensor Modeling Research Toolkit},
675
+ author={Ribeiro, Diogo},
676
+ year={2026},
677
+ url={https://github.com/DiogoRibeiro7/behavioral-sensing-research},
678
+ version={0.2.0},
679
+ doi={10.5281/zenodo.17070041}
680
+ }
681
+ ```
682
+
683
+ For the underlying methodology, please also cite relevant papers listed in [`CITATION.cff`](CITATION.cff).