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: usizeInput dimensionality (size of the state vector).
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).
Weight matrix from first hidden to second hidden layer (row-major, hidden × hidden).
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
impl NeuralOdeFunc
Sourcepub fn new(input_size: usize, hidden_size: usize, seed: u64) -> Self
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.
Sourcepub fn forward(&self, t: f64, z: &[f64]) -> Vec<f64>
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.
Sourcepub fn jvp(&self, t: f64, z: &[f64], v: &[f64], eps: f64) -> Vec<f64>
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.
Sourcepub fn params_flat(&self) -> Vec<f64>
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.
Sourcepub fn set_params_flat(&mut self, params: &[f64])
pub fn set_params_flat(&mut self, params: &[f64])
Restore all trainable parameters from a flat vector (same layout as params_flat).
Trait Implementations§
Source§impl Clone for NeuralOdeFunc
impl Clone for NeuralOdeFunc
Source§fn clone(&self) -> NeuralOdeFunc
fn clone(&self) -> NeuralOdeFunc
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for NeuralOdeFunc
impl RefUnwindSafe for NeuralOdeFunc
impl Send for NeuralOdeFunc
impl Sync for NeuralOdeFunc
impl Unpin for NeuralOdeFunc
impl UnsafeUnpin for NeuralOdeFunc
impl UnwindSafe for NeuralOdeFunc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.