Camiba – Compressed Sensing

Scenario

class camiba.cs.Scenario(mat_D, mat_C, algo)[source]
General Compressed Sensing Scenario

This class offers a very convenient but still abstract interface to a standard compressed sensing scenario, which generally consists of a dictionary matrix, a compression matrix and a reconstruction scheme represented by an algorithm.

compress(arr_y)[source]
Apply Compression
Parameters:

arr_y : ndarray

signal to compress

Returns:

ndarray

the compressed measurement

gen_sparse(num_s, entries=[], do_complex=False)[source]
Generate a Sparse Signal

This function generates a sparse ground truth signal according to the scenarios dimensions of a given sparsity order and makes use of a certain set of specified elements if provided.

Parameters:

num_s : int

desired sparsity order

entries : list

list of possible values

do_complex : bool

whether the elements are complex or not

Returns:

ndarray

the sparse vector

gen_sparse_sep(num_s, dist, entries=[], do_complex=False)[source]
Generate a Sparse Signal with Separation Condition

This function generates a sparse ground truth signal according to the scenarios dimensions of a given sparsity order and makes use of a certain set of specified elements if provided. Moreover, a separation condition is used to not put support elements closer than this distance. Ultimatively this generates more “well behaved” signals in terms of reconstruction.

Parameters:

num_s : int

desired sparsity order

num_dist : int

desired separation distance

entries : list

list of possible values

do_complex : bool

whether the elements are complex or not

Returns:

ndarray

the sparse signal

phase_trans_rec(num_s, fun_x, args, arr_snr, fun_noise, dct_fun_compare, num_trials)[source]
Calculate a phase transition

Given the scenario we generate sparse vectors with a certain fixed sparsity level and according to a provided scheme. Then we apply the forward model and the compression and add noise to the compressed measurements, which is generated by a provided noise generating function. Then we aim a reconstructing the original signal from this compressed and noisy data. This is done several times for each level of SNR and after each reconstruction, we compare the reconstruction with respect to one or more provided error metrics. Finally everything is saved and returned in a dictionary where the keys are given by the SNR and the name of the applied error metric.

Parameters:

num_s : int

sparsity level

fun_x : method

function, which takes the sparsity level as parameter to generate a sparse vector

args : dict

arguments for the recovery algorithm

arr_snr : ndarray

all level of SNR to go through

fun_noise : ndarray

noise generating function, taking the snr and the vector size as arguments

dct_fun_compare : dict

dictionary of comparison function

num_trials : int

number of trials to run at each snr level

Returns:

ndarray

the compressed measurement

pipeline(arr_x)[source]

Transform to measurment

This method takes a sparse vector and multiplies it with the dictionary to get the acutal signal from its sparse representation. Often this is called forward model. Then also the defined compression step is applied and we implemented the whole pipelein

Parameters:

arr_x : ndarray

sparse vector

Returns:

ndarray

the compressed measurement

recover(arr_b, args)[source]
Recover a sparse vector

Given a measurement and additional arguments for the recovery method we call this very method and return its result.

Parameters:

arr_b : ndarray

measurement vector

args : dict

recovery algorithms arguments

Returns:

ndarray

the sparse reconstructed vector

to_signal(arr_x)[source]
Transform to signal

This method takes a sparse vector and multiplies it with the dictionary to get the acutal signal from its sparse representation. Often this is called forward model.

Parameters:

arr_x : ndarray

sparse vector

Returns:

ndarray

the signal

Soe

class camiba.cs.Soe(num_n, num_m, mos_method='eft', *args, algorithm=<function recover>, **kwargs)[source]

Here we implement a Class, which provides different methods for sparsity order estimation from compressed measurements. Many of them are very good.

estimate(arr_b)[source]
Do Sparsity Order Estimation

This function does the acutal SOE process for a given measurement and returns the estimated size.

Parameters:

arr_b : ndarray

one ore several compressed measurements

Returns:

ndarray

the estimated sparsity orders

phase_trans_est(num_s, fun_x, arr_snr, fun_noise, dct_fun_compare, num_trials)[source]
Calculate a phase transition

Given the scenario we generate sparse vectors with a certain fixed sparsity level and according to a provided scheme. Then we apply the forward model and the compression and add noise to the compressed measurements, which is generated by a provided noise generating function. Here, we only estimate the sparsity order and check if it succeeds or fails. This is done several times for each level of SNR and after each reconstruction, we compare the reconstruction with respect to one or more provided error metrics. Finally everything is saved and returned in a dictionary where the keys are given by the SNR and the name of the applied error metric.

Parameters:

num_s : int

sparsity level

fun_x : method

function, which takes the sparsity level as parameter to generate a sparse vector

args : dict

arguments for the recovery algorithm

arr_snr : ndarray

all level of SNR to go through

fun_noise : ndarray

noise generating function, taking the snr and the vector size as arguments

dct_fun_compare : dict

dictionary of comparison function

num_trials : int

number of trials to run at each snr level

Returns:

ndarray

the compressed measurement

phase_trans_est_rec(num_s, fun_x, args, arr_snr, fun_noise, dct_fun_compare, num_trials)[source]
Calculate a phase transition

Given the scenario we generate sparse vectors with a certain fixed sparsity level and according to a provided scheme. Then we apply the forward model and the compression and add noise to the compressed measurements, which is generated by a provided noise generating function. Then we aim a reconstructing the original signal from this compressed and noisy data, where we also feed the estimated sparsity order, which is provided by this class as a parameter in the algorithm for reconstruction. This is done several times for each level of SNR and after each reconstruction, we compare the reconstruction with respect to one or more provided error metrics. Finally everything is saved and returned in a dictionary where the keys are given by the SNR and the name of the applied error metric.

Parameters:

num_s : int

sparsity level

fun_x : method

function, which takes the sparsity level as parameter to generate a sparse vector

args : dict

arguments for the recovery algorithm

arr_snr : ndarray

all level of SNR to go through

fun_noise : ndarray

noise generating function, taking the snr and the vector size as arguments

dct_fun_compare : dict

dictionary of comparison function

num_trials : int

number of trials to run at each snr level

Returns:

ndarray

the compressed measurement