API Reference#

Complete reference for all public classes and functions in MaldiDeepKit, organized by module.

Base Classes#

Every classifier inherits from BaseSpectralClassifier, which handles device placement, validation splits, early stopping, and persistence. Subclasses only need to override _build_model().

maldideepkit.BaseSpectralClassifier

Abstract base for all MaldiDeepKit classifiers.

maldideepkit.SpectralDataset

PyTorch Dataset wrapping a binned MALDI-TOF feature matrix.

maldideepkit.make_loaders

Build stratified train / validation DataLoader pairs.

Classifiers#

maldideepkit.MaldiMLPClassifier

sklearn-compatible MLP classifier with optional attention gating.

maldideepkit.MaldiCNNClassifier

sklearn-compatible 1-D CNN classifier for MALDI-TOF spectra.

maldideepkit.MaldiResNetClassifier

sklearn-compatible 1-D ResNet classifier for MALDI-TOF spectra.

maldideepkit.MaldiTransformerClassifier

sklearn-compatible 1-D ViT classifier for MALDI-TOF spectra.

Building Blocks#

Low-level nn.Module classes backing each classifier are re-exported through the maldideepkit.blocks namespace, so a user who wants to embed a single component in a custom network can import from one place. See Blocks Module for the full list, grouped into full backbones vs. composable primitives.

from maldideepkit.blocks import (
    SpectralTransformer1D,   # full backbones
    TransformerBlock,        # composable primitives
    PatchEmbed1D,
    BasicBlock1D,
    # ...
)

Training Utilities#

maldideepkit.utils.seed_everything

Seed Python, NumPy, and PyTorch (CPU + CUDA) RNGs in one call.

maldideepkit.utils.resolve_device

Resolve a user-facing device specifier to a torch.device.

maldideepkit.utils.EarlyStopping

Track the best validation loss and signal when to stop training.

maldideepkit.utils.train_loop

Run a classic train + validate loop with early stopping.

maldideepkit.utils.FocalLoss

Multi-class focal loss with optional class weighting and label smoothing.

maldideepkit.utils.SAMOptimizer

Wrap a base optimizer in the SAM two-step update.

maldideepkit.utils.tune_threshold

Pick the binary decision threshold that maximises metric.

maldideepkit.utils.fit_temperature

Fit a scalar temperature by LBFGS minimisation of NLL.

maldideepkit.utils.find_lr

Sweep learning rate geometrically and return the LR / loss curve.

maldideepkit.utils.SpectralEnsemble

Ensemble N fitted or unfitted spectral classifiers.

Augmentation#

Per-batch augmentations applied to training batches only; bypassed during validation and inference. See Augment Module for the full API.

maldideepkit.augment.SpectrumAugment

Composable per-batch spectrum augmentation.

maldideepkit.augment.apply_mixup

Mixup: convex-combine two random permutations of the batch.

maldideepkit.augment.apply_cutmix

CutMix on 1-D spectra: splice a contiguous m/z window.

Uncertainty Quantification#

Drop-in estimators that wrap a fitted classifier and return calibrated predictions plus per-sample uncertainty. See Uncertainty Module.

maldideepkit.uncertainty.MCDropoutEstimator

Monte Carlo Dropout estimator (Gal and Ghahramani, 2016).

maldideepkit.uncertainty.LaplaceEstimator

Laplace-approximation uncertainty estimator.

maldideepkit.uncertainty.ConformalPredictor

Split conformal predictor with the LAC non-conformity score.

maldideepkit.uncertainty.UncertaintyResult

Container for the output of a BaseUncertaintyEstimator.