Skip to main content

NeuralOdeFunc

Struct NeuralOdeFunc 

Source
pub struct NeuralOdeFunc {
    pub input_size: usize,
    pub hidden_size: usize,
    pub weights_in: Vec<f64>,
    pub bias_in: Vec<f64>,
    pub weights_hidden: Vec<f64>,
    pub bias_hidden: Vec<f64>,
    pub weights_out: Vec<f64>,
    pub bias_out: Vec<f64>,
}
Expand description

The dynamics function of a Neural ODE — a small MLP that maps (t, z) to dz/dt.

Architecture: z → tanh(W_in·z + b_in) → tanh(W_h·h + b_h) → W_out·h2 + b_out.

Fields§

§input_size: usize

Input dimensionality (size of the state vector).

§hidden_size: usize

Number of hidden units in each hidden layer.

§weights_in: Vec<f64>

Weight matrix from input to first hidden layer (row-major, hidden × input).

§bias_in: Vec<f64>

Bias for the first hidden layer (length hidden_size).

§weights_hidden: Vec<f64>

Weight matrix from first hidden to second hidden layer (row-major, hidden × hidden).

§bias_hidden: Vec<f64>

Bias for the second hidden layer (length hidden_size).

§weights_out: Vec<f64>

Weight matrix from second hidden to output (row-major, input × hidden).

§bias_out: Vec<f64>

Bias for the output layer (length input_size).

Implementations§

Source§

impl NeuralOdeFunc

Source

pub fn new(input_size: usize, hidden_size: usize, seed: u64) -> Self

Construct a NeuralOdeFunc with all weights initialised to small random values using a simple linear congruential generator seeded by seed.

Source

pub fn forward(&self, t: f64, z: &[f64]) -> Vec<f64>

Evaluate the ODE right-hand side: dz/dt = f(t, z).

The time t is concatenated to z before the first layer so the network can model non-autonomous dynamics.

Source

pub fn jvp(&self, t: f64, z: &[f64], v: &[f64], eps: f64) -> Vec<f64>

Compute the Jacobian-vector product J·v via forward-mode finite differences.

Used internally by the adjoint method to approximate (∂f/∂z) · v.

Source

pub fn params_flat(&self) -> Vec<f64>

Return all trainable parameters as a flat vector.

Layout: weights_in | bias_in | weights_hidden | bias_hidden | weights_out | bias_out.

Source

pub fn n_params(&self) -> usize

Total number of trainable parameters.

Source

pub fn set_params_flat(&mut self, params: &[f64])

Restore all trainable parameters from a flat vector (same layout as params_flat).

Source

pub fn param_grad_contrib( &self, t: f64, z: &[f64], adj: &[f64], eps: f64, ) -> Vec<f64>

Compute the parameter-gradient contribution at point (t, z) with adjoint vector adj: grad_j = Σ_i adj_i · ∂f_i(t,z)/∂θ_j

Uses central finite differences with step eps.

Trait Implementations§

Source§

impl Clone for NeuralOdeFunc

Source§

fn clone(&self) -> NeuralOdeFunc

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NeuralOdeFunc

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.