How to deal with underflow in scientific computing?

后端 未结 5 1660
梦谈多话
梦谈多话 2021-02-13 18:58

I am working on probabilistic models, and when doing inference on those models, the estimated probabilities can become very small. In order to avoid underflow, I am currently wo

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 19:55

    Rather than storing values in logarithmic form, I think you'd probably be better off using the same concept as doubles, namely, floating-point representation. For example, you might store each value as two longs, one for sign-and-mantissa and one for the exponent. (Real floating-point has a carefully tuned design to support lots of edge cases and avoid wasting a single bit; but you probably don't need to worry so much about any of those, and can focus on designing it in a way that's simple to implement.)

提交回复
热议问题