I am trying to use Mata to calculate a fraction in which each term in both the numerator and denominator is quite small (say 1e-500), so it will underflow even a double precision value and become 0. In simplest form, the fraction might be described as simply:
\[{P_l} = \frac{{{X_l}}}{{\sum\limits_{l = l}^L {{X_l}} }}\]
This arises as I try to implement a proposed Bayesian solution to a nonstandard approach involving categorical data. I don't know that the details of the origin of the problem will help, but I'll provide the obscure reference below for those interested. For whatever help it might be I'll say that Xl is the probability of the data assuming one particular value in a finite parameter space, and the denominator is the sum of the probabilities of the data assuming each of the L possible values of the parameter, where L is a small integer. (L = the number of response categories for each of several similar questionnaire items.)
I have been solving the problem up until now by scaling each Xl along the way by a big fixed value (say B =1e+250), so that I'm working with \[{P_l} = \frac{{B{X_l}}}{{\sum\limits_{l = l}^L {B{X_l}} }}\]
but that approach is no longer working for me at larger values of_N, where each Xl is much smaller and quite variable in magnitude. I don't see any helpful role for logs, given the sum in the denominator. I'm hoping/presuming that someone can point me toward a typical approach to what must be a common problem in some contexts/fields.
(Original reference: Appendix A of Romney, A., Weller, S. , Batchelder, W. 1986. "Culture as Consensus." American Anthropologist. 88, 2: 313-338. A huge applied literature issues out of this article, but not much is said computational issues.)
Regards, Mike
\[{P_l} = \frac{{{X_l}}}{{\sum\limits_{l = l}^L {{X_l}} }}\]
This arises as I try to implement a proposed Bayesian solution to a nonstandard approach involving categorical data. I don't know that the details of the origin of the problem will help, but I'll provide the obscure reference below for those interested. For whatever help it might be I'll say that Xl is the probability of the data assuming one particular value in a finite parameter space, and the denominator is the sum of the probabilities of the data assuming each of the L possible values of the parameter, where L is a small integer. (L = the number of response categories for each of several similar questionnaire items.)
I have been solving the problem up until now by scaling each Xl along the way by a big fixed value (say B =1e+250), so that I'm working with \[{P_l} = \frac{{B{X_l}}}{{\sum\limits_{l = l}^L {B{X_l}} }}\]
but that approach is no longer working for me at larger values of_N, where each Xl is much smaller and quite variable in magnitude. I don't see any helpful role for logs, given the sum in the denominator. I'm hoping/presuming that someone can point me toward a typical approach to what must be a common problem in some contexts/fields.
(Original reference: Appendix A of Romney, A., Weller, S. , Batchelder, W. 1986. "Culture as Consensus." American Anthropologist. 88, 2: 313-338. A huge applied literature issues out of this article, but not much is said computational issues.)
Regards, Mike
Comment