Avoid numerical problems with product of probabilities when taking logs or subtracting the maximum is not enough I have to take draws from the discrete posterior distribution:
$ P(X = x_i |y) \propto P(X = x_i)\prod_{t}^N p(Y_t|X)$
where $P(X = x )$ is the probability mass function of a discrete uniform with boundaries $a$ and $b$ and $p(Y_t|x)$ is the pdf of a student-t with $X$ degrees of freedom.
In MATLAB my problem is that for my realizations $Y_t = y_t$  when I evaluate the product of the student-t pdfs, namely $\prod_{t}^N p(y_t|X = x_i)$ I get zeros because of numerical problems. I took logarithms and calculated what follows:
$ exp\left[log(P(X = x_i |y))\right] \propto exp\left[ log(P(X = x_i)) + \sum_{t}^N log(p(y_t|X=x_i))\right] $
But same problem since when I compute the exponential function I get all zeros. I have tried then to subtract the maximum of value of the $\sum_i^N log(p(y_t|X = x_i))$ but again I have numerical problems with the exponent.
What can I do?
N.B: In general I am trying to take draws from equation (7) in
http://people.bu.edu/jacquier/papers/jpr.je2004.pdf
 A: I may not be that much less mentally negligible than last night, but here goes...
If this is only needed for the purpose of sampling from a discrete distribution, but we only have an un-normalised probability, $P(X=x_i) \propto Q(X=x_i)$, then we would generate a random number, $y$, in the range 0 to $U = \sum_{i}Q(X=x_i)$.  Pick $x_1$ if $y < Q(X=x_1)$, else $x_2$ if $y < Q(X=x_2)$, and so on.   The un-normalised probabilities are given by $Q(X=x_i) = \exp\{ \log(\lambda_i)\}$ and the problem is the $\lambda$ variables are so small that the $\exp$ is giving values that are small enough to cause numerical problems.  Possible solution, find the smallest (rather than largest) $\lambda_i$, which is $\lambda^\ast$ and subtract it, so that $Q(X=x_i) = \exp\{\log(\lambda_i) - \lambda^\ast\}$.  That means that the smallest argument to the $\exp$ function will be zero, giving $Q(X=x^\ast) = 1$, and all others will be greater than one.
The simple roulette sampler should work as before as it is just multiplying all of the un-normalised probabilities by the same amount, $\exp\{\lambda^\ast\}$, so it just changes the value of $U$.
ETA: sorry to spell it out, I was mostly spelling it out to myself to get my "thinking" straight - it has been a long year!
