pub struct MLPFeatureExtractor { /* private fields */ }Expand description
Multi-layer perceptron feature extractor.
The network is a sequence of DenseLayers applied in order; the
output of layer i is the input of layer i + 1. The layer stack
must be non-empty and layer shapes must match transitively.
Parameters are stored twice on purpose:
- as structured
layers: Vec<DenseLayer>— used byforward. - as flat
parameters: Vec<f64>— exposed to optimisers.
The two views are kept in sync: MLPFeatureExtractor::parameters_mut
returns a borrow into the flat buffer and
MLPFeatureExtractor::sync_from_flat pushes the flat buffer back
into the layer weights. Mutating the flat buffer directly requires a
subsequent sync_from_flat call before the next forward.
Implementations§
Source§impl MLPFeatureExtractor
impl MLPFeatureExtractor
Sourcepub fn from_layers(layers: Vec<DenseLayer>) -> Result<Self>
pub fn from_layers(layers: Vec<DenseLayer>) -> Result<Self>
Wrap an existing Vec<DenseLayer> as an MLP feature extractor.
Fails when the layer stack is empty or when consecutive layer shapes do not match.
Sourcepub fn xavier_init(
widths: &[usize],
activations: &[Activation],
seed: u64,
) -> Result<Self>
pub fn xavier_init( widths: &[usize], activations: &[Activation], seed: u64, ) -> Result<Self>
Build an MLP from a list of layer widths and a parallel list of
activations (one per weight matrix — i.e. widths.len() - 1
entries). Weights are Xavier/Glorot-normal initialised via
SciRS2-Core’s seeded RNG; biases are zero.
Sourcepub fn layers(&self) -> &[DenseLayer]
pub fn layers(&self) -> &[DenseLayer]
Immutable view of the layer stack.
Sourcepub fn num_layers(&self) -> usize
pub fn num_layers(&self) -> usize
Number of layers.
Sourcepub fn forward_with_cache(&self, input: &[f64]) -> Result<ForwardCache>
pub fn forward_with_cache(&self, input: &[f64]) -> Result<ForwardCache>
Forward pass with per-layer caches of (pre_activation, post_activation) tensors. Used by the analytical gradient path
in crate::deep_kernel::gradient.
Sourcepub fn sync_from_flat(&mut self) -> Result<()>
pub fn sync_from_flat(&mut self) -> Result<()>
Push the flat parameter buffer back into the per-layer
weights / biases. Call this after mutating the flat buffer
returned from Self::parameters_mut but before the next
forward pass.
Trait Implementations§
Source§impl Clone for MLPFeatureExtractor
impl Clone for MLPFeatureExtractor
Source§fn clone(&self) -> MLPFeatureExtractor
fn clone(&self) -> MLPFeatureExtractor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MLPFeatureExtractor
impl Debug for MLPFeatureExtractor
Source§impl NeuralFeatureMap for MLPFeatureExtractor
impl NeuralFeatureMap for MLPFeatureExtractor
Source§fn parameters_mut(&mut self) -> &mut [f64]
fn parameters_mut(&mut self) -> &mut [f64]
&mut [f64] so that optimisers can
apply updates in place without owning the extractor.Source§fn parameters(&self) -> &[f64]
fn parameters(&self) -> &[f64]
Source§fn parameter_count(&self) -> usize
fn parameter_count(&self) -> usize
Source§fn output_dim(&self) -> usize
fn output_dim(&self) -> usize
forward.Auto Trait Implementations§
impl Freeze for MLPFeatureExtractor
impl RefUnwindSafe for MLPFeatureExtractor
impl Send for MLPFeatureExtractor
impl Sync for MLPFeatureExtractor
impl Unpin for MLPFeatureExtractor
impl UnsafeUnpin for MLPFeatureExtractor
impl UnwindSafe for MLPFeatureExtractor
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<M> FeatureMapShape for Mwhere
M: NeuralFeatureMap,
impl<M> FeatureMapShape for Mwhere
M: NeuralFeatureMap,
Source§fn feature_dim(&self) -> usize
fn feature_dim(&self) -> usize
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more