annotate util/SMALL_solve.m @ 156:a4d0977d4595 danieleb

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