-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcheckProxConj.m
More file actions
72 lines (63 loc) · 2.13 KB
/
Copy pathcheckProxConj.m
File metadata and controls
72 lines (63 loc) · 2.13 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
function [ out, err ] = checkProxConj( x, prox, proxConj, varargin )
% [ out, err ] = checkProxConj( x, prox, proxConj [, 'tol', tol, 'nRand', nRand )
%
% Uses the Moreau decomposition to see if the proximal operator and the proximal
% operation of the conjugate function are correctly related.
%
% Assumes the proximal operator has the form prox( x, t );
% Assumes the proximal operator of the conjugate function has the form prox( x, sigma, t )
%
% 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( 'sigma', 1, @isnonnegative );
p.addParameter( 't', [], @ispositive );
p.addParameter( 'tol', 1d-6, @ispositive );
p.parse( varargin{:} );
nRand = p.Results.nRand;
sigma = p.Results.sigma;
t = p.Results.t;
tol = p.Results.tol;
out = false;
err = 0;
sx = size( x );
if max( min( x(:) ) ) == 0
x = ones( sx );
end
v1 = sigma * prox( x/sigma, 1/sigma );
v2 = proxConj( x, sigma, 1 );
thisErr = norm( x(:) - v1(:) - v2(:) ) / norm( x );
err = max( err, thisErr );
if thisErr > tol, return; end
if numel( t ) > 0 && t ~= 1
v1 = sigma * prox( x/sigma, t/sigma );
v2 = proxConj( x, sigma, t );
thisErr = norm( x(:) - v1(:) - v2(:) ) / norm( x );
err = max( err, thisErr );
if thisErr > tol, return; end
end
y = rand( sx );
v1 = sigma * prox( y/sigma, 1/sigma );
v2 = proxConj( y, sigma, 1 );
thisErr = norm( y(:) - v1(:) - v2(:) ) / norm( x );
err = max( err, thisErr );
if thisErr > tol, return; end
for randIndx = 1 : nRand
randSigma = rand(1,1);
lambda = rand(1,1);
y = rand( sx );
v1 = randSigma * prox( y/randSigma, lambda/randSigma );
v2 = proxConj( y, randSigma, lambda );
thisErr = norm( y(:) - v1(:) - v2(:) );
err = max( err, thisErr );
if thisErr > tol, return; end
end
out = true;
end