torch_ecg.utils.generate_weight_mask#
- torch_ecg.utils.generate_weight_mask(target_mask: ndarray[tuple[Any, ...], dtype[_ScalarT]], fg_weight: float | int, fs: float | int, reduction: float | int, radius: float | int, boundary_weight: float | int, plot: bool = False) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#
Generate weight mask for a binary target mask, accounting the foreground weight and boundary weight.
- Parameters:
target_mask (numpy.ndarray) – The target mask, assumed to be 1D and binary.
fg_weight (float or int) – Foreground (value 1) weight, usually > 1.
reduction (float or int) – Reduction ratio of the mask w.r.t. the signal.
radius (float or int) – Radius of the boundary, with units in seconds.
boundary_weight (float or int) – Weight for the boundaries (positions where values change) of the target map.
plot (bool, default False) – If True, target_mask and the result weight_mask will be plotted.
- Returns:
weight_mask – Weight mask generated from target_mask.
- Return type:
Examples
>>> target_mask = np.zeros(50000, dtype=int) >>> target_mask[500:14000] = 1 >>> target_mask[35800:44600] = 1 >>> fg_weight = 2.0 >>> fs = 500 >>> reduction = 1 >>> radius = 0.8 >>> boundary_weight = 5.0 >>> weight_mask = generate_weight_mask( ... target_mask, fg_weight, fs, reduction, radius, boundary_weight ... ) >>> weight_mask.shape (50000,) >>> reduction = 10 >>> weight_mask = generate_weight_mask( ... target_mask, fg_weight, fs, reduction, radius, boundary_weight ... ) >>> weight_mask.shape (5000,)