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_’.

get_config() dict[source]#
property mask_key: str#

Key under which the mask will be stored in the output dictionary.

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>’.

__call__(data: dict[str, ndarray], *, inverse: bool = False, **kwargs) dict[str, ndarray]#

Call self as a function.

extra_repr() str#
classmethod from_config(config: dict, custom_objects=None)#
log_det_jac(data: dict[str, ndarray], log_det_jac: dict[str, ndarray], inverse: bool = False, **kwargs) dict[str, ndarray]#