gpt4 book ai didi

java - Double.Min_Value 未按预期工作

转载 作者:行者123 更新时间:2023-11-29 07:00:52 24 4
gpt4 key购买 nike

我有以下代码,但当 mutuaInformation 为零时它不会通过 if。知道出了什么问题吗?

        int largestEntropyIndex = Integer.MIN_VALUE;
double largestMutualInfomation = Double.MIN_VALUE;
for (int i = 0; i < attributes.size(); i++) {
String attrName=this.attributes.get(i);
double conditionalEntropy = calcConditionalEntropy(i,
instances,
this.attributeValues.get(attrName).size(),
this.labels.size());

System.out.println("conditional entropy is: "+conditionalEntropy);
double mutualInformation = entropy - conditionalEntropy;
if (mutualInformation > largestMutualInfomation){
largestMutualInfomation = mutualInformation;
largestEntropyIndex = i;
}

最佳答案

Double.MIN_VALUE持有正数,所以 0 < Double.MIN_VALUE .

/**
* A constant holding the smallest positive nonzero value of type
* <code>double</code>, 2<sup>-1074</sup>. It is equal to the
* hexadecimal floating-point literal
* <code>0x0.0000000000001P-1022</code> and also equal to
* <code>Double.longBitsToDouble(0x1L)</code>.
*/
public static final double MIN_VALUE = 0x0.0000000000001P-1022; // 4.9e-324

您应该改用一些任意的负值(或者可能是 Double.NEGATIVE_INFINITY )。

关于java - Double.Min_Value 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26358726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com