dataeval.shift.OODReconstruction.Config

class dataeval.shift.OODReconstruction.Config

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

epochs

Number of training epochs.

Type:

int, default 20

batch_size

Batch size for training and scoring.

Type:

int, default 64

threshold_perc

Percentage of reference data considered normal.

Type:

float, default 95.0

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
>>> 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 config
OODReconstruction(loss_fn=None, optimizer=None, epochs=20, batch_size=64, threshold_perc=95.0, gmm_weight=0.5, gmm_score_mode='standardized', fitted=False)

Using custom configuration:

>>> config = OODReconstruction.Config(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 defaults
OODReconstruction(loss_fn=None, optimizer=None, epochs=10, batch_size=128, threshold_perc=99.0, gmm_weight=0.5, gmm_score_mode='standardized', fitted=False)

Using different config values:

>>> config = OODReconstruction.Config(epochs=100, batch_size=128)
>>> ood = OODReconstruction(VAE(input_shape=(1, 28, 28)), config=config)
>>> ood.fit(train_data)
OODReconstruction(loss_fn=None, optimizer=None, epochs=100, batch_size=128, threshold_perc=95.0, gmm_weight=0.5, gmm_score_mode='standardized', fitted=False)