dival.util.odl_noise_random_state module
Functions to create noise samples of different distributions.
This module is a copy of odl.phantom.noise
that was modified to support
random states instead of seeds.
- dival.util.odl_noise_random_state.white_noise(space, mean=0, stddev=1, seed=None, random_state=None)[source]
Standard gaussian noise in space, pointwise
N(mean, stddev**2)
.- Parameters:
space (TensorSpace or ProductSpace) – The space in which the noise is created.
mean (
space.field
element orspace
element-like, optional) – The mean of the white noise. If a scalar, it is interpreted asmean * space.one()
. Ifspace
is complex, the real and imaginary parts are interpreted as the mean of their respective part of the noise.stddev (float or
space
element-like, optional) – The standard deviation of the white noise. If a scalar, it is interpreted asstddev * space.one()
.seed (int, optional) – Random seed to use for generating the noise. For None, use the current seed. Only takes effect if
random_state is None
.random_state (numpy.random.RandomState, optional) – Random state to use for generating the noise. For None, use the global numpy random state (i.e. functions in
np.random
).
- Returns:
white_noise
- Return type:
space
element
See also
poisson_noise
,salt_pepper_noise
,numpy.random.normal
- dival.util.odl_noise_random_state.poisson_noise(intensity, seed=None, random_state=None)[source]
Poisson distributed noise with given intensity.
- Parameters:
intensity (TensorSpace or ProductSpace element) – The intensity (usually called lambda) parameter of the noise.
- Returns:
poisson_noise (
intensity.space
element) – Poisson distributed random variable.seed (int, optional) – Random seed to use for generating the noise. For None, use the current seed. Only takes effect if
random_state is None
.random_state (numpy.random.RandomState, optional) – Random state to use for generating the noise. For None, use the global numpy random state (i.e. functions in
np.random
).
Notes
For a Poisson distributed random variable \(X\) with intensity \(\lambda\), the probability of it taking the value \(k \in \mathbb{N}_0\) is given by
\[\frac{\lambda^k e^{-\lambda}}{k!}\]Note that the function only takes integer values.
See also
white_noise
,salt_pepper_noise
,uniform_noise
,numpy.random.poisson
- dival.util.odl_noise_random_state.salt_pepper_noise(vector, fraction=0.05, salt_vs_pepper=0.5, low_val=None, high_val=None, seed=None, random_state=None)[source]
Add salt and pepper noise to vector.
Salt and pepper noise replaces random elements in
vector
withlow_val
orhigh_val
.- Parameters:
vector (element of TensorSpace or ProductSpace) – The vector that noise should be added to.
fraction (float, optional) – The propotion of the elements in
vector
that should be converted to noise.salt_vs_pepper (float, optional) – Relative abundance of salt (high) vs pepper (low) noise. A high value means more salt than pepper noise.
low_val (float, optional) – The “pepper” color in the noise. Default: minimum value of
vector
. For product spaces the minimum value per subspace is taken.high_val (float, optional) – The “salt” value in the noise. Default: maximuim value of
vector
. For product spaces the maximum value per subspace is taken.seed (int, optional) – Random seed to use for generating the noise. For None, use the current seed. Only takes effect if
random_state is None
.random_state (numpy.random.RandomState, optional) – Random state to use for generating the noise. For None, use the global numpy random state (i.e. functions in
np.random
).
- Returns:
salt_pepper_noise –
vector
with salt and pepper noise.- Return type:
vector.space
element
See also
- dival.util.odl_noise_random_state.uniform_noise(space, low=0, high=1, seed=None, random_state=None)[source]
Uniformly distributed noise in
space
, pointwiseU(low, high)
.- Parameters:
space (TensorSpace or ProductSpace) – The space in which the noise is created.
low (
space.field
element orspace
element-like, optional) – The lower bound of the uniform noise. If a scalar, it is interpreted aslow * space.one()
. Ifspace
is complex, the real and imaginary parts are interpreted as their respective part of the noise.high (
space.field
element orspace
element-like, optional) – The upper bound of the uniform noise. If a scalar, it is interpreted ashigh * space.one()
. Ifspace
is complex, the real and imaginary parts are interpreted as their respective part of the noise.seed (int, optional) – Random seed to use for generating the noise. For None, use the current seed. Only takes effect if
random_state is None
.random_state (numpy.random.RandomState, optional) – Random state to use for generating the noise. For None, use the global numpy random state (i.e. functions in
np.random
).
- Returns:
white_noise
- Return type:
space
element
See also
poisson_noise
,salt_pepper_noise
,white_noise
,numpy.random.normal