-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfindMinMSE.m
More file actions
32 lines (26 loc) · 913 Bytes
/
Copy pathfindMinMSE.m
File metadata and controls
32 lines (26 loc) · 913 Bytes
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] = findMinMSE( est, truth, varargin )
% Result is min_k MSE( k * est - truth )
%
% out = findMinMSE( 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) calcMSE( k*est, truth );
LB = 0;
UB = max( abs(est(:)) ) / mean( abs(truth(:)) ) * 10;
k = goldenSectionSearch( f, LB, UB, 'tol', 1d-6, 'verbose', verbose );
out = f( k );
end