MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Problem with NMaximize

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90076] Re: [mg90045] Re: Problem with NMaximize
  • From: mante <claude.mante at univmed.fr>
  • Date: Sat, 28 Jun 2008 05:51:31 -0400 (EDT)
  • References: <g3vkvi$kio$1@smc.vnet.net> <4863CA88.5040100@gmail.com> <200806271016.GAA24166@smc.vnet.net>

DrMajorBob wrote:
> For instance,
>
> likelihood1[t1_?NumberQ, t2_?NumberQ, t3_?NumberQ, t4_?NumberQ,
>     t5_?NumberQ, t6_?NumberQ, t7_?NumberQ, t8_?NumberQ, t9_?NumberQ,
>     t10_?NumberQ, t11_?NumberQ, t12_?NumberQ] =
>    0.00001712341312000713` t1 + 5.648647024829866`*^-6 t10 +
>     8.90597537441381`*^-6 t11 + 1.9727284288726167`*^-6 t12 +
>     4.102725237468317`*^-6 t2 + 3.7864902508468615`*^-6 t3 +
>     9.215772325326653`*^-7 t4 + 0.000057161484895917856` t5 +
>     0.000012892953334779516` t6 + 8.646320198720343`*^-6 t7 +
>     5.877910295858781`*^-6 t8 + 1.6837835562631724`*^-6 t9;
> Sort@Cases[%, a_ b_Real :> {b, a}, 1]
>
> {{9.21577*10^-7, t4}, {1.68378*10^-6, t9}, {1.97273*10^-6,
>    t12}, {3.78649*10^-6, t3}, {4.10273*10^-6, t2}, {5.64865*10^-6,
>    t10}, {5.87791*10^-6, t8}, {8.64632*10^-6, t7}, {8.90598*10^-6,
>    t11}, {0.000012893, t6}, {0.0000171234, t1}, {0.0000571615, t5}}
>
> NMaximize[{likelihood1[t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11,
>     t12], t1 > 0, t2 > 0, t3 > 0, t4 > 0, t5 > 0, t6 > 0, t7 > 0,
>    t8 > 0, t9 > 0, t10 > 0, t11 > 0, t12 > 0,
>    t1 + t10 + t11 + t12 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 ==
>     1}, {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12}]
>
> {0.0000571615, {t1 -> -2.73483*10^-8, t10 -> 0., t11 -> 0., t12 -> 0.,
>     t2 -> 0., t3 -> 0., t4 -> 0., t5 -> 1., t6 -> 0., t7 -> 0.,
>    t8 -> 0., t9 -> 0.}}
>
> Notice the only non-zero t value, t5, is the one with the largest  
> coefficient.
>
> And that figures, doesn't it?
>
> Bobby
>
> On Thu, 26 Jun 2008 13:45:57 -0500, ramiro <ramiro.barrantes at uvm.edu>  
> wrote:
>
>   
>> Thank you very much for your responses, Bobby and Jean-Marc.   I did try  
>> changing the parametrization (thanks Bobby!) and I got an answer.  
>> However, let me try again with a hopefully more clear example, as I  
>> don't understand why this doesn't work, in particular, I don't  
>> understand why is it evaluating negative numbers if I am putting as a  
>> constraint that it shouldn't?
>>
>>
>> Sample likelihood,
>>
>> In[196]:=
>> logLikelihood1[t1_?NumberQ, t2_?NumberQ, t3_?NumberQ, t4_?NumberQ,
>>    t5_?NumberQ, t6_?NumberQ, t7_?NumberQ, t8_?NumberQ, t9_?NumberQ,
>>    t10_?NumberQ, t11_?NumberQ, t12_?NumberQ] :=
>>   Log[0.00001712341312000713` t1 + 5.648647024829866`*^-6 t10 +
>>     8.90597537441381`*^-6 t11 + 1.9727284288726167`*^-6 t12 +
>>     4.102725237468317`*^-6 t2 + 3.7864902508468615`*^-6 t3 +
>>     9.215772325326653`*^-7 t4 + 0.000057161484895917856` t5 +
>>     0.000012892953334779516` t6 + 8.646320198720343`*^-6 t7 +
>>     5.877910295858781`*^-6 t8 + 1.6837835562631724`*^-6 t9];
>>
>> Another version (without the NumberQ)...
>>
>> In[197]:=
>> logLikelihood2[t1_, t2_, t3_, t4_, t5_, t6_, t7_, t8_, t9_, t10_,
>>    t11_, t12_] :=
>>   Log[0.00001712341312000713` t1 + 5.648647024829866`*^-6 t10 +
>>     8.90597537441381`*^-6 t11 + 1.9727284288726167`*^-6 t12 +
>>     4.102725237468317`*^-6 t2 + 3.7864902508468615`*^-6 t3 +
>>     9.215772325326653`*^-7 t4 + 0.000057161484895917856` t5 +
>>     0.000012892953334779516` t6 + 8.646320198720343`*^-6 t7 +
>>     5.877910295858781`*^-6 t8 + 1.6837835562631724`*^-6 t9];
>>
>> In[198]:= NMaximize[{logLikelihood1[t1, t2, t3, t4, t5, t6, t7, t8,
>>    t9, t10, t11, t12], t1 > 0, t2 > 0, t3 > 0, t4 > 0, t5 > 0, t6 > 0,
>>    t7 > 0, t8 > 0, t9 > 0, t10 > 0, t11 > 0, t12 > 0,
>>   t1 + t10 + t11 + t12 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 ==
>>    1}, {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12}]
>>
>> During evaluation of In[198]:= NMaximize::nrnum: The function value \
>> 15.7729-3.14159 I is not a real number at \
>> {t1,t10,t11,t12,t2,t3,t4,t5,t6,t7,<<2>>} = {-0.490249,<<9>>,<<2>>}. \
>>  >>
>>
>> Out[198]= {-13.2945, {t1 -> 2.10942*10^-15, t10 -> -2.22045*10^-16,
>>   t11 -> -2.22045*10^-16, t12 -> -2.22045*10^-16,
>>   t2 -> -1.11022*10^-16, t3 -> -2.22045*10^-16, t4 -> -2.22045*10^-16,
>>    t5 -> -6.93889*10^-18, t6 -> -2.22045*10^-16,
>>   t7 -> -1.11022*10^-16, t8 -> -4.44089*10^-16, t9 -> 1.}}
>>
>> In[199]:= NMaximize[{logLikelihood2[t1, t2, t3, t4, t5, t6, t7, t8,
>>    t9, t10, t11, t12], t1 > 0, t2 > 0, t3 > 0, t4 > 0, t5 > 0, t6 > 0,
>>    t7 > 0, t8 > 0, t9 > 0, t10 > 0, t11 > 0, t12 > 0,
>>   t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 ==
>>    1}, {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12}]
>>
>> During evaluation of In[199]:= NMaximize::nrnum: The function value \
>> 15.7729-3.14159 I is not a real number at \
>> {t1,t10,t11,t12,t2,t3,t4,t5,t6,t7,<<2>>} = {-0.490249,<<9>>,<<2>>}. \
>>  >>
>>
>> Out[199]= {-13.2945, {t1 -> 2.10942*10^-15, t10 -> -2.22045*10^-16,
>>   t11 -> -2.22045*10^-16, t12 -> -2.22045*10^-16,
>>   t2 -> -1.11022*10^-16, t3 -> -2.22045*10^-16, t4 -> -2.22045*10^-16,
>>    t5 -> -6.93889*10^-18, t6 -> -2.22045*10^-16,
>>   t7 -> -1.11022*10^-16, t8 -> -4.44089*10^-16, t9 -> 1.}}
>>
>>     
>
>
>
>   
I think so! But in such cases, isn't it better to use LinearProgramming[] ?

-- 
*********************************

    Claude Manté

UMR CNRS 6117 LMGEM
http://www.com.univ-mrs.fr/LMGEM/

Centre d'Océanologie de Marseille
Campus de Luminy, Case 901
13288 MARSEILLE Cedex 09
tel : (+33) 491 829 127
fax : (+33) 491 829 119


********************************* 



  • Prev by Date: Re: Reading a module library from plain text file
  • Next by Date: Mouse focus in Mathematica
  • Previous by thread: Re: Problem with NMaximize
  • Next by thread: Re: Problem with NMaximize