-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfindMinRelErr.m
32 lines (26 loc) · 914 Bytes
/
findMinRelErr.m
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
function [out,k] = findMinRelErr( est, truth, varargin )
% Result is min_k MSE( k * est - truth )
%
% [out,k] = findMinRelErr( est, truth [, 'verbose', true/false ] )
%
% Written by Nicholas Dwork, Copyright 2024
%
% 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.
if nargin < 2
disp( 'Usage: out = findMinMSE( est, truth [, ''verbose'', true/false ] )' );
if nargout > 0, out = []; end
return;
end
p = inputParser;
p.addParameter( 'verbose', false );
p.parse( varargin{:} );
verbose = p.Results.verbose;
f = @(k) relErr( k * est, truth );
LB = 0;
UB = max( est(:) ) / mean( truth(:) ) * 10;
k = goldenSectionSearch( f, LB, UB, 'tol', 1d-6, 'verbose', verbose );
out = f( k );
end