#![deny(missing_docs)]
use crate::stochastics::*;
#[derive(Debug)]
pub struct BrownianMotion {}
impl Default for BrownianMotion {
fn default() -> Self {
Self::new()
}
}
impl BrownianMotion {
pub fn new() -> Self {
Self {}
}
}
impl StochasticProcess for BrownianMotion {
fn drift(&self, _x: f64) -> f64 {
0_f64
}
fn diffusion(&self, _x: f64) -> f64 {
1_f64
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::helpers::*;
#[test]
fn test_brownian_motion() -> Result<(), Box<dyn std::error::Error>> {
let bm = BrownianMotion::new();
let output_serial = (&bm).euler_maruyama(10.0, 0.0, 0.5, 100, 1000, false);
let output_parallel = (&bm).euler_maruyama(10.0, 0.0, 0.5, 100, 1000, true);
let file1 = "./Images/BM1.png";
plot_vector((&output_serial.trajectories[0]).clone(), file1).unwrap();
let file2 = "./Images/BM2.png";
plot_vector((&output_serial.trajectories[1]).clone(), file2).unwrap();
let file2 = "./Images/BM3_parallel.png";
plot_vector((&output_parallel.trajectories[0]).clone(), file2)
}
}