[R] Dealing with -Inf in a maximisation problem.

Charles C. Berry ccberry at ucsd.edu
Mon Nov 7 03:46:28 CET 2016


On Mon, 7 Nov 2016, Rolf Turner wrote:

> On 07/11/16 13:07, William Dunlap wrote:
>> Have you tried reparameterizing, using logb (=log(b)) instead of b?
>
> Uh, no.  I don't think that that makes any sense in my context.
>
> The "b" values are probabilities and must satisfy a "sum-to-1" constraint. 
> To accommodate this constraint I re-parametrise via a "logistic" style 
> parametrisation --- basically
>
>   b_i = exp(z_i)/[sum_j exp(z_j)], j = 1, ... n
>
> with the parameters that the optimiser works with being z_1, ..., z_{n-1} 
> (and with z_n == 0 for identifiability).  The objective function is of the 
> form sum_i(a_i * log(b_i)),


This is sum_i(a_i * z_i) - sum(a_i)*log(sum_j(exp(z_j)), isn't it?

So you don't need to evaluate b_i here, do you?

Large values of z_j will lead to exp(z_j) == Inf, but using

 	sum_i(a_i * (z_i-max.z)) - sum(a_i)*log(sum_j(exp(z_j-max.z))

will handle that.

HTH,

Chuck

p.s. Regarding "advice from younger and wiser heads", I probably cannot 
claim to be either.



More information about the R-help mailing list