我试图用很多方法构造一个deciscion树,但是每当我尝试在同一个包中引用一个类时,它就不会识别其中的方法。
代码:
public void generateBranches(DTNode parent)
{
double minEntropy = 2.0;
boolean y = false;
int j = 0;
ArrayList<Double> Entropyvalues = new ArrayList<Double>(parent.a.length);
//int boolean tmp = parent.a[0].getlabel();
for (int i = 0 ;i < parent.a.length ; i++) {
if (parent.a[i].label != parent.a[j].label)
{
Double Tempropy = InstanceEntropy(childInstance(parent,i,j));
//error here, childInstance succesfully returns an instance[] array
Entropyvalues.add(Tempropy);
}
}
//DTNode LChild = newDTnode()
这是我试图调用的方法(和类):
package DecisionTree;
import java.lang.*;
public class DTNode {
Instance[] a;
double testValue;
DTNode left, right;
public DTNode(Instance[] b)
{
a = b;
}
public Double InstanceEntropy(Instance[] a)
{
DTNode tmp = new DTNode(a);
return tmp.entropy(tmp);
}
和错误: &#34;方法InstanceEntropy(Instance [])未定义类型DecisionTree&#34;
答案 0 :(得分:2)
是的,您的方法位于同一个包中,因此调用者可以查看它,但它必须是对象的引用。该方法是非静态的,属于另一个类。尝试像
这样的东西Double Tempropy = new DTNode(..).InstanceEntropy(..)
另外,我会考虑阅读适当的Java命名约定,因为你的非常规非标准。
注意:根据@Bhesh Gurung,您需要为DTNode提供适当的Instance数组构造函数