Example usage for weka.core FastVector removeElementAt

List of usage examples for weka.core FastVector removeElementAt

Introduction

In this page you can find the example usage for weka.core FastVector removeElementAt.

Prototype

public final void removeElementAt(int index) 

Source Link

Document

Deletes an element from this vector.

Usage

From source file:net.sf.bddbddb.OrderClassifier.java

License:LGPL

public double importance(weka.core.Attribute attribute, String attrValue) {//, String classValue){

    int count = 0;
    int goodCount = 0, badCount = 0;
    List newInstances = new LinkedList();

    for (Iterator it = orders.iterator(); it.hasNext();) {
        Instance instance = (Instance) it.next();
        if (//!instance.stringValue(instance.classIndex()).equals(classValue) ||
        !instance.stringValue(attribute).equals(attrValue))
            continue;

        if (goodClusters.contains(instance.stringValue(instance.classIndex())))
            ++goodCount;/*from   w w w . j  a  v  a2 s  . c  o  m*/
        else
            ++badCount;

        Instance newInstance = new Instance(instance);
        newInstance.setDataset(instance.dataset());
        newInstances.add(newInstance);
    }
    goodCount *= attrOptions.size() - 1;
    badCount *= attrOptions.size() - 1;
    for (Iterator it = newInstances.iterator(); it.hasNext();) {
        Instance instance = (Instance) it.next();
        /*      if(//!instance.stringValue(instance.classIndex()).equals(classValue) || 
         !instance.stringValue(attribute).equals(attrValue)) continue;
         */

        String classValue = instance.stringValue(instance.classIndex());
        FastVector newOptions = new FastVector();
        newOptions.appendElements(attrOptions);
        newOptions.removeElementAt(newOptions.indexOf(instance.stringValue(attribute)));
        //int index = Math.abs(LearnedOrder.randomNumGen.nextInt()) % newOptions.size();
        int index = 0;
        while (index < newOptions.size()) {
            instance.setValue(attribute, attrOptions.indexOf(newOptions.elementAt(index)));
            String value = classify(instance);
            if (goodClusters.contains(classValue)) {
                if (goodClusters.contains(value))
                    --goodCount;
            } else if (!goodClusters.contains(classValue)) {
                if (!goodClusters.contains(value))
                    --badCount;
            }
            ++index;
        }
        //if(value.equals(classValue)) --count;
    }

    count = goodCount - badCount;
    count /= attrOptions.size() - 1;

    double importance = ((double) count) / newInstances.size();
    if (Double.isNaN(importance))
        return 0;
    return importance;
}