Hi,
I wanted to use SAMOA VHT to pass data to firstly, train the model and then
test it. I want to understand what are the steps required in order to
achieve this. I referred this examplehttps://github.com/ambodi/sentinel  and
then implemented the InstanceStream but the stats are not dumped into the
csv file. Request you to please let me know what am I doing wrong?



command I am using

bin/samoa storm "target/SAMOA-STORM.jar"  org.apache.samoa.LocalStormDoTask
"PrequentialEvaluation -d dump.csv -i 1000000 -f 100000 -l
(org.apache.samoa.learners.classifiers.trees.VerticalHoeffdingTree -p 4) -s
(com.my.samoa.examples.MyStreamInstance)"
package com.my.samoa.examples;

import java.util.ArrayList;
import java.util.Random;

import org.apache.samoa.instances.Attribute;

/*
 * #%L
 * SAMOA
 * %%
 * Copyright (C) 2014 - 2016 Apache Software Foundation
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import org.apache.samoa.instances.Instance;
import org.apache.samoa.instances.Instances;
import org.apache.samoa.instances.InstancesHeader;
import org.apache.samoa.instances.SparseInstance;
import org.apache.samoa.moa.core.Example;
import org.apache.samoa.moa.core.InstanceExample;
import org.apache.samoa.moa.core.ObjectRepository;
import org.apache.samoa.moa.options.AbstractOptionHandler;
import org.apache.samoa.moa.tasks.TaskMonitor;
import org.apache.samoa.streams.InstanceStream;

public class MyStreamInstance extends AbstractOptionHandler implements InstanceStream {

	@Override
	public InstancesHeader getHeader() {
		System.out.println("++++++++++++ MyStreamInstance.getHeader()");
		return null;
	}

	@Override
	public long estimatedRemainingInstances() {
		System.out.println("++++++++++++ MyStreamInstance.estimatedRemainingInstances()");
		return 0;
	}

	@Override
	public boolean hasMoreInstances() {
		System.out.println("++++++++++++ MyStreamInstance.hasMoreInstances()");
		return false;
	}

	@Override
	public Example<Instance> nextInstance() {
		System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
		System.out.println("++++++++++++ MyStreamInstance.nextInstance() +++++++++++++++++++++++++++++++++++++++++++++++++");
		System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
		int noOfAttributes = 5;
		double[] attrbuteValues = new double[5];
		int[] indexes = { 0, 1, 2, 3, 4 };
		for (int i = 0; i < noOfAttributes; i++) {
			attrbuteValues[i] = new Random().nextDouble();
		}
		Instance inst = new SparseInstance(1, attrbuteValues, indexes, noOfAttributes);
		Instances dataset;
		ArrayList<String> classVal = new ArrayList<String>();
        classVal.add("H");
        classVal.add("S");
        classVal.add("N");

        Attribute classAtt = new Attribute("class", classVal);

        ArrayList<Attribute> wekaAtt = new ArrayList<Attribute>();
        wekaAtt.add(classAtt);

        dataset = new Instances(getCLICreationString(InstanceStream.class), wekaAtt, 0);
        dataset.setClassIndex(0);
        InstancesHeader instancesHeader = new InstancesHeader(dataset);
        
		inst.setDataset(instancesHeader);
		
		InstanceExample instance = new InstanceExample(inst);
		return instance;
	}

	@Override
	public boolean isRestartable() {
		System.out.println("++++++++++++ MyStreamInstance.isRestartable()");
		return false;
	}

	@Override
	public void restart() {
		System.out.println("++++++++++++ MyStreamInstance.restart()");

	}

	@Override
	public void getDescription(StringBuilder sb, int indent) {
		System.out.println("++++++++++++ MyStreamInstance.getDescription()");

	}

	@Override
	protected void prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository) {
		System.out.println("++++++++++++ MyStreamInstance.getDescription()");

	}

}

Reply via email to