找到你要的答案

Q:How to handle extremely small numbers in java

Q:如何在java处理非常小的数字

I am developing a java application for sentiment analysis using Naive Bayes classifier. But while computing the probability the results are very small numbers due to which we are getting an output which is zero. Using BigDecimal didn't help.

我开发一个使用朴素贝叶斯分类器的情感分析java应用程序。但在计算概率的结果是非常小的数字,由于我们得到的输出是零。使用BigDecimal没有帮助。

answer1: 回答1:

Why not simply using BigDecimal numbers and wrap them into a custom class :

public class InfinitesimalNumber {
    private BigDecimal mantisse;
    private int exponent;
}

However, you would have to implement all the maths, which would not be so easy even if BigDecimal would do most of the job.

为什么不干脆使用BigDecimal数包成一个自定义类:

public class InfinitesimalNumber {
    private BigDecimal mantisse;
    private int exponent;
}

然而,你可以实现所有的数学,不即使BigDecimal会做大部分的工作是那么的容易。

answer2: 回答2:

IMO, BigDecimal should have been useful.

Another suggestion can be to use logarithm for multiplication.For example to compute product of abc*...*z you can use

product = exp(log(a) + log(b) + log(c) + ... + log(z))

Also if the result is really extremely small then does that probability needs to be taken into consideration? I am not sure but just asking out of curiosity.

在我看来,BigDecimal应该是有用的。

另一个建议可以使用对数乘法,例如计算ABC * * Z的产品

product = exp(log(a) + log(b) + log(c) + ... + log(z))

此外,如果结果是真的非常小,那么这种概率需要考虑?我不确定,只是好奇地问。

java