Struct SDEProblem

Source
pub struct SDEProblem<T, V, D, F>
where T: Real, V: State<T>, D: CallBackData, F: SDE<T, V, D>,
{ pub sde: F, pub t0: T, pub tf: T, pub y0: V, /* private fields */ }
Expand description

Initial Value Problem for Stochastic Differential Equations (SDEProblem)

The Initial Value Problem takes the form: dY = a(t, Y)dt + b(t, Y)dW, t0 <= t <= tf, Y(t0) = y0

where:

  • a(t, Y) is the drift term (deterministic part)
  • b(t, Y) is the diffusion term (stochastic part)
  • dW represents a Wiener process increment

§Overview

The SDEProblem struct provides a simple interface for solving stochastic differential equations:

§Example

use differential_equations::prelude::*;
use nalgebra::SVector;
use rand::SeedableRng;
use rand_distr::{Distribution, Normal};

struct GBM {
    rng: rand::rngs::StdRng,
}

impl GBM {
    fn new(seed: u64) -> Self {
        Self {
            rng: rand::rngs::StdRng::seed_from_u64(seed),
        }
    }
}

impl SDE<f64, SVector<f64, 1>> for GBM {
    fn drift(&self, _t: f64, y: &SVector<f64, 1>, dydt: &mut SVector<f64, 1>) {
        dydt[0] = 0.1 * y[0]; // μS
    }
     
    fn diffusion(&self, _t: f64, y: &SVector<f64, 1>, dydw: &mut SVector<f64, 1>) {
        dydw[0] = 0.2 * y[0]; // σS
    }
     
    fn noise(&mut self, dt: f64, dw: &mut SVector<f64, 1>) {
        let normal = Normal::new(0.0, dt.sqrt()).unwrap();
        dw[0] = normal.sample(&mut self.rng);
    }
}

let t0 = 0.0;
let tf = 1.0;
let y0 = SVector::<f64, 1>::new(100.0);
let mut solver = ExplicitRungeKutta::three_eighths(0.01);
let gbm = GBM::new(42);
let mut gbm_problem = SDEProblem::new(gbm, t0, tf, y0);

// Solve the SDE
let result = gbm_problem.solve(&mut solver);

§Fields

  • sde - SDE implementing the stochastic differential equation
  • t0 - Initial time
  • tf - Final time
  • y0 - Initial state vector

§Basic Usage

  • new(sde, t0, tf, y0) - Create a new SDE Problem
  • solve(&mut solver) - Solve using default output (solver step points)

§Output Control Methods

These methods configure how solution points are generated and returned:

  • even(dt) - Generate evenly spaced output points with interval dt
  • dense(n) - Include n interpolated points between each solver step
  • t_eval(points) - Evaluate solution at specific time points
  • solout(custom_solout) - Use a custom output handler
  • seed(u64) - Set a specific random seed for reproducible simulations

Fields§

§sde: F§t0: T§tf: T§y0: V

Implementations§

Source§

impl<T, V, D, F> SDEProblem<T, V, D, F>
where T: Real, V: State<T>, D: CallBackData, F: SDE<T, V, D>,

Source

pub fn new(sde: F, t0: T, tf: T, y0: V) -> Self

Create a new Stochastic Differential Equation Problem

§Arguments
  • sde - SDE containing the Stochastic Differential Equation and Optional Terminate Function
  • t0 - Initial Time
  • tf - Final Time
  • y0 - Initial State Vector
§Returns
  • SDE Problem ready to be solved
Source

pub fn solve<S>( &mut self, solver: &mut S, ) -> Result<Solution<T, V, D>, Error<T, V>>
where S: StochasticNumericalMethod<T, V, D> + Interpolation<T, V>,

Solve the SDE Problem using a default solout, e.g. outputting solutions at calculated steps

§Returns
  • Result<Solution<T, V, D>, Error<T, V>> - Ok(Solution) if successful or interrupted by events, Err(Error) if errors or issues are encountered
Source

pub fn solout<'a, O: Solout<T, V, D>>( &'a mut self, solout: &'a mut O, ) -> SDEProblemMutRefSoloutPair<'a, T, V, D, F, O>

Returns an SDE Problem with the provided solout function for outputting points

§Returns
  • SDE Problem with the provided solout function ready for .solve() method
Source

pub fn even( &mut self, dt: T, ) -> SDEProblemSoloutPair<'_, T, V, D, F, EvenSolout<T>>

Uses the an Even Solout implementation to output evenly spaced points between the initial and final time Note that this does not include the solution of the calculated steps

§Arguments
  • dt - Interval between each output point
§Returns
  • SDE Problem with Even Solout function ready for .solve() method
Source

pub fn dense( &mut self, n: usize, ) -> SDEProblemSoloutPair<'_, T, V, D, F, DenseSolout>

Uses the Dense Output method to output n number of interpolation points between each step Note this includes the solution of the calculated steps

§Arguments
  • n - Number of interpolation points between each step
§Returns
  • SDE Problem with Dense Output function ready for .solve() method
Source

pub fn t_eval( &mut self, points: Vec<T>, ) -> SDEProblemSoloutPair<'_, T, V, D, F, TEvalSolout<T>>

Uses the provided time points for evaluation instead of the default method Note this does not include the solution of the calculated steps

§Arguments
  • points - Custom output points
§Returns
  • SDE Problem with Custom Time Evaluation function ready for .solve() method
Source

pub fn crossing( &mut self, component_idx: usize, threshold: T, direction: CrossingDirection, ) -> SDEProblemSoloutPair<'_, T, V, D, F, CrossingSolout<T>>

Uses the CrossingSolout method to output points when a specific component crosses a threshold Note this does not include the solution of the calculated steps

§Arguments
  • component_idx - Index of the component to monitor for crossing
  • threshold - Value to cross
  • direction - Direction of crossing (positive or negative)
§Returns
  • SDE Problem with CrossingSolout function ready for .solve() method
Source

pub fn hyperplane_crossing<V1>( &mut self, point: V1, normal: V1, extractor: fn(&V) -> V1, direction: CrossingDirection, ) -> SDEProblemSoloutPair<'_, T, V, D, F, HyperplaneCrossingSolout<T, V1, V>>
where V1: State<T>,

Uses the HyperplaneCrossingSolout method to output points when a specific hyperplane is crossed Note this does not include the solution of the calculated steps

§Arguments
  • point - Point on the hyperplane
  • normal - Normal vector of the hyperplane
  • extractor - Function to extract the component from the state vector
  • direction - Direction of crossing (positive or negative)
§Returns
  • SDE Problem with HyperplaneCrossingSolout function ready for .solve() method

Trait Implementations§

Source§

impl<T, V, D, F> Clone for SDEProblem<T, V, D, F>
where T: Real + Clone, V: State<T> + Clone, D: CallBackData + Clone, F: SDE<T, V, D> + Clone,

Source§

fn clone(&self) -> SDEProblem<T, V, D, F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, V, D, F> Debug for SDEProblem<T, V, D, F>
where T: Real + Debug, V: State<T> + Debug, D: CallBackData + Debug, F: SDE<T, V, D> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, V, D, F> Freeze for SDEProblem<T, V, D, F>
where F: Freeze, T: Freeze, V: Freeze,

§

impl<T, V, D, F> RefUnwindSafe for SDEProblem<T, V, D, F>

§

impl<T, V, D, F> Send for SDEProblem<T, V, D, F>
where F: Send, V: Send, D: Send,

§

impl<T, V, D, F> Sync for SDEProblem<T, V, D, F>
where F: Sync, V: Sync, D: Sync,

§

impl<T, V, D, F> Unpin for SDEProblem<T, V, D, F>
where F: Unpin, T: Unpin, V: Unpin, D: Unpin,

§

impl<T, V, D, F> UnwindSafe for SDEProblem<T, V, D, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> CallBackData for T
where T: Clone + Debug,