How to find argmax for the function below?
이전 댓글 표시
Below are my codes. The LLF function has two unknowns, PD and rho, I make them into x variable that has x(1) and x(2) in the function. I tried to use fminsearch(-LLF) to find the argmax but it did not work. I used the fzero instead, but it gives me an error: Error using fzero (line 246)
FZERO cannot continue because user-supplied function_handle ==>...........
Index exceeds the number of array elements (1).
% x(1) = PD, x(2) = rho
r1 = 0.051;
r2 = 0.27;
r3 = 0.037;
r4 = 0.116;
r5 = 0.222;
r6 = 0.121;
r7 = 0.026;
r8 = 0.025;
r9 = 0.02;
r10 = 0.14;
LLF = @(x) log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r1))).*normpdf((sqrt(1-x(2)).*norminv(r1)-norminv(x(1)))./sqrt(x(2)))) +...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r2))).*normpdf((sqrt(1-x(2)).*norminv(r2)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r3))).*normpdf((sqrt(1-x(2)).*norminv(r3)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r4))).*normpdf((sqrt(1-x(2)).*norminv(r4)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r5))).*normpdf((sqrt(1-x(2)).*norminv(r5)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r6))).*normpdf((sqrt(1-x(2)).*norminv(r6)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r7))).*normpdf((sqrt(1-x(2)).*norminv(r7)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r8))).*normpdf((sqrt(1-x(2)).*norminv(r8)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r9))).*normpdf((sqrt(1-x(2)).*norminv(r9)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r10))).*normpdf((sqrt(1-x(2)).*norminv(r10)-norminv(x(1)))./sqrt(x(2))));
x0 = [0,0];
x = fzero(LLF,x0);
댓글 수: 3
John D'Errico
2020년 1월 29일
Um, fzero is not a minimizer. It is a root finder, that only works in ONE variable, NOT two. You cannot use fzero.
You have two variables, so you cannot use a tool like fminbnd.
You CAN use fminsearch. It is a minimization tool. So all you need to do is negate the function. Why it did not work is a mystery, since you have not accurately told us what you did.
Yijia Qiao
2020년 1월 29일
Walter Roberson
2020년 1월 30일
You need to add options like I showed.
답변 (1개)
Walter Roberson
2020년 1월 29일
r1 = 0.051;
r2 = 0.27;
r3 = 0.037;
r4 = 0.116;
r5 = 0.222;
r6 = 0.121;
r7 = 0.026;
r8 = 0.025;
r9 = 0.02;
r10 = 0.14;
LLF = @(x) log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r1))).*normpdf((sqrt(1-x(2)).*norminv(r1)-norminv(x(1)))./sqrt(x(2)))) +...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r2))).*normpdf((sqrt(1-x(2)).*norminv(r2)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r3))).*normpdf((sqrt(1-x(2)).*norminv(r3)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r4))).*normpdf((sqrt(1-x(2)).*norminv(r4)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r5))).*normpdf((sqrt(1-x(2)).*norminv(r5)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r6))).*normpdf((sqrt(1-x(2)).*norminv(r6)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r7))).*normpdf((sqrt(1-x(2)).*norminv(r7)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r8))).*normpdf((sqrt(1-x(2)).*norminv(r8)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r9))).*normpdf((sqrt(1-x(2)).*norminv(r9)-norminv(x(1)))./sqrt(x(2)))) + ...
log(sqrt(1-x(2))./(sqrt(x(2)).*normpdf(norminv(r10))).*normpdf((sqrt(1-x(2)).*norminv(r10)-norminv(x(1)))./sqrt(x(2))));
x0 = [0,0];
LLFmax = @(x) -LLF(x);
options = optimset('MaxFunEvals', 1e6, 'MaxIter', 1e6);
[bestx, fval] = fminsearch(LLFmax, x0, options)
when it eventually stops complaining it ran out of iterations, it will have fval of Inf and the first element of the output will be 0. Tis reflects that if you set x(1) to be 0 then you get out complex infinities, or NaN. The maximum is not well defined unless you add constraints.
카테고리
도움말 센터 및 File Exchange에서 Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!