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
use serde::{Deserialize, Serialize}; use crate::utils; #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] enum ThinningFunction { // Coefficients, from the highest order coefficient to the zero order coefficient Polynomial { coefficients: Vec<f64> }, } /// Thinning provides a means for non-stationary stochastic model behaviors. /// By providing a normalized thinning function (with the maximum value over /// the support being =1), model behavior will change based on the current /// global time. While thinning is a widely generalizable strategy for /// non-stationary stochastic behaviors, it is very inefficient for models /// where there is "heavy thinning" during large portions of the simulation /// execution. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Thinning { // Normalized thinning function with max(fn) = 1 over the support function: ThinningFunction, } impl Thinning { pub fn evaluate(self, point: f64) -> f64 { match &self.function { ThinningFunction::Polynomial { coefficients } => { utils::evaluate_polynomial(&coefficients, point) } } } }