⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multidimensionalstream.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         attTypes[i] = 2;  // numeric
       else if ( ((CategoricalAttribute)ma).isUnstoredCategories() )
         attTypes[i] = 1;  // categorical, of unstoredCategories type
       else
         attTypes[i] = 0;  // categorical, not of unstoredCategories type
     };

     // Fill dimension vactor:
     dimVec = new Vector[nAtt];
     for (int i = 0; i < nAtt; i++)
       dimVec[i] = new Vector();
     nVec = 0;
     while ( miningInputStream.next() ) {
       MiningVector mv = miningInputStream.read();
       for (int i = 0; i < nAtt; i++) {
         if (attTypes[i] > 0) continue;

         double dkey = mv.getValue(i);
         if ( Category.isMissingValue(dkey) )
           continue;

         int key = (int) dkey;
         if ( key >= dimVec[i].size() ) {
           for (int j = dimVec[i].size(); j < key; j++)
             dimVec[i].addElement(new IntVector());

           IntVector vecs = new IntVector();
           vecs.addElement(nVec);
           dimVec[i].addElement(vecs);
         }
         else {
           IntVector vecs = (IntVector) dimVec[i].elementAt(key);
           vecs.addElement(nVec);
         };
       };

       nVec = nVec + 1;

       if ((nVec / 10000)*10000 == nVec) System.out.println("nVec = " + nVec);
//       if (nVec > 2500000) break;
     };

     // Reset cursor:
     cursorPosition = -1;
  }

  // -----------------------------------------------------------------------
  //  Runs selection
  // -----------------------------------------------------------------------
  /**
   * Executes fast selection. All previous selection conditions are
   * removed.
   *
   * @param selAtts selection conditions
   * @return numbers of selected vectors
   * @exception MiningException couldn't run selection
   */
  public IntVector runSelections(SelectAttribute[] selAtts) throws MiningException {

    // No selection condition, return null:
    if (selAtts == null || selAtts.length == 0) {
      selVec = null;
      return selVec;
    }
    else
      selVec = new IntVector();

    // Call readMultidimensionalStreamData method first:
    if (dimVec == null)
      throw new MiningException("run readMultidimensionalStreamData method first");

    // Init selection:
    nSelAtt  = selAtts.length;
    vecSums  = new int[nVec];

    // Add the selection attribute conditions to vecSum:
    for (int i = 0; i < nSelAtt; i++)
      updateVecSums(selAtts[i], true);

    // Find selected vectors:
    for (int i = 0; i < nVec; i++)
      if ( vecSums[i] == nSelAtt ) selVec.addElement(i);

    // Reset cursor:
    cursorPosition = -1;

    // Run ordering (if defined):
    runOrdering();

    return selVec;
  }

  /**
   * Adds selection and executes the updated selections.
   *
   * @param selAtt new selection condition to be added
   * @return numbers of selected vectors
   * @exception MiningException couldn't run selection
   */
  public IntVector addSelection(SelectAttribute selAtt) throws MiningException {

    // No selection condition, return 'as is':
    if (selAtt == null)
      return selVec;
    else
      selVec = new IntVector();

    // Run selection:
    nSelAtt = nSelAtt + 1;

    // Add the selection attribute condition to vecSum:
    updateVecSums(selAtt, true);

    // Find selected vectors:
    for (int i = 0; i < nVec; i++)
      if ( vecSums[i] == nSelAtt ) selVec.addElement(i);

    // Reset cursor:
    cursorPosition = -1;

    // Run ordering (if defined):
    runOrdering();

    return selVec;
  }

  /**
   * Removes selection and executes the updated selections.
   *
   * @param selAtt new selection condition to be removed
   * @return numbers of selected vectors
   * @exception MiningException couldn't run selection
   */
  public IntVector removeSelection(SelectAttribute selAtt) throws MiningException {

    // No selection condition, return 'as is':
    if (selAtt == null)
      return selVec;
    else
      selVec = new IntVector();

    // Run selection:
    nSelAtt = nSelAtt - 1;

    // Remove the selection attribute condition from vecSum:
    updateVecSums(selAtt, false);

    // Find selected vectors:
    for (int i = 0; i < nVec; i++)
      if ( vecSums[i] == nSelAtt ) selVec.addElement(i);

    // Reset cursor:
    cursorPosition = -1;

    // Run ordering (if defined):
    runOrdering();

    return selVec;
  }

  /**
   * Update the vecSums vector containing the number of selections
   * meeting the selection conditions by applying a new
   * selection attribute.
   *
   * @param selAtt selection attribute to be applied
   * @param increaseOrDecrease add (true) or remove the selection attribute condition
   * @throws MiningException couldn't update the selection vector
   */
  private void updateVecSums(SelectAttribute selAtt, boolean increaseOrDecrease) throws MiningException {

    // Get selection attribute and check if valid:
    String sname = selAtt.getName();
    MiningAttribute sAtt = metaData.getMiningAttribute(sname);
    if (sAtt == null)
      throw new MiningException("unknown attribute name in selection attribute");
    int ind = metaData.getAttributeIndex(sAtt);
    if (attTypes[ind] == 1)
      throw new MiningException("selection attribute '" + sname + "' can't be of unstoredCategories type");
    else if (attTypes[ind] == 2)
      throw new MiningException("selection attribute '" + sname + "' can't be numeric");
    else if (attTypes[ind] == 3)
      throw new MiningException("selection attribute '" + sname + "' was excluded from selection");

    // Get selection categories:
    CategoricalAttribute cAtt = (CategoricalAttribute) sAtt;
    Vector catNames = selAtt.getCategories();
    for (int j = 0; j < catNames.size(); j++) {
      double key = cAtt.getKey( new Category(catNames.elementAt(j)) );
      if ( Category.isMissingValue(key) )
         throw new MiningException("unknown category name in selection attribute");

      int ikey = (int) key;
      if ( ikey > dimVec[ind].size() ) {
        System.out.println("warning: category '" + catNames.elementAt(j) + "' " +
                           "has never occured in initial data of multi stream");
        continue;
      };

      IntVector vecs = (IntVector) dimVec[ind].elementAt(ikey);
      for (int k = 0; k < vecs.size(); k++) {
        if (increaseOrDecrease)
          vecSums[ vecs.IntegerAt(k) ]++;
        else
          vecSums[ vecs.IntegerAt(k) ]--;
      };
    };
  }

  /**
   * Executes fast selection using a predicate. Internally the predicate
   * is converted into a multi predicate and the method runSelectionsMultiPredicate
   * is applied. This method does not affect the conditions defined by
   * SelectAttribute's.
   *
   * @param selPred selection predicate
   * @return numbers of selected vectors
   * @exception MiningException couldn't run selection
   */
  public IntVector runSelectionsPredicate(Predicate selPred) throws MiningException {

    MultiPredicate mpred = MultiPredicateConvert.convertToMultiPredicate(selPred);
    return runSelectionsMultiPredicate(mpred);
  }

  /**
   * Executes fast selection using a multi predicate. This method does not affect
   * the conditions defined by SelectAttribute's.
   *
   * @param selMultPred selection multi predicate
   * @return numbers of selected vectors
   * @exception MiningException couldn't run selection
   */
  public IntVector runSelectionsMultiPredicate(MultiPredicate selMultPred) throws MiningException {

    // No selection predicate, return null:
    if (selMultPred == null) {
      selVec = null;
      return selVec;
    }
    else
      selVec = new IntVector();

    // Call readMultidimensionalStreamData method first:
    if (dimVec == null)
      throw new MiningException("run readMultidimensionalStreamData method first");

    // Run selection:
    boolean[] vecBool = selMultPred.evaluate(this);

    // Find selected vectors:
    for (int i = 0; i < nVec; i++)
      if (vecBool[i]) selVec.addElement(i);

    // Reset cursor:
    cursorPosition = -1;

    // Run ordering (if defined):
    runOrdering();

    return selVec;
  }

  // -----------------------------------------------------------------------
  //  Runs ordering
  // -----------------------------------------------------------------------
  /** For Quicksort. Use Selectsort if set is lower this number. */
  static final int SORT_SMALL_SET = 15;

  /** Vector of ordering conditions. */
  protected Vector orderings = new Vector();

  /** Number of attributes of ordering mining vector. */
  private int nAttOrd;

  /** Indexes of attributes of ordering mining vector. */
  private int[] indOrd;

  /** Attribute types of ordering mining vector (true: categ, false: num). */
  private boolean[] attTypeOrd;

  /** Ordering types of mining vector (+1 GT if UP, -1 GT if DOWN). */
  private int[] resTypeOrd;

  /** Number of selected vectors. */
  int nSelVecOrd = 0;

  /** Permutation indexes of selected object. */
  private int[] selVecOrd;

  /**
   * Sets ordering conditions. All previous ordering conditions
   * are removed.
   *
   * @param ordAtts new ordering conditions, null to clear
   */
  public void setOrdering(OrderAttribute[] ordAtts) {

    orderings.clear();
    if (ordAtts == null)
      return;

    for (int i = 0; i < ordAtts.length; i++)
      orderings.addElement(ordAtts[i]);
  }

  /**
   * Add new ordering condition to current list.
   *
   * @param ordAtt new ordering condition to add
   */
  public void addOrdering(OrderAttribute ordAtt) {

    orderings.addElement(ordAtt);
  }

  /**
   * Removes ordering condition from current list.
   *
   * @param ordAtt ordering condition to be removed
   * @return true if order condition found in list
   */
  public boolean removeOrdering(OrderAttribute ordAtt) {

    return orderings.remove(ordAtt);
  }

  /**
   * Returns vector of order attributes.
   *
   * @return vector of order attributes
   */
  public Vector getOrderingAttributes()
  {
    return orderings;
  }

  /**
   * Executes ordering from ordering list.
   *
   * @exception MiningException initial stream does not support 'move' operation
   */
  public void runOrdering() throws MiningException {

    int nsize = orderings.size();
    if (nsize == 0)
      return;
    OrderAttribute[] ordAtts = new OrderAttribute[nsize];
    for (int i = 0; i < nsize; i++)
      ordAtts[i] = (OrderAttribute) orderings.elementAt(i);
    runOrdering(ordAtts);
  }

  /**
   * Executes ordering which is passed as argument.
   *
   * @param ordAtts order conditions
   * @exception MiningException initial stream does not support 'move' operation
   */
  public void runOrdering(OrderAttribute[] ordAtts) throws MiningException {

    if (ordAtts == null || ordAtts.length == 0)
      return;

    // No move operation allowed => stop:
    if (!allowsMove)
      throw new MiningException("cannot run ordering: initial stream must support 'move'");

    // No selection, fill selVec object:
    if (selVec == null) {
      selVec = new IntVector();
      if (dimVec == null)  // readMultidimensionalStreamData wasn't called
        nVec = miningInputStream.getVectorsNumber();
      for (int i = 0;  i < nVec; i++)
        selVec.addElement(i);
    }

    // Fill permutation vector:
    nSelVecOrd = selVec.size();
    selVecOrd  = new int[nSelVecOrd];
    for (int i = 0; i < nSelVecOrd; i++)
      selVecOrd[i] = i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -