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 comentarios

John D'Errico
John D'Errico el 29 de En. de 2020
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.
So I changed it to negative function. It gives me an exiting message as follows: Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: Inf
% 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 = fminsearch(LLF,x0);
Walter Roberson
Walter Roberson el 30 de En. de 2020
You need to add options like I showed.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 29 de En. de 2020
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.

Categorías

Más información sobre Optimization en Centro de ayuda y File Exchange.

Preguntada:

el 29 de En. de 2020

Comentada:

el 30 de En. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by