5

I'm trying to run some demo code of Massive Online Analysis (MOA) in Netbeans. Here is the code:

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);
        } 

}

And here is the output:

Can not access instrumentation environment. Please check if jar file containing SizeOfAgent class is specified in the java's "-javaagent" command line argument. 1000000 instances processed with 91.0458% accuracy in 5.5 seconds. BUILD SUCCESSFUL (total time: 5 seconds)

The thing is Netbeans was unable to access instrumentation environment, which I understand to be something similar to a profile. I have tried the suggestions from Netbeans how to set command line arguments in Java, by going to Run -> Set Project Configuration -> Customize. Set Arguments to -javaagent:sizeofag.jar . Yet it does not work! :( Please help me, thank you very much

Arghavan
  • 1,125
  • 1
  • 11
  • 17
Dang Manh Truong
  • 795
  • 2
  • 10
  • 35

1 Answers1

0

I usually setup java agent via Project->Properties->Run->VM and options like this:

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

Moreover I found old topic on netbens forum Configuring javaagent in NetBeans so it should work.

PS: please have a look below example

BTW I downloaded moa-release-2016.04.zip, unpacked, created simple java project in Netbeans, added path to <path>/moa-release-2016.04/lib/moa-2016.04.jar in Library section and ran your code without any errors or warnings. I didn't even mention javaagent in Run section. Here is my output window:

run:
1000000 instances processed with 91.0458% accuracy in 5.480392592 seconds.
BUILD SUCCESSFUL (total time: 5 seconds)
Vladislav Kysliy
  • 3,488
  • 3
  • 32
  • 44