sample_from_density

sample_from_density#

mrinufft.trajectories.sampling.sample_from_density(nb_samples, density, method='random', *, dim_compensation='auto')[source]#

Sample points based on a given density distribution.

Parameters:
  • nb_samples (int) – The number of samples to draw.

  • density (np.ndarray) – An array representing the density distribution from which samples are drawn, normalized automatically by its sum during the call for convenience.

  • method (str, optional) – The sampling method to use, either ‘random’ for random sampling over the discrete grid defined by the density or ‘lloyd’ for Lloyd’s algorithm over a continuous space, by default “random”.

  • dim_compensation (str, bool, optional) – Whether to apply a specific dimensionality compensation introduced in [Cha+14]. An exponent N/(N-1) with N the number of dimensions in density is applied to fix the observed density expectation when set to "auto" and method="lloyd". It is also relevant to set it to True when method="random" and one wants to create binary masks with continuous paths between drawn samples.

Returns:

An array of range-normalized sampled locations.

Return type:

np.ndarray

Raises:

ValueError – If nb_samples exceeds the total size of the density array or if the specified method is unknown.

References

[Cha+14]

Chauffert, Nicolas, Philippe Ciuciu, Jonas Kahn, and Pierre Weiss. “Variable density sampling with continuous trajectories.” SIAM Journal on Imaging Sciences 7, no. 4 (2014): 1962-1992.