Re: Newbie question about the behavior of NMaximize
- To: mathgroup at smc.vnet.net
- Subject: [mg50971] Re: [mg50955] Newbie question about the behavior of NMaximize
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 30 Sep 2004 04:52:16 -0400 (EDT)
- References: <200409290715.DAA10645@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Roger Levy wrote: > Hi, > > I'm confused about the behavior of NMaximize. It appears that some > inequality constraints I am stipulating are not being obeyed; a > stipulation that 0<p4<1 is still allowing a very small negative value > of p4. Is there something wrong with the way I'm stating inequality > constraints below? Any help much appreciated. > > Best, > > Roger Levy > > In[11]:= y = 5*Log[p1*q]+10*Log[p4*q]+25*Log[(p1+p2+p3)*(1-q)+p3*q]+20*Log[(p4+p5+p6)*(1-q)+p6*q] > > Out[11]= 5 Log[p1 q] + 10 Log[p4 q] + 25 Log[(p1 + p2 + p3) (1 - q) + > p3 q] + > > >> 20 Log[(p4 + p5 + p6) (1 - q) + p6 q] > > > In[13]:= NMaximize[{y,0<p1<1,0<p2<1,0<p3<1,0<p4<1,0<p5<1,0<p6<1,p1+p2+p3+p4+p5+p6==1,0<q<1},{p1,p2,p3,p4,p5,p6,q}] > > NMaximize::nnum: > The function value Indeterminate is not a number at > -16 > {p1, p2, p3, p4, p5, p6, q} = {0., 0., 0., -1.11022 10 , 0., 1., > 1.}. > > Out[13]= NMaximize[{5 Log[p1 q] + 10 Log[p4 q] + > > >> 25 Log[(p1 + p2 + p3) (1 - q) + p3 q] + > > >> 20 Log[(p4 + p5 + p6) (1 - q) + p6 q], 0 < p1 < 1, 0 < p2 < 1, > > >> 0 < p3 < 1, 0 < p4 < 1, 0 < p5 < 1, 0 < p6 < 1, > > >> p1 + p2 + p3 + p4 + p5 + p6 == 1, 0 < q < 1}, > > >> {p1, p2, p3, p4, p5, p6, q}] NMaximize really requires weak rather than strong inequalities. Looking at the logarithm terms, it is clear that certain variables should be constrained away from 0. Also, since they are nonnegative and sum to 1, they can all be constrained away from 1. Finally, note that it is possible for points to slip outside the constraint regions (enforcement methods such as penalties are imperfect at best). Hence it is prudent to wrap Re[] around the objective function in case any log arguments become negative. One can do all this as follows. y = 5*Log[p1*q]+10*Log[p4*q]+25*Log[(p1+p2+p3)*(1-q)+p3*q]+ 20*Log[(p4+p5+p6)*(1-q)+p6*q]; eps = 10^(-8); vars = {p1,p2,p3,p4,p5,p6,q}; constraints = Flatten[{Map[eps<=#<=1-eps&,{p1,p4,q}], Map[0<=#<=1-eps&,{p2,p3,p5,p6}], Apply[Plus,vars]==1}]; I get: In[24]:= InputForm[NMaximize[{Re[y],constraints}, vars]] Out[24]//InputForm= {-86.80125018812635, {p1 -> 0.43749810007557227, p2 -> 0., p3 -> 0., p4 -> 0.4375039905348629, p5 -> 0., p6 -> 0., q -> 0.12499790938956486}} Daniel Lichtblau Wolfram Research
- References:
- Newbie question about the behavior of NMaximize
- From: napofrog@hotmail.com (Roger Levy)
- Newbie question about the behavior of NMaximize