nifty7.operators.sampling_enabler module#

class SamplingDtypeSetter(op, dtype)[source]#

Bases: EndomorphicOperator

Class that adds the information whether the operator at hand is the covariance of a real-valued Gaussian or a complex-valued Gaussian probability distribution.

This wrapper class shall address the following ambiguity which arises when drawing a sampling from a Gaussian distribution with zero mean and given covariance. E.g. a ScalingOperator with 1. on its diagonal can be viewed as the covariance operator of both a real-valued and complex-valued Gaussian distribution. SamplingDtypeSetter specifies this data type.

Parameters:
  • op (EndomorphicOperator) – Operator which shall be supplemented with a dtype for sampling. Needs to be positive definite, hermitian and needs to implement the method draw_sample_with_dtype(). Note that these three properties are not checked in the constructor.

  • dtype (numpy.dtype or dict of numpy.dtype) – Dtype used for sampling from this operator. If the domain of op is a MultiDomain, the dtype can either be specified as one value for all components of the MultiDomain or in form of a dictionary whose keys need to conincide the with keys of the MultiDomain.

__repr__()[source]#

Return repr(self).

draw_sample(from_inverse=False)[source]#

Generates a sample from a Gaussian distribution with zero mean and covariance given by the operator.

May or may not be implemented. Only optional.

Parameters:

from_inverse (bool (default : False)) – if True, the sample is drawn from the inverse of the operator

Returns:

A sample from the Gaussian of given covariance.

Return type:

Field or MultiField

class SamplingEnabler(likelihood, prior, iteration_controller, approximation=None, start_from_zero=False)[source]#

Bases: EndomorphicOperator

Class which acts as a operator object built of (likelihood + prior) and enables sampling from its inverse even if the operator object itself does not support it.

Parameters:
  • likelihood (EndomorphicOperator) – Metric of the likelihood

  • prior (EndomorphicOperator) – Metric of the prior

  • iteration_controller (IterationController) – The iteration controller to use for the iterative numerical inversion done by a ConjugateGradient object.

  • approximation (LinearOperator, optional) – if not None, this linear operator should be an approximation to the operator, which supports the operation modes that the operator doesn’t have. It is used as a preconditioner during the iterative inversion, to accelerate convergence.

  • start_from_zero (boolean) – If true, the conjugate gradient algorithm starts from a field filled with zeros. Otherwise, it starts from a prior samples. Default is False.

__repr__()[source]#

Return repr(self).

draw_sample(from_inverse=False)[source]#

Generates a sample from a Gaussian distribution with zero mean and covariance given by the operator.

May or may not be implemented. Only optional.

Parameters:

from_inverse (bool (default : False)) – if True, the sample is drawn from the inverse of the operator

Returns:

A sample from the Gaussian of given covariance.

Return type:

Field or MultiField

draw_sample_with_dtype(dtype, from_inverse=False)[source]#

Generates a sample from a Gaussian distribution with zero mean, covariance given by the operator and specified data type.

This method is implemented only for operators which actually draw samples (e.g. DiagonalOperator). Operators which process the sample (like SandwichOperator) implement only draw_sample().

May or may not be implemented. Only optional.

Parameters:
  • dtype (numpy.dtype or dict of numpy.dtype) – Dtype used for sampling from this operator. If the domain of op is a MultiDomain, the dtype can either be specified as one value for all components of the MultiDomain or in form of a dictionary whose keys need to conincide the with keys of the MultiDomain.

  • from_inverse (bool (default : False)) – if True, the sample is drawn from the inverse of the operator

Returns:

A sample from the Gaussian of given covariance.

Return type:

Field or MultiField