Example usage for weka.core Instance dataset

List of usage examples for weka.core Instance dataset

Introduction

In this page you can find the example usage for weka.core Instance dataset.

Prototype

public Instances dataset();

Source Link

Document

Returns the dataset this instance has access to.

Usage

From source file:test.org.moa.opencl.IBk.java

License:Open Source License

/**
 * Adds the supplied instance to the training set.
 *
 * @param instance the instance to add/*from www  .j av  a 2  s  . c  om*/
 * @throws Exception if instance could not be incorporated
 * successfully
 */
public void updateClassifier(Instance instance) throws Exception {

    if (m_Train.equalHeaders(instance.dataset()) == false) {
        throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
    }
    if (instance.classIsMissing()) {
        return;
    }

    m_Train.add(instance);
    m_NNSearch.update(instance);
    m_kNNValid = false;
    if ((m_WindowSize > 0) && (m_Train.numInstances() > m_WindowSize)) {
        boolean deletedInstance = false;
        while (m_Train.numInstances() > m_WindowSize) {
            m_Train.delete(0);
            deletedInstance = true;
        }
        //rebuild datastructure KDTree currently can't delete
        if (deletedInstance == true)
            m_NNSearch.setInstances(m_Train);
    }
}

From source file:tr.gov.ulakbim.jDenetX.classifiers.WEKAClassifier.java

License:Open Source License

public void trainOnInstanceImpl(Instance inst) {
    try {//w w  w . j a  va2s  .co  m
        if (numberInstances == 0) {
            this.instancesBuffer = new Instances(inst.dataset());
            if (classifier instanceof UpdateableClassifier) {
                classifier.buildClassifier(instancesBuffer);
                this.isClassificationEnabled = true;
            } else {
                this.isBufferStoring = true;
            }
        }
        numberInstances++;

        if (classifier instanceof UpdateableClassifier) {
            if (numberInstances > 0) {
                ((UpdateableClassifier) classifier).updateClassifier(inst);
            }
        } else {
            if (numberInstances == widthInitOption.getValue()) {
                //Build first time Classifier
                buildClassifier();
                isClassificationEnabled = true;
                //Continue to store instances
                if (sampleFrequencyOption.getValue() != 0) {
                    isBufferStoring = true;
                }
            }
            if (widthOption.getValue() == 0) {
                //Used from SingleClassifierDrift
                if (isBufferStoring == true) {
                    instancesBuffer.add(inst);
                }
            } else {
                //Used form WekaClassifier without using SingleClassifierDrift
                int numInstances = numberInstances % sampleFrequencyOption.getValue();
                if (sampleFrequencyOption.getValue() == 0) {
                    numInstances = numberInstances;
                }
                if (numInstances == 0) {
                    //Begin to store instances
                    isBufferStoring = true;
                }
                if (isBufferStoring == true && numInstances <= widthOption.getValue()) {
                    //Store instances
                    instancesBuffer.add(inst);
                }
                if (numInstances == widthOption.getValue()) {
                    //Build Classifier
                    buildClassifier();
                    isClassificationEnabled = true;
                    this.instancesBuffer = new Instances(inst.dataset());
                }
            }
        }
    } catch (Exception e) {
        System.err.println("Training: " + e.getMessage());
    }
}

From source file:uzholdem.classifier.UpdateableMultilayerPerceptron.java

License:Open Source License

/**
 * Online backpropagation/*  ww w  .  j  a  v  a2  s.  c  o m*/
 * 
 * @return      the revision
 */
public void updateClassifier(Instance i) throws Exception {

    // setup m_instances
    if (this.m_instances == null) {

        this.m_instances = new Instances(i.dataset(), 0, 0);
    }
    ///////////

    if (m_useNomToBin) {
        if (this.m_nominalToBinaryFilter == null) {
            m_nominalToBinaryFilter = new NominalToBinary();
            m_nominalToBinaryFilter.setInputFormat(m_instances);
        }
        m_nominalToBinaryFilter.input(i);
        m_currentInstance = m_nominalToBinaryFilter.output();
        //    this.m_instances.add(m_currentInstance);
    } else {
        m_currentInstance = i;
        m_currentInstance.setDataset(m_instances);
        //      m_instances.add(m_currentInstance);
    }

    if (!m_currentInstance.classIsMissing()) {

        //this is where the network updating (and training occurs, for the
        //training set
        resetNetwork();
        calculateOutputs();

        this.calculateErrors();
        updateNetworkWeights(this.m_learningRate, m_momentum);

    }

}