Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Problem with NMaximize
Replies: 11   Last Post: Jun 28, 2008 5:58 AM

 Messages: [ Previous | Next ]
 Ramiro Barrantes-Reynolds Posts: 9 Registered: 10/14/07
Problem with NMaximize
Posted: Jun 26, 2008 4:45 AM

Hello,

I am trying to calculate the maximum likelihood of a logarithmic
function over 17 parameters. I am using NMaximize and setting all
the parameters to be over 0, and the sum of the a group of them (t's)
to be equal to 1 (i.e. t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 +
t10 + t11 + t12 == 1) (complete code at the end). My constraints
would then be:

l1 > 0, l2 > 0, l3 > 0, l4 > 0, 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

When I run NMaximize over my function I get:

NMaximize::nrnum: "The function value 28.2245-6.28319I is not a
real number at {a,l1,l2,l3,l4,t1,t10,t11,t12,t2,<<7>>}
={1.,2.,2.,<<6>>,0.0799689,<<7>>}."

which is because the number inside the logarithm is negative. When I
used EvaluationMonitor and looked at the iterations I saw that the
first iteration was:

In[189]:= data[[1, 1]]

Out[189]= {1., {2., 2., 2., 2.}, {1.22125*10^-15, 0.,
-2.22045*10^-16, 0., -2.22045*10^-16, -2.22045*10^-16,
-2.22045*10^-16, -1.11022*10^-16, 1., -2.22045*10^-16, 0., 0.}}

As you can see there are several negative numbers, even though the
constraints should enforce otherwise. The error I get I think is a
consequence of that,

In[188]:= data[[1, -1]]

Out[188]= {1., {2., 2., 2., 2.}, {t1, 0.0799689, 0.0478029,
0.0263613, 0.0356839, 0.0720513, 0.066108, 0.0861263, 1., 0.0849883,
0.0498477, 0.000577809}}

This input would lead to my function evaluating a negative logarithm.
However, NMaximize shouldn't be evaluating any negative numbers in the
parameters right?

Any ideas?
Thank you,

Ramiro

{res, data} =
Reap[NMaximize[{logLikelihood[{{5, 5, 0, 0}, {3, 1, 0, 1}}, {33, 83,
11, 14}, S,
a, {l1, l2, l3, l4}, {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
t11, t12}], l1 > 0, l2 > 0, l3 > 0, l4 > 0, 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}, {a, l1, l2, l3, l4, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10,
t11, t12},
EvaluationMonitor :>
Sow[{a, {l1, l2, l3, l4}, {t1, t2, t3, t4, t5, t6, t7, t8, t9,
t10, t11, t12}}]]];

NMaximize::nrnum: The function value 28.2245-6.28319 I is not a real \
number at {a,l1,l2,l3,l4,t1,t10,t11,t12,t2,<<7>>} = \
{1.,2.,2.,<<6>>,0.0799689,<<7>>}. >>

Date Subject Author
6/26/08 Ramiro Barrantes-Reynolds
6/27/08 Jean-Marc Gulliet
6/27/08 ramiro
6/27/08 DrMajorBob
6/27/08 DrMajorBob
6/27/08 Jean-Marc Gulliet
6/28/08 mante
6/28/08 Bill Rowe
6/28/08 Daniel Lichtblau