lib.utils
Collection of various utility functions supporting the main functionalities of the library.
- lib.utils.afclean(fh)
Tries to purge an anonymous function of all non-essential workspace data.
- Parameters
fh (function handle) – Input function handle to be cleansed.
- Returns
fh_clean – The same as fh, but with its workspace reduced to the essential variables.
- Return type
function handle
Example
>>> fh_clean = afclean(fh);
Note
Function retrieved from: Matt J (2021). Memory-efficient anonymous functions (https://www.mathworks.com/matlabcentral/fileexchange/45749-memory-efficient-anonymous-functions), MATLAB Central File Exchange. Retrieved October 17, 2021.
Warning
DISCLAIMERS (from the original author): The cleaning process will break anonymous functions that call nested functions or subfunctions. Unfortunately also, the implementation of AFCLEAN relies on a certain amount of undocumented MATLAB, in particular the FUNCTIONS command whose behavior in future releases of MATLAB, The MathWorks doesn’t guarantee. It also makes heavy use of EVAL. When the tool works, it seems to work well, but use at your own risk!
- lib.utils.solver_find_elipse_point(y, pU, A, T, xsol, v2, W, epsilont, max_iterations, min_iterations, eps, use_fb, max_no_el)
Generate an initial point to initialize
solver_proj_elipse_fb
.- Parameters
y (cell{:} of complex[:]) – Input data. Each cell entry corresponds to a data block.
pU (cell{:} of double[:]) – Diagonal preconditioner (encoded as a vector) involved in the definition of the ellipsoid.
A (anonymous function) – Function handle representing the measurement operator.
T (cell{:} of double[:]) – Noise whitening diagonal matrices (encoded as vectors) associated with each data block. Each cell entry corresponds to a data block.
xsol (double[:, :]) – Inital image estimate.
v2 (cell{:} of complex[:]) – Data-fidelity dual variables associated with each data block.
W (cell{:} of bool[:]) – Cell of boolean vector indicating the global position of each data point in the full Fourier space (undo blocking).
epsilont (cell{:} of double) – Radius of the ellispoid.
max_iterations (int) – Maximum number of iterations.
min_iterations (int) – Minimum number of iterations.
eps (double) – Stopping criterion tolerance (relative variation in norm between two consecutive iterates).
use_fb (bool) – Flag to use a forward-backward algorithm.
max_no_el (int) – Maximum number of elements per block (?).
- Returns
proj – Projection of the data y onto the ellipsoid considered.
- Return type
double[:]
Note
Deprecated function, still used in [Onose2017], https://github.com/basp-group/SARA-PPD.
- lib.utils.solver_proj_elipse_fb(v2, r2, y, U, epsilont, z0, max_itr, min_itr, eps)
Compute the projection of v2 + r2 onto the \(\ell_2\) ball centered in y, of radius epsilont with respect to the norm induced by the diagonal preconditioner U with the forward-backward algorithm.
- Parameters
v2 (complex[:]) – Part of the input point to be projected onto the ellipsoid.
r2 (complex[:]) – Part of the input point to be projected onto the ellipsoid.
y (complex[:]) – Visibility vector, center of the \(\ell_2\) ball.
U (double[:]) – Diagonal preconditioning matrix (encoded as a vector).
epsilont (double) – Radius of the \(\ell_2\) ball.
z0 (complex[:]) – Algorithm starting point.
max_itr (int) – Maximum number of iterations.
min_itr (int) – Minimum number of iterations.
eps (double) – Stopping criterion tolerance (relative variation in norm between two consecutive iterates).
- Returns
z (complex[:]) – Projection onto the ellipsoid.
k (int) – Number of iterations required to converge.
- lib.utils.util_create_pool(NumWorkers)
Opens a new paralel pool with NumWorkers workers. If a similar pool already exists, keeps the existing pool.
- Parameters
NumWorkers (int) – Numer of workers in the parallel pool.
- lib.utils.util_divisor(n)
Provides a list of integer divisors of a number.
- Parameters
n (int) – Input integer value.
- Returns
d – Row vector of all distinct divisors of the positive integer n, including 1 and n.
- Return type
int[1, :]
Example
>>> a = divisor(12); >>> a = [1, 2, 3, 4, 6, 12];
Note
This function uses the default factor() routine in Matlab and hence is limited to input values up to \(2^{32}\). However if factor() routine does get updated for larger integers, this function will still work fine. Using factor() provides a significant speed improvement over manually seaching for the each divisor of n.
Author: Yash Kochar ( yashkochar@yahoo.com )
Last modified: 21st June 2009.
See also
factor
,primes
- lib.utils.util_gen_L2_bounds(y0, input_snr, sigma_noise, l2_ball_definition, stopping_criterion, equal_bounds, param)
Generate the \(\ell_2\) bounds for synthetic data experiments
Note
- lib.utils.util_gen_block_structure(uw, vw, aWw, nWw, param)
Generate data blocks for synthetic data experiments.
Note
- lib.utils.util_gen_preconditioning_matrix(u, v, param)
Generate the diagnoal preconditioning matrix (accounting for the sampling density in the Fourier domain, similarly to uniform weighting [Onose2017]).
- Parameters
u (double[:]) – u coordinate of the data point in the Fourier domain.
v (double[:]) – v coordinate of the data points in the Fourier domain.
param (struct) – List of parameters to specify weights generation (can be omitted by default).
- Returns
aW – Diagonal preconditioner (uniform weighting), encoded as a vector.
- Return type
double[:]
- lib.utils.util_sort_find(x, LowerBound, UpperBound, exactLower, exactUpper)
Fast \(O(\log_2(N))\) computation of the range of indices of x that satify the upper and lower bound values using the fact that the x vector is sorted from low to high values. Computation is done via a binary search.
- Parameters
x (double[:]) – A vector of sorted values from low to high.
LowerBound (double[:]) – Lower boundary on the values of x in the search.
UpperBound (double[:]) – Upper boundary on the values of x in the search.
exactLower (int) – Bool to get values of x greater than LowerBound
exactUpper (int) – Bool to get values of x less than UpperBound
- Returns
lower_index (int) – The smallest index such that
LowerBound<=x(index)<=UpperBound
.upper_index (int) – The largest index such that
LowerBound<=x(index)<=UpperBound
.