I would like to know why during the computation of alpha and beta, you take the log? Is that because of the overflow/underflow problem? If yes, then when you calculate Mi*alpha and Mi*beta you first take the exponent of the matrix/vector elements and then multiply the exponents (and not adding the logs) which brings about  the precision errors.