Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.9K Views
|
9 Replies
|
0 Total Likes
View groups...
Share
Share this post:

FindMaximum finds non-existing values?

Posted 10 years ago

See for yourself... I can't imagine how FindMaximum finds a non-existing maximum. Help!

See for yourself... I can't understand how FindMaximum finds a non-existing maximum. Help!

POSTED BY: Bin Hu
9 Replies
Posted 10 years ago

Now if I eliminate all the unused code and ask it to evaluate only the expression that you wish to maximize

In[1]:= Phi[x_] = CDF[NormalDistribution[], x];
phi[x_] = PDF[NormalDistribution[], x];
Pi0sL[\[Mu]_, x0m_, x0s_] = p x0m - (sg + (c + m0) tg) x0s + Phi[(x0m - \[Mu])/\[Sigma]] (-p x0m + (eg + sg+
   (c + m0) tg) x0s + (-eg + p - sg - c tg - m0 tg) \[Mu]) + Phi[(x0s - \[Mu])/\[Sigma]] ((-eg - sg - (c +m0)
   tg) x0s + p \[Mu] + (eg - p + sg + c tg + m0 tg) \[Mu]) + phi[(x0m - \[Mu])/\[Sigma]] (eg - p + sg + c tg+
   m0 tg) \[Sigma] + phi[(x0s - \[Mu])/\[Sigma]] (-p \[Sigma] + (-eg + p - sg - c tg - m0 tg) \[Sigma]);
Pi0sR[\[Mu]_, x0m_, x0s_] = -(c + m0 + (1 + tg) r0) (x0s - x0m) - (tg (c + m0) + sg) x0s + p (-(x0s - \[Mu])
   Phi[(x0s - \[Mu])/\[Sigma]] - \[Sigma] phi[(x0s - \[Mu])/\[Sigma]] + x0s);
Pi0s[\[Mu]_, x0m_] := Max[FindMaxValue[{Pi0sL[\[Mu], x0m, x0s], 0 <= x0s <= x0m}, {x0s, x0m}],
   FindMaxValue[{Pi0sR[\[Mu], x0m, x0s], 18 >= x0s >= x0m}, {x0s, x0m}]];
Pi0mLR[d_, \[Gamma]_, x0m_] := -(c + m0) x0m + \[Gamma] Pi0s[L + d, x0m] + (1 - \[Gamma]) Pi0s[L, x0m];
Pi0m[d_, \[Gamma]_] := FindMaxValue[{Pi0mLR[d, \[Gamma], x0m], 0 <= x0m <= 18}, {x0m, L}];
L = 4; \[Sigma] = 1; p = 20; c = 1; m0 = 3; m1 = 6; sc = 0; sg = 2; eg = ec = 2; r0 = r1 = 4; tg = tc = 0;
Pi0mLR[2, .5, x]

then I get

Out[9]= 88.4042 - 4 x

and with 0<=x the maximum of that is the 88.4042 that you are seeing.

So FindMaximum returning an incorrect value does not appear to be your problem.

If you change your

Plot[Pi0mLR[2, .5, x], {x, 0, 10}]

to

Plot[Evaluate[Pi0mLR[2, .5, x]], {x, 0, 10}]

then you will see

plot

Why that happens is a whole different subject that I will leave to someone else to clearly explain.

POSTED BY: Bill Simpson
Posted 10 years ago

Thank you so much for digging into this issue and finding the root cause! I'm similarly puzzled. As you saw if you directly plot the function it's not linear. So it seems this has to do with the order of evolution. If it's evaluated with all parameters given like in the plot function then it's correct. If it's first analytically evaluated like what you did then it's wrong, although I don't know why (findmaxvalue should have refused to evaluate it wo all parameters; how findmaxvalue evaluates it in a different way from plot).

POSTED BY: Bin Hu
Posted 10 years ago

If you change

FindMaximum[{Pi0mLR[2, .5, x], x >= 0}, x]

to

Trace[FindMaximum[{Pi0mLR[2, .5, x], x >= 0}, x]]

and evaluate the notebook then you will see multiple screens of the details of finding the maximum. The final steps of that are to maximize 88.4042 - 4 x such that x >= 0 and that results in x being zero and the maximum being 88.4042. The 88.4042 results from 53.2021 + 35.2021. The 35 is half of 70.4042, the 70.4042 is the max of 70.4042 and 68.49...

If you work your way carefully back through that step by step you should be able to find exactly where in your screenful of long equations every step that FindMaximum is taking to give you the result. This is much better than some other corners of Mathematica where there is no information available on exactly how it came to the conclusion.

A hint may be that if I give a starting estimate for x

FindMaximum[{Pi0mLR[2, .5, x], x >= 0}, {x, 1}]

it tells me

{88.4042, {x -> 0.}}

no matter what starting estimate I give it.

POSTED BY: Bill Simpson
Posted 10 years ago

New Error

Cannot find the kernel with the specified name "Local 2".

POSTED BY: Bill Simpson
Posted 10 years ago

well that's my kernel name. In Evaluation => Notebook's Kernel you can specify your kernel.

POSTED BY: Bin Hu
Posted 10 years ago

Wow! I didn't know this. Thank you so much. Let me try my patience with this case later.

POSTED BY: Bin Hu
Posted 10 years ago

Evaluate notebook gives me a stream of errors about not being a Real number when trying to evaluate Pi0m[2, .5]

Can you reproduce this when you download a fresh copy of your attachment and evaluate that?

POSTED BY: Bill Simpson
Posted 10 years ago

I'm sorry I realized I attached a wrong version. This is the one that should run without an error. Make sure to run the entire NB.

I had to write a naive linear search to find the maximum. So my problem is solved. Just curious... it's one thing FindMaximum can't find the correct solution, but finding a value that doesn't exist? I just don't get it.

Attachments:
POSTED BY: Bin Hu
Posted 10 years ago

Maximize returns the same solution, BTW. I'm attaching this haunted file.

Attachments:
POSTED BY: Bin Hu
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard