def validate_output(): _numeric('alpha', ('integer', 'floating'), shape=(A.shape[1], 1)) _generic('history', 'mapping', keys_in=('alpha_bar', 'MSE', 'threshold_parameters', 'stop_criterion', 'stop_criterion_value', 'stop_iteration', 'stop_reason'))
def validate_input(): _numeric('x_org', ('integer', 'floating'), shape=None) if np.count_nonzero(x_org) == 0: raise ValueError('x_org must not be all zeros') _numeric('x_recons', ('integer', 'floating'), shape=x_org.shape)
def validate_input(): _numeric('X', ('boolean', 'integer', 'floating'), shape=(-1, -1)) _generic('ax', mpl.axes.Axes, ignore_none=True) _generic('intensity_func', 'function', ignore_none=True) _generic('intensity_args', 'explicit collection') _generic('show_axis', 'string', value_in=('none', 'top', 'inherit', 'frame'))
def validate_input(): _numeric('data', ('integer', 'floating'), shape=(-1,)) _levels('hdrs', (_generic(None, 'explicit collection'), _generic(None, 'explicit collection', len_=2))) for i in range(len(hdrs)): _generic(('hdrs', i, 0), 'string')
def __init__(self, var): super(IIDG, self).__init__(var) @_decorate_validation def validate_channel_parameters(): _generic(('var', 'input_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'theta_bar'), ('integer', 'floating')) _numeric(('var', 'input_channel_parameters', 'theta_tilde'), ('integer', 'floating'), range_='[0;inf)') _numeric(('var', 'input_channel_parameters', 'use_em'), 'boolean') _numeric(('var', 'n'), 'integer', range_='[0;inf)') _generic(('var', 'convert'), type) validate_channel_parameters() c_params = var['input_channel_parameters'] self._use_em = c_params['use_em'] # Whether or not to use EM learning self._EM_states = {'mean': np.nan, 'variance': np.nan} self._n = var['convert'](var['n']) self.channel_parameters = _Configger( { 'theta_bar': var['convert'](c_params['theta_bar']), 'theta_tilde': var['convert'](c_params['theta_tilde']) }, { 'theta_bar': _numeric(None, 'floating'), 'theta_tilde': _numeric(None, 'floating', range_='[0;inf)') })
def validate_input(): _generic('path', 'string') _generic('label', 'string') _numeric('delta', ('floating', 'integer'), range_='[0;1]', shape=(-1, ), ignore_none=True)
def validate_input(): _numeric('l', 'floating', range_='[{};inf)'.format(_min_l)) _numeric('w', 'floating', range_='[{};inf)'.format(_min_w)) _numeric('speed', 'floating', range_='[{};inf)'.format(_min_speed)) _numeric('sample_rate', 'floating', range_='[{};inf)'.format(_min_sample_rate)) _numeric('time', 'floating', range_='[{};inf)'.format(_min_time))
def validate_output(): _numeric('alpha', ('integer', 'floating', 'complex'), shape=(A.shape[1], 1), precision=convert(0).nbytes * 8) _generic('history', 'mapping', keys_in=('alpha', 'MSE', 'stop_criterion', 'stop_criterion_value', 'stop_iteration', 'stop_reason'))
def validate_input(): _generic('update_dict', 'mapping', keys_in=('F_norm',)) if 'F_norm' in update_dict: _numeric(('update_dict', 'F_norm'), ('integer', 'floating', 'complex'), shape=(-1, -1), ignore_none=True)
def __init__(self, var): super(IIDL, self).__init__(var) @_decorate_validation def validate_channel_parameters(): _generic(('var', 'input_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'mu'), ('integer', 'floating')) _numeric(('var', 'input_channel_parameters', 'b'), ('integer', 'floating'), range_='(0;inf)') _numeric(('var', 'input_channel_parameters', 'use_em'), 'boolean') _numeric(('var', 'n'), 'integer', range_='[0;inf)') _generic(('var', 'convert'), type) validate_channel_parameters() c_params = var['input_channel_parameters'] self._use_em = c_params['use_em'] # Whether or not to use EM learning self._EM_states = {'all_u': np.nan, 'all_o': np.nan} self._n = var['convert'](var['n']) self._std_norm_rv = stats.norm() self.channel_parameters = _Configger( { 'mu': var['convert'](c_params['mu']), 'b': var['convert'](c_params['b']) }, { 'mu': _numeric(None, 'floating'), 'b': _numeric(None, 'floating', range_='(0;inf)') })
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') _numeric('pixels', 'integer', shape=(-1, 2)) _numeric('pixels[:, 0]', 'integer', shape=(-1,), range_='[0;{})'.format(w), var=pixels[:, 0]) _numeric('pixels[:, 1]', 'integer', shape=(-1,), range_='[0;{})'.format(h), var=pixels[:, 1])
def validate_input(): _numeric('coords', 'floating', shape=(-1, 2)) _numeric('h', 'integer', range_='[1;inf)') _numeric('w', 'integer', range_='[1;inf)') _numeric('coords[:, 0]', 'floating', range_='[0;{}]'.format(w), shape=(-1,), var=coords[:, 0]) _numeric('coords[:, 1]', 'floating', range_='[0;{}]'.format(h), shape=(-1,), var=coords[:, 1])
def validate_input(): _generic('func', 'function') _generic('conj_trans', 'function') _generic('args', 'explicit collection') _levels('shape', (_generic(None, 'explicit collection', len_=2), _numeric(None, 'integer'))) _numeric('is_complex', 'boolean') _numeric('is_valid', 'boolean')
def validate_input(): _numeric('img', ('integer', 'floating', 'complex'), shape=(-1, -1)) _levels( 'transforms', (_generic(None, 'explicit collection'), _generic(None, 'string', value_in=_utils.get_transform_names()))) _generic('output_path', 'string', ignore_none=True) _generic('fig_ext', 'string')
def validate_input(): _numeric('Phi', ('integer', 'floating', 'complex'), shape=(-1, -1)) _numeric('Psi', ('integer', 'floating', 'complex'), shape=(Phi.shape[1], -1)) _generic('method', 'string', value_in=('min', 'diff', 'mean', 'std'), ignore_none=True)
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') _numeric('scan_length', 'floating', range_='[{};inf)'.format(_min_scan_length)) _numeric('num_points', 'integer', range_='[{};inf)'.format(_min_num_points)) _numeric('angle', 'floating', range_='(0;{})'.format(np.arctan(h / w)))
def validate_channel_parameters(): _generic(('var', 'output_channel_parameters'), 'mapping') _numeric(('var', 'output_channel_parameters', 'sigma_sq'), ('integer', 'floating'), range_='[0;inf)') _generic( ('var', 'output_channel_parameters', 'noise_level_estimation'), 'string', value_in=['sample_variance', 'median', 'em', 'fixed'])
def validate_output(): _levels('coefficients', (_generic(None, 'explicit collection'), _numeric(None, ('integer', 'floating', 'complex'), shape=img.shape))) _levels('reconstructions', (_generic(None, 'explicit collection'), _numeric(None, ('integer', 'floating', 'complex'), shape=img.shape)))
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') _numeric('pixels', 'integer', shape=(-1, 2)) _numeric('pixels[:, 0]', 'integer', range_='[0;{}]'.format(w - 1), shape=(-1,), var=pixels[:, 0]) _numeric('pixels[:, 1]', 'integer', range_='[0;{}]'.format(h - 1), shape=(-1,), var=pixels[:, 1]) _generic('output_path', 'string', ignore_none=True)
def validate_threshold_parameters(): _generic(('var', 'threshold_parameters'), 'mapping') _generic(('var', 'threshold_parameters', 'threshold_level_update_method'), 'string', value_in=['residual', 'median']) _numeric(('var', 'threshold_parameters', 'theta'), ('integer', 'floating'), range_='(0;inf)') _numeric(('var', 'threshold_parameters', 'tau_hat_sq'), ('integer', 'floating'), range_='[0;inf)')
def validate_channel_parameters(): _generic(('var', 'input_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'tau'), ('integer', 'floating'), range_='[0;1]') _numeric(('var', 'input_channel_parameters', 'theta_bar'), ('integer', 'floating')) _numeric(('var', 'input_channel_parameters', 'theta_tilde'), ('integer', 'floating'), range_='[0;inf)') _numeric(('var', 'input_channel_parameters', 'use_em'), 'boolean') _numeric(('var', 'n'), 'integer', range_='[0;inf)') _generic(('var', 'convert'), type)
def validate_input(): _numeric('coords', ('integer', 'floating'), shape=(-1, 2)) _numeric('h', 'integer', range_='[1;inf)') _numeric('w', 'integer', range_='[1;inf)') _numeric('coords[:, 0]', ('integer', 'floating'), range_='[0;{}]'.format(w), shape=(-1, ), var=coords[:, 0]) _numeric('coords[:, 1]', ('integer', 'floating'), range_='[0;{}]'.format(h), shape=(-1, ), var=coords[:, 1])
def validate_input(): _levels('shape', (_generic(None, 'explicit collection', len_=2), _numeric(None, 'integer', range_='[1;inf)'))) if overcomplete_shape is not None: _generic('overcomplete_shape', 'explicit collection', len_=2), _numeric(('overcomplete_shape', 0), 'integer', range_='[{};inf)'.format(shape[0])) _numeric(('overcomplete_shape', 1), 'integer', range_='[{};inf)'.format(shape[1]))
def validate_input(): _generic('attrs', 'mapping', has_keys=('xPixels', 'yPixels')) _levels('buffers', (_generic( None, 'explicit collection'), _generic(None, Buffer))) attrs = self.attrs for i, buffer_ in enumerate(buffers): if buffer_.attrs['bufferLabel'][:9] != 'Thumbnail': _numeric('buffers[{}].data'.format(i), ('integer', 'floating'), shape=(attrs['yPixels'], attrs['xPixels']), var=buffer_.data)
def validate_input(): _numeric('l', 'floating', range_='[{};inf)'.format(_min_l)) _numeric('w', 'floating', range_='[{};inf)'.format(_min_w)) if l != w: msg = ('The value of >>h<<, {!r}, must equal the value of >>w<<, ' '{!r}, for an archimedian spiral to make sense.') raise ValueError(msg.format(l, w)) _numeric('speed', 'floating', range_='[{};inf)'.format(_min_speed)) _numeric('sample_rate', 'floating', range_='[{};inf)'.format(_min_sample_rate)) _numeric('time', 'floating', range_='[{};inf)'.format(_min_time))
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') _numeric('scan_length', 'floating', range_='[{};inf)'.format(_min_scan_length)) _numeric('num_points', 'integer', range_='[{};inf)'.format(_min_num_points))
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') if h != w: msg = ('The value of >>h<<, {!r}, must equal the value of >>w<<, ' '{!r}, for an archimedian spiral to make sense.') raise ValueError(msg.format(h, w)) _numeric('scan_length', 'floating', range_='[{};inf)'.format(_min_scan_length)) _numeric('num_points', 'integer', range_='[{};inf)'.format(_min_num_points)) _numeric('rect_area', 'boolean')
def validate_output(): # complex128 is two float64 (real and imaginary part) each taking 8*8 # bits. Thus, in total 2*8*8=128 bits. However, we only consider it to # be "64 bit precision" since that is what each part is. bits_pr_nbytes = 4 if np.iscomplexobj(convert(0)) else 8 _numeric('alpha', ('integer', 'floating', 'complex'), shape=(A.shape[1], 1), precision=convert(0).nbytes * bits_pr_nbytes) _generic('history', 'mapping', keys_in=('alpha_bar', 'alpha_tilde', 'MSE', 'input_channel_parameters', 'output_channel_parameters', 'stop_criterion', 'stop_criterion_value', 'stop_iteration', 'stop_reason'))
def validate_channel_parameters(): _generic(('var', 'input_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'tau'), ('integer', 'floating'), range_='[0;1]') _generic(('var', 'input_channel_parameters', 'phi_channel'), 'class', superclass=ValidatedBasicMMSEInputChannel) _generic( ('var', 'input_channel_parameters', 'phi_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'use_em'), 'boolean') _numeric(('var', 'n'), 'integer', range_='[0;inf)') _numeric(('var', 'input_channel_parameters', 'weights'), 'floating', range_='[0;1]', shape=(var['n'], 1), ignore_none=True) _generic(('var', 'convert'), type) if 'adjust_tau_method' in var['input_channel_parameters']: _generic( ('var', 'input_channel_parameters', 'adjust_tau_method'), 'string', value_in=('truncate', 'reweight'))
def validate_input(): _numeric('delta', 'floating', range_='[0;1]', shape=(-1,)) _numeric('rho', 'floating', range_='[0;1]', shape=(-1,)) _numeric('dist', 'floating', range_='[0;inf]', shape=(delta.shape[0], rho.shape[0], -1)) _numeric('plot_l1', 'boolean') _generic('output_path', 'string', ignore_none=True)
def validate_input(): _numeric('F', ('integer', 'floating', 'complex'), shape=(-1, -1)) _numeric('D', ('integer', 'floating', 'complex'), shape=(-1, F.shape[0]), ignore_none=True) _numeric('l_ran_arr', 'integer', shape=(F.shape[1], ), range_='[-1;1]', ignore_none=True) _numeric('g_ran_arr', 'integer', shape=(F.shape[1], ), range_='[0;{})'.format(F.shape[1]), ignore_none=True) if (l_ran_arr is not None and np.count_nonzero(l_ran_arr) != F.shape[1]): raise ValueError( 'The "l_ran_arr" array must only contain values ' + 'in {{-1, 1}}') if (g_ran_arr is not None and len(np.unique(g_ran_arr)) != F.shape[1]): raise ValueError( 'The "r_ran_arr" array must contain exactly one copy ' + 'of each of the values in range({})'.format(F.shape[1]))
def validate_input(): _levels('coefficients', (_generic(None, 'explicit collection'), _numeric(None, ('integer', 'floating', 'complex'), shape=(-1, -1)))) _levels('reconstructions', (_generic(None, 'explicit collection', len_=len(coefficients)), _numeric(None, ('integer', 'floating', 'complex'), shape=(-1, -1)))) _generic('transform', 'string', value_in=_utils.get_transform_names()) _levels('fractions', (_generic(None, 'explicit collection', len_=len(coefficients)), _numeric(None, 'floating', range_='[0;1]'))) _generic('output_path', 'string', ignore_none=True) _generic('fig_ext', 'string')
def validate_input(): _numeric('delta', 'floating', range_='[0;1]', shape=(-1, )) _numeric('rho', 'floating', range_='[0;1]', shape=(-1, )) _numeric('dist', 'floating', range_='[0;inf]', shape=(delta.shape[0], rho.shape[0], -1)) _numeric('plot_l1', 'boolean') _generic('output_path', 'string', ignore_none=True)
def validate_channel_parameters(): _generic(('var', 'input_channel_parameters'), 'mapping') _numeric(('var', 'input_channel_parameters', 'tau'), ('integer', 'floating'), range_='[0;1]') _numeric(('var', 'input_channel_parameters', 'theta_bar'), ('integer', 'floating')) _numeric(('var', 'input_channel_parameters', 'theta_tilde'), ('integer', 'floating'), range_='[0;inf)') _numeric(('var', 'input_channel_parameters', 'use_em'), ('boolean')) if var['input_channel_parameters']['use_em']: _numeric(('var', 'input_channel_parameters', 'em_damping'), ('integer', 'floating'), range_='[0;1)')
def _validate_transform_bwd(x, mn_tuple, overcomplete_mn_tuple=None): """ Validate a 2D transform. Parameters ---------- x : ndarray The m*n x 1 vector representing the associated column stacked matrix. mn_tuple : tuple of int `(m, n)` - `m` number of rows in the associated matrix, `n` number of columns in the associated matrix. overcomplete_mn_tuple : tuple of int, optional `(mo, no)` - `mo` number of rows in the associated matrix, `no` number of columns in the associated matrix. """ _levels('mn_tuple', (_generic(None, 'explicit collection', len_=2), _numeric(None, 'integer', range_='[1;inf)'))) m, n = mn_tuple if overcomplete_mn_tuple is None: shape = (m * n, 1) else: _generic('overcomplete_mn_tuple', 'explicit collection', len_=2) _numeric(('overcomplete_mn_tuple', 0), 'integer', range_='[{};inf)'.format(m)) _numeric(('overcomplete_mn_tuple', 1), 'integer', range_='[{};inf)'.format(n)) shape = (overcomplete_mn_tuple[0] * overcomplete_mn_tuple[1], 1) _numeric('x', ('integer', 'floating', 'complex'), shape=shape)
def validate_input(): _generic('func', 'function') _generic('namespace', 'mapping') _levels('args_list', (_generic(None, 'collection', ignore_none=True), _generic(None, 'explicit collection'))) _levels('kwargs_list', (_generic(None, 'collection', ignore_none=True), _generic(None, 'mapping'))) if args_list is None and kwargs_list is None: msg = ('The value of >>args_list<<, {!r}, and/or the value of ' '>>kwargs_list<<, {!r}, must be different from {!r}.') raise ValueError(msg.format(args_list, kwargs_list, None)) elif args_list is not None and kwargs_list is not None: if len(args_list) != len(kwargs_list): msg = ('The value of >>len(args_list)<<, {!r}, must be equal ' 'to the value of >>len(kwargs_list)<<, {!r}.') raise ValueError(msg.format(len(args_list), len(kwargs_list))) _numeric('maxtasks', 'integer', range_='(0;inf)', ignore_none=True)
def validate_input(): _generic('algorithm', 'function') _generic('path', 'string') _generic('label', 'string') # regular expression matching invalid characters match = re.search(r'[^a-zA-Z0-9 ,.\-_/]', label) if match is not None: msg = 'The value of >>label<<, {!r}, may not contain {!r}.' raise RuntimeError(msg.format(label, match.group())) # regular expression matching labels without empty path components match = re.search(r'^([^/]+/)*[^/]+$', label) if match is None: msg = "The value of >>label<<, {!r}, may not contain '' folders." raise RuntimeError(msg.format(label)) _numeric('overwrite', 'boolean')
def validate_input(): _numeric('h', 'integer', range_='[2;inf)') _numeric('w', 'integer', range_='[2;inf)') if h != w: msg = ('The value of >>h<<, {!r}, must equal the value of >>w<<, ' '{!r}, for an archimedian spiral to make sense.') raise ValueError(msg.format(h, w)) _numeric('scan_length', 'floating', range_='[{};inf)'.format(_min_scan_length)) _numeric('num_points', 'integer', range_='[{};inf)'.format(_min_num_points))
def _validate_transform(x, m, n): """ Validatate a 2D transform. """ _numeric('m', 'integer', range_='[1;inf)') _numeric('n', 'integer', range_='[1;inf)') _numeric('x', ('integer', 'floating', 'complex'), shape=(m * n, 1))
def validate_input(): _levels('hdrs', (_generic(None, 'explicit collection'), _generic(None, 'explicit collection', len_=2))) for i in range(len(hdrs)): _generic(('hdrs', i, 0), 'string') _numeric('width', 'integer', range_='[1;inf)') _numeric('height', 'integer', range_='[1;inf)') _numeric('data', ('integer', 'floating'), shape=(height * width,))
def validate_input(): _levels('curves', (_generic(None, 'collection'), _generic(None, 'mapping', has_keys=('delta', 'rho', 'label')))) for i, curve in enumerate(curves): _numeric(('curves', i, 'delta'), 'floating', range_='[0;1]', shape=(-1,)) _numeric(('curves', i, 'rho'), 'floating', range_='[0;1]', shape=(curve['delta'].shape[0],)) _generic(('curves', i, 'label'), 'string') _numeric('plot_l1', 'boolean') _generic('output_path', 'string', ignore_none=True)
def validate_input(): _numeric('x', ('boolean', 'integer', 'floating', 'complex'), shape=(-1, -1))
def validate_input(): _numeric('c', 'complex') _numeric('max_iterations', 'integer', range_='(0;inf)') _numeric('threshold', 'integer', range_='(0;inf)')
def validate_input(): _numeric('re_min', 'floating') _numeric('re_max', 'floating', range_='({};inf)'.format(re_min)) _numeric('im_min', 'floating') _numeric('im_max', 'floating', range_='({};inf)'.format(im_min)) _numeric('num_points', 'integer', range_='[1;inf)')
def validate_input(): _levels('shape', (_generic(None, 'explicit collection', len_=2), _numeric(None, 'integer', range_='[1;inf)')))
Module providing configuration options for the multiprocessing subpackage. See also -------- magni.utils.config.Configger : The Configger class used Notes ----- This module instantiates the `Configger` class provided by `magni.utils.config`. The configuration options are the following: silence_exceptions : bool A flag indicating if exceptions should be silenced (the default is False, which implies that exceptions are raised). workers : int The number of workers to use for multiprocessing (the default is 0, which implies no multiprocessing). """ from __future__ import division from magni.utils.config import Configger as _Configger from magni.utils.validation import validate_numeric as _numeric configger = _Configger( {'silence_exceptions': False, 'workers': 0}, {'silence_exceptions': _numeric(None, 'boolean'), 'workers': _numeric(None, 'integer', range_='[0;inf)')})
""" from __future__ import division import numpy as np from magni.cs.reconstruction._config import Configger as _Configger from magni.utils.validation import validate_generic as _generic from magni.utils.validation import validate_numeric as _numeric configger = _Configger( {'iterations': 300, 'kappa_fixed': 0.65, 'precision_float': np.float64, 'threshold': 'far', 'threshold_fixed': 0.1, 'tolerance': 1e-3}, {'iterations': _numeric(None, 'integer', range_='[1;inf)'), 'kappa_fixed': _numeric(None, 'floating', range_='[0;1]'), 'precision_float': _generic(None, type, value_in=( np.float, getattr(np, 'float16', np.float_), getattr(np, 'float32', np.float_), getattr(np, 'float64', np.float_), getattr(np, 'float128', np.float_))), 'threshold': _generic(None, 'string', value_in=('far', 'oracle')), 'threshold_fixed': _numeric(None, 'floating', range_='[0;1]'), 'tolerance': _numeric(None, 'floating', range_='[0;inf]')})
def validate_input(): _numeric('x_org', ('integer', 'floating'), shape=None) _numeric('x_recons', ('integer', 'floating'), shape=x_org.shape) _numeric('peak', ('integer', 'floating'), range_='(0;inf)')
def validate_input(): _levels('brews', (_generic(None, 'mapping'), _generic(None, 'explicit collection'), _generic(None, 'explicit collection', len_=3), _numeric(None, 'integer', range_='[0;255]')))
def validate_input(): _numeric('m', 'integer', range_='[1;inf)') _numeric('n', 'integer', range_='[1;inf)') _numeric('x', ('boolean', 'integer', 'floating', 'complex'), shape=(m * n, 1))
def validate_input(): _numeric('x_mod', ('integer', 'floating', 'complex'), shape=(-1, -1)) _numeric('x_org', ('integer', 'floating', 'complex'), shape=x_mod.shape)
def validate_input(): _numeric('x', ('integer', 'floating', 'complex'), shape=(-1, 1)) _numeric('Phi', ('integer', 'floating', 'complex'), shape=(-1, x.shape[0])) _numeric('Psi', ('integer', 'floating', 'complex'), shape=(x.shape[0], -1))
def validate_input(): _numeric('value', ('integer', 'floating', 'complex'), shape=(self._Phi.shape[0], 1))
def validate_input(): _numeric('y', ('integer', 'floating', 'complex'), shape=(-1, 1)) _numeric('Phi', ('integer', 'floating', 'complex'), shape=(y.shape[0], -1)) _numeric('Psi', ('integer', 'floating', 'complex'), shape=(Phi.shape[1], -1))
def validate_input(): _numeric('x_org', ('integer', 'floating'), shape=None) _numeric('x_recons', ('integer', 'floating'), shape=x_org.shape)
def validate_input(): _numeric('img', 'floating', shape=(-1, -1)) _numeric('max_val', ('integer', 'floating'), range_='(0;inf)')