-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathavgOpIter.m
More file actions
78 lines (69 loc) · 2.42 KB
/
Copy pathavgOpIter.m
File metadata and controls
78 lines (69 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [x,objValues] = avgOpIter( x0, S, varargin )
% Implements and averaged opterator iteration. See "Line Search for Averaged
% Operator Iteration" by Gisellson et al. (2016)
%
% x = avgOpIter( x0, S [, 'alpha', alpha, 'N', N ] )
%
% Inputs:
% x0 - the initial guess
% S - either a matrix or a a function handle that is the non-expansive operator
%
% Optional Inputs:
% alpha - the scalar for the combination of the averaged operator iteration (default is 0.5)
% N - the number of iterations to run (default is 100)
% objFunction - a function handle to the objective function
% printEvery - print verbose statements every printEvery iterations
%
% Outputs:
% x - the value of the domain variable after all iterations are complete
% objValues - the value of objFunction evaluated on x at each iteration
%
% Written by Nicholas - Copyright 2024
%
% https://github.com/ndwork/dworkLib.git
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
p = inputParser;
p.addParameter( 'alpha', 0.5, @(x) x>0 && x<1 );
p.addParameter( 'N', 100, @ispositive );
p.addParameter( 'objFunction', [] );
p.addParameter( 'printEvery', 1, @ispositive );
p.addParameter( 'verbose', false );
p.parse( varargin{:} );
alpha = p.Results.alpha;
N = p.Results.N;
objFunction = p.Results.objFunction;
printEvery = p.Results.printEvery;
verbose = p.Results.verbose;
if nargout > 1
if numel( objFunction ) == 0
error( 'Must specify an objective function to return objective values' );
end
objValues = zeros( N, 1 );
end
x = x0;
for optIter = 1 : N
if isa( S, 'function_handle' )
x = ( 1 - alpha ) * x + alpha * S( x );
else
x = ( 1 - alpha ) * x + alpha * S * x;
end
if nargout > 1 || ( numel(objFunction) > 0 && verbose == true )
objValue = objFunction( x );
end
if nargout > 1
objValues( optIter ) = objValue;
end
if verbose == true && mod( optIter, printEvery ) == 0
outStr = [ 'avgOpIter: Completed ', indx2str(optIter,N), ' of ', num2str(N) ];
if numel( objFunction ) > 0
outStr = [ outStr, ' objective: ', num2str( objValue ) ]; %#ok<AGROW>
end
disp( outStr );
end
objValues(optIter) = objFunction( x );
end
end