iints-sdk-python35 0.0.18__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 (118) hide show
  1. iints/__init__.py +183 -0
  2. iints/analysis/__init__.py +12 -0
  3. iints/analysis/algorithm_xray.py +387 -0
  4. iints/analysis/baseline.py +92 -0
  5. iints/analysis/clinical_benchmark.py +198 -0
  6. iints/analysis/clinical_metrics.py +551 -0
  7. iints/analysis/clinical_tir_analyzer.py +136 -0
  8. iints/analysis/diabetes_metrics.py +43 -0
  9. iints/analysis/edge_efficiency.py +33 -0
  10. iints/analysis/edge_performance_monitor.py +315 -0
  11. iints/analysis/explainability.py +94 -0
  12. iints/analysis/explainable_ai.py +232 -0
  13. iints/analysis/hardware_benchmark.py +221 -0
  14. iints/analysis/metrics.py +117 -0
  15. iints/analysis/population_report.py +188 -0
  16. iints/analysis/reporting.py +345 -0
  17. iints/analysis/safety_index.py +311 -0
  18. iints/analysis/sensor_filtering.py +54 -0
  19. iints/analysis/validator.py +273 -0
  20. iints/api/__init__.py +0 -0
  21. iints/api/base_algorithm.py +307 -0
  22. iints/api/registry.py +103 -0
  23. iints/api/template_algorithm.py +195 -0
  24. iints/assets/iints_logo.png +0 -0
  25. iints/cli/__init__.py +0 -0
  26. iints/cli/cli.py +2598 -0
  27. iints/core/__init__.py +1 -0
  28. iints/core/algorithms/__init__.py +0 -0
  29. iints/core/algorithms/battle_runner.py +138 -0
  30. iints/core/algorithms/correction_bolus.py +95 -0
  31. iints/core/algorithms/discovery.py +92 -0
  32. iints/core/algorithms/fixed_basal_bolus.py +58 -0
  33. iints/core/algorithms/hybrid_algorithm.py +92 -0
  34. iints/core/algorithms/lstm_algorithm.py +138 -0
  35. iints/core/algorithms/mock_algorithms.py +162 -0
  36. iints/core/algorithms/pid_controller.py +88 -0
  37. iints/core/algorithms/standard_pump_algo.py +64 -0
  38. iints/core/device.py +0 -0
  39. iints/core/device_manager.py +64 -0
  40. iints/core/devices/__init__.py +3 -0
  41. iints/core/devices/models.py +160 -0
  42. iints/core/patient/__init__.py +9 -0
  43. iints/core/patient/bergman_model.py +341 -0
  44. iints/core/patient/models.py +285 -0
  45. iints/core/patient/patient_factory.py +117 -0
  46. iints/core/patient/profile.py +41 -0
  47. iints/core/safety/__init__.py +12 -0
  48. iints/core/safety/config.py +37 -0
  49. iints/core/safety/input_validator.py +95 -0
  50. iints/core/safety/supervisor.py +39 -0
  51. iints/core/simulation/__init__.py +0 -0
  52. iints/core/simulation/scenario_parser.py +61 -0
  53. iints/core/simulator.py +874 -0
  54. iints/core/supervisor.py +367 -0
  55. iints/data/__init__.py +53 -0
  56. iints/data/adapter.py +142 -0
  57. iints/data/column_mapper.py +398 -0
  58. iints/data/datasets.json +132 -0
  59. iints/data/demo/__init__.py +1 -0
  60. iints/data/demo/demo_cgm.csv +289 -0
  61. iints/data/importer.py +275 -0
  62. iints/data/ingestor.py +162 -0
  63. iints/data/nightscout.py +128 -0
  64. iints/data/quality_checker.py +550 -0
  65. iints/data/registry.py +166 -0
  66. iints/data/tidepool.py +38 -0
  67. iints/data/universal_parser.py +813 -0
  68. iints/data/virtual_patients/clinic_safe_baseline.yaml +9 -0
  69. iints/data/virtual_patients/clinic_safe_hyper_challenge.yaml +9 -0
  70. iints/data/virtual_patients/clinic_safe_hypo_prone.yaml +9 -0
  71. iints/data/virtual_patients/clinic_safe_midnight.yaml +9 -0
  72. iints/data/virtual_patients/clinic_safe_pizza.yaml +9 -0
  73. iints/data/virtual_patients/clinic_safe_stress_meal.yaml +9 -0
  74. iints/data/virtual_patients/default_patient.yaml +11 -0
  75. iints/data/virtual_patients/patient_559_config.yaml +11 -0
  76. iints/emulation/__init__.py +80 -0
  77. iints/emulation/legacy_base.py +414 -0
  78. iints/emulation/medtronic_780g.py +337 -0
  79. iints/emulation/omnipod_5.py +367 -0
  80. iints/emulation/tandem_controliq.py +393 -0
  81. iints/highlevel.py +451 -0
  82. iints/learning/__init__.py +3 -0
  83. iints/learning/autonomous_optimizer.py +194 -0
  84. iints/learning/learning_system.py +122 -0
  85. iints/metrics.py +34 -0
  86. iints/population/__init__.py +11 -0
  87. iints/population/generator.py +131 -0
  88. iints/population/runner.py +327 -0
  89. iints/presets/__init__.py +28 -0
  90. iints/presets/presets.json +114 -0
  91. iints/research/__init__.py +30 -0
  92. iints/research/config.py +68 -0
  93. iints/research/dataset.py +319 -0
  94. iints/research/losses.py +73 -0
  95. iints/research/predictor.py +329 -0
  96. iints/scenarios/__init__.py +3 -0
  97. iints/scenarios/generator.py +92 -0
  98. iints/templates/__init__.py +0 -0
  99. iints/templates/default_algorithm.py +91 -0
  100. iints/templates/scenarios/__init__.py +0 -0
  101. iints/templates/scenarios/chaos_insulin_stacking.json +29 -0
  102. iints/templates/scenarios/chaos_runaway_ai.json +25 -0
  103. iints/templates/scenarios/example_scenario.json +35 -0
  104. iints/templates/scenarios/exercise_stress.json +30 -0
  105. iints/utils/__init__.py +3 -0
  106. iints/utils/plotting.py +50 -0
  107. iints/utils/run_io.py +152 -0
  108. iints/validation/__init__.py +133 -0
  109. iints/validation/schemas.py +94 -0
  110. iints/visualization/__init__.py +34 -0
  111. iints/visualization/cockpit.py +691 -0
  112. iints/visualization/uncertainty_cloud.py +612 -0
  113. iints_sdk_python35-0.0.18.dist-info/METADATA +225 -0
  114. iints_sdk_python35-0.0.18.dist-info/RECORD +118 -0
  115. iints_sdk_python35-0.0.18.dist-info/WHEEL +5 -0
  116. iints_sdk_python35-0.0.18.dist-info/entry_points.txt +10 -0
  117. iints_sdk_python35-0.0.18.dist-info/licenses/LICENSE +28 -0
  118. iints_sdk_python35-0.0.18.dist-info/top_level.txt +1 -0
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Clinical Benchmark System
4
+ Compares AI algorithms against real-world clinical outcomes
5
+ """
6
+
7
+ import sys
8
+ from pathlib import Path
9
+ import pandas as pd
10
+ import numpy as np
11
+ from rich.console import Console
12
+ from rich.table import Table
13
+ from rich.panel import Panel
14
+ from rich.progress import Progress, SpinnerColumn, TextColumn
15
+
16
+ # Add project root to path
17
+ project_root = Path(__file__).parent.parent.parent
18
+ sys.path.insert(0, str(project_root))
19
+
20
+ from iints.data.adapter import DataAdapter
21
+
22
+ class ClinicalBenchmark:
23
+ """Clinical benchmark comparison system"""
24
+
25
+ def __init__(self):
26
+ self.console = Console()
27
+ self.adapter = DataAdapter()
28
+
29
+ def run_ohio_benchmark(self):
30
+ """Run clinical benchmark against Ohio T1DM dataset"""
31
+ self.console.print("\n[bold blue] Clinical Benchmark Study[/bold blue]")
32
+ self.console.print("Comparing AI algorithms against real-world patient outcomes\n")
33
+
34
+ # Get available Ohio patients
35
+ patients = self.adapter.get_available_ohio_patients()
36
+
37
+ if not patients:
38
+ self.console.print("[red] No Ohio T1DM patients found[/red]")
39
+ self.console.print("Run: [cyan]python tools/import_ohio.py /path/to/ohio/dataset[/cyan]")
40
+ return
41
+
42
+ self.console.print(f"[green] Found {len(patients)} Ohio T1DM patients[/green]")
43
+
44
+ # Select patient for benchmark
45
+ if len(patients) == 1:
46
+ selected_patient = patients[0]
47
+ else:
48
+ self.console.print("\nAvailable patients:")
49
+ for i, patient in enumerate(patients, 1):
50
+ self.console.print(f" {i}. Patient {patient}")
51
+
52
+ try:
53
+ choice = int(input("\nSelect patient (1-{}): ".format(len(patients)))) - 1
54
+ selected_patient = patients[choice]
55
+ except (ValueError, IndexError):
56
+ selected_patient = patients[0]
57
+
58
+ self.console.print(f"\n[yellow] Running benchmark on Patient {selected_patient}[/yellow]")
59
+
60
+ # Run benchmark comparison
61
+ with Progress(
62
+ SpinnerColumn(),
63
+ TextColumn("[progress.description]{task.description}"),
64
+ console=self.console
65
+ ) as progress:
66
+ task = progress.add_task("Running clinical benchmark...", total=None)
67
+
68
+ results = self.adapter.clinical_benchmark_comparison(
69
+ selected_patient,
70
+ ['rule_based', 'lstm', 'hybrid']
71
+ )
72
+
73
+ progress.update(task, completed=True)
74
+
75
+ # Display results
76
+ self._display_benchmark_results(results)
77
+
78
+ return results
79
+
80
+ def _display_benchmark_results(self, results):
81
+ """Display benchmark results in formatted table with visualization"""
82
+
83
+ # Import visualization tools
84
+ from tools.glucose_visualizer import GlucoseVisualizer
85
+ viz = GlucoseVisualizer()
86
+
87
+ # Show patient overview first
88
+ patient_id = results['patient_id']
89
+ self.console.print(f"\n[bold] Patient {patient_id} Clinical Data Visualization[/bold]")
90
+ viz.show_patient_overview(patient_id)
91
+
92
+ # Original patient performance
93
+ original = results['original_performance']
94
+
95
+ self.console.print(f"\n[bold] Clinical Benchmark Results - Patient {results['patient_id']}[/bold]")
96
+
97
+ # Original performance panel
98
+ original_panel = Panel(
99
+ f"Time in Range: [cyan]{original['tir_70_180']:.1f}%[/cyan]\n"
100
+ f"GMI (Glucose Management Indicator): [cyan]{original['gmi']:.1f}[/cyan]\n"
101
+ f"Coefficient of Variation: [cyan]{original['cv_percent']:.1f}%[/cyan]",
102
+ title="[yellow]Original Patient Performance[/yellow]",
103
+ border_style="yellow"
104
+ )
105
+ self.console.print(original_panel)
106
+
107
+ # Algorithm comparison table with visual indicators
108
+ table = Table(title="AI Algorithm Performance vs. Original")
109
+ table.add_column("Algorithm", style="cyan", no_wrap=True)
110
+ table.add_column("Time in Range", justify="right")
111
+ table.add_column("Improvement", justify="right")
112
+ table.add_column("Visual Progress", justify="center")
113
+ table.add_column("Clinical Impact", justify="center")
114
+
115
+ for algo, metrics in results['algorithm_results'].items():
116
+ tir = metrics['tir_70_180']
117
+ improvement = metrics['improvement_percent']
118
+
119
+ # Create visual progress bar
120
+ progress_chars = int(improvement / 2) # Scale to reasonable size
121
+ progress_bar = "" * max(0, progress_chars) + "" * max(0, 10 - progress_chars)
122
+
123
+ # Determine clinical impact
124
+ if improvement > 10:
125
+ impact = "[green] Excellent[/green]"
126
+ elif improvement > 5:
127
+ impact = "[yellow] Good[/yellow]"
128
+ elif improvement > 0:
129
+ impact = "[blue] Modest[/blue]"
130
+ else:
131
+ impact = "[red] Poor[/red]"
132
+
133
+ table.add_row(
134
+ algo.upper(),
135
+ f"{tir:.1f}%",
136
+ f"{improvement:+.1f}%",
137
+ progress_bar,
138
+ impact
139
+ )
140
+
141
+ self.console.print(table)
142
+
143
+ # Clinical interpretation with visual elements
144
+ best_algo = max(results['algorithm_results'].items(),
145
+ key=lambda x: x[1]['improvement_percent'])
146
+
147
+ # Create improvement visualization
148
+ original_tir = original['tir_70_180']
149
+ best_tir = best_algo[1]['tir_70_180']
150
+
151
+ improvement_viz = f"""
152
+ [bold]Before:[/bold] {'█' * int(original_tir/10)}{'░' * (10 - int(original_tir/10))} {original_tir:.1f}%
153
+ [bold]After: [/bold] {'█' * int(best_tir/10)}{'░' * (10 - int(best_tir/10))} {best_tir:.1f}%
154
+ """
155
+
156
+ interpretation = Panel(
157
+ f"{improvement_viz}\n"
158
+ f"[bold] Best Algorithm:[/bold] {best_algo[0].upper()}\n"
159
+ f"[bold] Clinical Improvement:[/bold] {best_algo[1]['improvement_percent']:+.1f}% TIR\n"
160
+ f"[bold] Research Validation:[/bold] Based on Ohio University T1DM Dataset\n"
161
+ f"[bold] Publication Quality:[/bold] Suitable for peer-reviewed research",
162
+ title="[green] Clinical Impact Analysis[/green]",
163
+ border_style="green"
164
+ )
165
+ self.console.print(interpretation)
166
+
167
+ def export_benchmark_results(self, results, filename="clinical_benchmark.json"):
168
+ """Export benchmark results for publication"""
169
+ import json
170
+ from datetime import datetime
171
+
172
+ export_data = {
173
+ "study_metadata": {
174
+ "timestamp": datetime.now().isoformat(),
175
+ "dataset": "Ohio University T1DM Dataset",
176
+ "patient_id": results['patient_id'],
177
+ "framework": "IINTS-AF v1.0"
178
+ },
179
+ "clinical_benchmarks": results['original_performance'],
180
+ "algorithm_results": results['algorithm_results'],
181
+ "citation": "Marling, C., & Bunescu, R. (2018). The OhioT1DM Dataset for Blood Glucose Level Prediction"
182
+ }
183
+
184
+ with open(filename, 'w') as f:
185
+ json.dump(export_data, f, indent=2)
186
+
187
+ self.console.print(f"\n[green] Results exported to {filename}[/green]")
188
+
189
+ def main():
190
+ """Run clinical benchmark as standalone tool"""
191
+ benchmark = ClinicalBenchmark()
192
+ results = benchmark.run_ohio_benchmark()
193
+
194
+ if results:
195
+ benchmark.export_benchmark_results(results)
196
+
197
+ if __name__ == "__main__":
198
+ main()