-
Notifications
You must be signed in to change notification settings - Fork 3
/
elFamObj.m
66 lines (55 loc) · 1.3 KB
/
elFamObj.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
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
function f = elFamObj(crLambda, p, elike, deriv)
% Computes the negated GEL objective function or its derivative for the given
% crLambda value. (0 for EL, -1 for exponential tilting).
% Used internally by other routines.
%
switch crLambda
case 0
f = elComputePi(p,elike,deriv);
case -1
f = etiltComputePi(p,elike,deriv);
otherwise
f = gelComputePi(p, elike, deriv);
end
function f = elComputePi(p, elike, deriv)
% Compute the objective function or its derivatives for empirical
% likelihood
switch deriv
case 0
f = -sum(log(p));
case 1
f = -1 ./ p;
case 2
f = p .^ -2;
end
end;
function f = etiltComputePi(p, elike, deriv)
% Compute objective function for exponential tilting
switch deriv
case 0
f = -sum(p .* log(p));
case 1
f = log(p);
case 2
f = 1 ./ p;
end
end;
function f = gelComputePi(p, elike, deriv)
% Works for general member of GEL family as long as there's no
% divide-by-zero problem (e.g. EL or ET)
l = crLambda;
switch deriv
case 0
f = sum(p .^ -l);
case 1
f = -l * p .^ (-1-l);
case 2
f = -l * (-1-l) * p .^ (-2-l);
end
% Note: omit the 1/(l * (1+l)) scaling factor (only the sign matters)
if -1 < l && 0 > l
f = -f;
end
f = f / numel(p);
end;
end