sciforge 0.0.3

A comprehensive scientific computing library in pure Rust with zero dependencies
Documentation
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
//! Dispatch handler for parasitology functions.

use super::super::params::*;
use crate::hub::domain::biology as bio;
use crate::hub::domain::common::errors::{HubError, HubResult};
use crate::hub::engine::experience::runner::RunOutput;

pub(super) fn dispatch(func: &str, p: &Params) -> HubResult<RunOutput> {
    match func {
        "parasite_r0" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::parasite_r0(
                get_f(p, "beta")?,
                get_f(p, "host_density")?,
                get_f(p, "recovery_rate")?,
                get_f(p, "mortality_rate")?,
            ),
        )),
        "parasite_transmission_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::parasite_transmission_rate(
                get_f(p, "contact_rate")?,
                get_f(p, "infectivity")?,
                get_f(p, "density_susceptible")?,
                get_f(p, "density_infected")?,
            ),
        )),
        "sir_parasite_step" => {
            let (a, b, c) = bio::parasitology::epidemiology::sir_parasite_step(
                get_f(p, "s")?,
                get_f(p, "i")?,
                get_f(p, "r")?,
                get_f(p, "beta")?,
                get_f(p, "gamma")?,
                get_f(p, "mu")?,
                get_f(p, "dt")?,
            );
            Ok(RunOutput::Triple(a, b, c))
        }
        "parasite_aggregation_k" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::parasite_aggregation_k(
                get_f(p, "mean_burden")?,
                get_f(p, "variance_burden")?,
            ),
        )),
        "parasite_negative_binomial_prevalence" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::parasite_negative_binomial_prevalence(
                get_f(p, "mean_burden")?,
                get_f(p, "k")?,
            ),
        )),
        "superinfection_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::superinfection_rate(
                get_u(p, "current_parasites")?,
                get_u(p, "max_parasites")?,
                get_f(p, "exposure_rate")?,
            ),
        )),
        "vector_borne_r0" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::vector_borne_r0(
                get_f(p, "mosquito_density")?,
                get_f(p, "biting_rate")?,
                get_f(p, "prob_m_to_h")?,
                get_f(p, "prob_h_to_m")?,
                get_f(p, "mosquito_mortality")?,
                get_f(p, "extrinsic_incubation")?,
                get_f(p, "recovery")?,
            ),
        )),
        "definitive_intermediate_host_cycle" => Ok(RunOutput::Scalar(
            bio::parasitology::epidemiology::definitive_intermediate_host_cycle(
                get_f(p, "cercariae_production")?,
                get_f(p, "snail_infection_rate")?,
                get_f(p, "human_exposure")?,
                get_f(p, "worm_establishment")?,
            ),
        )),
        "host_parasite_lotka_volterra" => {
            let (a, b) = bio::parasitology::host_parasite::host_parasite_lotka_volterra(
                get_f(p, "h")?,
                get_f(p, "p")?,
                get_f(p, "r")?,
                get_f(p, "k")?,
                get_f(p, "a")?,
                get_f(p, "c")?,
                get_f(p, "d")?,
            );
            Ok(RunOutput::Pair(a, b))
        }
        "anderson_may" => {
            let (a, b) = bio::parasitology::host_parasite::anderson_may(
                get_f(p, "h")?,
                get_f(p, "p")?,
                get_f(p, "alpha")?,
                get_f(p, "beta")?,
                get_f(p, "b")?,
                get_f(p, "d_h")?,
                get_f(p, "d_p")?,
                get_f(p, "k_aggregation")?,
            );
            Ok(RunOutput::Pair(a, b))
        }
        "negative_binomial_prevalence" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::negative_binomial_prevalence(
                get_f(p, "mean_burden")?,
                get_f(p, "k")?,
            ),
        )),
        "parasite_aggregation_index" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::parasite_aggregation_index(
                get_f(p, "variance")?,
                get_f(p, "mean")?,
            ),
        )),
        "superinfection_probability" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::superinfection_probability(
                get_f(p, "exposure_rate")?,
                get_f(p, "current_burden")?,
                get_f(p, "max_burden")?,
            ),
        )),
        "basic_reproduction_number_parasite" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::basic_reproduction_number_parasite(
                get_f(p, "beta")?,
                get_f(p, "lambda")?,
                get_f(p, "h")?,
                get_f(p, "mu_p")?,
                get_f(p, "mu_h")?,
                get_f(p, "alpha")?,
            ),
        )),
        "coevolution_red_queen" => {
            let (a, b) = bio::parasitology::host_parasite::coevolution_red_queen(
                get_f(p, "host_fitness")?,
                get_f(p, "parasite_fitness")?,
                get_f(p, "arms_race_rate")?,
            );
            Ok(RunOutput::Pair(a, b))
        }
        "nicholson_bailey" => {
            let (a, b) = bio::parasitology::host_parasite::nicholson_bailey(
                get_f(p, "h")?,
                get_f(p, "p")?,
                get_f(p, "r")?,
                get_f(p, "a")?,
            );
            Ok(RunOutput::Pair(a, b))
        }
        "negative_binomial_zero_class" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::negative_binomial_zero_class(
                get_f(p, "mean_burden")?,
                get_f(p, "k")?,
            ),
        )),
        "parasite_induced_mortality" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::parasite_induced_mortality(
                get_f(p, "alpha")?,
                get_f(p, "burden")?,
            ),
        )),
        "acquired_immunity_reduction" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::acquired_immunity_reduction(
                get_f(p, "exposure")?,
                get_f(p, "max_immunity")?,
                get_f(p, "half_exposure")?,
            ),
        )),
        "intermediate_host_prevalence" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::intermediate_host_prevalence(
                get_f(p, "beta")?,
                get_f(p, "h2")?,
                get_f(p, "mu_l")?,
                get_f(p, "mu_h2")?,
            ),
        )),
        "cercarial_force_of_infection" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::cercarial_force_of_infection(
                get_f(p, "cercarial_density")?,
                get_f(p, "contact_rate")?,
                get_f(p, "penetration_prob")?,
            ),
        )),
        "predator_prey_parasite_manipulation" => {
            let (a, b) = bio::parasitology::host_parasite::predator_prey_parasite_manipulation(
                get_f(p, "h")?,
                get_f(p, "p")?,
                get_f(p, "prey")?,
                get_f(p, "r")?,
                get_f(p, "a")?,
                get_f(p, "manipulation_factor")?,
                get_f(p, "conversion")?,
                get_f(p, "death")?,
            );
            Ok(RunOutput::Pair(a, b))
        }
        "density_dependent_fecundity" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::density_dependent_fecundity(
                get_f(p, "fecundity_max")?,
                get_f(p, "burden")?,
                get_f(p, "k_dens")?,
            ),
        )),
        "mate_probability_dioecious" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::mate_probability_dioecious(
                get_f(p, "burden")?,
                get_f(p, "k_agg")?,
            ),
        )),
        "parasite_free_equilibrium" => Ok(RunOutput::Scalar(
            bio::parasitology::host_parasite::parasite_free_equilibrium(
                get_f(p, "birth")?,
                get_f(p, "death")?,
                get_f(p, "carrying_capacity")?,
            ),
        )),
        "antigenic_variation_escape" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::antigenic_variation_escape(
                get_f(p, "immune_recognition")?,
                get_f(p, "switch_rate")?,
                get_u(p, "variants")?,
            ),
        )),
        "immune_evasion_molecular_mimicry" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::immune_evasion_molecular_mimicry(
                get_f(p, "host_molecule_similarity")?,
                get_f(p, "immune_response_base")?,
            ),
        )),
        "immunosuppression_by_parasite" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::immunosuppression_by_parasite(
                get_f(p, "il10_induction")?,
                get_f(p, "treg_expansion")?,
                get_f(p, "effector_response")?,
            ),
        )),
        "encapsulation_melanization" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::encapsulation_melanization(
                get_f(p, "hemocyte_density")?,
                get_f(p, "parasite_surface_area")?,
                get_f(p, "phenoloxidase")?,
            ),
        )),
        "acquired_immunity_buildup" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::acquired_immunity_buildup(
                get_u(p, "exposure_events")?,
                get_f(p, "max_immunity")?,
                get_f(p, "rate")?,
            ),
        )),
        "parasit_maternal_antibody_decay" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::maternal_antibody_decay(
                get_f(p, "initial_titer")?,
                get_f(p, "half_life_weeks")?,
                get_f(p, "age_weeks")?,
            ),
        )),
        "concomitant_immunity" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::concomitant_immunity(
                get_f(p, "adult_worms")?,
                get_f(p, "larval_killing_rate")?,
                get_f(p, "new_larvae")?,
            ),
        )),
        "eosinophil_response" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::eosinophil_response(
                get_f(p, "parasite_burden")?,
                get_f(p, "il5_level")?,
                get_f(p, "eosinophil_base")?,
            ),
        )),
        "granuloma_formation_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::granuloma_formation_rate(
                get_f(p, "antigen_deposition")?,
                get_f(p, "macrophage_activation")?,
                get_f(p, "fibrosis_rate")?,
            ),
        )),
        "hygiene_hypothesis_index" => Ok(RunOutput::Scalar(
            bio::parasitology::immunity::hygiene_hypothesis_index(
                get_f(p, "parasite_exposure")?,
                get_f(p, "allergy_risk_base")?,
                get_f(p, "protection_factor")?,
            ),
        )),
        "parasite_virulence_tradeoff" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::parasite_virulence_tradeoff(
                get_f(p, "virulence")?,
                get_f(p, "beta_max")?,
                get_f(p, "v_half")?,
            ),
        )),
        "optimal_virulence" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::optimal_virulence(
                get_f(p, "beta_max")?,
                get_f(p, "v_half")?,
                get_f(p, "mortality_background")?,
            ),
        )),
        "immune_evasion_probability" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::immune_evasion_probability(
                get_f(p, "parasite_diversity")?,
                get_f(p, "immune_memory")?,
            ),
        )),
        "worm_burden_distribution_mean" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::worm_burden_distribution_mean(
                get_f(p, "epg")?,
                get_f(p, "fecundity")?,
            ),
        )),
        "force_of_infection" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::force_of_infection(
                get_f(p, "contact_rate")?,
                get_f(p, "environmental_contamination")?,
                get_f(p, "susceptibility")?,
            ),
        )),
        "age_intensity_profile" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::age_intensity_profile(
                get_f(p, "age")?,
                get_f(p, "peak_age")?,
                get_f(p, "max_intensity")?,
                get_f(p, "shape")?,
            ),
        )),
        "superinfection_threshold" => Ok(RunOutput::Boolean(
            bio::parasitology::virulence::superinfection_threshold(
                get_f(p, "r0_resident")?,
                get_f(p, "r0_challenger")?,
            ),
        )),
        "aggregation_parameter" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::aggregation_parameter(
                get_f(p, "mean_burden")?,
                get_f(p, "variance")?,
            ),
        )),
        "drug_resistance_spread" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::drug_resistance_spread(
                get_f(p, "sensitive_freq")?,
                get_f(p, "resistant_fitness")?,
                get_f(p, "treatment_coverage")?,
            ),
        )),
        "basic_reproduction_number_macroparasite" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::basic_reproduction_number_macroparasite(
                get_f(p, "beta")?,
                get_f(p, "lambda")?,
                get_f(p, "mu_host")?,
                get_f(p, "mu_parasite")?,
                get_f(p, "alpha")?,
            ),
        )),
        "parasit_case_fatality_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::case_fatality_rate(
                get_f(p, "virulence")?,
                get_f(p, "host_resistance")?,
            ),
        )),
        "parasite_clearance_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::parasite_clearance_rate(
                get_f(p, "immune_activity")?,
                get_f(p, "drug_efficacy")?,
                get_f(p, "natural_death")?,
            ),
        )),
        "morbidity_intensity" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::morbidity_intensity(
                get_f(p, "burden")?,
                get_f(p, "threshold")?,
                get_f(p, "severity_coeff")?,
            ),
        )),
        "transmission_seasonality" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::transmission_seasonality(
                get_f(p, "baseline_beta")?,
                get_f(p, "amplitude")?,
                get_f(p, "t")?,
                get_f(p, "period")?,
            ),
        )),
        "mass_drug_administration_impact" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::mass_drug_administration_impact(
                get_f(p, "prevalence")?,
                get_f(p, "coverage")?,
                get_f(p, "efficacy")?,
            ),
        )),
        "reinfection_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::reinfection_rate(
                get_f(p, "force_of_infection")?,
                get_f(p, "waning_immunity")?,
                get_f(p, "time_since_treatment")?,
            ),
        )),
        "pathogen_shedding_rate" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::pathogen_shedding_rate(
                get_f(p, "burden")?,
                get_f(p, "per_parasite_shed")?,
                get_f(p, "saturation")?,
            ),
        )),
        "environmental_reservoir_decay" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::environmental_reservoir_decay(
                get_f(p, "contamination")?,
                get_f(p, "decay_rate")?,
                get_f(p, "input_rate")?,
            ),
        )),
        "host_specificity_index" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::host_specificity_index(
                get_f(p, "hosts_used")?,
                get_f(p, "hosts_available")?,
            ),
        )),
        "virulence_evolution_si" => Ok(RunOutput::Scalar(
            bio::parasitology::virulence::virulence_evolution_si(
                get_f(p, "beta")?,
                get_f(p, "alpha")?,
                get_f(p, "gamma")?,
                get_f(p, "mu")?,
            ),
        )),
        _ => Err(HubError::InvalidInput(format!("unknown function: {func}"))),
    }
}