magni.cs.phase_transition._data module

Module providing problem suite instance and noise generation functionality.

The problem suite instances consist of a matrix, A, and a coefficient vector, alpha, with which the measurement vector, y, can be generated (with or without noise from the noise vector e)

Routine listings

generate_matrix(m, n)
Generate a matrix belonging to a specific problem suite.
generate_noise(m, n, k)
Generate a noise vector of a specific type.
generate_vector(n, k)
Generate a vector belonging to a specific problem suite.

See also

magni.cs.phase_transition._config
Configuration options.

Notes

The matrices and vectors generated in this module use the numpy.random submodule. Consequently, the calling script or function should control the seed to ensure reproducibility.

The choice of non-zero indices in the coefficient vector is controlled by the configuration option ‘support_structure’ whereas the distribution of the non-zero coefficients is controlled by the configuration option ‘coefficient’.

Examples

For example generate a sample from the USE/Rademacher problem suite:

>>> import numpy as np, magni
>>> from magni.cs.phase_transition import _data
>>> m, n, k = 400, 800, 100
>>> A = _data.generate_matrix(m, n)
>>> alpha = _data.generate_vector(n, k)
>>> y = np.dot(A, alpha)

Or generate a problem suite instance with “linear” support distribution.

>>> support_distrib = np.reshape(np.arange(n, dtype=np.float) + 1, (n, 1))
>>> support_distrib /= np.sum(support_distrib)
>>> magni.cs.phase_transition.config['support_distribution'] = support_distrib
>>> A = _data.generate_matrix(m, n)
>>> alpha = _data.generate_vector(n, k)
>>> y = np.dot(A, alpha)

Or generate an AWGN noise vector based on a 40 dB SNR

>>> magni.cs.phase_transition.config['noise'] = 'AWGN'
>>> e = _data.generate_noise(m, n, k)
magni.cs.phase_transition._data.generate_matrix(m, n)[source]

Generate a matrix belonging to a specific problem suite.

The available matrices are

  • A random matrix drawn from the Uniform Spherical Ensemble (USE).
  • A fixed uniformly row sub-sampled DCT matrix ensemble (RandomDCT2D).
  • An option to use custom matrix factory (see notes below).

See Notes for a description of these matrices. Which of the available matrices is used, is specified as a configuration option.

Parameters:
  • m (int) – The number of rows.
  • n (int) – The number of columns.
Returns:

A (ndarray) – The generated matrix.

See also

magni.cs.phase_transition.config()
Configuration options.
magni.utils.matrices.MatrixCollection()
Fast transform implementation.

Notes

The Uniform Spherical Ensemble:
The matrices of this ensemble have i.i.d. Gaussian entries of mean zero and variance one. Its columns are then normalised to have unit length.
Fixed uniformly row sub-sampled DCT ensemble:
The matrices of this ensemble correspond to the combination of a 2D array sub-sampled using a uniform point pattern and a 2D Discrete Cosine Transform (DCT) matrix. The combined matrix is implemented as a fast transform with a DCT based on an FFT routine.
Custom matrix factory:
The matrix generation is delegated to the configured custom_system_matrix_factory callable which is expected to take the arguments m, n and return A.
magni.cs.phase_transition._data.generate_noise(m, n, k)[source]

Generate a noise vector of a specific type.

The available types are:

  • AWGN : Additive White Gaussian Noise
  • AWLN : Additive White Laplacian Noise
  • custom : The noise generation is delegated to the configured custom_noise_factory callable which is expected to take the arguments m, n, k, noise_power.

Which of the available types is used, is specified as a configuration option.

Parameters:
  • m (int) – The number of rows.
  • n (int) – The number of columns.
  • k (int) – The number of non-zero coefficients.
Returns:

e (ndarray) – The generated noise vector.

See also

magni.cs.phase_transition.config()
Configuration options.

Notes

The noise power is computed from the configured SNR and the theoretical ensemble variance of the coefficients generated by generate_cofficients.

magni.cs.phase_transition._data.generate_vector(n, k)[source]

Generate a vector belonging to a specific problem suite.

The available ensembles are:

  • Gaussian
  • Rademacher
  • Laplace
  • Bernoulli

See Notes for a description of the ensembles. Which of the available ensembles is used, is specified as a configuration option. Note, that the non-zero k non-zero coefficients are the k first entries if no support structure specified in the configuration.

Parameters:
  • n (int) – The length of the vector.
  • k (int) – The number of non-zero coefficients.
Returns:

alpha (ndarray) – The generated vector.

See also

magni.cs.phase_transition.config()
Configuration options.

Notes

The Gaussian ensemble:
The non-zero coefficients are drawn from the normal Gaussian distribution.
The Rademacher ensemble:
The non-zero coefficients are drawn from the constant amplitude with random signs ensemble.
The Laplace ensemble:
The non-zero coefficients are drawn from the zero-mean, unit scale Laplace distribution (variance = 2).
The Bernoulli ensemble:
The non-zero coefficients are all equal to one.