# magni.cs.reconstruction.gamp.input_channel module¶

Module providing input channel functions for the Generalised Approximate Message Passing (GAMP) algorithm.

## Routine listings¶

ValidatedMMSEInputChannel(magni.utils.validation.types.MMSEInputChannel)
A base class for validated magni.cs.reconstruction.gamp input channels.
ValidatedBasicMMSEInputChannel(ValidatedMMSEInputChannel)
A base class for validated basic input channels.
GWS(ValidatedMMSEInputChannel)
A General Weighted Sparse MMSE input channel.
IIDG(ValidatedBasicMMSEInputChannel)
An i.i.d. Gaussian MMSE input channel.
IIDL(ValidatedBasicMMSEInputChannel)
An i.i.d. Laplace MMSE input channel.
IIDBG(ValidatedMMSEInputChannel)
An i.i.d. Bernoulli Gauss MMSE input channel.
IIDsGB(ValidatedMMSEInputChannel)
An i.i.d. sparse Gauss Bernoulli MMSE input channel.
class magni.cs.reconstruction.gamp.input_channel.ValidatedMMSEInputChannel(var)[source]

A base class for validated magni.cs.reconstruction.gamp input channels.

Parameters: var (dict) – The input channel state variables.
compute(var)[source]

Compute the input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.

Notes

This method honors magni.utils.validation.enable_allow_validate_once.

Subclasses of this class are expected to override this method and then call it using super since it only implements the necessary input validation.

class magni.cs.reconstruction.gamp.input_channel.ValidatedBasicMMSEInputChannel(var)[source]

A base class for validated basic input channels.

The term “basic” refers to channels that may be used in combination with the General Weighted Sparse (GWS) channel framework.

Parameters: var (dict) – The input channel state variables.
compute_Z(var)[source]

Compute the input channel normalisation constant.

Parameters: var (dict) – The variables used in computing of the normalisation constant. Z (ndarray) – The computed normalisation constant.

Notes

This method honors magni.utils.validation.enable_allow_validate_once.

Subclasses of this class are expected to override this method and then call it using super since it only implements the necessary input validation.

get_EM_element(channel_parameter)[source]

Return the element needed in computing the channel_parameter EM update.

Parameters: channel_parameter (str) – The channel parameter for which the EM element is needed. EM_element (ndarray) – The EM element needed for the channel parameter EM update.

Notes

This method honors magni.utils.validation.enable_allow_validate_once.

Subclasses of this class are expected to override this method and then call it using super since it only implements the necessary input validation.

class magni.cs.reconstruction.gamp.input_channel.GWS(var)[source]

A General Weighted Sparse MMSE input channel.

This channel is a an independent but non-identically weighted linear combination of a Bernoulli component and a “phi” component from another arbitrary distribution.

Parameters: tau (float or int) – The prior signal “density” (fraction of “phi” to Bernouilli). weights (ndarray or None) – The n-by-1 vector of channel weights. If None, a vector of all ones is used. phi_channel (ValidatedBasicMMSEInputChannel) – The input channel instance implementing the “phi” component. phi_channel_parameters (dict) – The dictionary containing the parameters needed to initialise the phi_channel. use_em (bool) – The indicator of whether or not to use Expectation Maximazion (EM) to learn the prior parameters. adjust_tau_method ({‘truncate’, ‘reweight’}) – The adjustment method to use if the EM-update of tau gets larger than one.

Notes

The above Parameters are the input channel parameters that must be passed in a var dict to the channel constructor.

If use_em is True, the value given for tau is used for initialialisation. When using EM, the phi_channel_parameters are updated in alphabetical order.

If the tau EM-update gets larger than one, it must be adjusted to avoid divergence of the GAMP algorithm. Two methods for this adjustment are available:

• Truncate: Truncate tau to 1. (The default.)
• Reweight: Adjust the weights to be close to unity weights.

In addition to the above parameters it is assumed that the var dict includes the following keys:

• ‘n’: The number of variables on which the channel acts.
• ‘convert’: The precision conversion callable.
compute(var)[source]

Compute the GWS input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.
_adjust_tau(tau, pi, method)[source]

Adjust the value of tau if its EM-update is larger than one.

Parameters: tau (float) – The current value of tau. pi (ndarray) – The current GAMP posterior support probabilities. method ({‘truncate’, ‘reweight’}) – The adjustment method to use. tau (float) – The adjusted value of tau.
class magni.cs.reconstruction.gamp.input_channel.IIDG(var)[source]

An i.i.d. Gaussian MMSE input channel.

Parameters: theta_bar (float or int) – The prior Gaussian mean. theta_tilde (float or int) – The prior Gaussian variance. use_em (bool) – The indicator of whether or not to use Expectation Maximazion (EM) to learn the prior parameters.

Notes

The above Parameters are the input channel parameters that must be passed in a var dict to the channel constructor.

If use_em is True, the values given for theta_bar, and theta_tilde are used for initialialisation.

In addition to the above parameters it is assumed that the var dict includes the following keys:

• ‘n’: The number of variables on which the channel acts.
• ‘convert’: The precision conversion callable.
compute(var)[source]

Compute the IIDG input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.
compute_Z(var)[source]

Compute the IIDG input channel normalisation constant.

Parameters: var (dict) – The variables used in computing of the normalisation constant. Z (ndarray) – The computed normalisation constant.
get_EM_element(channel_parameter)[source]

Return the element needed in computing the channel_parameter EM update.

Parameters: channel_parameter (str) – The channel parameter for which the EM element is needed. EM_element (ndarray) – The EM element needed for the channel parameter EM update.
class magni.cs.reconstruction.gamp.input_channel.IIDL(var)[source]

An i.i.d. Laplace MMSE input channel.

This channel is a generalisation of the Laplacian prior detailed in [5]. Specifically, the Laplace term is allowed to have a mean different from zero.

Parameters: mu (float or int) – The prior Laplace mean. b (float or int) – The prior Laplace scale parameter (i.e. 1/lambda with lambda the rate parameter). use_em (bool) – The indicator of whether or not to use Expectation Maximazion (EM) to learn the prior parameters.

Notes

The above Parameters are the input channel parameters that must be passed in a var dict to the channel constructor.

If use_em is True, the values given for mu, and b are used for initialialisation.

In addition to the above parameters it is assumed that the var dict includes the following keys:

• ‘n’: The number of variables on which the channel acts.
• ‘convert’: The precision conversion callable.

References

 [5] J. Ziniel “Message Passing Approaches to Compressive Inference Under Structured Signal Priors”, Ph.D. dissertation, Graduate School of The Ohio State University, 2014.
compute(var)[source]

Compute the IIDL input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.
compute_Z(var)[source]

Compute the IIDL input channel normalisation constant.

Parameters: var (dict) – The variables used in computing of the normalisation constant. Z (ndarray) – The computed normalisation constant.
get_EM_element(channel_parameter)[source]

Return the element needed in computing the channel_parameter EM update.

Parameters: channel_parameter (str) – The channel parameter for which the EM element is needed. EM_element (ndarray) – The EM element needed for the channel parameter EM update.
_npcr(x)[source]

Return the pdf/cdf ratio of a standard normal RV evaluated at x.

Parameters: x (ndarray) – The values to evaluate the ratio at. npcr_values (ndarray) – The evaluated ratios.
class magni.cs.reconstruction.gamp.input_channel.IIDBG(var)[source]

An i.i.d. Bernoulli Gauss MMSE input channel.

This channel is based on equations (6), (7) in [3] and allows for using Expectation Maximization (EM) for learning the channel parameters as detailed in equations (19), (25), and (32) in [3] (see also [4] for an introduction to EM for GAMP).

Parameters: tau (float or int) – The prior signal “density” (fraction of Gauss to Bernouilli). theta_bar (float or int) – The prior Gaussian mean. theta_tilde (float or int) – The prior Gaussian variance. use_em (bool) – The indicator of whether or not to use Expectation Maximazion (EM) to learn the prior parameters.

Notes

The above Parameters are the input channel parameters that must be passed in a var dict to the channel constructor.

If use_em is True, the values given for tau, theta_bar, and theta_tilde are used for initialialisation.

In addition to the above parameters it is assumed that the var dict includes the following keys:

• ‘n’: The number of variables on which the channel acts.
• ‘convert’: The precision conversion callable.

This channel is theoretically equivalent to the IIDsGB channel. However, due to numerical subtleties, it may give different results.

References

 [3] (1, 2) J. Vila, J. and P. Schniter, “Expectation-Maximization Bernoulli-Gaussian Approximate Message Passing”, in Forty Fifth Asilomar Conference on Signals, Systems and Computers (ASILOMAR), pp. 799-803, Pacific Grove, California, USA, Nov. 6-9, 2011
 [4] J. P. Vila and P. Schniter, “Expectation-Maximization Gaussian-Mixture Approximate Message Passing”, IEEE Transactions on Signal Processing, 2013, vol. 61, no. 19, pp. 4658-4672, Oct. 2013.
compute(var)[source]

Compute the IIDBG input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.
class magni.cs.reconstruction.gamp.input_channel.IIDsGB(var)[source]

An i.i.d. sparse Gauss Bernoulli MMSE input channel.

This channel is based on equations (68), (69) in [1] and allows for using Expectation Maximization (EM) for learning the channel parameters as detailed in equations (74), (78), and (79) in [1] (see also [2] for an introduction to EM for GAMP).

Parameters: tau (float or int) – The prior signal “density” (fraction of Gauss to Bernouilli). theta_bar (float or int) – The prior Gaussian mean. theta_tilde (float or int) – The prior Gaussian variance. use_em (bool) – The indicator of whether or not to use Expectation Maximazion (EM) to learn the prior parameters. em_damping (float or int) – The damping of the EM updates (if using EM).

Notes

The above Parameters are the input channel parameters that must be passed in a var dict to the channel constructor.

If use_em is True, the values given for tau, theta_bar, and theta_tilde are used for initialialisation. The em_damping must be in [0, 1) with 0 being no damping.

In addition to the above parameters it is assumed that the var dict includes the following keys:

• ‘n’: The number of variables on which the channel acts.
• ‘m’: The number of measurements on which the estimation is based.
• ‘convert’: The precision conversion callable.

This channel is theoretically equivalent to the IIDBG channel. However, due to numerical subtleties, it may give different results.

References

 [1] (1, 2) F. Krzakala, M. Mezard, F. Sausset, Y. Sun, and L. Zdeborova, “Probabilistic reconstruction in compressed sensing: algorithms, phase diagrams, and threshold achieving matrices”, Journal of Statistical Mechanics: Theory and Experiment, vol. P08009, pp. 1-57, Aug. 2012.
 [2] J. P. Vila and P. Schniter, “Expectation-Maximization Gaussian-Mixture Approximate Message Passing”, IEEE Transactions on Signal Processing, 2013, vol. 61, no. 19, pp. 4658-4672, Oct. 2013.
compute(var)[source]

Compute the IIDsGB input channel value.

Parameters: var (dict) – The variables used in computing of the input channel value. mean (ndarray) – The computed input channel mean. variance (ndarray) – The computed input channel variance.