Netbeans中的大规模在线分析:无法访问仪器环境

时间:2017-07-07 11:32:26

标签: java netbeans machine-learning

我正在尝试在Netbeans中运行Massive Online Analysis(MOA)的一些演示代码。这是代码:

package javaapplication10_moa;

import moa.classifiers.trees.HoeffdingTree;
import moa.classifiers.Classifier;
import moa.core.TimingUtils;
import moa.streams.generators.RandomRBFGenerator;
import com.yahoo.labs.samoa.instances.Instance;
import java.io.IOException;


/**
 *
 * @author LENOVO
 */
public class JavaApplication10_MOA {

        public JavaApplication10_MOA(){            
        }

        public void run(int numInstances, boolean isTesting){
                Classifier learner = new HoeffdingTree();
                RandomRBFGenerator stream = new RandomRBFGenerator();
                stream.prepareForUse();

                learner.setModelContext(stream.getHeader());
                learner.prepareForUse();

                int numberSamplesCorrect = 0;
                int numberSamples = 0;
                boolean preciseCPUTiming = TimingUtils.enablePreciseTiming();
                long evaluateStartTime = TimingUtils.getNanoCPUTimeOfCurrentThread();
                while (stream.hasMoreInstances() && numberSamples < numInstances) {
                        Instance trainInst = stream.nextInstance().getData();
                        if (isTesting) {
                                if (learner.correctlyClassifies(trainInst)){
                                        numberSamplesCorrect++;
                                }
                        }
                        numberSamples++;
                        learner.trainOnInstance(trainInst);
                }
                double accuracy = 100.0 * (double) numberSamplesCorrect/ (double) numberSamples;
                double time = TimingUtils.nanoTimeToSeconds(TimingUtils.getNanoCPUTimeOfCurrentThread()- evaluateStartTime);
                System.out.println(numberSamples + " instances processed with " + accuracy + "% accuracy in "+time+" seconds.");
        }        

        public static void main(String[] args) throws IOException {
                JavaApplication10_MOA exp = new JavaApplication10_MOA();
                exp.run(1000000, true);
        } 

}

这是输出:

  

无法访问检测环境。请检查jar文件   包含SizeOfAgent类在java的“-javaagent”中指定   命令行参数。处理了1000000个实例,91.0458%   准确度在5.5秒内。建立成功(总时间:5秒)

事情是Netbeans无法访问仪器环境,我理解这与配置文件类似。我尝试了Netbeans how to set command line arguments in Java的建议,转到Run - &gt;设置项目配置 - &gt;定制。将参数设置为-javaagent:sizeofag.jar。但它不起作用! :( 请帮助我,非常感谢

1 个答案:

答案 0 :(得分:0)

我通常通过Project->Properties->Run->VM和以下选项设置java代理:

-javaagent:"<full path to jar>/target.jar"

此外,我在netbens论坛Configuring javaagent in NetBeans上找到了老话题,所以它应该有效。

PS:请看下面example

BTW我下载了moa-release-2016.04.zip,解压缩,在Netbeans中创建了简单的java项目,在Library部分添加了<path>/moa-release-2016.04/lib/moa-2016.04.jar的路径并运行了代码而没有任何错误或警告。我甚至没有在Run部分提到javaagent。这是我的输出窗口:

run:
1000000 instances processed with 91.0458% accuracy in 5.480392592 seconds.
BUILD SUCCESSFUL (total time: 5 seconds)