nirs4all.operators.transforms.fck_static module

Fractional Convolutional Kernel (FCK) static transformer.

A small, fixed bank of normalised fractional-derivative filters applied as 1D convolutions across the wavelength axis. Each filter is built from a Gaussian envelope multiplied by a signed fractional-power profile, then zero-meaned (for alpha > 0) and L1-normalised.

The bank is the Cartesian product of alphas × scales × kernel_sizes. With the defaults the bank has 16 filters ({0.5, 1.0, 1.5, 2.0} × {1, 2} × {15, 31}); the output is the horizontally concatenated convolution responses, shape (n, K * L).

The transformer is stateless: fit only validates the input. The filters depend solely on the constructor hyperparameters, so no information leaks from training data into the bank.

class nirs4all.operators.transforms.fck_static.FCKStaticTransformer(alphas: Sequence[float] = (0.5, 1.0, 1.5, 2.0), scales: Sequence[float] = (1, 2), kernel_sizes: Sequence[int] = (15, 31), sigma: float = 3.0, mode: str = 'nearest', flatten: bool = True, *, copy: bool = True)[source]

Bases: TransformerMixin, BaseEstimator

Static fractional convolutional kernel bank for 1D spectra.

Parameters:
  • alphas (sequence of float, default=(0.5, 1.0, 1.5, 2.0)) – Fractional orders for the filter bank.

  • scales (sequence of float, default=(1, 2)) – Index-axis multipliers.

  • kernel_sizes (sequence of int, default=(15, 31)) – Odd kernel lengths.

  • sigma (float, default=3.0) – Gaussian envelope sigma. Fixed (not searched) to keep the bank small.

  • mode ({'nearest', 'reflect', 'mirror', 'constant', 'wrap'}, default='nearest') – Boundary mode passed to scipy.ndimage.convolve1d().

  • flatten (bool, default=True) – If True (default), output shape is (n_samples, K * n_features) so the transformer composes directly with sklearn estimators that expect 2D input. If False, output is (n_samples, K, n_features).

  • copy (bool, default=True) – Honoured by the sklearn transformer protocol; the implementation always allocates a new output array.

Variables:
  • kernels (np.ndarray) – Bank of shape (K, kernel_size_max) after fitting. Variable-length kernels are right-padded with zeros for storage; the actual per-kernel length is recovered from kernel_specs_.

  • kernel_specs (list of tuple[float, float, int]) – (alpha, scale, kernel_size) for each filter in bank order.

  • n_kernels (int) – Number of filters in the bank.

Examples

>>> import numpy as np
>>> from nirs4all.operators.transforms import FCKStaticTransformer
>>> X = np.random.RandomState(0).randn(10, 200)
>>> fck = FCKStaticTransformer().fit(X)
>>> fck.transform(X).shape
(10, 3200)
fit(X, y=None)[source]

Validate the input and build the (data-independent) filter bank.

Building the bank in fit rather than __init__ makes sklearn.base.clone() and set_params work as expected: the bank is rebuilt whenever hyperparameters change.

transform(X, y=None)[source]

Apply each filter as a 1D convolution along the wavelength axis.