-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvancomycin_propagation.sio
More file actions
141 lines (122 loc) · 4.57 KB
/
vancomycin_propagation.sio
File metadata and controls
141 lines (122 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//@ run-pass
//@ check-only
// Vancomycin AUC/MIC dosing — conservative epistemic propagation smoke.
//
// This test intentionally uses a conservative surface that compiles on the
// recovered 2026-04-05 integration branch:
// - plain structs
// - explicit uncertainty propagation helpers
// - standard field names (`confidence`, not `.ε`)
//
// The scientific intent remains the same:
// 1. start from a guideline base dose
// 2. adjust by weight
// 3. attenuate by renal function
// 4. apply a nephrotoxicity penalty
// 5. compare propagated confidence against a direct trough measurement
struct KnowledgeF64 {
value: f64,
uncertainty: f64,
confidence: f64
}
fn abs_f64(x: f64) -> f64 {
if x < 0.0 {
return -x
}
return x
}
fn min_f64(a: f64, b: f64) -> f64 {
if a < b {
return a
}
return b
}
fn make_knowledge(value: f64, uncertainty: f64, confidence: f64) -> KnowledgeF64 {
return KnowledgeF64 {
value: value,
uncertainty: uncertainty,
confidence: confidence
}
}
// Conservative first-order multiplication bound.
fn gum_mul(a: KnowledgeF64, b: KnowledgeF64) -> KnowledgeF64 {
let nominal = a.value * b.value
let propagated = abs_f64(b.value) * a.uncertainty + abs_f64(a.value) * b.uncertainty
return KnowledgeF64 {
value: nominal,
uncertainty: propagated,
confidence: min_f64(a.confidence, b.confidence)
}
}
// Conservative first-order division bound.
fn gum_div(a: KnowledgeF64, b: KnowledgeF64) -> KnowledgeF64 {
let nominal = a.value / b.value
let term_a = a.uncertainty / abs_f64(b.value)
let term_b = abs_f64(a.value) * b.uncertainty / (b.value * b.value)
return KnowledgeF64 {
value: nominal,
uncertainty: term_a + term_b,
confidence: min_f64(a.confidence, b.confidence)
}
}
fn main() with IO {
println("=================================================================")
println(" Vancomycin AUC/MIC Dosing — Conservative Epistemic Smoke")
println(" ASHP 2020 style workflow on current integration branch")
println("=================================================================")
println("")
// 15 mg/kg/day guideline base dose.
let base_dose = make_knowledge(15.0, 0.6, 0.92)
// Weight adjustment for a 78.5 kg patient relative to 70 kg reference.
let weight = make_knowledge(78.5, 0.5, 0.98)
let ref_wt = make_knowledge(70.0, 0.1, 1.0)
let weight_factor = gum_div(weight, ref_wt)
let dose1 = gum_mul(base_dose, weight_factor)
println("Step 1 weight-adjusted dose")
println(dose1.value)
println(dose1.uncertainty)
println(dose1.confidence)
// Renal attenuation using conservative Cockcroft-Gault confidence.
let crcl = make_knowledge(65.0, 8.0, 0.72)
let crcl_ref = make_knowledge(120.0, 1.0, 1.0)
let renal_adj = gum_div(crcl, crcl_ref)
let dose2 = gum_mul(dose1, renal_adj)
println("Step 2 renal-adjusted dose")
println(dose2.value)
println(dose2.uncertainty)
println(dose2.confidence)
// NSAID co-exposure penalty.
let nephro = make_knowledge(0.85, 0.03, 0.65)
let dose3 = gum_mul(dose2, nephro)
let conf_dose = dose3.confidence
println("Step 3 nephrotox-adjusted dose")
println(dose3.value)
println(dose3.uncertainty)
println(conf_dose)
// Direct trough measurement remains higher-confidence.
let trough = make_knowledge(14.2, 0.2, 0.96)
let conf_trough = trough.confidence
println("Step 4 trough measurement confidence")
println(conf_trough)
println("")
println("Step 5 Safety gate — dose pipeline (confidence >= 0.82)")
if conf_dose >= 0.82 {
println(" PRESCRIBE: propagated dose confidence sufficient")
} else {
println(" BLOCKED: refine renal estimate before AUC-guided dosing")
}
println("Step 5 Safety gate — trough measurement (confidence >= 0.82)")
if conf_trough >= 0.82 {
println(" PRESCRIBE: trough confidence sufficient for TDM adjustment")
} else {
println(" BLOCKED: insufficient lab confidence")
}
println("")
println("=================================================================")
println(" Summary")
println(" propagated dose confidence degrades through chained transforms")
println(" direct trough measurement remains high-confidence")
println(" current branch proves the scientific workflow without advanced")
println(" Knowledge<T> parser/typechecker features")
println("=================================================================")
}