Skip to content

Mixing Configuration

spectrans.config.layers.mixing

Configuration models for mixing layer components.

This module provides Pydantic models for validating and typing configuration data used to construct mixing layers in spectrans.

Classes:

Name Description
WaveletMixingConfig

Configuration for WaveletMixing layer.

WaveletMixing2DConfig

Configuration for WaveletMixing2D layer.

FourierMixingConfig

Configuration for Fourier mixing layers.

GlobalFilterMixingConfig

Configuration for global filter mixing layers.

Notes

All configuration models use Pydantic v2 BaseModel for validation and type safety. Mixing layer configurations inherit from base layer configuration classes in the parent models module.

Examples:

>>> from spectrans.config.layers.mixing import WaveletMixingConfig
>>> config = WaveletMixingConfig(hidden_dim=768, wavelet="db4", levels=3)
>>> print(config.wavelet)
'db4'

Classes

WaveletMixingConfig

Bases: BaseLayerConfig

Configuration model for WaveletMixing layer.

Attributes:

Name Type Description
wavelet WaveletType

Wavelet family name, defaults to "db4".

levels int

Number of decomposition levels, must be between 1 and 6, defaults to 3.

mixing_mode Literal['pointwise', 'subband']

Mixing operation mode, defaults to "pointwise".

Methods:

Name Description
validate_wavelet

Validate that wavelet name is supported.

Functions
validate_wavelet classmethod
validate_wavelet(v: WaveletType) -> WaveletType

Validate that wavelet name is supported.

Source code in spectrans/config/layers/mixing.py
@field_validator("wavelet")
@classmethod
def validate_wavelet(cls, v: WaveletType) -> WaveletType:
    """Validate that wavelet name is supported."""
    if not v:
        raise ValueError("Wavelet name cannot be empty")
    return v

WaveletMixing2DConfig

Bases: BaseModel

Configuration model for WaveletMixing2D layer.

Attributes:

Name Type Description
channels int

Number of input channels, must be positive.

wavelet WaveletType

Wavelet family name, defaults to "db4".

levels int

Number of decomposition levels, must be between 1 and 6, defaults to 2.

mixing_mode Literal['subband', 'channel']

2D mixing operation mode, defaults to "subband".

Methods:

Name Description
validate_wavelet

Validate that wavelet name is supported.

Functions
validate_wavelet classmethod
validate_wavelet(v: WaveletType) -> WaveletType

Validate that wavelet name is supported.

Source code in spectrans/config/layers/mixing.py
@field_validator("wavelet")
@classmethod
def validate_wavelet(cls, v: WaveletType) -> WaveletType:
    """Validate that wavelet name is supported."""
    if not v:
        raise ValueError("Wavelet name cannot be empty")
    return v

FourierMixingConfig

Bases: UnitaryLayerConfig

Configuration for standard Fourier mixing layers.

Attributes:

Name Type Description
keep_complex bool

If True, keeps complex values from FFT. If False (default), takes only the real part as in original FNet.

GlobalFilterMixingConfig

Bases: FilterLayerConfig

Configuration for global filter mixing layers.

Attributes:

Name Type Description
activation ActivationType

Activation function for filters, defaults to "sigmoid".

AFNOMixingConfig

Bases: BaseLayerConfig

Configuration for Adaptive Fourier Neural Operator mixing layers.

Attributes:

Name Type Description
max_sequence_length int

Maximum sequence length for mode truncation, must be positive.

modes_seq int | None

Number of Fourier modes in sequence dimension, defaults to max_sequence_length // 2.

modes_hidden int | None

Number of Fourier modes in hidden dimension, defaults to hidden_dim // 2.

mlp_ratio float

MLP expansion ratio in frequency domain, defaults to 2.0.

activation ActivationType

Activation function for MLP, defaults to "gelu".