oncoray/mirp

Replace legacy numpy randomiser by generator-based randomisation

Closed this issue · 1 comments

mirp currently relies on the numpy.random module for randomisation, which uses the legacy RandomState randomiser. The drawback of the legacy implementation is that there is no default seed, i.e., some output may vary per run, even for the same input. An option would be to set a global seed using numpy.random.seed. However this may change the global state of the user environment, and for that reason should be avoided.

We should switch to the newer generator-based implementation in numpy.random.Generator, which allows for setting a seed locally and thus generating reproducible output.

The following functions and methods are affected:

  • get_volumetric_morphological_features: for computing Moran's I and Geary's C measures.
  • GenericImage.add_noise: for generating normally distributed additive noise.
  • MaskImage.fractional_volume_change: for randomly selecting voxels on the outer rim of the region of interest so that the intended volume fraction can be achieved.
  • MaskImage.randomise_mask: for randomly selecting subvoxels based on partial overlap with the ROI.

For the latter three, the seed should not be fully fixed, but rather defined by the workflow configuration parameters.

Addresses #43 .