pycsamt.ai.training.dataset#
PyTorch Dataset wrapper and normalisation utilities for EM training data.
Normalizer applies z-score normalisation (fit on training data,
applied to val/test without refit). EMDataset wraps a
ForwardDataset and handles:
z-score normalisation of X and y
log₁₀ transform of thickness values in y
NaN masking (NaN targets are left as
torch.nanfor masked loss)Optional on-the-fly noise augmentation
Usage#
>>> from pycsamt.forward.batch import generate_dataset
>>> from pycsamt.ai.training.dataset import EMDataset, Normalizer
>>> ds = generate_dataset(n_samples=1000, seed=0, verbose=False)
>>> train_ds = EMDataset(ds, log_thickness=True)
>>> train_ds.x_norm.mean.shape # (n_features,)
Classes
|
PyTorch |
|
Z-score normaliser that handles NaN values. |
- class pycsamt.ai.training.dataset.Normalizer(eps=1e-08)[source]#
Bases:
objectZ-score normaliser that handles NaN values.
- Parameters:
eps (float) – Small constant added to std to avoid division by zero.
- Variables:
- class pycsamt.ai.training.dataset.EMDataset(forward_ds, *, n_layers=None, log_thickness=True, x_norm=None, y_norm=None, augment_noise=0.0)[source]#
Bases:
objectPyTorch
Dataset-compatible wrapper for aForwardDataset.Handles normalisation, log₁₀ thickness transform, and optional on-the-fly noise augmentation.
- Parameters:
forward_ds (ForwardDataset) – Source data produced by
generate_dataset().n_layers (int or None) – If given, only samples with
meta.n_layers == n_layersare kept.Nonekeeps all samples (variable n_layers, NaN-padded).log_thickness (bool) – Apply log₁₀ to thickness values in y before normalising. Strongly recommended when thicknesses span > 2 orders of magnitude.
x_norm (Normalizer or None) – Pre-fitted normaliser for X. If
Nonea new one is fitted on this dataset (use on training split only).y_norm (Normalizer or None) – Pre-fitted normaliser for y.
augment_noise (float) – If > 0, add Gaussian noise (this level) to X on-the-fly each epoch.
- Variables: