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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? em.java

?? 一個(gè)數(shù)據(jù)挖掘系統(tǒng)的源碼
?? 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.clusterers;

/**
 * <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.Enumeration;
import java.util.Random;
import java.util.Vector;

import org.agentacademy.modules.dataminer.core.Instance;
import org.agentacademy.modules.dataminer.core.Instances;
import org.agentacademy.modules.dataminer.core.Option;
import org.agentacademy.modules.dataminer.core.OptionHandler;
import org.agentacademy.modules.dataminer.core.Utils;

import weka.estimators.DiscreteEstimator;
import weka.estimators.Estimator;

import org.apache.log4j.Logger;

/**
 * Simple EM (estimation maximisation) class. <p>
 *
 * EM assigns a probability distribution to each instance which
 * indicates the probability of it belonging to each of the clusters.
 * EM can decide how many clusters to create by cross validation, or you
 * may specify apriori how many clusters to generate. <p>
 *
 * Valid options are:<p>
 *
 * -V <br>
 * Verbose. <p>
 *
 * -N <number of clusters> <br>
 * Specify the number of clusters to generate. If omitted,
 * EM will use cross validation to select the number of clusters
 * automatically. <p>
 *
 * -I <max iterations> <br>
 * Terminate after this many iterations if EM has not converged. <p>
 *
 * -S <seed> <br>
 * Specify random number seed. <p>
 *
 * -M <num> <br>
 * Set the minimum allowable standard deviation for normal density calculation.
 * <p>
 *
 */
public class EM
  extends DistributionClusterer
  implements OptionHandler
{

  public static Logger                log = Logger.getLogger(EM.class);
  /** hold the discrete estimators for each cluster */
  private Estimator m_model[][];

  /** hold the normal estimators for each cluster */
  private double m_modelNormal[][][];

  /** default minimum standard deviation */
  private double m_minStdDev = 1e-6;

  /** hold the weights of each instance for each cluster */
  private double m_weights[][];

  /** the prior probabilities for clusters */
  private double m_priors[];

  /** the loglikelihood of the data */
  private double m_loglikely;

  /** training instances */
  private Instances m_theInstances = null;

  /** number of clusters selected by the user or cross validation */
  private int m_num_clusters;

  /** the initial number of clusters requested by the user--- -1 if
      xval is to be used to find the number of clusters */
  private int m_initialNumClusters;

  /** number of attributes */
  private int m_num_attribs;

  /** number of training instances */
  private int m_num_instances;

  /** maximum iterations to perform */
  private int m_max_iterations;

  /** random numbers and seed */
  private Random m_rr;
  private int m_rseed;

  /** Constant for normal distribution. */
  private static double m_normConst = Math.sqrt(2*Math.PI);

  /** Verbose? */
  private boolean m_verbose;

  /**
   * Returns a string describing this clusterer
   * @return a description of the evaluator suitable for
   * displaying in the explorer/experimenter gui
   */
  public String globalInfo() {
    return "Cluster data using expectation maximization";
  }


  /**
   * Returns an enumeration describing the available options.. <p>
   *
   * Valid options are:<p>
   *
   * -V <br>
   * Verbose. <p>
   *
   * -N <number of clusters> <br>
   * Specify the number of clusters to generate. If omitted,
   * EM will use cross validation to select the number of clusters
   * automatically. <p>
   *
   * -I <max iterations> <br>
   * Terminate after this many iterations if EM has not converged. <p>
   *
   * -S <seed> <br>
   * Specify random number seed. <p>
   *
   * -M <num> <br>
   *  Set the minimum allowable standard deviation for normal density
   * calculation. <p>
   *
   * @return an enumeration of all the available options.
   *
   **/
  public Enumeration listOptions () {
    Vector newVector = new Vector(6);
    newVector.addElement(new Option("\tnumber of clusters. If omitted or"
				    + "\n\t-1 specified, then cross "
				    + "validation is used to\n\tselect the "
				    + "number of clusters.", "N", 1
				    , "-N <num>"));
    newVector.addElement(new Option("\tmax iterations.\n(default 100)", "I"
				    , 1, "-I <num>"));
    newVector.addElement(new Option("\trandom number seed.\n(default 1)"
				    , "S", 1, "-S <num>"));
    newVector.addElement(new Option("\tverbose.", "V", 0, "-V"));
    newVector.addElement(new Option("\tminimum allowable standard deviation "
				    +"for normal density computation "
				    +"\n\t(default 1e-6)"
				    ,"M",1,"-M <num>"));
    return  newVector.elements();
  }


  /**
   * Parses a given list of options.
   * @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
  {
    resetOptions();
    setDebug(Utils.getFlag('V', options));
    String optionString = Utils.getOption('I', options);

    if (optionString.length() != 0) {
      setMaxIterations(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption('N', options);

    if (optionString.length() != 0) {
      setNumClusters(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption('S', options);

    if (optionString.length() != 0) {
      setSeed(Integer.parseInt(optionString));
    }

    optionString = Utils.getOption('M', options);
    if (optionString.length() != 0) {
      setMinStdDev((new Double(optionString)).doubleValue());
    }
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String minStdDevTipText() {
    return "set minimum allowable standard deviation";
  }

  /**
   * Set the minimum value for standard deviation when calculating
   * normal density. Reducing this value can help prevent arithmetic
   * overflow resulting from multiplying large densities (arising from small
   * standard deviations) when there are many singleton or near singleton
   * values.
   * @param m minimum value for standard deviation
   */
  public void setMinStdDev(double m) {
    m_minStdDev = m;
  }

  /**
   * Get the minimum allowable standard deviation.
   * @return the minumum allowable standard deviation
   */
  public double getMinStdDev() {
    return m_minStdDev;
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String seedTipText() {
    return "random number seed";
  }


  /**
   * Set the random number seed
   *
   * @param s the seed
   */
  public void setSeed (int s) {
    m_rseed = s;
  }


  /**
   * Get the random number seed
   *
   * @return the seed
   */
  public int getSeed () {
    return  m_rseed;
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String numClustersTipText() {
    return "set number of clusters. -1 to select number of clusters "
      +"automatically by cross validation.";
  }

  /**
   * Set the number of clusters (-1 to select by CV).
   *
   * @param n the number of clusters
   * @exception Exception if n is 0
   */
  public void setNumClusters (int n)
    throws Exception {

    if (n == 0) {
      throw  new Exception("Number of clusters must be > 0. (or -1 to "
			   + "select by cross validation).");
    }

    if (n < 0) {
      m_num_clusters = -1;
      m_initialNumClusters = -1;
    }
    else {
      m_num_clusters = n;
      m_initialNumClusters = n;
    }
  }


  /**
   * Get the number of clusters
   *
   * @return the number of clusters.
   */
  public int getNumClusters () {
    return  m_initialNumClusters;
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String maxIterationsTipText() {
    return "maximum number of iterations";
  }

  /**
   * Set the maximum number of iterations to perform
   *
   * @param i the number of iterations
   * @exception Exception if i is less than 1
   */
  public void setMaxIterations (int i)
    throws Exception
  {
    if (i < 1) {
      throw  new Exception("Maximum number of iterations must be > 0!");
    }

    m_max_iterations = i;
  }


  /**
   * Get the maximum number of iterations
   *
   * @return the number of iterations
   */
  public int getMaxIterations () {
    return  m_max_iterations;
  }


  /**
   * Set debug mode - verbose output
   *
   * @param v true for verbose output
   */
  public void setDebug (boolean v) {
    m_verbose = v;
  }


  /**
   * Get debug mode
   *
   * @return true if debug mode is set
   */
  public boolean getDebug () {
    return  m_verbose;
  }


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

    if (m_verbose) {
      options[current++] = "-V";
    }

    options[current++] = "-I";
    options[current++] = "" + m_max_iterations;
    options[current++] = "-N";
    options[current++] = "" + getNumClusters();
    options[current++] = "-S";
    options[current++] = "" + m_rseed;
    options[current++] = "-M";
    options[current++] = ""+getMinStdDev();

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

    return  options;
  }

  /**
   * Initialised estimators and storage.
   *
   * @param inst the instances
   * @param num_cl the number of clusters
   **/
  private void EM_Init (Instances inst, int num_cl)
    throws Exception
  {
    m_weights = new double[inst.numInstances()][num_cl];
    int z;
    m_model = new Estimator[num_cl][m_num_attribs];
    m_modelNormal = new double[num_cl][m_num_attribs][3];
    m_priors = new double[num_cl];

    for (int i = 0; i < inst.numInstances(); i++) {
      for (int j = 0; j < num_cl; j++) {
        m_weights[i][j] = m_rr.nextDouble();
      }

      Utils.normalize(m_weights[i]);
    }

    // initial priors
    estimate_priors(inst, num_cl);
  }


  /**
   * calculate prior probabilites for the clusters
   *
   * @param inst the instances
   * @param num_cl the number of clusters
   * @exception Exception if priors can't be calculated
   **/
  private void estimate_priors (Instances inst, int num_cl)
    throws Exception
  {
    for (int i = 0; i < num_cl; i++) {
      m_priors[i] = 0.0;
    }

    for (int i = 0; i < inst.numInstances(); i++) {
      for (int j = 0; j < num_cl; j++) {
        m_priors[j] += m_weights[i][j];
      }
    }

    Utils.normalize(m_priors);
  }


  /**
   * Density function of normal distribution.
   * @param x input value
   * @param mean mean of distribution
   * @param stdDev standard deviation of distribution
   */
  private double normalDens (double x, double mean, double stdDev) {
    double diff = x - mean;

    return  (1/(m_normConst*stdDev))*Math.exp(-(diff*diff/(2*stdDev*stdDev)));
  }


  /**
   * New probability estimators for an iteration
   *
   * @param num_cl the numbe of clusters
   */
  private void new_estimators (int num_cl) {
    for (int i = 0; i < num_cl; i++) {
      for (int j = 0; j < m_num_attribs; j++) {
        if (m_theInstances.attribute(j).isNominal()) {
          m_model[i][j] = new DiscreteEstimator(m_theInstances.
						attribute(j).numValues()
						, true);
        }
        else {
          m_modelNormal[i][j][0] = m_modelNormal[i][j][1] =
	    m_modelNormal[i][j][2] = 0.0;
        }
      }
    }
  }


  /**
   * The M step of the EM algorithm.
   * @param inst the training instances
   * @param num_cl the number of clusters
   */
  private void M (Instances inst, int num_cl)
    throws Exception
  {
    int i, j, l;
    new_estimators(num_cl);

    for (i = 0; i < num_cl; i++) {
      for (j = 0; j < m_num_attribs; j++) {
        for (l = 0; l < inst.numInstances(); l++) {
          if (!inst.instance(l).isMissing(j)) {

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天堂va蜜桃一区二区三区漫画版| 亚洲aaa精品| 欧美日韩中文精品| 奇米影视在线99精品| 国产精品久久久久久久久免费相片| 欧美日韩在线一区二区| 国产精品一二三在| 日本91福利区| 亚洲一区在线观看网站| 欧美激情在线一区二区三区| 欧美精品免费视频| 91麻豆蜜桃一区二区三区| 九九**精品视频免费播放| 一区二区三区久久久| 国产精品午夜免费| 精品国产伦一区二区三区观看体验 | 91精品国产一区二区| 成人福利在线看| 久久99精品国产麻豆婷婷洗澡| 亚洲一区在线观看免费观看电影高清| 国产人妖乱国产精品人妖| 在线播放91灌醉迷j高跟美女| 色综合天天综合| 色综合久久88色综合天天6| 精品一区二区国语对白| 亚洲成a人片在线观看中文| 亚洲丝袜精品丝袜在线| 国产日韩一级二级三级| 精品国产一区二区亚洲人成毛片| 欧美日韩日日摸| 91麻豆视频网站| 91麻豆.com| jvid福利写真一区二区三区| 国产福利精品一区二区| 精品在线你懂的| 日韩精品成人一区二区三区| 亚洲高清免费在线| 亚洲成人手机在线| 一区二区三区精品视频| 亚洲欧美激情小说另类| 国产精品私人影院| 中文字幕av一区 二区| 国产欧美日韩综合| 国产精品天干天干在观线| 国产精品免费丝袜| 国产精品三级久久久久三级| 国产精品久久久久久久岛一牛影视| 国产女人水真多18毛片18精品视频| 久久久久亚洲蜜桃| 久久久三级国产网站| 久久久www免费人成精品| 国产亚洲成年网址在线观看| 国产亚洲女人久久久久毛片| 国产精品久久福利| 亚洲精品欧美专区| 天堂在线亚洲视频| 美女网站视频久久| 国产精品99久久久久久宅男| 成人深夜福利app| 91年精品国产| 欧美群妇大交群中文字幕| 日韩视频永久免费| 久久久高清一区二区三区| 国产精品久久国产精麻豆99网站 | 91精品国产综合久久久蜜臀图片 | 日韩av电影天堂| 久久精品国产**网站演员| 国产精品一二二区| 一本到不卡精品视频在线观看| 欧亚洲嫩模精品一区三区| 91麻豆精品国产91久久久| 精品国产电影一区二区| 欧美激情一区二区三区| 亚洲老司机在线| 日韩影视精彩在线| 国产麻豆午夜三级精品| 91在线观看一区二区| 欧美视频日韩视频在线观看| 日韩欧美中文字幕公布| 国产精品天天看| 一区二区三区在线视频观看58| 日本系列欧美系列| 成人国产精品视频| 欧美电影在线免费观看| 国产午夜精品久久久久久免费视 | 国产精品视频你懂的| 亚洲自拍另类综合| 黑人巨大精品欧美黑白配亚洲| 99久久亚洲一区二区三区青草| 欧美日韩在线播放三区四区| 久久亚洲免费视频| 一区二区三区加勒比av| 久久成人免费电影| 一本到高清视频免费精品| 精品国产一区二区在线观看| 亚洲另类在线视频| 国产精品一区二区不卡| 欧美日韩小视频| 中文字幕在线视频一区| 麻豆国产精品777777在线| 91在线丨porny丨国产| 亚洲精品在线三区| 亚洲电影在线免费观看| 成人深夜在线观看| 精品国产91洋老外米糕| 亚洲成av人片一区二区梦乃| 国产不卡视频一区二区三区| 777午夜精品视频在线播放| 亚洲欧美aⅴ...| 成人中文字幕电影| 精品国产乱码久久久久久免费| 亚洲免费观看视频| 粉嫩av一区二区三区在线播放| 777色狠狠一区二区三区| 亚洲裸体在线观看| 国产激情视频一区二区在线观看 | 亚洲综合男人的天堂| 成人三级伦理片| 欧美videos中文字幕| 天堂精品中文字幕在线| 91国产丝袜在线播放| 中文字幕一区视频| 国产美女在线精品| 精品国产91乱码一区二区三区 | 亚洲免费观看在线视频| 国产精品一区二区x88av| 日韩视频永久免费| 日日夜夜一区二区| 欧美日韩综合不卡| 悠悠色在线精品| 99精品黄色片免费大全| 国产精品久久久久久久午夜片| 国产在线不卡一区| 欧美成人a∨高清免费观看| 视频一区欧美精品| 欧美日韩国产天堂| 亚洲永久免费av| 91在线一区二区三区| 中文字幕中文字幕一区二区| 成人免费视频一区| 国产精品久久二区二区| 成人97人人超碰人人99| 中文字幕一区二区日韩精品绯色| 国产成人精品综合在线观看| 久久精品亚洲乱码伦伦中文| 国产99久久久久久免费看农村| 国产网红主播福利一区二区| 国产精华液一区二区三区| 国产日韩在线不卡| 成人性生交大片| 国产精品久久久久影院色老大| 成人99免费视频| 有坂深雪av一区二区精品| 精品视频在线看| 视频一区二区三区中文字幕| 欧美一级电影网站| 老司机免费视频一区二区三区| 精品第一国产综合精品aⅴ| 国产成人av一区二区三区在线观看| 中文字幕免费在线观看视频一区| 99久久伊人精品| 亚洲一二三专区| 日韩一区二区三区av| 国产在线一区观看| 亚洲欧美综合色| 欧美性大战久久久久久久蜜臀| 亚洲国产精品久久人人爱| 欧美一区二区三区人| 精彩视频一区二区| 国产精品黄色在线观看| 在线亚洲+欧美+日本专区| 日韩福利视频网| 久久久久综合网| 91色在线porny| 琪琪一区二区三区| 国产亲近乱来精品视频| 91国偷自产一区二区三区观看 | 国产露脸91国语对白| 亚洲女子a中天字幕| 91精品国产一区二区三区蜜臀 | 国产福利一区二区三区在线视频| 亚洲欧美综合另类在线卡通| 69堂国产成人免费视频| 国产精品中文字幕一区二区三区| 亚洲视频在线一区观看| 欧美一区午夜精品| 成人污视频在线观看| 亚洲va天堂va国产va久| 久久久久久亚洲综合| 欧美无人高清视频在线观看| 国产在线精品一区二区三区不卡 | 日韩你懂的在线播放| av电影在线不卡| 日韩精品欧美成人高清一区二区| 国产亚洲污的网站| 在线观看国产一区二区| 粉嫩av一区二区三区粉嫩| 同产精品九九九| 国产精品久久久久永久免费观看| 日韩午夜电影在线观看|