Example usage for weka.core FastVector elements

List of usage examples for weka.core FastVector elements

Introduction

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

Prototype

public final Enumeration<E> elements() 

Source Link

Document

Returns an enumeration of this vector.

Usage

From source file:LabeledItemSet.java

License:Open Source License

/**
 * Updates counter of a specific item set
 * @param itemSets an item sets/*www .j av a  2 s . c o m*/
 * @param instancesNoClass instances without the class attribute
 * @param instancesClass the values of the class attribute sorted according to instances
 */
public static void upDateCounters(FastVector itemSets, Instances instancesNoClass, Instances instancesClass) {

    for (int i = 0; i < instancesNoClass.numInstances(); i++) {
        Enumeration enu = itemSets.elements();
        while (enu.hasMoreElements())
            ((LabeledItemSet) enu.nextElement()).upDateCounter(instancesNoClass.instance(i),
                    instancesClass.instance(i));
    }

}

From source file:cba.Apriori.java

License:Open Source License

/**
 * Returns an enumeration describing the available options.
 *
 * @return an enumeration of all the available options.
 *///from  w  w  w. jav  a2 s. c  o  m
public Enumeration listOptions() {

    String string1 = "\tThe required number of rules. (default = " + m_numRules + ")",
            string2 = "\tThe minimum confidence of a rule. (default = " + m_minMetric + ")",
            string3 = "\tThe delta by which the minimum support is decreased in\n",
            string4 = "\teach iteration. (default = " + m_delta + ")",
            string5 = "\tThe lower bound for the minimum support. (default = " + m_lowerBoundMinSupport + ")",
            string6 = "\tIf used, rules are tested for significance at\n",
            string7 = "\tthe given level. Slower. (default = no significance testing)",
            string8 = "\tIf set the itemsets found are also output. (default = no)",
            string9 = "\tIf set class association rules are mined. (default = no)",
            string10 = "\tThe class index. (default = last)",
            stringType = "\tThe metric type by which to rank rules. (default = " + "confidence)",
            stringZeroAsMissing = "\tTreat zero (i.e. first value of nominal attributes) as " + "missing";

    FastVector newVector = new FastVector(11);

    newVector.addElement(new Option(string1, "N", 1, "-N <required number of rules output>"));
    newVector.addElement(
            new Option(stringType, "T", 1, "-T <0=confidence | 1=lift | " + "2=leverage | 3=Conviction>"));
    newVector.addElement(new Option(string2, "C", 1, "-C <minimum metric score of a rule>"));
    newVector.addElement(new Option(string3 + string4, "D", 1, "-D <delta for minimum support>"));
    newVector.addElement(new Option("\tUpper bound for minimum support. " + "(default = 1.0)", "U", 1,
            "-U <upper bound for minimum support>"));
    newVector.addElement(new Option(string5, "M", 1, "-M <lower bound for minimum support>"));
    newVector.addElement(new Option(string6 + string7, "S", 1, "-S <significance level>"));
    newVector.addElement(new Option(string8, "I", 0, "-I"));
    newVector.addElement(
            new Option("\tRemove columns that contain " + "all missing values (default = no)", "R", 0, "-R"));
    newVector.addElement(new Option("\tReport progress iteratively. (default " + "= no)", "V", 0, "-V"));
    newVector.addElement(new Option(string9, "A", 0, "-A"));
    newVector.addElement(new Option(stringZeroAsMissing, "Z", 0, "-Z"));
    newVector.addElement(new Option(string10, "c", 1, "-c <the class index>"));

    return newVector.elements();
}

From source file:cba.Apriori.java

License:Open Source License

/** 
 * Method that finds all association rules and performs significance test.
 *
 * @throws Exception if an attribute is numeric
 *//*  w w w . j  a va  2 s  . c  om*/
private void findRulesBruteForce() throws Exception {

    FastVector[] rules;

    // Build rules
    for (int j = 1; j < m_Ls.size(); j++) {
        FastVector currentItemSets = (FastVector) m_Ls.elementAt(j);
        Enumeration enumItemSets = currentItemSets.elements();
        while (enumItemSets.hasMoreElements()) {
            AprioriItemSet currentItemSet = (AprioriItemSet) enumItemSets.nextElement();
            //AprioriItemSet currentItemSet = new AprioriItemSet((ItemSet)enumItemSets.nextElement());
            rules = currentItemSet.generateRulesBruteForce(m_minMetric, m_metricType, m_hashtables, j + 1,
                    m_instances.numInstances(), m_significanceLevel);
            for (int k = 0; k < rules[0].size(); k++) {
                m_allTheRules[0].addElement(rules[0].elementAt(k));
                m_allTheRules[1].addElement(rules[1].elementAt(k));
                m_allTheRules[2].addElement(rules[2].elementAt(k));

                m_allTheRules[3].addElement(rules[3].elementAt(k));
                m_allTheRules[4].addElement(rules[4].elementAt(k));
                m_allTheRules[5].addElement(rules[5].elementAt(k));
            }
        }
    }
}

From source file:cba.Apriori.java

License:Open Source License

/** 
 * Method that finds all association rules.
 *
 * @throws Exception if an attribute is numeric
 *//*  ww  w . ja  va  2s  . c  o m*/
private void findRulesQuickly() throws Exception {

    FastVector[] rules;

    // Build rules
    for (int j = 1; j < m_Ls.size(); j++) {
        FastVector currentItemSets = (FastVector) m_Ls.elementAt(j);
        Enumeration enumItemSets = currentItemSets.elements();
        while (enumItemSets.hasMoreElements()) {
            AprioriItemSet currentItemSet = (AprioriItemSet) enumItemSets.nextElement();
            //AprioriItemSet currentItemSet = new AprioriItemSet((ItemSet)enumItemSets.nextElement());
            rules = currentItemSet.generateRules(m_minMetric, m_hashtables, j + 1);
            for (int k = 0; k < rules[0].size(); k++) {
                m_allTheRules[0].addElement(rules[0].elementAt(k));
                m_allTheRules[1].addElement(rules[1].elementAt(k));
                m_allTheRules[2].addElement(rules[2].elementAt(k));
            }
        }
    }
}

From source file:cba.Apriori.java

License:Open Source License

/** 
 * Method that finds all class association rules.
 *
 * @throws Exception if an attribute is numeric
 *//*  ww  w . j a  v  a2 s  .  co  m*/
private void findCarRulesQuickly() throws Exception {

    FastVector[] rules;

    // Build rules
    for (int j = 0; j < m_Ls.size(); j++) {
        FastVector currentLabeledItemSets = (FastVector) m_Ls.elementAt(j);
        Enumeration enumLabeledItemSets = currentLabeledItemSets.elements();
        while (enumLabeledItemSets.hasMoreElements()) {
            LabeledItemSet currentLabeledItemSet = (LabeledItemSet) enumLabeledItemSets.nextElement();
            rules = currentLabeledItemSet.generateRules(m_minMetric, false);
            for (int k = 0; k < rules[0].size(); k++) {
                m_allTheRules[0].addElement(rules[0].elementAt(k));
                m_allTheRules[1].addElement(rules[1].elementAt(k));
                m_allTheRules[2].addElement(rules[2].elementAt(k));
            }
        }
    }
}

From source file:cba.AprioriItemSet.java

License:Open Source License

/**
 * Generates rules with more than one item in the consequence.
 *
 * @param rules all the rules having (k-1)-item sets as consequences
 * @param numItemsInSet the size of the item set for which the rules
 * are to be generated//from w  w  w . j a  v a  2  s.c  om
 * @param numItemsInConsequence the value of (k-1)
 * @param minConfidence the minimum confidence a rule has to have
 * @param hashtables the hashtables containing all(!) previously generated
 * item sets
 * @return all the rules having (k)-item sets as consequences
 */
private final FastVector[] moreComplexRules(FastVector[] rules, int numItemsInSet, int numItemsInConsequence,
        double minConfidence, FastVector hashtables) {

    AprioriItemSet newPremise;
    FastVector[] result, moreResults;
    FastVector newConsequences, newPremises = new FastVector(), newConf = new FastVector();
    Hashtable hashtable;

    if (numItemsInSet > numItemsInConsequence + 1) {
        hashtable = (Hashtable) hashtables.elementAt(numItemsInSet - numItemsInConsequence - 2);
        newConsequences = mergeAllItemSets(rules[1], numItemsInConsequence - 1, m_totalTransactions);
        Enumeration enu = newConsequences.elements();
        while (enu.hasMoreElements()) {
            AprioriItemSet current = (AprioriItemSet) enu.nextElement();
            current.m_counter = m_counter;
            newPremise = subtract(current);
            newPremise.m_counter = ((Integer) hashtable.get(newPremise)).intValue();
            newPremises.addElement(newPremise);
            newConf.addElement(new Double(confidenceForRule(newPremise, current)));
        }
        result = new FastVector[3];
        result[0] = newPremises;
        result[1] = newConsequences;
        result[2] = newConf;
        pruneRules(result, minConfidence);
        moreResults = moreComplexRules(result, numItemsInSet, numItemsInConsequence + 1, minConfidence,
                hashtables);
        if (moreResults != null)
            for (int i = 0; i < moreResults[0].size(); i++) {
                result[0].addElement(moreResults[0].elementAt(i));
                result[1].addElement(moreResults[1].elementAt(i));
                result[2].addElement(moreResults[2].elementAt(i));
            }
        return result;
    } else
        return null;
}

From source file:cba.ItemSet.java

License:Open Source License

/**
 * Updates counters for a set of item sets and a set of instances.
 *
 * @param itemSets the set of item sets which are to be updated
 * @param instances the instances to be used for updating the counters
 *//*from  w ww  .j  a v a 2  s  .  c  om*/
public static void upDateCounters(FastVector itemSets, Instances instances) {

    for (int i = 0; i < instances.numInstances(); i++) {
        Enumeration enu = itemSets.elements();
        while (enu.hasMoreElements())
            ((ItemSet) enu.nextElement()).upDateCounter(instances.instance(i));
    }
}

From source file:com.entopix.maui.filters.MauiFilter.java

License:Open Source License

/**
 * Input an instance for filtering. Ordinarily the instance is processed and
 * made available for output immediately. Some filters require all instances
 * be read before producing output.//w  w  w .j  av  a  2s. c  o m
 *
 * @param instance the input instance
 * @return true if the filtered instance may now be collected with output().
 * @exception Exception if the input instance was not of the correct format
 * or if there was a problem with the filtering.
 */
@SuppressWarnings("unchecked")
public boolean input(Instance instance) throws MauiFilterException {

    if (getInputFormat() == null) {
        throw new MauiFilterException("No input instance format defined");
    }
    if (m_NewBatch) {
        resetQueue();
        m_NewBatch = false;
    }

    if (debugMode) {
        log.info("-- Reading instance");
    }

    try {
        phraseFilter.input(instance);
        phraseFilter.batchFinished();
        instance = phraseFilter.output();
    } catch (Exception e) {
        throw new MauiFilterException("Error applying PhraseFilter ");
    }

    if (vocabularyName.equals("none")) {
        try {
            numbersFilter.input(instance);
            numbersFilter.batchFinished();
            instance = numbersFilter.output();
        } catch (Exception e) {
            throw new MauiFilterException("Error applying NumbersFilter ");
        }
    }

    if (globalDictionary == null) {

        bufferInput(instance);
        return false;

    } else {

        FastVector vector = convertInstance(instance, false);
        Enumeration<Instance> en = vector.elements();
        while (en.hasMoreElements()) {
            Instance inst = en.nextElement();
            push(inst);
        }
        return true;
    }

}

From source file:com.entopix.maui.filters.MauiFilter.java

License:Open Source License

/**
 * Sets output format and converts pending input instances.
 *//*from  w  w  w  .  j  a  v  a 2  s.co m*/
@SuppressWarnings("unchecked")
private void convertPendingInstances() {

    if (debugMode) {
        log.info("--- Converting pending instances");
    }

    // Create output format for filter
    FastVector atts = new FastVector();
    for (int i = 1; i < getInputFormat().numAttributes(); i++) {
        if (i == documentAtt) {
            atts.addElement(new Attribute("Candidate_name", (FastVector) null)); // 0
            atts.addElement(new Attribute("Candidate_original", (FastVector) null)); // 1

            atts.addElement(new Attribute("Term_frequency")); // 0
            atts.addElement(new Attribute("IDF")); // 1
            atts.addElement(new Attribute("TFxIDF")); // 2 
            atts.addElement(new Attribute("First_occurrence")); // 3
            atts.addElement(new Attribute("Last_occurrence")); // 4
            atts.addElement(new Attribute("Spread")); // 5
            atts.addElement(new Attribute("Domain_keyphraseness")); // 6
            atts.addElement(new Attribute("Length")); // 7
            atts.addElement(new Attribute("Generality")); // 8
            atts.addElement(new Attribute("Node_degree")); // 9
            atts.addElement(new Attribute("Wikipedia_keyphraseness")); // 10
            atts.addElement(new Attribute("Wikipedia_inlinks")); // 11
            atts.addElement(new Attribute("Wikipedia_generality")); // 12

            atts.addElement(new Attribute("Probability")); // 16
            atts.addElement(new Attribute("Rank")); // 17

        } else if (i == keyphrasesAtt) {
            if (nominalClassValue) {
                FastVector vals = new FastVector(2);
                vals.addElement("False");
                vals.addElement("True");
                atts.addElement(new Attribute("Keyphrase?", vals));
            } else {
                atts.addElement(new Attribute("Keyphrase?"));
            }
        } else {
            atts.addElement(getInputFormat().attribute(i));
        }
    }

    Instances outFormat = new Instances("mauidata", atts, 0);
    setOutputFormat(outFormat);

    // Convert pending input instances into output data
    for (int i = 0; i < getInputFormat().numInstances(); i++) {
        Instance current = getInputFormat().instance(i);
        FastVector vector = convertInstance(current, true);
        Enumeration<Instance> en = vector.elements();
        while (en.hasMoreElements()) {
            Instance inst = (Instance) en.nextElement();
            push(inst);
        }
    }
}

From source file:com.openkm.kea.filter.KEAFilter.java

License:Open Source License

/**
 * Input an instance for filtering. Ordinarily the instance is processed
 * and made available for output immediately. Some filters require all
 * instances be read before producing output.
 *
 * @param instance the input instance/*from w ww  .j a  va  2s.  c  o  m*/
 * @return true if the filtered instance may now be
 * collected with output().
 * @exception Exception if the input instance was not of the correct 
 * format or if there was a problem with the filtering.
 */
@SuppressWarnings("unchecked")
public boolean input(Instance instance) throws Exception {
    if (getInputFormat() == null) {
        throw new Exception("No input instance format defined");
    }
    if (m_NewBatch) {
        resetQueue();
        m_NewBatch = false;
    }

    if (m_Debug) {
        log.info("-- Reading instance");
    }

    m_PunctFilter.input(instance);
    m_PunctFilter.batchFinished();
    instance = m_PunctFilter.output();

    if (m_vocabulary.equals("none")) {
        m_NumbersFilter.input(instance);
        m_NumbersFilter.batchFinished();
        instance = m_NumbersFilter.output();
    }

    if (m_Dictionary == null) {
        bufferInput(instance);
        return false;
    } else {
        FastVector vector = convertInstance(instance, false);
        Enumeration<Instance> en = vector.elements();
        while (en.hasMoreElements()) {
            Instance inst = en.nextElement();
            push(inst);
        }
        return true;
    }

}