Struct FftAttention

Source
pub struct FftAttention<A = f32> { /* private fields */ }
Expand description

FFT-based attention mechanism for temporal pattern recognition.

This implementation is based on “The FFT Strikes Back: Fast and Accurate Spectral-Pruning Neural Networks” (https://arxiv.org/pdf/2502.18394).

The mechanism:

  1. Transforms input to frequency domain using FFT
  2. Applies soft thresholding to frequency components based on energy distribution
  3. Enhances important frequency patterns
  4. Returns to time domain with inverse FFT

The attention mechanism is parameterized by steepness and threshold, which control the sensitivity of the attention to frequency components.

Implementations§

Source§

impl<A> FftAttention<A>

Source

pub fn new() -> Self
where A: FromPrimitive,

Create a new attention module with the given parameters

Source

pub const fn steepness(&self) -> &A

returns an immutable reference to the steepness of the attention module

Source

pub fn steepness_mut(&mut self) -> &mut A

returns a mutable reference to the steepness of the attention module to allow for gradient descent

Source

pub const fn threshold(&self) -> &A

returns an immutable reference to the threshold of the attention module

Source

pub fn threshold_mut(&mut self) -> &mut A

returns a mutable reference to the threshold of the attention module to allow for gradient descent

Source

pub fn set_steepness(&mut self, steepness: A)

set the steepness of the attention mechanism

Source

pub fn set_threshold(&mut self, threshold: A)

set the threshold of the attention mechanism

Source

pub fn with_steepness(self, steepness: A) -> Self

consumes the current instance and returns another with the given steepness

Source

pub fn with_threshold(self, threshold: A) -> Self

consumes the current instance and returns another with the given threshold

Source

pub fn forward<X, Y>(&self, input: &X) -> Result<Y>
where Self: Forward<X, Output = Y>,

Trait Implementations§

Source§

impl<A: Clone> Clone for FftAttention<A>

Source§

fn clone(&self) -> FftAttention<A>

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<A: Debug> Debug for FftAttention<A>

Source§

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

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

impl<A> Default for FftAttention<A>
where A: FromPrimitive,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, A> Deserialize<'de> for FftAttention<A>
where A: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A, S> Forward<ArrayBase<S, Dim<[usize; 1]>>> for FftAttention<A>
where A: FftNum + Float + FromPrimitive + ScalarOperand, S: Data<Elem = A>,

Source§

type Output = ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>

Source§

fn forward(&self, input: &ArrayBase<S, Ix1>) -> Result<Self::Output>

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<A, S> Forward<ArrayBase<S, Dim<[usize; 2]>>> for FftAttention<A>
where A: FftNum + Float + FromPrimitive + ScalarOperand, S: Data<Elem = A>,

Source§

type Output = ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>

Source§

fn forward(&self, input: &ArrayBase<S, Ix2>) -> Result<Self::Output>

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<A: Hash> Hash for FftAttention<A>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<A: Ord> Ord for FftAttention<A>

Source§

fn cmp(&self, other: &FftAttention<A>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A: PartialEq> PartialEq for FftAttention<A>

Source§

fn eq(&self, other: &FftAttention<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A: PartialOrd> PartialOrd for FftAttention<A>

Source§

fn partial_cmp(&self, other: &FftAttention<A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A> Serialize for FftAttention<A>
where A: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<A: Copy> Copy for FftAttention<A>

Source§

impl<A: Eq> Eq for FftAttention<A>

Source§

impl<A> StructuralPartialEq for FftAttention<A>

Auto Trait Implementations§

§

impl<A> Freeze for FftAttention<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for FftAttention<A>
where A: RefUnwindSafe,

§

impl<A> Send for FftAttention<A>
where A: Send,

§

impl<A> Sync for FftAttention<A>
where A: Sync,

§

impl<A> Unpin for FftAttention<A>
where A: Unpin,

§

impl<A> UnwindSafe for FftAttention<A>
where A: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<M, U, V> Predict<U> for M
where M: Forward<U, Output = V>,

Source§

type Output = V

Source§

fn __private__(&self) -> Seal

Source§

fn predict(&self, input: &U) -> Result<<M as Predict<U>>::Output, NeuralError>

Source§

impl<M, U, A, D> PredictWithConfidence<U> for M
where A: Float + FromPrimitive + ScalarOperand, D: Dimension, M: Predict<U, Output = ArrayBase<OwnedRepr<A>, D>>,

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,