No big deal, but it looks a bit funny to be subtracting stuff off the inside of the exp(..) *and* dividing by row_sum, which is equivalent to subtracting off log(row_sum) on the inside of the exp. If there any particular rationale for doing things this way just document it?