Help with a minimize problem

조회 수: 2 (최근 30일)
Roberto López
Roberto López 2017년 3월 5일
편집: Walter Roberson 2017년 3월 6일
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

채택된 답변

John D'Errico
John D'Errico 2017년 3월 5일
편집: John D'Errico 2017년 3월 5일
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
Roberto López
Roberto López 2017년 3월 6일
Thank you sincerly, I was completely confused. It's the solution I was looking for.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

kowshik Thopalli
kowshik Thopalli 2017년 3월 5일
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
Roberto López
Roberto López 2017년 3월 5일
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?

댓글을 달려면 로그인하십시오.


Roger Stafford
Roger Stafford 2017년 3월 5일
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
Roberto López
Roberto López 2017년 3월 5일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by