Package weka.core

Examples of weka.core.FastVector


        pred = Utils.missingValue();
      }
      updateStatsForClassifier(dist, instance);
      if (storePredictions) {
        if (m_Predictions == null)
          m_Predictions = new FastVector();
        m_Predictions.addElement(new NominalPrediction(instance.classValue(), dist,
                                                       instance.weight()));
      }
    } else {
      pred = dist[0];
      updateStatsForPredictor(pred, instance);
      if (storePredictions) {
        if (m_Predictions == null)
          m_Predictions = new FastVector();
        m_Predictions.addElement(new NumericPrediction(instance.classValue(), pred,
                                                       instance.weight()));
      }
    }
View Full Code Here


   * Initializes the members.
   */
  protected void initialize() {
    super.initialize();
   
    m_PlotShapes             = new FastVector();
    m_PlotSizes              = new FastVector();
    m_Classifier             = null;
    m_ClassIndex             = -1;
    m_Evaluation             = null;
    m_SaveForVisualization   = true;
    m_MinimumPlotSizeNumeric = ExplorerDefaults.getClassifierErrorsMinimumPlotSizeNumeric();
View Full Code Here

   * if instances are not saved for visualization.
   *
   * @see #getSaveForVisualization()
   */
  protected void determineFormat() {
    FastVector   hv;
    Attribute   predictedClass;
    Attribute   classAt;
    FastVector   attVals;
    int    i;
   
    if (!m_SaveForVisualization) {
      m_PlotInstances = null;
      return;
    }
   
    hv = new FastVector();

    classAt = m_Instances.attribute(m_ClassIndex);
    if (classAt.isNominal()) {
      attVals = new FastVector();
      for (i = 0; i < classAt.numValues(); i++)
  attVals.addElement(classAt.value(i));
      predictedClass = new Attribute("predicted" + classAt.name(), attVals);
    }
    else {
      predictedClass = new Attribute("predicted" + classAt.name());
    }
View Full Code Here

  protected void addPredictionIntervals() {
    int    maxNum;
    int    num;
    int    i;
    int    n;
    FastVector  preds;
    FastVector  atts;
    Instances  data;
    Instance  inst;
    Instance  newInst;
    double[]  values;
    double[][]  predInt;
   
    // determine the maximum number of intervals
    maxNum = 0;
    preds  = m_Evaluation.predictions();
    for (i = 0; i < preds.size(); i++) {
      num = ((NumericPrediction) preds.elementAt(i)).predictionIntervals().length;
      if (num > maxNum)
  maxNum = num;
    }
   
    // create new header
    atts = new FastVector();
    for (i = 0; i < m_PlotInstances.numAttributes(); i++)
      atts.addElement(m_PlotInstances.attribute(i));
    for (i = 0; i < maxNum; i++) {
      atts.addElement(new Attribute("predictionInterval_" + (i+1) + "-lowerBoundary"));
      atts.addElement(new Attribute("predictionInterval_" + (i+1) + "-upperBoundary"));
      atts.addElement(new Attribute("predictionInterval_" + (i+1) + "-width"));
    }
    data = new Instances(m_PlotInstances.relationName(), atts, m_PlotInstances.numInstances());
    data.setClassIndex(m_PlotInstances.classIndex());
   
    // update data
View Full Code Here

      m_ClassFilters = null;

    } else if (m_Method == METHOD_1_AGAINST_1) {
      // generate fastvector of pairs
      FastVector pairs = new FastVector();
      for (int i=0; i<insts.numClasses(); i++) {
  for (int j=0; j<insts.numClasses(); j++) {
    if (j<=i) continue;
    int[] pair = new int[2];
    pair[0] = i; pair[1] = j;
    pairs.addElement(pair);
  }
      }

      numClassifiers = pairs.size();
      m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, numClassifiers);
      m_ClassFilters = new Filter[numClassifiers];
      m_SumOfWeights = new double[numClassifiers];

      // generate the classifiers
      for (int i=0; i<numClassifiers; i++) {
  RemoveWithValues classFilter = new RemoveWithValues();
  classFilter.setAttributeIndex("" + (insts.classIndex() + 1));
  classFilter.setModifyHeader(true);
  classFilter.setInvertSelection(true);
  classFilter.setNominalIndicesArr((int[])pairs.elementAt(i));
  Instances tempInstances = new Instances(insts, 0);
  tempInstances.setClassIndex(-1);
  classFilter.setInputFormat(tempInstances);
  newInsts = Filter.useFilter(insts, classFilter);
  if (newInsts.numInstances() > 0) {
    newInsts.setClassIndex(insts.classIndex());
    m_Classifiers[i].buildClassifier(newInsts);
    m_ClassFilters[i] = classFilter;
          m_SumOfWeights[i] = newInsts.sumOfWeights();
  } else {
    m_Classifiers[i] = null;
    m_ClassFilters[i] = null;
  }
      }

      // construct a two-class header version of the dataset
      m_TwoClassDataset = new Instances(insts, 0);
      int classIndex = m_TwoClassDataset.classIndex();
      m_TwoClassDataset.setClassIndex(-1);
      m_TwoClassDataset.deleteAttributeAt(classIndex);
      FastVector classLabels = new FastVector();
      classLabels.addElement("class0");
      classLabels.addElement("class1");
      m_TwoClassDataset.insertAttributeAt(new Attribute("class", classLabels),
            classIndex);
      m_TwoClassDataset.setClassIndex(classIndex);

    } else { // use error correcting code style methods
View Full Code Here

 
      case STRING :
  //System.err.println("String --> nominal");
  attributeTypes[i - 1] = Attribute.NOMINAL;
  nominalIndexes[i - 1] = new Hashtable();
  nominalStrings[i - 1] = new FastVector();
  break;
      case TEXT:
  //System.err.println("Text --> string");
  attributeTypes[i - 1] = Attribute.STRING;
  nominalIndexes[i - 1] = new Hashtable();
  nominalStrings[i - 1] = new FastVector();
  break;
      case BOOL:
  //System.err.println("boolean --> nominal");
  attributeTypes[i - 1] = Attribute.NOMINAL;
  nominalIndexes[i - 1] = new Hashtable();
  nominalIndexes[i - 1].put("false", new Double(0));
  nominalIndexes[i - 1].put("true", new Double(1));
  nominalStrings[i - 1] = new FastVector();
  nominalStrings[i - 1].addElement("false");
  nominalStrings[i - 1].addElement("true");
  break;
      case DOUBLE:
  //System.err.println("BigDecimal --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case BYTE:
  //System.err.println("byte --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case SHORT:
  //System.err.println("short --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case INTEGER:
  //System.err.println("int --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case LONG:
  //System.err.println("long --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case FLOAT:
  //System.err.println("float --> numeric");
  attributeTypes[i - 1] = Attribute.NUMERIC;
  break;
      case DATE:
  attributeTypes[i - 1] = Attribute.DATE;
  break;
      case TIME:
  attributeTypes[i - 1] = Attribute.DATE;
  break;
      default:
  //System.err.println("Unknown column type");
  attributeTypes[i - 1] = Attribute.STRING;
      }
    }

    // For sqlite
    // cache column names because the last while(rs.next()) { iteration for
    // the tuples below will close the md object: 
    Vector<String> columnNames = new Vector<String>();
    for (int i = 0; i < numAttributes; i++) {
      columnNames.add(md.getColumnLabel(i + 1));
    }

    // Step through the tuples
    if (m_Debug)
      System.err.println("Creating instances...");
    FastVector instances = new FastVector();
    int rowCount = 0;
    while(rs.next()) {
      if (rowCount % 100 == 0) {
        if (m_Debug)  {
    System.err.print("read " + rowCount + " instances \r");
    System.err.flush();
        }
      }
      double[] vals = new double[numAttributes];
      for(int i = 1; i <= numAttributes; i++) {
  /*switch (md.getColumnType(i)) {
  case Types.CHAR:
  case Types.VARCHAR:
  case Types.LONGVARCHAR:
  case Types.BINARY:
  case Types.VARBINARY:
  case Types.LONGVARBINARY:*/
  switch (translateDBColumnType(md.getColumnTypeName(i))) {
  case STRING :
    String str = rs.getString(i);
   
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      Double index = (Double)nominalIndexes[i - 1].get(str);
      if (index == null) {
        index = new Double(nominalStrings[i - 1].size());
        nominalIndexes[i - 1].put(str, index);
        nominalStrings[i - 1].addElement(str);
      }
      vals[i - 1] = index.doubleValue();
    }
    break;
  case TEXT:
    String txt = rs.getString(i);
   
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      Double index = (Double)nominalIndexes[i - 1].get(txt);
      if (index == null) {
        index = new Double(nominalStrings[i - 1].size());
        nominalIndexes[i - 1].put(txt, index);
        nominalStrings[i - 1].addElement(txt);
      }
      vals[i - 1] = index.doubleValue();
    }
    break;
  case BOOL:
    boolean boo = rs.getBoolean(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (boo ? 1.0 : 0.0);
    }
    break;
  case DOUBLE:
    //    BigDecimal bd = rs.getBigDecimal(i, 4);
    double dd = rs.getDouble(i);
    // Use the column precision instead of 4?
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      //      newInst.setValue(i - 1, bd.doubleValue());
      vals[i - 1] =  dd;
    }
    break;
  case BYTE:
    byte by = rs.getByte(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)by;
    }
    break;
  case SHORT:
    short sh = rs.getShort(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)sh;
    }
    break;
  case INTEGER:
    int in = rs.getInt(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)in;
    }
    break;
  case LONG:
    long lo = rs.getLong(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)lo;
    }
    break;
  case FLOAT:
    float fl = rs.getFloat(i);
    if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
      vals[i - 1] = (double)fl;
    }
    break;
  case DATE:
          Date date = rs.getDate(i);
          if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
            // TODO: Do a value check here.
            vals[i - 1] = (double)date.getTime();
          }
          break;
  case TIME:
          Time time = rs.getTime(i);
          if (rs.wasNull()) {
      vals[i - 1] = Utils.missingValue();
    } else {
            // TODO: Do a value check here.
            vals[i - 1] = (double) time.getTime();
          }
          break;
  default:
    vals[i - 1] = Utils.missingValue();
  }
      }
      Instance newInst;
      if (m_CreateSparseData) {
  newInst = new SparseInstance(1.0, vals);
      } else {
  newInst = new DenseInstance(1.0, vals);
      }
      instances.addElement(newInst);
      rowCount++;
    }
    //disconnectFromDatabase();  (perhaps other queries might be made)
   
    // Create the header and add the instances to the dataset
    if (m_Debug)
      System.err.println("Creating header...");
    FastVector attribInfo = new FastVector();
    for (int i = 0; i < numAttributes; i++) {
      /* Fix for databases that uppercase column names */
      // String attribName = attributeCaseFix(md.getColumnName(i + 1));
      String attribName = attributeCaseFix(columnNames.get(i));
      switch (attributeTypes[i]) {
      case Attribute.NOMINAL:
  attribInfo.addElement(new Attribute(attribName, nominalStrings[i]));
  break;
      case Attribute.NUMERIC:
  attribInfo.addElement(new Attribute(attribName));
  break;
      case Attribute.STRING:
  Attribute att = new Attribute(attribName, (FastVector) null);
  attribInfo.addElement(att);
  for (int n = 0; n < nominalStrings[i].size(); n++) {
    att.addStringValue((String) nominalStrings[i].elementAt(n));
  }
  break;
      case Attribute.DATE:
  attribInfo.addElement(new Attribute(attribName, (String)null));
  break;
      default:
  throw new Exception("Unknown attribute type");
      }
    }
View Full Code Here

            : m_minSupport;
    }

    do {
      // Reserve space for variables
      m_Ls = new FastVector();
      m_hashtables = new FastVector();
      m_allTheRules = new FastVector[6];
      m_allTheRules[0] = new FastVector();
      m_allTheRules[1] = new FastVector();
      m_allTheRules[2] = new FastVector();
      //if (m_metricType != CONFIDENCE || m_significanceLevel != -1) {
  m_allTheRules[3] = new FastVector();
  m_allTheRules[4] = new FastVector();
  m_allTheRules[5] = new FastVector();
     // }
      sortedRuleSet = new FastVector[6];
      sortedRuleSet[0] = new FastVector();
      sortedRuleSet[1] = new FastVector();
      sortedRuleSet[2] = new FastVector();
      //if (m_metricType != CONFIDENCE || m_significanceLevel != -1) {
  sortedRuleSet[3] = new FastVector();
  sortedRuleSet[4] = new FastVector();
  sortedRuleSet[5] = new FastVector();
      //}
      if(!m_car){
        // Find large itemsets and rules
        findLargeItemSets();
        if (m_significanceLevel != -1 || m_metricType != CONFIDENCE)
View Full Code Here

  private void pruneRulesForUpperBoundSupport() {
    int necMaxSupport = (int)(m_upperBoundMinSupport * (double)m_instances.numInstances()+0.5);
   
    FastVector[] prunedRules = new FastVector[6];
    for (int i = 0; i < 6; i++) {
      prunedRules[i] = new FastVector();
    }
   
    for (int i = 0; i < m_allTheRules[0].size(); i++) {
      if (((ItemSet)m_allTheRules[1].elementAt(i)).support() <= necMaxSupport) {
        prunedRules[0].addElement(m_allTheRules[0].elementAt(i));
View Full Code Here

      +"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();
  }
View Full Code Here

   *
   * @throws Exception if an attribute is numeric
   */
  private void findLargeItemSets() throws Exception {
   
    FastVector kMinusOneSets, kSets;
    Hashtable hashtable;
    int necSupport, necMaxSupport,i = 0;
   
   
   
    // Find large itemsets

    // minimum support
    necSupport = (int)(m_minSupport * (double)m_instances.numInstances()+0.5);
    necMaxSupport = (int)(m_upperBoundMinSupport * (double)m_instances.numInstances()+0.5);
  
    kSets = AprioriItemSet.singletons(m_instances, m_treatZeroAsMissing);
    AprioriItemSet.upDateCounters(kSets,m_instances);
    kSets = AprioriItemSet.deleteItemSets(kSets, necSupport, m_instances.numInstances());
    if (kSets.size() == 0)
      return;
    do {
      m_Ls.addElement(kSets);
      kMinusOneSets = kSets;
      kSets = AprioriItemSet.mergeAllItemSets(kMinusOneSets, i, m_instances.numInstances());
      hashtable = AprioriItemSet.getHashtable(kMinusOneSets, kMinusOneSets.size());
      m_hashtables.addElement(hashtable);
      kSets = AprioriItemSet.pruneItemSets(kSets, hashtable);
      AprioriItemSet.upDateCounters(kSets, m_instances);
      kSets = AprioriItemSet.deleteItemSets(kSets, necSupport, m_instances.numInstances());
      i++;
View Full Code Here

TOP

Related Classes of weka.core.FastVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.