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

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

?? em.java

?? 一個數據挖掘系統的源碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
            if (inst.attribute(j).isNominal()) {
              m_model[i][j].addValue(inst.instance(l).value(j),
				     m_weights[l][i]);
            }
            else {
              m_modelNormal[i][j][0] += (inst.instance(l).value(j) *
					 m_weights[l][i]);
              m_modelNormal[i][j][2] += m_weights[l][i];
              m_modelNormal[i][j][1] += (inst.instance(l).value(j) *
					 inst.instance(l).value(j)*m_weights[l][i]);
            }
          }
        }
      }
    }

       // calcualte mean and std deviation for numeric attributes
    for (j = 0; j < m_num_attribs; j++) {
      if (!inst.attribute(j).isNominal()) {
        for (i = 0; i < num_cl; i++) {
          if (m_modelNormal[i][j][2] < 0) {
            m_modelNormal[i][j][1] = 0;
          } else {

	  // variance
	    m_modelNormal[i][j][1] = (m_modelNormal[i][j][1] -
				      (m_modelNormal[i][j][0] *
				       m_modelNormal[i][j][0] /
				       m_modelNormal[i][j][2])) /
	      m_modelNormal[i][j][2];

	    // std dev
	    m_modelNormal[i][j][1] = Math.sqrt(m_modelNormal[i][j][1]);

	    if (m_modelNormal[i][j][1] <= m_minStdDev
		|| Double.isNaN(m_modelNormal[i][j][1])) {
	      m_modelNormal[i][j][1] =
		m_minStdDev;
	    }

	    // mean
	    if (m_modelNormal[i][j][2] > 0.0) {
	      m_modelNormal[i][j][0] /= m_modelNormal[i][j][2];
	    }
	  }
        }
      }
    }
  }


  /**
   * The E step of the EM algorithm. Estimate cluster membership
   * probabilities.
   *
   * @param inst the training instances
   * @param num_cl the number of clusters
   * @return the average log likelihood
   */
  private double E (Instances inst, int num_cl)
    throws Exception
  {
    int i, j, l;
    double prob;
    double loglk = 0.0;

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

          if (!inst.instance(l).isMissing(j)) {
            if (inst.attribute(j).isNominal()) {
              m_weights[l][i] *=
		m_model[i][j].getProbability(inst.instance(l).value(j));

            }
            else {
              // numeric attribute
              m_weights[l][i] *= normalDens(inst.instance(l).value(j),
					    m_modelNormal[i][j][0],
					    m_modelNormal[i][j][1]);
	      if (Double.isInfinite(m_weights[l][i])) {
		throw new Exception("Joint density has overflowed. Try "
				    +"increasing the minimum allowable "
				    +"standard deviation for normal "
				    +"density calculation.");
	      }
            }
	    if (m_weights[l][i] > max) {
	      max = m_weights[l][i];
	    }
          }
        }
	if (max > 0 && max < 1e-75) { // check for underflow
	  for (int zz = 0; zz < num_cl; zz++) {
	    // rescale
	    m_weights[l][zz] *= 1e75;
	  }
	}
      }

      double temp1 = 0;

      for (i = 0; i < num_cl; i++) {
        temp1 += m_weights[l][i];
      }

      if (temp1 > 0) {
        loglk += Math.log(temp1);
      }

      // normalise the weights for this instance
      try {
	Utils.normalize(m_weights[l]);
      } catch (Exception e) {
	throw new Exception("An instance has zero cluster memberships. Try "
			    +"increasing the minimum allowable "
			    +"standard deviation for normal "
			    +"density calculation.");
      }
    }

    // reestimate priors
    estimate_priors(inst, num_cl);
    return  loglk/inst.numInstances();
  }


  /**
   * Constructor.
   *
   **/
  public EM () {
    resetOptions();
  }


  /**
   * Reset to default options
   */
  protected void resetOptions () {
    m_minStdDev = 1e-6;
    m_max_iterations = 100;
    m_rseed = 100;
    m_num_clusters = -1;
    m_initialNumClusters = -1;
    m_verbose = false;
  }


  /**
   * Outputs the generated clusters into a string.
   */
  public String toString () {
    StringBuffer text = new StringBuffer();
    text.append("\nEM\n==\n");
    if (m_initialNumClusters == -1) {
      text.append("\nNumber of clusters selected by cross validation: "
		  +m_num_clusters+"\n");
    } else {
      text.append("\nNumber of clusters: " + m_num_clusters + "\n");
    }

    for (int j = 0; j < m_num_clusters; j++) {
      text.append("\nCluster: " + j + " Prior probability: "
		  + Utils.doubleToString(m_priors[j], 4) + "\n\n");

      for (int i = 0; i < m_num_attribs; i++) {
        text.append("Attribute: " + m_theInstances.attribute(i).name() + "\n");

        if (m_theInstances.attribute(i).isNominal()) {
          if (m_model[j][i] != null) {
            text.append(m_model[j][i].toString());
          }
        }
        else {
          text.append("Normal Distribution. Mean = "
		      + Utils.doubleToString(m_modelNormal[j][i][0], 4)
		      + " StdDev = "
		      + Utils.doubleToString(m_modelNormal[j][i][1], 4)
		      + "\n");
        }
      }
    }

    return  text.toString();
  }


  /**
   * verbose output for debugging
   * @param inst the training instances
   */
  private void EM_Report (Instances inst) {
    int i, j, l, m;
    System.out.println("======================================");

    for (j = 0; j < m_num_clusters; j++) {
      for (i = 0; i < m_num_attribs; i++) {
	System.out.println("Clust: " + j + " att: " + i + "\n");

	if (m_theInstances.attribute(i).isNominal()) {
	  if (m_model[j][i] != null) {
	    System.out.println(m_model[j][i].toString());
	  }
	}
	else {
	  System.out.println("Normal Distribution. Mean = "
			     + Utils.doubleToString(m_modelNormal[j][i][0]
						    , 8, 4)
			     + " StandardDev = "
			     + Utils.doubleToString(m_modelNormal[j][i][1]
						    , 8, 4)
			     + " WeightSum = "
			     + Utils.doubleToString(m_modelNormal[j][i][2]
						    , 8, 4));
	}
      }
    }

    for (l = 0; l < inst.numInstances(); l++) {
      m = Utils.maxIndex(m_weights[l]);
      System.out.print("Inst " + Utils.doubleToString((double)l, 5, 0)
		       + " Class " + m + "\t");
      for (j = 0; j < m_num_clusters; j++) {
	System.out.print(Utils.doubleToString(m_weights[l][j], 7, 5) + "  ");
      }
      System.out.println();
    }
  }


  /**
   * estimate the number of clusters by cross validation on the training
   * data.
   *
   * @return the number of clusters selected
   */
  private int CVClusters ()
    throws Exception
  {
    double CVLogLikely = -Double.MAX_VALUE;
    double templl, tll;
    boolean CVdecreased = true;
    int num_cl = 1;
    int i;
    Random cvr;
    Instances trainCopy;
    int numFolds = (m_theInstances.numInstances() < 10)
      ? m_theInstances.numInstances()
      : 10;

    while (CVdecreased) {
      CVdecreased = false;
      cvr = new Random(m_rseed);
      trainCopy = new Instances(m_theInstances);
      trainCopy.randomize(cvr);
      // theInstances.stratify(10);
      templl = 0.0;

      for (i = 0; i < numFolds; i++) {
	Instances cvTrain = trainCopy.trainCV(numFolds, i);
	Instances cvTest = trainCopy.testCV(numFolds, i);
	EM_Init(cvTrain, num_cl);
	iterate(cvTrain, num_cl, false);
	tll = E(cvTest, num_cl);

	if (m_verbose) {
	  System.out.println("# clust: " + num_cl + " Fold: " + i
			     + " Loglikely: " + tll);
	}

	templl += tll;
      }

      templl /= (double)numFolds;

      if (m_verbose) {
	System.out.println("==================================="
			   + "==============\n# clust: "
			   + num_cl
			   + " Mean Loglikely: "
			   + templl
			   + "\n================================"
			   + "=================");
      }

      if (templl > CVLogLikely) {
	CVLogLikely = templl;
	CVdecreased = true;
	num_cl++;
      }
    }

    if (m_verbose) {
      System.out.println("Number of clusters: " + (num_cl - 1));
    }

    return  num_cl - 1;
  }


  /**
   * Returns the number of clusters.
   *
   * @return the number of clusters generated for a training dataset.
   * @exception Exception if number of clusters could not be returned
   * successfully
   */
  public int numberOfClusters ()
    throws Exception
  {
    if (m_num_clusters == -1) {
      throw  new Exception("Haven't generated any clusters!");
    }

    return  m_num_clusters;
  }


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

    m_theInstances = data;
    doEM();

    // save memory
    m_theInstances = new Instances(m_theInstances,0);
  }

  /**
   * Computes the density for a given instance.
   *
   * @param inst the instance to compute the density for
   * @return the density.
   * @exception Exception if the density could not be computed
   * successfully
   */
  public double densityForInstance(Instance inst) throws Exception {
    return Utils.sum(weightsForInstance(inst));
  }

  /**
   * Predicts the cluster memberships for a given instance.
   *
   * @param data set of test instances
   * @param instance the instance to be assigned a cluster.
   * @return an array containing the estimated membership
   * probabilities of the test instance in each cluster (this
   * should sum to at most 1)
   * @exception Exception if distribution could not be
   * computed successfully
   */
  public double[] distributionForInstance (Instance inst)
    throws Exception {
    double [] distrib = weightsForInstance(inst);
    Utils.normalize(distrib);
    return distrib;
  }

  /**
   * Returns the weights (indicating cluster membership) for a given instance
   *
   * @param inst the instance to be assigned a cluster
   * @return an array of weights
   * @exception Exception if weights could not be computed
   */
  protected double[] weightsForInstance(Instance inst)
    throws Exception {

    int i, j;
    double prob;
    double[] wghts = new double[m_num_clusters];

    for (i = 0; i < m_num_clusters; i++) {
      prob = 1.0;

      for (j = 0; j < m_num_attribs; j++) {
	if (!inst.isMissing(j)) {
	  if (inst.attribute(j).isNominal()) {
	    prob *= m_model[i][j].getProbability(inst.value(j));
	  }
	  else { // numeric attribute
	    prob *= normalDens(inst.value(j),
			       m_modelNormal[i][j][0],
			       m_modelNormal[i][j][1]);
	  }
	}
      }

      wghts[i] = (prob*m_priors[i]);
    }

    return  wghts;
  }


  /**
   * Perform the EM algorithm
   */
  private void doEM ()
    throws Exception
  {
    if (m_verbose) {
      System.out.println("Seed: " + m_rseed);
    }

    m_rr = new Random(m_rseed);
    m_num_instances = m_theInstances.numInstances();
    m_num_attribs = m_theInstances.numAttributes();

    if (m_verbose) {
      System.out.println("Number of instances: "
			 + m_num_instances
			 + "\nNumber of atts: "
			 + m_num_attribs
			 + "\n");
    }

    // setDefaultStdDevs(theInstances);
    // cross validate to determine number of clusters?
    if (m_initialNumClusters == -1) {
      if (m_theInstances.numInstances() > 9) {
	m_num_clusters = CVClusters();
      } else {
	m_num_clusters = 1;
      }
    }

    // fit full training set
    EM_Init(m_theInstances, m_num_clusters);
    m_loglikely = iterate(m_theInstances, m_num_clusters, m_verbose);
  }


  /**
   * iterates the M and E steps until the log likelihood of the data
   * converges.
   *
   * @param inst the training instances.
   * @param num_cl the number of clusters.
   * @param report be verbose.
   * @return the log likelihood of the data
   */
  private double iterate (Instances inst, int num_cl, boolean report)
    throws Exception
  {
    int i;
    double llkold = 0.0;
    double llk = 0.0;

    if (report) {
      EM_Report(inst);
    }

    for (i = 0; i < m_max_iterations; i++) {
      M(inst, num_cl);
      llkold = llk;
      llk = E(inst, num_cl);

      if (report) {
	System.out.println("Loglikely: " + llk);
      }

      if (i > 0) {
	if ((llk - llkold) < 1e-6) {
	  break;
	}
      }
    }

    if (report) {
      EM_Report(inst);
    }

    return  llk;
  }


  // ============
  // Test method.
  // ============
  /**
   * Main method for testing this class.
   *
   * @param argv should contain the following arguments: <p>
   * -t training file [-T test file] [-N number of clusters] [-S random seed]
   */
  public static void main (String[] argv) {
    try {
      System.out.println(ClusterEvaluation.
			 evaluateClusterer(new EM(), argv));
    }
    catch (Exception e) {
      log.error(e.getMessage());
      log.error(e.getStackTrace().toString());
    }
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品视频在线免费观看| 一区二区三区欧美在线观看| 亚洲丝袜精品丝袜在线| 日日夜夜精品免费视频| 不卡一区二区中文字幕| 亚洲精品在线三区| 日本不卡在线视频| 欧美体内she精视频| 国产欧美综合色| 狂野欧美性猛交blacked| 91福利国产精品| 国产精品国产三级国产| 国产精品69毛片高清亚洲| 欧美一级日韩一级| 亚洲成a人片在线观看中文| 91亚洲精品久久久蜜桃| 国产精品久久久久久久久免费樱桃 | 日韩三区在线观看| 一片黄亚洲嫩模| 色综合天天性综合| 国产精品乱人伦| 国产69精品一区二区亚洲孕妇| 日韩免费观看高清完整版在线观看| 亚洲成人自拍一区| 在线免费亚洲电影| 亚洲综合图片区| 欧美特级限制片免费在线观看| 一区二区欧美精品| 欧洲人成人精品| 亚洲国产sm捆绑调教视频| 欧美日韩性生活| 日韩在线卡一卡二| 日韩精品中文字幕一区二区三区| 奇米色一区二区三区四区| 日韩一区二区在线免费观看| 日本欧美久久久久免费播放网| 91精品国产综合久久精品麻豆| 日精品一区二区三区| 日韩欧美亚洲国产另类| 久久国产乱子精品免费女| 久久蜜桃av一区二区天堂| 国产 欧美在线| 亚洲精品日韩一| 欧美日韩一区二区三区高清| 日韩国产精品久久久| 91精品国产aⅴ一区二区| 韩国一区二区在线观看| 欧美国产精品中文字幕| 一本大道久久a久久综合| 亚洲丶国产丶欧美一区二区三区| 欧美男男青年gay1069videost| 欧美aa在线视频| 国产日韩精品一区二区三区| 色香蕉成人二区免费| 天天操天天色综合| 久久久欧美精品sm网站| 色综合久久久久综合体| 水蜜桃久久夜色精品一区的特点| 欧美一区二区三区免费在线看 | 国产欧美中文在线| 一道本成人在线| 麻豆91在线播放| 中文字幕乱码一区二区免费| 欧美在线制服丝袜| 国产精品自在在线| 亚洲综合自拍偷拍| 久久色中文字幕| 欧美日韩一级大片网址| 国产成人aaaa| 日日欢夜夜爽一区| 最新日韩av在线| 日韩一区二区三区在线视频| 99精品欧美一区二区蜜桃免费| 日韩经典一区二区| 国产精品卡一卡二卡三| 日韩欧美卡一卡二| 色先锋久久av资源部| 国产精品影音先锋| 婷婷开心激情综合| 亚洲码国产岛国毛片在线| 亚洲精品在线观看视频| 欧美日产在线观看| 9i看片成人免费高清| 精品一区二区日韩| 首页综合国产亚洲丝袜| 亚洲美女在线一区| 国产精品国产馆在线真实露脸| 精品久久久久99| 欧美日韩精品专区| 在线视频国内一区二区| 成人福利视频网站| 国产又黄又大久久| 久久精品99久久久| 午夜不卡在线视频| 亚洲国产三级在线| 17c精品麻豆一区二区免费| 久久午夜免费电影| 欧美大片日本大片免费观看| 欧美另类变人与禽xxxxx| 一本一道综合狠狠老| 成人精品免费视频| 国产夫妻精品视频| 国产一区二区在线观看视频| 奇米精品一区二区三区在线观看| 亚洲成人自拍网| 亚洲午夜精品一区二区三区他趣| 亚洲视频一区在线| 亚洲男人的天堂一区二区| 成人欧美一区二区三区白人| 国产欧美日韩不卡| 国产精品欧美一区喷水| 中文字幕久久午夜不卡| 国产精品私人影院| 国产精品麻豆网站| 亚洲欧美一区二区三区久本道91| 成人欧美一区二区三区视频网页 | 久久久99久久| 国产欧美一区二区精品性色超碰| 久久综合资源网| 久久久777精品电影网影网 | 99久久亚洲一区二区三区青草| 成人av电影在线| 972aa.com艺术欧美| 91在线免费看| 在线国产电影不卡| 欧美日本一区二区| 日韩一区二区电影| 国产日韩在线不卡| 亚洲视频一区二区在线观看| 亚洲一二三专区| 久久9热精品视频| 国产成人在线电影| 色综合久久中文字幕| 欧美日本一区二区三区四区| 精品久久人人做人人爽| 久久精品一级爱片| 国产精品成人一区二区三区夜夜夜| 亚洲同性同志一二三专区| 香蕉影视欧美成人| 国产一区二区在线看| 91亚洲大成网污www| 欧美人与性动xxxx| 国产视频一区二区三区在线观看| 最新国产成人在线观看| 亚洲成人激情av| 国产不卡视频在线观看| 日韩一区二区免费视频| 久久午夜国产精品| 亚洲一二三专区| 国产精品一区2区| 欧美亚日韩国产aⅴ精品中极品| 日韩亚洲欧美一区| 日韩美女视频一区二区| 热久久国产精品| youjizz久久| 日韩欧美国产一区二区在线播放| 国产精品国产自产拍在线| 日本不卡一区二区| 91在线视频播放地址| 日韩一级免费一区| 一区二区三区在线播放| 久草这里只有精品视频| 91成人免费在线视频| 2021中文字幕一区亚洲| 水野朝阳av一区二区三区| 99热在这里有精品免费| 亚洲精品在线免费观看视频| 怡红院av一区二区三区| 国产成人免费视频网站高清观看视频| 欧美三级午夜理伦三级中视频| 国产拍欧美日韩视频二区| 美女爽到高潮91| 欧美日韩三级一区二区| 亚洲欧美区自拍先锋| 国产91精品精华液一区二区三区| 91精品午夜视频| 亚洲成av人片| 91免费国产视频网站| 日本一区二区三区四区| 国模大尺度一区二区三区| 91麻豆精品国产自产在线观看一区 | 偷拍自拍另类欧美| 色综合久久综合网欧美综合网 | 不卡的av网站| 国产三级精品视频| 捆绑调教美女网站视频一区| 91麻豆精品国产自产在线观看一区 | 久久先锋影音av鲁色资源| 日本伊人色综合网| 欧美日本精品一区二区三区| 亚洲午夜久久久久久久久电影院| 日本韩国一区二区三区视频| 亚洲女爱视频在线| 色噜噜夜夜夜综合网| 伊人夜夜躁av伊人久久| 91国产免费观看| 亚洲在线成人精品| 欧美麻豆精品久久久久久| 亚洲电影一级黄| 欧美一区二区成人|