-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstatrobustwfun.m
More file actions
87 lines (73 loc) · 1.88 KB
/
statrobustwfun.m
File metadata and controls
87 lines (73 loc) · 1.88 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
79
80
81
82
83
84
85
86
87
function [eid,emsg,wfun,tune] = statrobustwfun(wfun,tune)
%STATROBUSTWFUN Get robust weighting function and tuning constant
% Copyright 2005-2007 The MathWorks, Inc.
% $Revision: 1.1.8.1 $ $Date: 2010/03/16 00:30:25 $
eid = '';
emsg = '';
% Convert name of weight function to a handle to a local function, and get
% the default value of the tuning parameter
t = [];
if ischar(wfun)
switch(wfun)
case 'andrews'
wfun = @andrews;
t = 1.339;
case 'bisquare'
wfun = @bisquare;
t = 4.685;
case 'cauchy'
wfun = @cauchy;
t= 2.385;
case 'fair'
wfun = @fair;
t = 1.400;
case 'huber'
wfun = @huber;
t = 1.345;
case 'logistic'
wfun = @logistic;
t = 1.205;
case 'ols'
wfun = @ols;
t = 1;
case 'talwar'
wfun = @talwar;
t = 2.795;
case 'welsch'
wfun = @welsch;
t = 2.985;
end
end
% Use the default tuning parameter or check the supplied one
if isempty(tune)
if isempty(t)
eid = 'TooFewInputs';
emsg = 'Missing tuning constant for weight function.';
return
end
tune = t;
elseif (tune<=0)
eid = 'BadTuningConstant';
emsg = 'Tuning constant must be positive.';
end
% --------- weight functions
function w = andrews(r)
r = max(sqrt(eps(class(r))), abs(r));
w = (abs(r)<pi) .* sin(r) ./ r;
function w = bisquare(r)
w = (abs(r)<1) .* (1 - r.^2).^2;
function w = cauchy(r)
w = 1 ./ (1 + r.^2);
function w = fair(r)
w = 1 ./ (1 + abs(r));
function w = huber(r)
w = 1 ./ max(1, abs(r));
function w = logistic(r)
r = max(sqrt(eps(class(r))), abs(r));
w = tanh(r) ./ r;
function w = ols(r)
w = ones(size(r));
function w = talwar(r)
w = 1 * (abs(r)<1);
function w = welsch(r)
w = exp(-(r.^2));