torch_ecg.utils.generate_weight_mask

torch_ecg.utils.generate_weight_mask(target_mask: ndarray, fg_weight: Real, fs: Real, reduction: Real, radius: Real, boundary_weight: Real, plot: bool = False) ndarray[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 (numbers.Real) – Foreground (value 1) weight, usually > 1.

  • fs (numbers.Real) – Sampling frequency of the signal.

  • reduction (numbers.Real) – Reduction ratio of the mask w.r.t. the signal.

  • radius (numbers.Real) – Radius of the boundary, with units in seconds.

  • boundary_weight (numbers.Real) – 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:

numpy.ndarray

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,)