idamnjanovic@8: function solver = SMALL_solve(Problem, solver) ivan@161: %% SMALL sparse solver caller function idamnjanovic@24: % ivan@85: % Function gets as input SMALL structure that contains SPARCO problem to ivan@85: % be solved, name of the toolbox and solver, and parameters file for ivan@85: % particular solver. ivan@85: % ivan@85: % Outputs are solution, reconstructed signal and time spent ivan@85: idamnjanovic@24: % Centre for Digital Music, Queen Mary, University of London. idamnjanovic@24: % This file copyright 2009 Ivan Damnjanovic. idamnjanovic@24: % idamnjanovic@24: % This program is free software; you can redistribute it and/or idamnjanovic@24: % modify it under the terms of the GNU General Public License as idamnjanovic@24: % published by the Free Software Foundation; either version 2 of the idamnjanovic@24: % License, or (at your option) any later version. See the file idamnjanovic@24: % COPYING included with this distribution for more information. idamnjanovic@24: % idamnjanovic@8: %% idamnjanovic@8: idamnjanovic@8: if isa(Problem.A,'float') idamnjanovic@8: A = Problem.A; idamnjanovic@8: SparseLab_A=Problem.A; idamnjanovic@8: m = size(Problem.A,1); % m is the no. of rows. idamnjanovic@8: n = size(Problem.A,2); % n is the no. of columns. idamnjanovic@8: else idamnjanovic@8: A = @(x) Problem.A(x,1); % The operator idamnjanovic@8: AT = @(y) Problem.A(y,2); % and its transpose. idamnjanovic@8: SparseLab_A =@(mode, m, n, x, I, dim) SL_A(Problem.A, mode, m, n, x, I, dim); idamnjanovic@8: m = Problem.sizeA(1); % m is the no. of rows. idamnjanovic@8: n = Problem.sizeA(2); % n is the no. of columns. idamnjanovic@8: idamnjanovic@1: end idamnjanovic@37: % if signal that needs to be represented is different then training set for idamnjanovic@37: % dictionary learning it should be stored in Problem.b1 matix idamnjanovic@37: if isfield(Problem, 'b1') idamnjanovic@37: b = Problem.b1; idamnjanovic@37: else idamnjanovic@37: b = Problem.b; % The right-hand-side vector. idamnjanovic@37: end idamnjanovic@8: %% ivan@140: if (solver.profile) ivan@140: fprintf('\nStarting solver %s... \n', solver.name); ivan@140: end ivan@140: idamnjanovic@8: start=cputime; idamnjanovic@37: tStart=tic; idamnjanovic@8: if strcmpi(solver.toolbox,'sparselab') idamnjanovic@8: y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']); idamnjanovic@8: elseif strcmpi(solver.toolbox,'sparsify') ivan@154: if isa(Problem.A,'float') ivan@154: y = eval([solver.name,'(b, A, n,',solver.param,');']); ivan@154: else ivan@154: y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']); ivan@154: end idamnjanovic@8: elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr')) idamnjanovic@8: y = eval([solver.name,'(b, A,',solver.param,');']); idamnjanovic@8: elseif (strcmpi(solver.toolbox,'SPAMS')) idamnjanovic@8: y = eval([solver.name,'(b, A, solver.param);']); idamnjanovic@8: elseif (strcmpi(solver.toolbox,'SMALL')) idamnjanovic@8: if isa(Problem.A,'float') idamnjanovic@8: y = eval([solver.name,'(A, b, n,',solver.param,');']); idamnjanovic@8: else idamnjanovic@8: y = eval([solver.name,'(A, b, n,',solver.param,',AT);']); idamnjanovic@8: end idamnjanovic@37: elseif (strcmpi(solver.toolbox, 'ompbox')) idamnjanovic@37: G=A'*A; idamnjanovic@37: epsilon=solver.param.epsilon; idamnjanovic@37: maxatoms=solver.param.maxatoms; idamnjanovic@37: y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']); idamnjanovic@37: elseif (strcmpi(solver.toolbox, 'ompsbox')) idamnjanovic@37: basedict = Problem.basedict; ivan@154: if issparse(Problem.A) idamnjanovic@37: A = Problem.A; ivan@154: else idamnjanovic@37: A = sparse(Problem.A); ivan@154: end idamnjanovic@37: G = dicttsep(basedict,A,dictsep(basedict,A,speye(size(A,2)))); idamnjanovic@37: epsilon=solver.param.epsilon; idamnjanovic@37: maxatoms=solver.param.maxatoms; idamnjanovic@37: y = eval([solver.name,'(basedict, A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']); idamnjanovic@37: Problem.sparse=1; ivan@154: elseif (strcmpi(solver.toolbox, 'ALPS')) ivan@154: if ~isa(Problem.A,'float') ivan@154: % ALPS does not accept implicit dictionary definition ivan@154: A = opToMatrix(Problem.A, 1); ivan@154: end ivan@154: [y, numiter, time, y_path] = wrapper_ALPS_toolbox(b, A, solver.param); ivan@155: elseif (strcmpi(solver.toolbox, 'MMbox')) ivan@155: if ~isa(Problem.A,'float') ivan@161: % MMbox does not accept implicit dictionary definition ivan@155: A = opToMatrix(Problem.A, 1); ivan@155: end ivan@154: ivan@155: [y, cost] = wrapper_mm_solver(b, A, solver.param); ivan@155: ivan@155: ivan@154: ivan@154: % To introduce new sparse representation algorithm put the files in ivan@154: % your Matlab path. Next, unique name for your toolbox and ivan@154: % prefferd API needs to be defined. ivan@154: % ivan@154: % elseif strcmpi(solver.toolbox,'') ivan@154: % ivan@154: % % - Evaluate the function (solver.name - defined in the main) with ivan@154: % % parameters given above ivan@154: % ivan@154: % y = eval([solver.name,'();']); ivan@154: idamnjanovic@8: else idamnjanovic@8: printf('\nToolbox has not been registered. Please change SMALL_solver file.\n'); idamnjanovic@8: return idamnjanovic@8: end idamnjanovic@8: idamnjanovic@8: %% idamnjanovic@8: % Sparse representation time idamnjanovic@37: tElapsed=toc(tStart); idamnjanovic@8: solver.time = cputime - start; ivan@140: if (solver.profile) ivan@140: fprintf('Solver %s finished task in %2f seconds (cpu time). \n', solver.name, solver.time); ivan@140: fprintf('Solver %s finished task in %2f seconds (tic-toc time). \n', solver.name, tElapsed); ivan@140: end idamnjanovic@37: solver.time=tElapsed; idamnjanovic@8: % geting around out of memory problem when converting big matrix from idamnjanovic@8: % sparse to full... idamnjanovic@8: idamnjanovic@18: if isfield(Problem, 'sparse')&&(Problem.sparse==1) idamnjanovic@8: solver.solution = y; idamnjanovic@8: else idamnjanovic@8: solver.solution = full(y); idamnjanovic@8: end idamnjanovic@37: if isfield(Problem,'reconstruct') ivan@140: % Reconstruct the signal from the solution ivan@140: solver.reconstructed = Problem.reconstruct(solver.solution); idamnjanovic@8: end idamnjanovic@37: end