def feature_sign_search(dictionary, signals, sparsity, max_iter=1000, solution=None):
 dictionary = np.asarray(dictionary)
 _feature_sign_checkargs(dictionary, signals, sparsity, max_iter, solution)
 signals_ndim = signals.ndim
 signals = np.atleast_2d(signals)
 if (solution is None):
  solution = np.zeros((signals.shape[0], dictionary.shape[1]), dtype=signals.dtype)
  orig_sol = None
 else:
  orig_sol = solution
  solution = np.atleast_2d(solution)
 for (row, (signal, sol)) in enumerate(izip(signals, solution)):
  (_, iters) = _feature_sign_search_single(dictionary, signal, sparsity, max_iter, sol)
  if (iters >= max_iter):
   log.warning(('maximum number of iterations reached when optimizing code for training case %d; solution may not be optimal' % iters))
 if ((orig_sol is not None) and (orig_sol.ndim == 1)):
  solution = orig_sol
 elif ((orig_sol is None) and (signals_ndim == 1)):
  solution = solution.squeeze()
 return solution

def feature_sign_search ( dictionary , signals , sparsity , max_iter = 1000 , solution = None ) : dictionary = np . asarray ( dictionary ) _feature_sign_checkargs ( dictionary , signals , sparsity , max_iter , solution ) signals_ndim = signals . ndim signals = np . atleast_2d ( signals ) if ( solution is None ) : solution = np . zeros ( ( signals . shape [ 0 ] , dictionary . shape [ 1 ] ) , dtype = signals . dtype ) orig_sol = None else : orig_sol = solution solution = np . atleast_2d ( solution ) for ( row , ( signal , sol ) ) in enumerate ( izip ( signals , solution ) ) : ( _ , iters ) = _feature_sign_search_single ( dictionary , signal , sparsity , max_iter , sol ) if ( iters >= max_iter ) : log . warning ( ( 'maximum number of iterations reached when optimizing code for training case %d; solution may not be optimal' % iters ) ) if ( ( orig_sol is not None ) and ( orig_sol . ndim == 1 ) ) : solution = orig_sol elif ( ( orig_sol is None ) and ( signals_ndim == 1 ) ) : solution = solution . squeeze ( ) return solution
solve l1-penalized quadratic minimization problems with feature-sign search .