dataeval.shift.OODReconstructionConfig¶
- class dataeval.shift.OODReconstructionConfig¶
Configuration for OODReconstruction detector training and threshold computation.
This dataclass provides default values for common training parameters that can be overridden when needed. It’s designed to work with the hybrid approach where parameters can be set either via config or directly in fit().
- loss_fn¶
Loss function for training. If None, will use default based on model type: - AE: MSELoss() - VAE: ELBOLoss() - GMM models: MSELoss() (reconstruction only)
- Type:¶
Callable or None, default None
- optimizer¶
Optimizer for training. If None, uses Adam with lr=0.001.
- Type:¶
torch.optim.Optimizer or None, default None
- gmm_weight¶
Weight for GMM component when combining with reconstruction error (α in the formula). Final score = (1-α) * recon_score + α * gmm_score, where both are standardized. Only used when use_gmm=True. Range [0, 1]: 0=reconstruction only, 1=GMM only.
- Type:¶
float, default 0.5
- gmm_score_mode¶
Method for combining reconstruction and GMM scores when use_gmm=True: - “standardized”: Z-score normalization of both components, then weighted sum - “percentile”: Convert to percentiles, combine as 1 - (P_recon * P_gmm)
- Type:¶
{“standardized”, “percentile”}, default “standardized”
Examples
>>> from dataeval.shift import OODReconstruction, OODReconstructionConfig >>> from dataeval.utils.models import VAE >>> >>> train_data = torch.rand(10, 1, 28, 28)Using default configuration:
>>> ood = OODReconstruction(VAE(input_shape=(1, 28, 28))) >>> ood.fit(train_data) # Uses default configUsing custom configuration:
>>> config = OODReconstructionConfig(epochs=10, batch_size=128, threshold_perc=99.0) >>> ood = OODReconstruction(VAE(input_shape=(1, 28, 28)), config=config) >>> ood.fit(train_data) # Uses config defaultsOverriding config in fit():
>>> config = OODReconstructionConfig(epochs=10, batch_size=128) >>> ood = OODReconstruction(VAE(input_shape=(1, 28, 28)), config=config) >>> ood.fit(train_data, epochs=100) # Override config.epochs