annotate util/SMALL_solve.m @ 8:33850553b702

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:56:54 +0000
parents 7750624e0c73
children bcc748594b61
rev   line source
idamnjanovic@8 1 function solver = SMALL_solve(Problem, solver)
idamnjanovic@8 2 %%% SMALL sparse solver
idamnjanovic@8 3 % Ivan Damnjanovic 2009
idamnjanovic@8 4 % Function gets as input SMALL structure that contains SPARCO problem to
idamnjanovic@8 5 % be solved, name of the toolbox and solver, and parameters file for
idamnjanovic@8 6 % particular solver.
idamnjanovic@8 7 %
idamnjanovic@8 8 % Outputs are solution, reconstructed signal and time spent
idamnjanovic@8 9 %%
idamnjanovic@8 10
idamnjanovic@8 11 if isa(Problem.A,'float')
idamnjanovic@8 12 A = Problem.A;
idamnjanovic@8 13 SparseLab_A=Problem.A;
idamnjanovic@8 14 m = size(Problem.A,1); % m is the no. of rows.
idamnjanovic@8 15 n = size(Problem.A,2); % n is the no. of columns.
idamnjanovic@8 16 else
idamnjanovic@8 17 A = @(x) Problem.A(x,1); % The operator
idamnjanovic@8 18 AT = @(y) Problem.A(y,2); % and its transpose.
idamnjanovic@8 19 SparseLab_A =@(mode, m, n, x, I, dim) SL_A(Problem.A, mode, m, n, x, I, dim);
idamnjanovic@8 20 m = Problem.sizeA(1); % m is the no. of rows.
idamnjanovic@8 21 n = Problem.sizeA(2); % n is the no. of columns.
idamnjanovic@8 22
idamnjanovic@1 23 end
idamnjanovic@8 24 b = Problem.b; % The right-hand-side vector.
idamnjanovic@8 25 %%
idamnjanovic@8 26 fprintf('\nStarting solver %s... \n', solver.name);
idamnjanovic@8 27 start=cputime;
idamnjanovic@8 28
idamnjanovic@8 29 if strcmpi(solver.toolbox,'sparselab')
idamnjanovic@8 30 y = eval([solver.name,'(SparseLab_A, b, n,',solver.param,');']);
idamnjanovic@8 31 elseif strcmpi(solver.toolbox,'sparsify')
idamnjanovic@8 32 y = eval([solver.name,'(b, A, n, ''P_trans'', AT,',solver.param,');']);
idamnjanovic@8 33 elseif (strcmpi(solver.toolbox,'spgl1')||strcmpi(solver.toolbox,'gpsr'))
idamnjanovic@8 34 y = eval([solver.name,'(b, A,',solver.param,');']);
idamnjanovic@8 35 elseif (strcmpi(solver.toolbox,'SPAMS'))
idamnjanovic@8 36 y = eval([solver.name,'(b, A, solver.param);']);
idamnjanovic@8 37 elseif (strcmpi(solver.toolbox,'SMALL'))
idamnjanovic@8 38 if isa(Problem.A,'float')
idamnjanovic@8 39 y = eval([solver.name,'(A, b, n,',solver.param,');']);
idamnjanovic@8 40 else
idamnjanovic@8 41 y = eval([solver.name,'(A, b, n,',solver.param,',AT);']);
idamnjanovic@8 42 end
idamnjanovic@8 43
idamnjanovic@8 44 % To introduce new sparse representation algorithm put the files in
idamnjanovic@8 45 % your Matlab path. Next, unique name <TolboxID> for your toolbox and
idamnjanovic@8 46 % prefferd API <Preffered_API> needs to be defined.
idamnjanovic@8 47 %
idamnjanovic@8 48 % elseif strcmpi(solver.toolbox,'<ToolboxID>')
idamnjanovic@8 49 %
idamnjanovic@8 50 % % - Evaluate the function (solver.name - defined in the main) with
idamnjanovic@8 51 % % parameters given above
idamnjanovic@8 52 %
idamnjanovic@8 53 % y = eval([solver.name,'(<Preffered_API>);']);
idamnjanovic@8 54
idamnjanovic@8 55 else
idamnjanovic@8 56 printf('\nToolbox has not been registered. Please change SMALL_solver file.\n');
idamnjanovic@8 57 return
idamnjanovic@8 58 end
idamnjanovic@8 59
idamnjanovic@8 60 %%
idamnjanovic@8 61 % Sparse representation time
idamnjanovic@8 62
idamnjanovic@8 63 solver.time = cputime - start;
idamnjanovic@8 64 fprintf('Solver %s finished task in %2f seconds. \n', solver.name, solver.time);
idamnjanovic@8 65
idamnjanovic@8 66 % geting around out of memory problem when converting big matrix from
idamnjanovic@8 67 % sparse to full...
idamnjanovic@8 68
idamnjanovic@8 69 if (Problem.sparse==1)
idamnjanovic@8 70 solver.solution = y;
idamnjanovic@8 71 else
idamnjanovic@8 72 solver.solution = full(y);
idamnjanovic@8 73 end
idamnjanovic@8 74
idamnjanovic@8 75 % Reconstruct the signal from the solution
idamnjanovic@8 76 solver.reconstructed = Problem.reconstruct(solver.solution);
idamnjanovic@8 77 end