annotate util/SMALL_solve.m @ 51:217a33ac374e

(none)
author idamnjanovic
date Mon, 14 Mar 2011 16:52:27 +0000
parents d80c103d9876
children fd1c32cda22c
rev   line source
idamnjanovic@8 1 function solver = SMALL_solve(Problem, solver)
idamnjanovic@8 2 %%% SMALL sparse solver
idamnjanovic@24 3 %
idamnjanovic@24 4 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@24 5 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@24 6 %
idamnjanovic@24 7 % This program is free software; you can redistribute it and/or
idamnjanovic@24 8 % modify it under the terms of the GNU General Public License as
idamnjanovic@24 9 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@24 10 % License, or (at your option) any later version. See the file
idamnjanovic@24 11 % COPYING included with this distribution for more information.
idamnjanovic@24 12 %
idamnjanovic@8 13 % Function gets as input SMALL structure that contains SPARCO problem to
idamnjanovic@8 14 % be solved, name of the toolbox and solver, and parameters file for
idamnjanovic@8 15 % particular solver.
idamnjanovic@8 16 %
idamnjanovic@8 17 % Outputs are solution, reconstructed signal and time spent
idamnjanovic@8 18 %%
idamnjanovic@8 19
idamnjanovic@8 20 if isa(Problem.A,'float')
idamnjanovic@8 21 A = Problem.A;
idamnjanovic@8 22 SparseLab_A=Problem.A;
idamnjanovic@8 23 m = size(Problem.A,1); % m is the no. of rows.
idamnjanovic@8 24 n = size(Problem.A,2); % n is the no. of columns.
idamnjanovic@8 25 else
idamnjanovic@8 26 A = @(x) Problem.A(x,1); % The operator
idamnjanovic@8 27 AT = @(y) Problem.A(y,2); % and its transpose.
idamnjanovic@8 28 SparseLab_A =@(mode, m, n, x, I, dim) SL_A(Problem.A, mode, m, n, x, I, dim);
idamnjanovic@8 29 m = Problem.sizeA(1); % m is the no. of rows.
idamnjanovic@8 30 n = Problem.sizeA(2); % n is the no. of columns.
idamnjanovic@8 31
idamnjanovic@1 32 end
idamnjanovic@37 33 % if signal that needs to be represented is different then training set for
idamnjanovic@37 34 % dictionary learning it should be stored in Problem.b1 matix
idamnjanovic@37 35 if isfield(Problem, 'b1')
idamnjanovic@37 36 b = Problem.b1;
idamnjanovic@37 37 else
idamnjanovic@37 38 b = Problem.b; % The right-hand-side vector.
idamnjanovic@37 39 end
idamnjanovic@8 40 %%
idamnjanovic@8 41 fprintf('\nStarting solver %s... \n', solver.name);
idamnjanovic@8 42 start=cputime;
idamnjanovic@37 43 tStart=tic;
idamnjanovic@8 44 if strcmpi(solver.toolbox,'sparselab')
idamnjanovic@8 45 y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
idamnjanovic@8 46 elseif strcmpi(solver.toolbox,'sparsify')
idamnjanovic@8 47 y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
idamnjanovic@8 48 elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
idamnjanovic@8 49 y = eval([solver.name,'(b, A,',solver.param,');']);
idamnjanovic@8 50 elseif (strcmpi(solver.toolbox,'SPAMS'))
idamnjanovic@8 51 y = eval([solver.name,'(b, A, solver.param);']);
idamnjanovic@8 52 elseif (strcmpi(solver.toolbox,'SMALL'))
idamnjanovic@8 53 if isa(Problem.A,'float')
idamnjanovic@8 54 y = eval([solver.name,'(A, b, n,',solver.param,');']);
idamnjanovic@8 55 else
idamnjanovic@8 56 y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
idamnjanovic@8 57 end
idamnjanovic@37 58 elseif (strcmpi(solver.toolbox, 'ompbox'))
idamnjanovic@37 59 G=A'*A;
idamnjanovic@37 60 epsilon=solver.param.epsilon;
idamnjanovic@37 61 maxatoms=solver.param.maxatoms;
idamnjanovic@37 62 y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
idamnjanovic@37 63 elseif (strcmpi(solver.toolbox, 'ompsbox'))
idamnjanovic@37 64 basedict = Problem.basedict;
idamnjanovic@37 65 if issparse(Problem.A)
idamnjanovic@37 66 A = Problem.A;
idamnjanovic@37 67 else
idamnjanovic@37 68 A = sparse(Problem.A);
idamnjanovic@37 69 end
idamnjanovic@37 70 G = dicttsep(basedict,A,dictsep(basedict,A,speye(size(A,2))));
idamnjanovic@37 71 epsilon=solver.param.epsilon;
idamnjanovic@37 72 maxatoms=solver.param.maxatoms;
idamnjanovic@37 73 y = eval([solver.name,'(basedict, A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
idamnjanovic@37 74 Problem.sparse=1;
idamnjanovic@8 75 % To introduce new sparse representation algorithm put the files in
idamnjanovic@8 76 % your Matlab path. Next, unique name <TolboxID> for your toolbox and
idamnjanovic@8 77 % prefferd API <Preffered_API> needs to be defined.
idamnjanovic@8 78 %
idamnjanovic@8 79 % elseif strcmpi(solver.toolbox,'<ToolboxID>')
idamnjanovic@8 80 %
idamnjanovic@8 81 % % - Evaluate the function (solver.name - defined in the main) with
idamnjanovic@8 82 % % parameters given above
idamnjanovic@8 83 %
idamnjanovic@8 84 % y = eval([solver.name,'(<Preffered_API>);']);
idamnjanovic@8 85
idamnjanovic@8 86 else
idamnjanovic@8 87 printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
idamnjanovic@8 88 return
idamnjanovic@8 89 end
idamnjanovic@8 90
idamnjanovic@8 91 %%
idamnjanovic@8 92 % Sparse representation time
idamnjanovic@37 93 tElapsed=toc(tStart);
idamnjanovic@8 94 solver.time = cputime - start;
idamnjanovic@8 95 fprintf('Solver %s finished task in %2f seconds. \n', solver.name, solver.time);
idamnjanovic@37 96 fprintf('Solver %s finished task in %2f seconds. \n', solver.name, tElapsed);
idamnjanovic@37 97 solver.time=tElapsed;
idamnjanovic@8 98 % geting around out of memory problem when converting big matrix from
idamnjanovic@8 99 % sparse to full...
idamnjanovic@8 100
idamnjanovic@18 101 if isfield(Problem, 'sparse')&&(Problem.sparse==1)
idamnjanovic@8 102 solver.solution = y;
idamnjanovic@8 103 else
idamnjanovic@8 104 solver.solution = full(y);
idamnjanovic@8 105 end
idamnjanovic@37 106 if isfield(Problem,'reconstruct')
idamnjanovic@8 107 % Reconstruct the signal from the solution
idamnjanovic@8 108 solver.reconstructed = Problem.reconstruct(solver.solution);
idamnjanovic@8 109 end
idamnjanovic@37 110 end