-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheckProx.m
More file actions
53 lines (45 loc) · 1.42 KB
/
Copy pathcheckProx.m
File metadata and controls
53 lines (45 loc) · 1.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
function [ out, err ] = checkProx( x, prox, f, varargin )
% [ out, err ] = checkProx( x, prox, f [, 'nRand', nRand )
%
% u = prox_f(x) iff x - u in subderivative of h at u
% iff f(z) >= f(u) + (x-u)^T (z-u)
%
% Note: if this function fails, then prox is faulty. If it passes, it does
% not guarantee that prox is correct.
%
% Inputs:
% x - argument for the proximal operator
% prox - function handle to proximal operator that accepts input and scalar
% f - function handle to the function for which prox is the proximal operator
%
% Optional Inputs:
% nRand - the number of randome vectors to evaluate
%
% Written by Nicholas Dwork, Copyright 2020
%
% 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( 'nRand', 1, @ispositive );
p.addParameter( 't', 1, @(x) ispositive(x) || x==0 );
p.parse( varargin{:} );
nRand = p.Results.nRand;
t = p.Results.t;
out = false;
err = 0;
u = prox( x, t );
for randIndx = 1 : nRand
z = rand( size( u ) );
fu = f( u );
fz = f( z );
if fz < fu + dotP( z - u, x - u )
err = fu + dotP( z - u, x - u ) - fz;
return;
end
end
out = true;
end