[R] Dealing with -Inf in a maximisation problem.
Rolf Turner
r.turner at auckland.ac.nz
Mon Nov 7 04:15:48 CET 2016
On 07/11/16 15:46, Charles C. Berry wrote:
> 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.
Wow!!! That looks like it will work!!! I won't completely believe it
until I've programmed it up and tried it --- but for the first time in
days I'm feeling hopeful.
>
> HTH,
>
> Chuck
>
> p.s. Regarding "advice from younger and wiser heads", I probably cannot
> claim to be either.
On present evidence you certainly appear to be one hell of a lot wiser!!!
Thanks.
cheers,
Rolf
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list