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:
- Transforms input to frequency domain using FFT
- Applies soft thresholding to frequency components based on energy distribution
- Enhances important frequency patterns
- 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>
impl<A> FftAttention<A>
Sourcepub fn new() -> Selfwhere
A: FromPrimitive,
pub fn new() -> Selfwhere
A: FromPrimitive,
Create a new attention module with the given parameters
Sourcepub const fn steepness(&self) -> &A
pub const fn steepness(&self) -> &A
returns an immutable reference to the steepness of the attention module
Sourcepub fn steepness_mut(&mut self) -> &mut A
pub fn steepness_mut(&mut self) -> &mut A
returns a mutable reference to the steepness of the attention module to allow for gradient descent
Sourcepub const fn threshold(&self) -> &A
pub const fn threshold(&self) -> &A
returns an immutable reference to the threshold of the attention module
Sourcepub fn threshold_mut(&mut self) -> &mut A
pub fn threshold_mut(&mut self) -> &mut A
returns a mutable reference to the threshold of the attention module to allow for gradient descent
Sourcepub fn set_steepness(&mut self, steepness: A)
pub fn set_steepness(&mut self, steepness: A)
set the steepness of the attention mechanism
Sourcepub fn set_threshold(&mut self, threshold: A)
pub fn set_threshold(&mut self, threshold: A)
set the threshold of the attention mechanism
Sourcepub fn with_steepness(self, steepness: A) -> Self
pub fn with_steepness(self, steepness: A) -> Self
consumes the current instance and returns another with the given steepness
Sourcepub fn with_threshold(self, threshold: A) -> Self
pub fn with_threshold(self, threshold: A) -> Self
consumes the current instance and returns another with the given threshold
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>
impl<A: Clone> Clone for FftAttention<A>
Source§fn clone(&self) -> FftAttention<A>
fn clone(&self) -> FftAttention<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more