[Date Index]
[Thread Index]
[Author Index]
Re: NMaximize problem
*To*: mathgroup at smc.vnet.net
*Subject*: [mg90018] Re: [mg89962] NMaximize problem
*From*: DrMajorBob <drmajorbob at att.net>
*Date*: Thu, 26 Jun 2008 04:45:00 -0400 (EDT)
*References*: <4905780.1214439672215.JavaMail.root@m08>
*Reply-to*: drmajorbob at longhorns.com
> (complete code at the end).
You did NOT give us complete code, since you didn't define logLikelihood.
However, guessing from what you didn't tell us, you might try replacing
all those variables that must be positive (but less than one, since they
add up to one) with the exponentials of negative variables. For instance,
replace t1 with Exp[lt1] and require lt1 < 0, et cetera. Reformulate the
problem in terms of the new variables, and THEN try NMaximize.
There are no guarantees when dealing with numerical methods, but that
approach should at least avoid calculating logs of negative numbers.
Or, if you DO post the complete code, you might get other, better
suggestions.
Bobby
On Wed, 25 Jun 2008 05:27:44 -0500, Ramiro <ramiro.barrantes at gmail.com>
wrote:
> 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.}, {-0.549516, 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>>}. >>
>
>
--
DrMajorBob at longhorns.com
Prev by Date:
**Re: Re: Symbolic complex conjugation?**
Next by Date:
**standard error output**
Previous by thread:
**NMaximize problem**
Next by thread:
**Timing out while waiting for Manipulate code to load**
| |