亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cfssubseteval.java

?? 一個數據挖掘系統的源碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:

/**
 *
 *   AgentAcademy - an open source Data Mining framework for
 *   training intelligent agents
 *
 *   Copyright (C)   2001-2003 AA Consortium.
 *
 *   This library is open source software; you can redistribute it
 *   and/or modify it under the terms of the GNU Lesser General
 *   Public License as published by the Free Software Foundation;
 *   either version 2.0 of the License, or (at your option) any later
 *   version.
 *
 *   This library 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 Lesser General Public
 *   License along with this library; if not, write to the Free
 *   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *   MA  02111-1307 USA
 *
 */

package  org.agentacademy.modules.dataminer.attributeSelection;

import java.util.BitSet;
import java.util.Enumeration;
import java.util.Vector;

import org.agentacademy.modules.dataminer.core.ContingencyTables;
import org.agentacademy.modules.dataminer.core.Instance;
import org.agentacademy.modules.dataminer.core.Instances;
import org.agentacademy.modules.dataminer.core.Matrix;
import org.agentacademy.modules.dataminer.core.Option;
import org.agentacademy.modules.dataminer.core.OptionHandler;
import org.agentacademy.modules.dataminer.core.Utils;
import org.agentacademy.modules.dataminer.filters.DiscretizeFilter;
import org.agentacademy.modules.dataminer.filters.Filter;
import org.apache.log4j.Logger;

/**
 * CFS attribute subset evaluator.
 * For more information see: <p>
 *
 * Hall, M. A. (1998). Correlation-based Feature Subset Selection for Machine
 * Learning. Thesis submitted in partial fulfilment of the requirements of the
 * degree of Doctor of Philosophy at the University of Waikato. <p>
 *
 * Valid options are:
 *
 * -M <br>
 * Treat missing values as a seperate value. <p>
 *
 * -L <br>
 * Include locally predictive attributes. <p>
 *
 * @author Mark Hall (mhall@cs.waikato.ac.nz)
 * @version $Revision: 1.3 $
 */
public class CfsSubsetEval
  extends SubsetEvaluator
  implements OptionHandler
{

 public static Logger                log = Logger.getLogger(CfsSubsetEval.class);
  /** The training instances */
  private Instances m_trainInstances;
  /** Discretise attributes when class in nominal */
  private DiscretizeFilter m_disTransform;
  /** The class index */
  private int m_classIndex;
  /** Is the class numeric */
  private boolean m_isNumeric;
  /** Number of attributes in the training data */
  private int m_numAttribs;
  /** Number of instances in the training data */
  private int m_numInstances;
  /** Treat missing values as seperate values */
  private boolean m_missingSeperate;
  /** Include locally predicitive attributes */
  private boolean m_locallyPredictive;
  /** Holds the matrix of attribute correlations */
  private Matrix m_corr_matrix;
  /** Standard deviations of attributes (when using pearsons correlation) */
  private double[] m_std_devs;
  /** Threshold for admitting locally predictive features */
  private double m_c_Threshold;

  /**
   * Returns a string describing this attribute evaluator
   * @return a description of the evaluator suitable for
   * displaying in the explorer/experimenter gui
   */
  public String globalInfo() {
    return "CfsSubsetEval :\n\nEvaluates the worth of a subset of attributes "
      +"by considering the individual predictive ability of each feature "
      +"along with the degree of redundancy between them.\n\n"
      +"Subsets of features that are highly correlated with the class "
      +"while having low intercorrelation are preferred.\n";
  }

  /**
   * Constructor
   */
  public CfsSubsetEval () {
    resetOptions();
  }


  /**
   * Returns an enumeration describing the available options.
   * @return an enumeration of all the available options.
   *
   **/
  public Enumeration listOptions () {
    Vector newVector = new Vector(3);
    newVector.addElement(new Option("\tTreat missing values as a seperate"
				    + "\n\tvalue.", "M", 0, "-M"));
    newVector.addElement(new Option("\tInclude locally predictive attributes"
				    + ".", "L", 0, "-L"));
    return  newVector.elements();
  }


  /**
   * Parses and sets a given list of options. <p>
   *
   * Valid options are:
   *
   * -M <br>
   * Treat missing values as a seperate value. <p>
   *
   * -L <br>
   * Include locally predictive attributes. <p>
   *
   * @param options the list of options as an array of strings
   * @exception Exception if an option is not supported
   *
   **/
  public void setOptions (String[] options)
    throws Exception
  {
    String optionString;
    resetOptions();
    setMissingSeperate(Utils.getFlag('M', options));
    setLocallyPredictive(Utils.getFlag('L', options));
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String locallyPredictiveTipText() {
    return "Identify locally predictive attributes. Iteratively adds "
      +"attributes with the highest correlation with the class as long "
      +"as there is not already an attribute in the subset that has a "
      +"higher correlation with the attribute in question";
  }

  /**
   * Include locally predictive attributes
   *
   * @param b true or false
   */
  public void setLocallyPredictive (boolean b) {
    m_locallyPredictive = b;
  }


  /**
   * Return true if including locally predictive attributes
   *
   * @return true if locally predictive attributes are to be used
   */
  public boolean getLocallyPredictive () {
    return  m_locallyPredictive;
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String missingSeperateTipText() {
    return "Treat missing as a separate value. Otherwise, counts for missing "
      +"values are distributed across other values in proportion to their "
      +"frequency.";
  }

  /**
   * Treat missing as a seperate value
   *
   * @param b true or false
   */
  public void setMissingSeperate (boolean b) {
    m_missingSeperate = b;
  }


  /**
   * Return true is missing is treated as a seperate value
   *
   * @return true if missing is to be treated as a seperate value
   */
  public boolean getMissingSeperate () {
    return  m_missingSeperate;
  }


  /**
   * Gets the current settings of CfsSubsetEval
   *
   * @return an array of strings suitable for passing to setOptions()
   */
  public String[] getOptions () {
    String[] options = new String[2];
    int current = 0;

    if (getMissingSeperate()) {
      options[current++] = "-M";
    }

    if (getLocallyPredictive()) {
      options[current++] = "-L";
    }

    while (current < options.length) {
      options[current++] = "";
    }

    return  options;
  }


  /**
   * Generates a attribute evaluator. Has to initialize all fields of the
   * evaluator that are not being set via options.
   *
   * CFS also discretises attributes (if necessary) and initializes
   * the correlation matrix.
   *
   * @param data set of instances serving as training data
   * @exception Exception if the evaluator has not been
   * generated successfully
   */
  public void buildEvaluator (Instances data)
    throws Exception
  {
    if (data.checkForStringAttributes()) {
      throw  new Exception("Can't handle string attributes!");
    }

    m_trainInstances = data;
    m_trainInstances.deleteWithMissingClass();
    m_classIndex = m_trainInstances.classIndex();
    m_numAttribs = m_trainInstances.numAttributes();
    m_numInstances = m_trainInstances.numInstances();
    m_isNumeric = m_trainInstances.attribute(m_classIndex).isNumeric();

    if (!m_isNumeric) {
      m_disTransform = new DiscretizeFilter();
      m_disTransform.setUseBetterEncoding(true);
      m_disTransform.setInputFormat(m_trainInstances);
      m_trainInstances = Filter.useFilter(m_trainInstances, m_disTransform);
    }

    m_std_devs = new double[m_numAttribs];
    m_corr_matrix = new Matrix(m_numAttribs, m_numAttribs);

    for (int i = 0; i < m_corr_matrix.numRows(); i++) {
      m_corr_matrix.setElement(i, i, 1.0);
      m_std_devs[i] = 1.0;
    }

    for (int i = 0; i < m_numAttribs; i++) {
      for (int j = i + 1; j < m_numAttribs; j++) {
        m_corr_matrix.setElement(i, j, -999);
        m_corr_matrix.setElement(j, i, -999);
      }
    }
  }


  /**
   * evaluates a subset of attributes
   *
   * @param subset a bitset representing the attribute subset to be
   * evaluated
   * @exception Exception if the subset could not be evaluated
   */
  public double evaluateSubset (BitSet subset)
    throws Exception
  {
    double num = 0.0;
    double denom = 0.0;
    double corr;

    // do numerator
    for (int i = 0; i < m_numAttribs; i++) {
      if (i != m_classIndex) {
        if (subset.get(i)) {
          if (m_corr_matrix.getElement(i, m_classIndex) == -999) {
            corr = correlate(i, m_classIndex);
            m_corr_matrix.setElement(i, m_classIndex, corr);
            m_corr_matrix.setElement(m_classIndex, i, corr);
            num += (m_std_devs[i] * corr);
          }
          else {num += (m_std_devs[i] *
			m_corr_matrix.getElement(i, m_classIndex));
	  }
	}
      }
    }

    // do denominator
    for (int i = 0; i < m_numAttribs; i++) {
      if (i != m_classIndex) {
	if (subset.get(i)) {
	  denom += (1.0 * m_std_devs[i] * m_std_devs[i]);

	  for (int j = i + 1; j < m_numAttribs; j++) {if (subset.get(j)) {
	    if (m_corr_matrix.getElement(i, j) == -999) {
	      corr = correlate(i, j);
	      m_corr_matrix.setElement(i, j, corr);
	      m_corr_matrix.setElement(j, i, corr);
	      denom += (2.0 * m_std_devs[i] * m_std_devs[j] * corr);
	    }
	    else {denom += (2.0 * m_std_devs[i] * m_std_devs[j] *
			    m_corr_matrix.getElement(i, j));
	    }
	  }
	  }
	}
      }
    }

    if (denom < 0.0) {
      denom *= -1.0;
    }

    if (denom == 0.0) {
      return  (0.0);
    }

    double merit = (num/Math.sqrt(denom));

    if (merit < 0.0) {
      merit *= -1.0;
    }

    return  merit;
  }


  private double correlate (int att1, int att2) {
    if (!m_isNumeric) {
      return  symmUncertCorr(att1, att2);
    }

    boolean att1_is_num = (m_trainInstances.attribute(att1).isNumeric());
    boolean att2_is_num = (m_trainInstances.attribute(att2).isNumeric());

    if (att1_is_num && att2_is_num) {
      return  num_num(att1, att2);
    }
    else {if (att2_is_num) {
      return  num_nom2(att1, att2);
    }
    else {if (att1_is_num) {
      return  num_nom2(att2, att1);
    }
    }
    }

    return  nom_nom(att1, att2);
  }


  private double symmUncertCorr (int att1, int att2) {
    int i, j, k, ii, jj;
    int nnj, nni, ni, nj;
    double sum = 0.0;
    double sumi[], sumj[];
    double counts[][];
    Instance inst;
    double corr_measure;
    boolean flag = false;
    double temp = 0.0;

    if (att1 == m_classIndex || att2 == m_classIndex) {
      flag = true;
    }

    ni = m_trainInstances.attribute(att1).numValues() + 1;
    nj = m_trainInstances.attribute(att2).numValues() + 1;
    counts = new double[ni][nj];
    sumi = new double[ni];
    sumj = new double[nj];

    for (i = 0; i < ni; i++) {
      sumi[i] = 0.0;

      for (j = 0; j < nj; j++) {
	sumj[j] = 0.0;
	counts[i][j] = 0.0;
      }
    }

    // Fill the contingency table
    for (i = 0; i < m_numInstances; i++) {
      inst = m_trainInstances.instance(i);

      if (inst.isMissing(att1)) {
	ii = ni - 1;
      }
      else {
	ii = (int)inst.value(att1);
      }

      if (inst.isMissing(att2)) {
	jj = nj - 1;
      }
      else {
	jj = (int)inst.value(att2);
      }

      counts[ii][jj]++;
    }

    // get the row totals
    for (i = 0; i < ni; i++) {
      sumi[i] = 0.0;

      for (j = 0; j < nj; j++) {
	sumi[i] += counts[i][j];
	sum += counts[i][j];
      }
    }

    // get the column totals
    for (j = 0; j < nj; j++) {
      sumj[j] = 0.0;

      for (i = 0; i < ni; i++) {
	sumj[j] += counts[i][j];
      }
    }

    // distribute missing counts
    if (!m_missingSeperate &&
	(sumi[ni-1] < m_numInstances) &&
	(sumj[nj-1] < m_numInstances)) {
      double[] i_copy = new double[sumi.length];
      double[] j_copy = new double[sumj.length];
      double[][] counts_copy = new double[sumi.length][sumj.length];

      for (i = 0; i < ni; i++) {
	System.arraycopy(counts[i], 0, counts_copy[i], 0, sumj.length);
      }

      System.arraycopy(sumi, 0, i_copy, 0, sumi.length);
      System.arraycopy(sumj, 0, j_copy, 0, sumj.length);
      double total_missing =
	(sumi[ni - 1] + sumj[nj - 1] - counts[ni - 1][nj - 1]);

      // do the missing i's
      if (sumi[ni - 1] > 0.0) {
	for (j = 0; j < nj - 1; j++) {
	  if (counts[ni - 1][j] > 0.0) {
	    for (i = 0; i < ni - 1; i++) {
	      temp = ((i_copy[i]/(sum - i_copy[ni - 1]))*counts[ni - 1][j]);
	      counts[i][j] += temp;
	      sumi[i] += temp;
	    }

	    counts[ni - 1][j] = 0.0;
	  }
	}
      }

      sumi[ni - 1] = 0.0;

      // do the missing j's
      if (sumj[nj - 1] > 0.0) {
	for (i = 0; i < ni - 1; i++) {
	  if (counts[i][nj - 1] > 0.0) {
	    for (j = 0; j < nj - 1; j++) {
	      temp = ((j_copy[j]/(sum - j_copy[nj - 1]))*counts[i][nj - 1]);
	      counts[i][j] += temp;
	      sumj[j] += temp;
	    }

	    counts[i][nj - 1] = 0.0;
	  }
	}
      }

      sumj[nj - 1] = 0.0;

      // do the both missing
      if (counts[ni - 1][nj - 1] > 0.0 && total_missing != sum) {
	for (i = 0; i < ni - 1; i++) {
	  for (j = 0; j < nj - 1; j++) {
	    temp = (counts_copy[i][j]/(sum - total_missing)) *
	      counts_copy[ni - 1][nj - 1];

	    counts[i][j] += temp;
	    sumi[i] += temp;
	    sumj[j] += temp;
	  }
	}

	counts[ni - 1][nj - 1] = 0.0;
      }
    }

    // corr_measure = Correlate.symm_uncert(counts,sumi,sumj,sum,ni,nj,flag);
    corr_measure = ContingencyTables.symmetricalUncertainty(counts);

    // corr_measure = ContingencyTables.gainRatio(counts);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区成人| 欧美一区二区三区公司| 国产精品丝袜黑色高跟| 国产精品一区免费在线观看| 欧美电视剧免费全集观看| 九色|91porny| 国产欧美日韩另类视频免费观看| 国产精品一区二区三区网站| 国产亚洲精品资源在线26u| 国产不卡在线一区| 亚洲精品日韩综合观看成人91| 99久久夜色精品国产网站| 亚洲黄色av一区| 欧美电影一区二区| 国产一区二区网址| 中文字幕中文字幕在线一区| 在线观看国产一区二区| 香蕉成人伊视频在线观看| 精品国产一区二区精华| 高清国产一区二区| 亚洲成人福利片| 2021国产精品久久精品| 不卡一区中文字幕| 午夜欧美一区二区三区在线播放| 欧美成人三级电影在线| 91色porny在线视频| 午夜亚洲福利老司机| 国产日韩欧美麻豆| 欧美日韩国产一二三| 国产美女在线精品| 伊人婷婷欧美激情| 日韩欧美一级片| 一本色道综合亚洲| 国产曰批免费观看久久久| 亚洲欧美日韩系列| 久久久91精品国产一区二区三区| 91麻豆成人久久精品二区三区| 热久久国产精品| **欧美大码日韩| 日韩精品中文字幕在线一区| 91捆绑美女网站| 国产在线看一区| 亚洲第四色夜色| 亚洲欧美日韩国产手机在线 | 在线国产亚洲欧美| 狠狠色综合日日| 亚洲一区二区视频在线| 国产日韩综合av| 欧美一区二区三区喷汁尤物| 91丨porny丨在线| 国产成a人亚洲| 国产一区二区中文字幕| 香蕉成人啪国产精品视频综合网| 国产精品高潮呻吟久久| 久久久久久麻豆| 日韩一区二区三区视频在线观看 | 老司机精品视频导航| 久久精品国产精品亚洲综合| 成人免费小视频| 国产日韩欧美制服另类| 亚洲精品在线三区| 日韩欧美中文字幕制服| 欧美无人高清视频在线观看| www.日韩精品| 高清国产一区二区| 成人午夜又粗又硬又大| 国产一区二区调教| 久久国产日韩欧美精品| 青娱乐精品视频在线| 亚洲h精品动漫在线观看| 一区二区三区久久| 亚洲黄色性网站| 亚洲一区国产视频| 亚洲国产精品一区二区www在线| 亚洲激情欧美激情| 一区二区三区高清在线| 亚洲精品国产a| 一区二区三区四区视频精品免费 | 色国产综合视频| 99久久99久久精品免费观看 | 欧美一区二区精品在线| 欧美一区二区三区思思人| 欧美日韩免费一区二区三区| 欧美日韩一区二区三区不卡| 色综合视频在线观看| 日本韩国欧美国产| 欧美偷拍一区二区| 欧美日韩视频在线第一区| 欧美精品日韩一区| 日韩一级黄色大片| 精品福利在线导航| 亚洲国产精品成人久久综合一区| 国产午夜一区二区三区| 国产精品三级久久久久三级| 亚洲品质自拍视频| 亚洲与欧洲av电影| 日韩经典中文字幕一区| 激情文学综合网| 国产福利精品导航| 91天堂素人约啪| 欧美日韩高清一区二区不卡| 欧美成人精品福利| 中文字幕巨乱亚洲| 亚洲午夜视频在线观看| 人人超碰91尤物精品国产| 国产精品亚洲第一 | 99久久99精品久久久久久 | 美日韩一区二区三区| 国内精品国产三级国产a久久| 国产精品一区二区在线看| 91麻豆福利精品推荐| 欧美一级高清片在线观看| 亚洲国产精品精华液ab| 婷婷综合久久一区二区三区| 极品少妇xxxx偷拍精品少妇| av电影在线观看不卡 | 日韩一二在线观看| 欧美激情一区在线观看| 亚洲午夜精品17c| 久久www免费人成看片高清| 99久久国产综合精品麻豆| 欧美丰满嫩嫩电影| 欧美激情综合网| 天天av天天翘天天综合网| 国产精品白丝jk黑袜喷水| 欧美在线999| 国产日韩欧美一区二区三区乱码 | 最好看的中文字幕久久| 日韩成人午夜精品| 99精品在线免费| 精品国产乱码久久| 一区二区成人在线| 成人免费黄色在线| 日韩免费成人网| 成人中文字幕电影| 欧美一区二区三区免费在线看| 国产精品久久久久久户外露出| 久久精品国产在热久久| 欧美在线一区二区三区| 国产精品久久综合| 狠狠色狠狠色合久久伊人| 欧美性做爰猛烈叫床潮| ...xxx性欧美| 国产99久久精品| 精品国精品自拍自在线| 日一区二区三区| 91高清在线观看| 亚洲三级小视频| 粉嫩绯色av一区二区在线观看 | 一本大道久久精品懂色aⅴ| 久久久久免费观看| 狠狠色丁香婷婷综合| 日韩片之四级片| 日本美女视频一区二区| 一本大道av一区二区在线播放| 欧美国产欧美亚州国产日韩mv天天看完整 | 国产欧美在线观看一区| 看片的网站亚洲| 91麻豆精品国产91久久久久久久久 | 国产精品综合二区| 欧美r级电影在线观看| 日韩中文欧美在线| 69堂国产成人免费视频| 亚洲国产毛片aaaaa无费看| 色综合久久88色综合天天6| 国产精品不卡视频| 色综合天天综合色综合av | 日韩一区二区在线免费观看| 亚洲成年人网站在线观看| 色偷偷88欧美精品久久久 | 亚洲动漫第一页| 欧美视频一区二区三区四区| 亚洲一区日韩精品中文字幕| 欧美色综合影院| 天天做天天摸天天爽国产一区| 日本高清不卡在线观看| 亚洲一区二区偷拍精品| 欧美日韩dvd在线观看| 五月激情综合网| 精品精品欲导航| 国产在线视频一区二区| 国产精品欧美极品| 色妞www精品视频| 亚瑟在线精品视频| 日韩午夜精品电影| 国产精品亚洲视频| 亚洲图片激情小说| 欧美日韩日本视频| 秋霞午夜鲁丝一区二区老狼| 精品国产99国产精品| 国产激情一区二区三区四区| 亚洲欧美怡红院| 欧美日韩www| 国产在线视频精品一区| 亚洲视频图片小说| 日韩无一区二区| 国产69精品久久久久777| 亚洲最新在线观看| 日韩视频一区在线观看| 粉嫩久久99精品久久久久久夜|