annotate util/SMALL_solve.m @ 159:23763c5fbda5 danieleb

Merge
author Daniele Barchiesi <daniele.barchiesi@eecs.qmul.ac.uk>
date Wed, 31 Aug 2011 10:43:32 +0100
parents a4d0977d4595 b14209313ba4
children 4ea4badb2266
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.
idamnjanovic@24 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;
idamnjanovic@8 48 if strcmpi(solver.toolbox,'sparselab')
idamnjanovic@8 49 y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
idamnjanovic@8 50 elseif strcmpi(solver.toolbox,'sparsify')
ivan@154 51 if isa(Problem.A,'float')
ivan@154 52 y = eval([solver.name,'(b, A, n,',solver.param,');']);
ivan@154 53 else
ivan@154 54 y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
ivan@154 55 end
idamnjanovic@8 56 elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
idamnjanovic@8 57 y = eval([solver.name,'(b, A,',solver.param,');']);
idamnjanovic@8 58 elseif (strcmpi(solver.toolbox,'SPAMS'))
idamnjanovic@8 59 y = eval([solver.name,'(b, A, solver.param);']);
idamnjanovic@8 60 elseif (strcmpi(solver.toolbox,'SMALL'))
idamnjanovic@8 61 if isa(Problem.A,'float')
idamnjanovic@8 62 y = eval([solver.name,'(A, b, n,',solver.param,');']);
idamnjanovic@8 63 else
idamnjanovic@8 64 y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
idamnjanovic@8 65 end
idamnjanovic@37 66 elseif (strcmpi(solver.toolbox, 'ompbox'))
idamnjanovic@37 67 G=A'*A;
idamnjanovic@37 68 epsilon=solver.param.epsilon;
idamnjanovic@37 69 maxatoms=solver.param.maxatoms;
idamnjanovic@37 70 y = eval([solver.name,'(A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
idamnjanovic@37 71 elseif (strcmpi(solver.toolbox, 'ompsbox'))
idamnjanovic@37 72 basedict = Problem.basedict;
ivan@154 73 if issparse(Problem.A)
idamnjanovic@37 74 A = Problem.A;
ivan@154 75 else
idamnjanovic@37 76 A = sparse(Problem.A);
ivan@154 77 end
idamnjanovic@37 78 G = dicttsep(basedict,A,dictsep(basedict,A,speye(size(A,2))));
idamnjanovic@37 79 epsilon=solver.param.epsilon;
idamnjanovic@37 80 maxatoms=solver.param.maxatoms;
idamnjanovic@37 81 y = eval([solver.name,'(basedict, A, b, G,epsilon,''maxatoms'',maxatoms,''checkdict'',''off'');']);
idamnjanovic@37 82 Problem.sparse=1;
ivan@154 83 elseif (strcmpi(solver.toolbox, 'ALPS'))
ivan@154 84 if ~isa(Problem.A,'float')
ivan@154 85 % ALPS does not accept implicit dictionary definition
ivan@154 86 A = opToMatrix(Problem.A, 1);
ivan@154 87 end
ivan@154 88 [y, numiter, time, y_path] = wrapper_ALPS_toolbox(b, A, solver.param);
ivan@155 89 elseif (strcmpi(solver.toolbox, 'MMbox'))
ivan@155 90 if ~isa(Problem.A,'float')
ivan@155 91 % ALPS does not accept implicit dictionary definition
ivan@155 92 A = opToMatrix(Problem.A, 1);
ivan@155 93 end
ivan@154 94
ivan@155 95 [y, cost] = wrapper_mm_solver(b, A, solver.param);
ivan@155 96
ivan@155 97
ivan@154 98
ivan@154 99 % To introduce new sparse representation algorithm put the files in
ivan@154 100 % your Matlab path. Next, unique name <TolboxID> for your toolbox and
ivan@154 101 % prefferd API <Preffered_API> needs to be defined.
ivan@154 102 %
ivan@154 103 % elseif strcmpi(solver.toolbox,'<ToolboxID>')
ivan@154 104 %
ivan@154 105 % % - Evaluate the function (solver.name - defined in the main) with
ivan@154 106 % % parameters given above
ivan@154 107 %
ivan@154 108 % y = eval([solver.name,'(<Preffered_API>);']);
ivan@154 109
idamnjanovic@8 110 else
idamnjanovic@8 111 printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
idamnjanovic@8 112 return
idamnjanovic@8 113 end
idamnjanovic@8 114
idamnjanovic@8 115 %%
idamnjanovic@8 116 % Sparse representation time
idamnjanovic@37 117 tElapsed=toc(tStart);
idamnjanovic@8 118 solver.time = cputime - start;
ivan@140 119 if (solver.profile)
ivan@140 120 fprintf('Solver %s finished task in %2f seconds (cpu time). \n', solver.name, solver.time);
ivan@140 121 fprintf('Solver %s finished task in %2f seconds (tic-toc time). \n', solver.name, tElapsed);
ivan@140 122 end
idamnjanovic@37 123 solver.time=tElapsed;
idamnjanovic@8 124 % geting around out of memory problem when converting big matrix from
idamnjanovic@8 125 % sparse to full...
idamnjanovic@8 126
idamnjanovic@18 127 if isfield(Problem, 'sparse')&&(Problem.sparse==1)
idamnjanovic@8 128 solver.solution = y;
idamnjanovic@8 129 else
idamnjanovic@8 130 solver.solution = full(y);
idamnjanovic@8 131 end
idamnjanovic@37 132 if isfield(Problem,'reconstruct')
ivan@140 133 % Reconstruct the signal from the solution
ivan@140 134 solver.reconstructed = Problem.reconstruct(solver.solution);
idamnjanovic@8 135 end
idamnjanovic@37 136 end