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

📄 multisimplesetpredicate.java

📁 一个数据挖掘软件ALPHAMINERR的整个过程的JAVA版源代码
💻 JAVA
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/**
 * Title: XELOPES Data Mining Library
 * Description: The XELOPES library is an open platform-independent and data-source-independent library for Embedded Data Mining.
 * Copyright: Copyright (c) 2002 Prudential Systems Software GmbH
 * Company: ZSoft (www.zsoft.ru), Prudsys (www.prudsys.com)
 * @author Michael Thess
 * @version 1.2
 */

package com.prudsys.pdm.Input.Multidimensional;

import java.util.Vector;

import com.prudsys.pdm.Core.CategoricalAttribute;
import com.prudsys.pdm.Core.Category;
import com.prudsys.pdm.Core.MiningAttribute;
import com.prudsys.pdm.Core.MiningDataSpecification;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Core.NumericAttribute;
import com.prudsys.pdm.Input.Predicates.SimpleSetPredicate;
import com.prudsys.pdm.Utils.IntHashtable;
import com.prudsys.pdm.Utils.IntVector;

/**
  * SimpleSetPredicate for evaluations on multidimensional stream.
  */
public class MultiSimpleSetPredicate extends SimpleSetPredicate implements MultiPredicate
{
  // -----------------------------------------------------------------------
  //  Constructors
  // -----------------------------------------------------------------------
  /**
   * Empty constructor.
   */
  public MultiSimpleSetPredicate()
  {
  }

  /**
   * SimpleSetPredicate with condition elements.
   * Set to be specified via setValue methods.
   *
   * @param attribute attribute for evaluation
   * @param op operator for evaluation
   * @param valuesNumber cardinality of comparison set
   */
  public MultiSimpleSetPredicate(MiningAttribute attribute, int op, int valuesNumber) {

    super(attribute, op, valuesNumber);
  }

  // -----------------------------------------------------------------------
  //  Evaluate predicate
  // -----------------------------------------------------------------------
  /**
   * Evaluates predicates for all mining vectors of MultidimensionalStream.
   *
   * @param multidimStream multidimensional stream for predicate evaluations
   * @return evaluation result as array for each mining vector
   * @exception MiningException can't evaluate mining vector
   */
  public boolean[] evaluate(MultidimensionalStream multidimStream)
    throws MiningException {

    int nVec = multidimStream.nVec;
    boolean[] vecBool = new boolean[nVec];

    MiningDataSpecification metaData = multidimStream.getMetaData();
    if (metaData == null)
      throw new MiningException("multidimStream has no meta data");
    MiningAttribute ma = metaData.getMiningAttribute(name);
    if (ma == null)
      throw new MiningException("MiningAttribute "+name+" not found in multidimStream");
    int ind = metaData.getAttributeIndex(ma);

    if (ma instanceof CategoricalAttribute)
    {
      CategoricalAttribute cAtt = (CategoricalAttribute) ma;
      if ( cAtt.isUnstoredCategories() )
        throw new MiningException("SimpleSetPredicate: categorical attribute can't be of unstoredCategories type");

      Vector categs = new Vector();
      IntHashtable hcat = new IntHashtable();
      for (int i = 0; i < values.size(); i++) {
        Category catValue = new Category( values.elementAt(i) );
        if (op == IS_IN)
          categs.addElement(catValue);
        else {
          double key = cAtt.getKey(catValue);
          if ( Category.isMissingValue(key) )
            continue;
          hcat.put( (int) key, 0 );
        };
      }
      if (op == IS_NOT_IN) {
        for (int i = 0; i < cAtt.getCategoriesNumber(); i++) {
          if (hcat.get(i) != null)
            continue;
          Category cat = cAtt.getCategory(i);
          categs.addElement(cat);
        }
      }
      for (int i = 0; i < categs.size(); i++) {
        double key = cAtt.getKey( (Category) categs.elementAt(i) );
        if ( Category.isMissingValue(key) )
          throw new MiningException("SimpleSetPredicate: unknown category");
        int ikey = (int) key;

        IntVector vecs = (IntVector) multidimStream.dimVec[ind].elementAt(ikey);
        for (int k = 0; k < vecs.size(); k++) {
          vecBool[ vecs.IntegerAt(k) ] = true;
        };
      };

      return vecBool;
    }
    else if (ma instanceof NumericAttribute)
    {
      throw new MiningException("selection attribute can't be numeric");
    }
    else throw new MiningException("SimpleSetPredicate: unknown attribute type");
  }
}

⌨️ 快捷键说明

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