Help with a minimize problem

2 visualizzazioni (ultimi 30 giorni)
Roberto López
Roberto López il 5 Mar 2017
f
unction b = two_var(v)
x = v(1);
y = v(2);
b = 242*log(1-x-y)+120*log(2*x-x^2-2*x*y)+79*log(2*y-y^2-2*x*y)+33*log(2*x*y);
end
v = [0.5,0.5]
a = fminsearch(@two_var,v);
I'm trying to minimize this function with the next code. The answer is x=0.247 and y=0.173
I leave the link where the problem comes from. Page 4

Risposta accettata

John D'Errico
John D'Errico il 5 Mar 2017
Modificato: John D'Errico il 5 Mar 2017
Time to think about your function. ALWAYS do that. Plot it if possible.
fun = @(x,y) 242*log(1-x-y)+120*log(2*x-x^2-2*x*y)+79*log(2*y-y^2-2*x*y)+33*log(2*x*y);
fun(.5,.5)
ans =
-Inf
fun(-1,-1)
ans =
609.016175390547 + 625.176938064369i
fun(.247, .173)
ans =
-455.717889710442
So some values of x and y generate -inf. Some generate complex numbers. That is completely expected, since the log function does nasty stuff at 0 or negative values. Well, nasty in terms of what fminsearch will expect.
Basic rule: fminsearch expects a continuous, real valued function of the inputs.
If that presumption fails, then expect all hell to break loose in the eyes of fminsearch.
ezsurf(fun)
So, what do we see? First, the function is certainly unbounded from below, going to -inf along the line
x + y = 1
Next, it appears to have a MAXIMUM at the location you describe.
So honestly, I think you are confused. Are you trying to MAXIMIZE this function?
fminseach is a MINIMIZATION tool. You can make it maximize by negating the function as returned. It still minimizes, but the negative of your original function, so a maximum.
fun2 = @(xy) -fun(xy(1),xy(2));
[xymax,fmax] = fminsearch(fun2,[.2 .2])
xymax =
0.246457832567394 0.17315985403955
fmax =
455.717447610379
  1 Commento
Roberto López
Roberto López il 6 Mar 2017
Thank you sincerly, I was completely confused. It's the solution I was looking for.

Accedi per commentare.

Più risposte (2)

kowshik Thopalli
kowshik Thopalli il 5 Mar 2017
I dont understand.
two_var =@(x) 242*log(1-x(1)-x(2))+120*log(2*x(1)-x(1)^2-2*x(1)*x(2))+79*log(2*x(2)-x(2)^2-2*x(1)*x(2))+33*log(2*x(1)*x(2));
v = [0.5,0.5];
x = fminsearch(fun,v)
this gives me x =
0.525000000000000 0.500000000000000
You forgot to attach the link. Changing v would give a different answer. What is it that you exactly want to do?
  1 Commento
Roberto López
Roberto López il 5 Mar 2017
https://ocw.mit.edu/courses/mathematics/18-443-statistics-for-applications-fall-2006/lecture-notes/lecture12.pdf
Sorry this is the link. Is for finding numerically the Maximum likelihood estimator for a chi square test. The sum of p+q+r= 1, r is described by p and q as r=1-p-q. The solution =.5 and 0.52 is incorrect because they must sum less than 1. With other values for example [.3, .2] The function does not work even if I increase MaxFunEvals option as Matlab suggest. Do you know how can I solve it?

Accedi per commentare.


Roger Stafford
Roger Stafford il 5 Mar 2017
It is quite possible for functions such as yours to have more than one point of local minimum. If that is the case, the one that fminsearch will arrive at will depend on the given initial estimate. You need to try a different initial estimate if you are to arrive at the value you refer to in the MIT article.
  1 Commento
Roberto López
Roberto López il 5 Mar 2017
Yeah, I've tried with values close to that given by the article but message appears about MaxFunEvals must be increase even If I do it. It's still not working, maybe the problem looks to be singular but I don't know how these values in the article were obtain.

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by