Skip to main content

MLPFeatureExtractor

Struct MLPFeatureExtractor 

Source
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 by forward.
  • 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

Source

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.

Source

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.

Source

pub fn layers(&self) -> &[DenseLayer]

Immutable view of the layer stack.

Source

pub fn num_layers(&self) -> usize

Number of layers.

Source

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.

Source

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

Source§

fn clone(&self) -> MLPFeatureExtractor

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 Debug for MLPFeatureExtractor

Source§

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

Formats the value using the given formatter. Read more
Source§

impl NeuralFeatureMap for MLPFeatureExtractor

Source§

fn forward(&self, input: &[f64]) -> Result<Vec<f64>>

Map an input vector to feature space.
Source§

fn parameters_mut(&mut self) -> &mut [f64]

Mutable view of the flat parameter vector (weights + biases, in layer order). Exposed as &mut [f64] so that optimisers can apply updates in place without owning the extractor.
Source§

fn parameters(&self) -> &[f64]

Immutable view of the flat parameter vector.
Source§

fn parameter_count(&self) -> usize

Number of trainable scalar parameters.
Source§

fn input_dim(&self) -> usize

Input dimension expected by forward.
Source§

fn output_dim(&self) -> usize

Output dimension produced by forward.

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<M> FeatureMapShape for M

Source§

fn feature_dim(&self) -> usize

Output dimension of the feature map — i.e. the dimension the base kernel will see.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V