NanToNum#
- class bayesflow.adapters.transforms.NanToNum(key: str, default_value: float = 0.0, return_mask: bool = False, mask_prefix: str = 'mask')[source]#
Bases:
Transform
Replace NaNs with a default value, and optionally encode a missing-data mask as a separate output key.
This is based on “Missing data in amortized simulation-based neural posterior estimation” by Wang et al. (2024).
- Parameters:
- keystr
The variable key to look for in the simulation data dict.
- default_valuefloat, optional
Value to substitute wherever data is NaN. Default is 0.0.
- return_maskbool, optional
If True, a mask array will be returned under a new key. Default is False.
- mask_prefixstr, optional
Prefix for the mask key in the output dictionary. Default is ‘mask_’.
- forward(data: dict[str, any], **kwargs) dict[str, any] [source]#
Forward transform: fill NaNs and optionally output mask under ‘mask_<key>’.
- inverse(data: dict[str, any], **kwargs) dict[str, any] [source]#
Inverse transform: restore NaNs using the mask under ‘mask_<key>’.