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

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

?? c45split.java

?? 一個數據挖掘系統的源碼
?? JAVA
字號:

/**
 *   
 *   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.classifiers;

/**
 * <p>Title: The Data Miner prototype</p>
 * <p>Description: A prototype for the DataMiner (DM), the Agent Academy (AA) module responsible for performing data mining on the contents of the Agent Use Repository (AUR). The extracted knowledge is to be sent back to the AUR in the form of a PMML document.</p>
 * <p>Copyright: Copyright (c) 2002</p>
 * <p>Company: CERTH</p>
 * @author asymeon
 * @version 0.3
 */

import java.util.*;
import org.agentacademy.modules.dataminer.core.*;

/**
 * Class implementing a C4.5-type split on an attribute.
 *
 */
public class C45Split extends ClassifierSplitModel{

  /** Desired number of branches. */
  private int m_complexityIndex;

  /** Attribute to split on. */
  private int m_attIndex;

  /** Minimum number of objects in a split.   */
  private int m_minNoObj;

  /** Value of split point. */
  private double m_splitPoint;

  /** InfoGain of split. */
  private double m_infoGain;

  /** GainRatio of split.  */
  private double m_gainRatio;

  /** The sum of the weights of the instances. */
  private double m_sumOfWeights;

  /** Number of split points. */
  private int m_index;

  /** Static reference to splitting criterion. */
  private static InfoGainSplitCrit infoGainCrit = new InfoGainSplitCrit();

  /** Static reference to splitting criterion. */
  private static GainRatioSplitCrit gainRatioCrit = new GainRatioSplitCrit();

  /**
   * Initializes the split model.
   */
  public C45Split(int attIndex,int minNoObj, double sumOfWeights) {

    // Get index of attribute to split on.
    m_attIndex = attIndex;

    // Set minimum number of objects.
    m_minNoObj = minNoObj;

    // Set the sum of the weights
    m_sumOfWeights = sumOfWeights;
  }

  /**
   * Creates a C4.5-type split on the given data. Assumes that none of
   * the class values is missing.
   *
   * @exception Exception if something goes wrong
   */
  public void buildClassifier(Instances trainInstances)
       throws Exception {

    // Initialize the remaining instance variables.
    m_numSubsets = 0;
    m_splitPoint = Double.MAX_VALUE;
    m_infoGain = 0;
    m_gainRatio = 0;

    // Different treatment for enumerated and numeric
    // attributes.
    if (trainInstances.attribute(m_attIndex).isNominal()) {
      m_complexityIndex = trainInstances.attribute(m_attIndex).numValues();
      m_index = m_complexityIndex;
      handleEnumeratedAttribute(trainInstances);
    }else{
      m_complexityIndex = 2;
      m_index = 0;
      trainInstances.sort(trainInstances.attribute(m_attIndex));
      handleNumericAttribute(trainInstances);
    }
  }

  /**
   * Returns index of attribute for which split was generated.
   */
  public final int attIndex() {

    return m_attIndex;
  }

  /**
   * Gets class probability for instance.
   *
   * @exception Exception if something goes wrong
   */
  public final double classProb(int classIndex,Instance instance,
				int theSubset) throws Exception {

    if (theSubset <= -1) {
      double [] weights = weights(instance);
      if (weights == null) {
	return m_distribution.prob(classIndex);
      } else {
	double prob = 0;
	for (int i = 0; i < weights.length; i++) {
	  prob += weights[i] * m_distribution.prob(classIndex, i);
	}
	return prob;
      }
    } else {
      if (Utils.gr(m_distribution.perBag(theSubset), 0)) {
	return m_distribution.prob(classIndex, theSubset);
      } else {

	// This doesn't make much sense to me but it
	// appears to be what C4.5 does.
	if (m_distribution.maxClass() == classIndex)
	  return 1;
	else
	  return 0;
      }
    }
  }

  /**
   * Returns coding cost for split (used in rule learner).
   */
  public final double codingCost() {

    return Utils.log2(m_index);
  }

  /**
   * Returns (C4.5-type) gain ratio for the generated split.
   */
  public final double gainRatio() {
    return m_gainRatio;
  }

  /**
   * Creates split on enumerated attribute.
   *
   * @exception Exception if something goes wrong
   */
  private void handleEnumeratedAttribute(Instances trainInstances)
       throws Exception {

    Instance instance;

    m_distribution = new Distribution(m_complexityIndex,
			      trainInstances.numClasses());

    // Only Instances with known values are relevant.
    Enumeration enum = trainInstances.enumerateInstances();
    while (enum.hasMoreElements()) {
      instance = (Instance) enum.nextElement();
      if (!instance.isMissing(m_attIndex))
	m_distribution.add((int)instance.value(m_attIndex),instance);
    }

    // Check if minimum number of Instances in at least two
    // subsets.
    if (m_distribution.check(m_minNoObj)) {
      m_numSubsets = m_complexityIndex;
      m_infoGain = infoGainCrit.
	splitCritValue(m_distribution,m_sumOfWeights);
      m_gainRatio =
	gainRatioCrit.splitCritValue(m_distribution,m_sumOfWeights,
				     m_infoGain);
    }
  }

  /**
   * Creates split on numeric attribute.
   *
   * @exception Exception if something goes wrong
   */
  private void handleNumericAttribute(Instances trainInstances)
       throws Exception {

    int firstMiss;
    int next = 1;
    int last = 0;
    int splitIndex = -1;
    double currentInfoGain;
    double defaultEnt;
    double minSplit;
    Instance instance;
    int i;

    // Current attribute is a numeric attribute.
    m_distribution = new Distribution(2,trainInstances.numClasses());

    // Only Instances with known values are relevant.
    Enumeration enum = trainInstances.enumerateInstances();
    i = 0;
    while (enum.hasMoreElements()) {
      instance = (Instance) enum.nextElement();
      if (instance.isMissing(m_attIndex))
	break;
      m_distribution.add(1,instance);
      i++;
    }
    firstMiss = i;

    // Compute minimum number of Instances required in each
    // subset.
    minSplit =  0.1*(m_distribution.total())/
      ((double)trainInstances.numClasses());
    if (Utils.smOrEq(minSplit,m_minNoObj))
      minSplit = m_minNoObj;
    else
      if (Utils.gr(minSplit,25))
	minSplit = 25;

    // Enough Instances with known values?
    if (Utils.sm((double)firstMiss,2*minSplit))
      return;

    // Compute values of criteria for all possible split
    // indices.
    defaultEnt = infoGainCrit.oldEnt(m_distribution);
    while (next < firstMiss) {

      if (trainInstances.instance(next-1).value(m_attIndex)+1e-5 <
	  trainInstances.instance(next).value(m_attIndex)) {

	// Move class values for all Instances up to next
	// possible split point.
	m_distribution.shiftRange(1,0,trainInstances,last,next);

	// Check if enough Instances in each subset and compute
	// values for criteria.
	if (Utils.grOrEq(m_distribution.perBag(0),minSplit) &&
	    Utils.grOrEq(m_distribution.perBag(1),minSplit)) {
	  currentInfoGain = infoGainCrit.
	    splitCritValue(m_distribution,m_sumOfWeights,
			   defaultEnt);
	  if (Utils.gr(currentInfoGain,m_infoGain)) {
	    m_infoGain = currentInfoGain;
	    splitIndex = next-1;
	  }
	  m_index++;
	}
	last = next;
      }
      next++;
    }

    // Was there any useful split?
    if (m_index == 0)
      return;

    // Compute modified information gain for best split.
    m_infoGain = m_infoGain-(Utils.log2(m_index)/m_sumOfWeights);
    if (Utils.smOrEq(m_infoGain,0))
      return;

    // Set instance variables' values to values for
    // best split.
    m_numSubsets = 2;
    m_splitPoint =
      (trainInstances.instance(splitIndex+1).value(m_attIndex)+
       trainInstances.instance(splitIndex).value(m_attIndex))/2;

    // Restore distributioN for best split.
    m_distribution = new Distribution(2,trainInstances.numClasses());
    m_distribution.addRange(0,trainInstances,0,splitIndex+1);
    m_distribution.addRange(1,trainInstances,splitIndex+1,firstMiss);

    // Compute modified gain ratio for best split.
    m_gainRatio = gainRatioCrit.
      splitCritValue(m_distribution,m_sumOfWeights,
		     m_infoGain);
  }

  /**
   * Returns (C4.5-type) information gain for the generated split.
   */
  public final double infoGain() {

    return m_infoGain;
  }

  /**
   * Prints left side of condition..
   *
   * @param data training set.
   */
  public final String leftSide(Instances data) {

    return data.attribute(m_attIndex).name();
  }

  /**
   * Prints the condition satisfied by instances in a subset.
   *
   * @param index of subset
   * @param data training set.
   */
  public final String rightSide(int index,Instances data) {

    StringBuffer text;

    text = new StringBuffer();
    if (data.attribute(m_attIndex).isNominal())
      text.append(" = "+
		  data.attribute(m_attIndex).value(index));
    else
      if (index == 0)
	text.append(" <= "+
		    Utils.doubleToString(m_splitPoint,6));
      else
	text.append(" > "+
		    Utils.doubleToString(m_splitPoint,6));
    return text.toString();
  }

  /**
   * Returns a string containing java source code equivalent to the test
   * made at this node. The instance being tested is called "i".
   *
   * @param index index of the nominal value tested
   * @param data the data containing instance structure info
   * @return a value of type 'String'
   */
  public final String sourceExpression(int index, Instances data) {

    StringBuffer expr = null;
    if (index < 0) {
      return "i[" + m_attIndex + "] == null";
    }
    if (data.attribute(m_attIndex).isNominal()) {
      expr = new StringBuffer("i[");
      expr.append(m_attIndex).append("]");
      expr.append(".equals(\"").append(data.attribute(m_attIndex)
				     .value(index)).append("\")");
    } else {
      expr = new StringBuffer("((Double) i[");
      expr.append(m_attIndex).append("])");
      if (index == 0) {
	expr.append(".doubleValue() <= ").append(m_splitPoint);
      } else {
	expr.append(".doubleValue() > ").append(m_splitPoint);
      }
    }
    return expr.toString();
  }

  /**
   * Sets split point to greatest value in given data smaller or equal to
   * old split point.
   * (C4.5 does this for some strange reason).
   */
  public final void setSplitPoint(Instances allInstances) {

    double newSplitPoint = -Double.MAX_VALUE;
    double tempValue;
    Instance instance;

    if ((allInstances.attribute(m_attIndex).isNumeric()) &&
	(m_numSubsets > 1)) {
      Enumeration enum = allInstances.enumerateInstances();
      while (enum.hasMoreElements()) {
	instance = (Instance) enum.nextElement();
	if (!instance.isMissing(m_attIndex)) {
	  tempValue = instance.value(m_attIndex);
	  if (Utils.gr(tempValue,newSplitPoint) &&
	      Utils.smOrEq(tempValue,m_splitPoint))
	    newSplitPoint = tempValue;
	}
      }
      m_splitPoint = newSplitPoint;
    }
  }

  /**
   * Returns the minsAndMaxs of the index.th subset.
   */
  public final double [][] minsAndMaxs(Instances data, double [][] minsAndMaxs,
				       int index) {

    double [][] newMinsAndMaxs = new double[data.numAttributes()][2];

    for (int i = 0; i < data.numAttributes(); i++) {
      newMinsAndMaxs[i][0] = minsAndMaxs[i][0];
      newMinsAndMaxs[i][1] = minsAndMaxs[i][1];
      if (i == m_attIndex)
	if (data.attribute(m_attIndex).isNominal())
	  newMinsAndMaxs[m_attIndex][1] = 1;
	else
	  newMinsAndMaxs[m_attIndex][1-index] = m_splitPoint;
    }

    return newMinsAndMaxs;
  }

  /**
   * Sets distribution associated with model.
   */
  public void resetDistribution(Instances data) throws Exception {

    Instances insts = new Instances(data, data.numInstances());
    for (int i = 0; i < data.numInstances(); i++) {
      if (whichSubset(data.instance(i)) > -1) {
	insts.add(data.instance(i));
      }
    }
    Distribution newD = new Distribution(insts, this);
    newD.addInstWithUnknown(data, m_attIndex);
    m_distribution = newD;
  }

  /**
   * Returns weights if instance is assigned to more than one subset.
   * Returns null if instance is only assigned to one subset.
   */
  public final double [] weights(Instance instance) {

    double [] weights;
    int i;

    if (instance.isMissing(m_attIndex)) {
      weights = new double [m_numSubsets];
      for (i=0;i<m_numSubsets;i++)
	weights [i] = m_distribution.perBag(i)/m_distribution.total();
      return weights;
    }else{
      return null;
    }
  }

  /**
   * Returns index of subset instance is assigned to.
   * Returns -1 if instance is assigned to more than one subset.
   *
   * @exception Exception if something goes wrong
   */
  public final int whichSubset(Instance instance)
       throws Exception {

    if (instance.isMissing(m_attIndex))
      return -1;
    else{
      if (instance.attribute(m_attIndex).isNominal())
	return (int)instance.value(m_attIndex);
      else
	if (Utils.smOrEq(instance.value(m_attIndex),m_splitPoint))
	  return 0;
	else
	  return 1;
    }
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色琪琪一区二区三区亚洲区| 成人99免费视频| 欧美一区二区三区视频免费播放| 亚洲国产精品麻豆| 欧美日韩专区在线| 青娱乐精品视频| 精品福利一二区| 成人午夜激情在线| 亚洲夂夂婷婷色拍ww47| 91精品国产91久久久久久一区二区 | 亚洲观看高清完整版在线观看 | 日韩精品欧美精品| 欧美v日韩v国产v| 国产91精品精华液一区二区三区| 国产精品久久久久影视| 欧洲日韩一区二区三区| 麻豆免费看一区二区三区| 久久久久国产成人精品亚洲午夜 | 色94色欧美sute亚洲线路一ni| 亚洲国产精品嫩草影院| 2017欧美狠狠色| 一本到一区二区三区| 丝袜亚洲另类丝袜在线| 亚洲国产精品av| 欧美网站大全在线观看| 国产一区二区三区日韩| 一区二区三区日韩| 欧美成人精品二区三区99精品| 成人一区二区三区| 图片区日韩欧美亚洲| 国产亚洲一二三区| 精品污污网站免费看| 黄色成人免费在线| 性做久久久久久久久| 久久精品视频网| 欧美久久一区二区| 波多野结衣亚洲| 美美哒免费高清在线观看视频一区二区 | 日本成人在线一区| 自拍偷拍亚洲激情| 亚洲精品在线观看网站| 欧洲中文字幕精品| 粉嫩一区二区三区在线看| 亚洲国产成人91porn| 中文幕一区二区三区久久蜜桃| 91精品国产综合久久婷婷香蕉| 成人av动漫在线| 精品一区中文字幕| 午夜精品一区在线观看| 亚洲欧美日韩综合aⅴ视频| 久久综合久久99| 日韩限制级电影在线观看| 91麻豆国产精品久久| 国产精品456露脸| 青娱乐精品在线视频| 亚洲成人tv网| 亚洲第一久久影院| 亚洲精品欧美专区| 亚洲少妇中出一区| 国产精品传媒在线| 国产精品久久久久aaaa樱花| 久久日韩精品一区二区五区| 日韩欧美资源站| 91精品国产乱| 51精品久久久久久久蜜臀| 欧美性猛交xxxx黑人交| 91麻豆免费视频| 91免费在线看| 色偷偷88欧美精品久久久| 91网站视频在线观看| 不卡欧美aaaaa| heyzo一本久久综合| 成人美女视频在线观看18| 4438x成人网最大色成网站| 91精品欧美综合在线观看最新| 欧美天天综合网| 欧美日韩欧美一区二区| 欧美日韩精品一区二区天天拍小说 | 久久精品免费在线观看| 国产亚洲精品福利| 欧美激情在线看| 最新国产の精品合集bt伙计| 中文字幕中文字幕一区二区| 亚洲天堂免费在线观看视频| 玉足女爽爽91| 午夜视黄欧洲亚洲| 日本不卡视频一二三区| 裸体一区二区三区| 国内不卡的二区三区中文字幕 | 美女脱光内衣内裤视频久久网站 | 91麻豆精品久久久久蜜臀| 欧美一级免费观看| 2欧美一区二区三区在线观看视频| 日韩久久久精品| 亚洲国产精品传媒在线观看| 亚洲欧美日韩国产手机在线| 91蜜桃婷婷狠狠久久综合9色| 欧美色区777第一页| 欧美一区二区三区视频在线观看| 久久久久综合网| 自拍偷拍欧美激情| 日韩电影一二三区| 国产69精品久久99不卡| 在线影院国内精品| 日韩无一区二区| 亚洲国产精品精华液2区45| 亚洲欧美日韩精品久久久久| 欧美aⅴ一区二区三区视频| 国产乱人伦偷精品视频不卡| 91同城在线观看| 91精品国产综合久久久久久| 国产日韩精品视频一区| 尤物av一区二区| 精品夜夜嗨av一区二区三区| 成人av网址在线| 91精品国产免费| 亚洲欧美日韩久久| 久久99久久久久| 99久久99精品久久久久久 | 欧美日韩一级片在线观看| 久久亚洲精精品中文字幕早川悠里| 中文字幕一区视频| 久久精品99久久久| 色综合夜色一区| 久久久久久久久岛国免费| 亚洲一区二区三区视频在线 | 成人免费在线播放视频| 日韩精品欧美精品| 日本韩国欧美国产| 国产日韩欧美激情| 天天色综合成人网| 日韩精品最新网址| 亚洲精品成人a在线观看| 国产米奇在线777精品观看| 欧美丝袜丝交足nylons| 国产女同互慰高潮91漫画| 日韩不卡免费视频| 99re成人精品视频| 久久综合色8888| 男女激情视频一区| 欧美性受极品xxxx喷水| 国产精品国产自产拍在线| 久久97超碰国产精品超碰| 7878成人国产在线观看| 亚洲色图清纯唯美| 国产成人在线视频网址| 日韩欧美你懂的| 日韩va欧美va亚洲va久久| 色综合咪咪久久| 国产精品成人免费精品自在线观看| 极品美女销魂一区二区三区免费| 欧美情侣在线播放| 一级日本不卡的影视| 91精品福利在线| 洋洋成人永久网站入口| 91麻豆.com| 亚洲欧美在线另类| 成a人片亚洲日本久久| 国产目拍亚洲精品99久久精品| 国产在线精品一区在线观看麻豆| 欧美一区二区在线免费观看| 日韩av中文在线观看| 91精品国产乱| 久久激五月天综合精品| 亚洲精品一线二线三线| 精品一区二区三区av| 精品国产乱子伦一区| 韩国女主播一区二区三区| 久久亚洲精华国产精华液 | 日韩欧美亚洲国产另类| 日韩av中文字幕一区二区| 欧美一级免费大片| 激情综合网激情| 国产日产亚洲精品系列| 成人免费黄色在线| ...xxx性欧美| 欧美性猛交xxxx黑人交| 三级久久三级久久| 日韩欧美第一区| 国产一区不卡精品| 国产精品久久久久久久久久免费看 | 欧美一级在线观看| 激情久久久久久久久久久久久久久久| 久久综合国产精品| 国产凹凸在线观看一区二区| 国产精品初高中害羞小美女文| 91久久精品网| 免费高清成人在线| 中文字幕乱码日本亚洲一区二区| av在线这里只有精品| 亚洲国产成人高清精品| 日韩欧美不卡在线观看视频| 国产一区二区三区观看| 日韩一区在线免费观看| 欧美剧在线免费观看网站| 狠狠色丁香久久婷婷综合_中| 国产精品伦理在线| 欧美乱妇20p| 成人手机电影网| 视频在线观看国产精品|