使用Weka-Java的字符串缓冲区问题

时间:2012-08-19 13:33:04

标签: java string weka stringbuffer

我正在改变一些Weka代码,因此它在分类新数据时会提供信息。尝试存储时,字符串缓冲区是否存在问题。正如你所看到的,我已经在控制台中输出了所有要输出的内容,它工作正常,但stringBuffer不输出任何内容!我在类的标题中声明它如下:

/** Comments for calculating new instance */
public StringBuffer comment = new StringBuffer("");


public double[] distributionForInstance(Instance instance) 
        throws Exception {

    double [] currentProbs = null;
    double [] sumProbs;
    double currentWeight, weight = 1;
    int i,j;

    // Get probabilities.
    sumProbs = new double [instance.numClasses()];
    i = 0;

    while (Utils.gr(weight,0)){

            System.out.println(" rules Make Dec List " + theRules.elementAt(i).toString());

        currentWeight = ((ClassifierDecList)theRules.elementAt(i)).weight(instance);

        if (Utils.gr(currentWeight,0)) {
        comment.append("This Rule is being used: ");
            System.out.println("This Rule is being used: ");
            currentProbs = ((ClassifierDecList)theRules.elementAt(i)).distributionForInstance(instance);
            //  System.out.println(" dist for instance in MakeDecList" + currentProbs[0] + " " + currentProbs[1]); 
            for (j = 0; j < sumProbs.length; j++)
                sumProbs[j] += weight*currentProbs[j];
            weight = weight*(1-currentWeight);
        }

//      System.out.println(instance.enumerateAttributes().toString());
        comment.append("Rule number " + i + " is \n" + theRules.elementAt(i).toString());
        System.out.println("Rule number " + i + " is \n" + theRules.elementAt(i).toString());
        i++;
    }

    for(int pos = i; pos < theRules.size(); pos++){
        System.out.println("Rule number " + pos + " is \n" + theRules.elementAt(pos).toString());
        comment.append("Rule number " + pos + " is \n" + theRules.elementAt(pos).toString());
    }
    int tag = instance.classAttribute().index();
    Attribute here = instance.attributeSparse(tag);
    String attrib = here.toString();
    String[] temp = attrib.split("[\\s]+");
    temp[2] = temp[2].replace("{", "");
    temp[2] = temp[2].replace("}", "");

    String[] tags = temp[2].split(",");

    System.out.println("The probability of this instance being: \n");
    for(j = 0; j < sumProbs.length; j++){
        System.out.println( tags[j] + " is " + sumProbs[j]);
        comment.append(tags[j] + " is " + sumProbs[j]);
    }

    System.out.println("commment stored " + comment.toString());

    return sumProbs;
}

0 个答案:

没有答案