sim/input_modeling/
thinning.rs

1use serde::{Deserialize, Serialize};
2
3use crate::utils::errors::SimulationError;
4use crate::utils::evaluate_polynomial;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8enum ThinningFunction {
9    // Coefficients, from the highest order coefficient to the zero order coefficient
10    Polynomial { coefficients: Vec<f64> },
11}
12
13/// Thinning provides a means for non-stationary stochastic model behaviors.
14/// By providing a normalized thinning function (with the maximum value over
15/// the support being =1), model behavior will change based on the current
16/// global time.  While thinning is a widely generalizable strategy for
17/// non-stationary stochastic behaviors, it is very inefficient for models
18/// where there is "heavy thinning" during large portions of the simulation
19/// execution.
20#[derive(Debug, Clone, Serialize, Deserialize)]
21pub struct Thinning {
22    // Normalized thinning function with max(fn) = 1 over the support
23    function: ThinningFunction,
24}
25
26impl Thinning {
27    pub fn evaluate(self, point: f64) -> Result<f64, SimulationError> {
28        match &self.function {
29            ThinningFunction::Polynomial { coefficients } => {
30                evaluate_polynomial(coefficients, point)
31            }
32        }
33    }
34}