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

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

?? naivebayescat.java

?? Naive Bayes算法java代碼
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
	    attrImp[i] = 0;
        }
	  else {
	    double condEnt = Entropy.cond_entropy(instList.counters().value_counts()[i], instList.counters().attr_counts()[i], instList.total_weight());

	    if(condEnt < 0 && -condEnt < MLJ.realEpsilon) {
	       condEnt = 0;
          }
	    attrImp[i] = 100 - 100 * (condEnt / ent);
	    if(attrImp[i] < 0 && attrImp[i] >= -1000 * MLJ.realEpsilon) {
	       attrImp[i] = 0;  // avoid small negatives
          }
	    else if(attrImp[i] < 0) {
	       Error.fatalErr("compute_importance: attribute " + i +
		      " had importance " + attrImp[i] + "which is severly negative");
          }
	  }
      }
      else {
	 Error.fatalErr("compute_importance: attribute " + i + " has " +
	    "unsupported type.  Must be real or nominal.");
      }
    }
    return attrImp;
  }  /** Computes the distance metrics for all attributes.    * Should only be called once.    */  private void compute_kl_distances() {    if(unkIsVal != null) {      Error.fatalErr("NaiveBayesCat.compute_kl_distances: kl distances already computed");    }    unkIsVal = new boolean[get_schema().num_attr()];    for(int i=0; i<get_schema().num_attr(); i++) {      if(!get_schema().attr_info(i).can_cast_to_nominal()) {	  Error.fatalErr("NaiveBayesCat.categorize: UNKNOWN_IS_VALUE is set and " +	      get_schema().attr_name(i) + " is a real value with unknowns.  " +            "UNKNOWN_IS_VALUE settings of " +	      "yes and auto are not supported for undiscretized real values " +	      "with unknowns.");      }            double dist = kl_distance(i);      if(dist >= klThreshold) {	  logOptions.LOG(1, "k-l distance for attribute " + get_schema().attr_name(i)	      + " (" + dist + ") exceeds threshold" + endl);
	  unkIsVal[i] = true;
      }
      else {
        unkIsVal[i] = false;
      }
    }
  }  /** copyAttrImportance copys the array of doubles stored in the attrImportance
    * Array and returns the new Array. This function is used to copy NaiveBayesCat
    * Objects.    * @author James Plummer added to package for compatibility.    * @return the new copy of attrImportance.    */  private double[] copyAttrImportance() {
    if ( this.attrImportance != null ) {
      double[] result = new double[attrImportance.length];
      for (int i = 0; i < attrImportance.length; i++) {
        result[i] = attrImportance[i];
      }
      return result;
    }
    else {
      return null;
    }    
  }  /** copyContinNorm copys the array of NBNorms stored in the continNorm
    * Array and returns the new Array. This function is used to copy NaiveBayesCat
    * Objects.    * @author James Plummer added for compatiblity.    * @return the new copy of continNorm.    */  private NBNorm[][] copyContinNorm() {
    if ( this.continNorm != null ) {
      NBNorm[][] result = new NBNorm[continNorm.length][];
      for (int i = 0; i < continNorm.length; i++) {
        result[i] = new NBNorm[continNorm[i].length];
        for (int j = 0; j < continNorm[i].length; j++) {
          result[i][j] = new NBNorm(continNorm[i][j]);
        }
      }

      return result;
    }
    else {
      return null;
    }    
  }  /** Prints a readable representation of the Cat to the
    *given stream.    */  public void display_struct(BufferedWriter stream, DisplayPref dp) {
    try {
    if (stream != null) {
      logOptions.set_log_stream(stream);
    }
    stream.write("Simple NaiveBayes Cat " + this.description() + 
                 " categorizing using prevalence data in BagCounter: "  + endl + 
                 nominCounts + endl);
   
    if ( continNorm != null ) {
      stream.write("Categorizing uses Normal Density to estimate probability" +
	  " of continuous attributes.  The mean, variance, and standard" +
	  " deviation of each attribute,label combination is: " + endl);
      for (int i = 0; i < numAttributes; i++) {
	  if ( nominCounts.value_counts()[i] != null )    // nominal attribute
	    stream.write("Attribute " + i + ":" + " Nominal Attribute." + endl);
	  else {
	    stream.write("Attribute " + i + ":" + endl);
	    for (int j = 0; j < num_categories(); j++) 
	       stream.write("  Label " + j + "\t\t" + continNorm[i][j].mean +
		              "\t" + continNorm[i][j].var + endl);
	  }
      }
    }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }  /** findMax finds the largest value for an array of doubles
    * @author James Plummer added to match C++ functionality.    * @param d - the array of doubles.
    * @return the maximum number.
    */  public static double findMax(double[] d) {
    double result = d[0];
    for (int i = 1; i < d.length; i++) {
      if (result < d[i]) {
        result = d[i];
      }
    }
    return result;
  }  /** findMin finds the smallest value for an array of doubles
    * @author James Plummer added to match C++ functionality.    * @param d - the array of doubles.
    * @return the minimum number.
    */
  public static double findMin(double[] d) {
    double result = d[0];
    for (int i = 1; i < d.length; i++) {
      if (result > d[i]) {
        result = d[i];
      }
    }
    return result;
  }  /** Helper function: generate a single probability using     * the Laplace correction.    * Evidence projection is not used if there's no data    * (labelCount == 0).    */  private double generate_cond_probability(double labelValCount, double labelCount,
					            int numAttrVals, int numAttr) {
    if(useEvidenceProjection && labelCount > 0) {
      double maxEvidence = MLJ.log_bin(1.0 + trainWeight*evidenceFactor);
      return CatDist.single_evidence_projection(labelValCount, labelCount, maxEvidence);
    }
    else if (useLaplace) {
      double effectiveMEstimate = mEstimateFactor;
      if(effectiveMEstimate == 0.0) {
	  effectiveMEstimate = 1.0 / trainWeight;
      }
      return (labelValCount + effectiveMEstimate) / (labelCount + numAttrVals * effectiveMEstimate);
    }
    else if (labelValCount == 0) {
      if(noMatchesFactor >= 0) {
	  return noMatchesFactor / trainWeight;
      }
      else if(noMatchesFactor == -1) {
	  return (double)(labelCount) / trainWeight / trainWeight;
      }
      else if(noMatchesFactor == -2) {
	 return (double)(labelCount) / trainWeight
	    / (trainWeight * this.get_schema().num_attr());
      }
      else {
	 Error.fatalErr("NaiveBayesCat.generate_cond_probability: noMatchesFactor has illegal value of " +
	    noMatchesFactor);
	 return 0;
      }
    }
    else {
      // if labelCount == 0, then labelValCount should also be 0 and we'll
      // choose the case above instead of this one.
      MLJ.ASSERT( (labelCount > 0), "NaiveBayesCat.generate_cond_probability()");
      return (double)(labelValCount / labelCount);
    }
  }  /** Helper function: generate a single probability.  Allow
    * for Laplace correction.    */  private double generate_probability_prior(double labelCount, int numLabels) {
   if(useEvidenceProjection) {
      double maxEvidence = MLJ.log_bin(1.0 + trainWeight*evidenceFactor);
      return CatDist.single_evidence_projection(labelCount, trainWeight, maxEvidence);
   }
   else if(useLaplace) {
      double effectiveMEstimate = mEstimateFactor;
      if(effectiveMEstimate == 0.0) {
	 effectiveMEstimate = 1.0 / trainWeight;
      }
      return (labelCount + effectiveMEstimate) / (trainWeight + numLabels * effectiveMEstimate);
   }
   else if(labelCount == 0)
      return 0;

   else {
      // if labelCount == 0, then labelValCount should also be 0 and we'll
      // choose the case above instead of this one.
      MLJ.ASSERT( (labelCount > 0), "NaiveBayesCat.generate_probablility()");
      return labelCount / trainWeight;
   }
  }    /** Removed function *//*  public void generate_viz(BufferedWriter stream, boolean[] autoDiscVector, int evivizVersion) throws IOException {
  }*/  /** fuctions for retrieving and setting optional variables. */  public double get_evidence_factor() { return evidenceFactor; }
  public double get_kl_threshold() { return klThreshold; }
  public double get_m_estimate_factor() { return mEstimateFactor; }
  public double get_no_matches_factor() { return noMatchesFactor; }
  public int get_unknown_is_value() { return unknownIsValue; }
  public boolean get_use_evidence_projection() { return useEvidenceProjection; }
  public boolean get_use_laplace() { return useLaplace; }
  public void set_evidence_factor(double f) { evidenceFactor = f; }
  public void set_kl_threshold(double th) { klThreshold = th; }
  /** Initialize the probabilities to be the class probabilities
    * P(L = l)     * @param nominCoutns - the BagCounter to initilize.    */  public static void init_class_prob(BagCounters nominCounts,
                      double trainWeight,
                      double[] prob, boolean useLaplace,
                      boolean useEvidenceProjection,
                      double evidenceFactor)
  {
    if (useEvidenceProjection) {
      for (int labelVal = 0; labelVal < prob.length; labelVal++) {
        prob[labelVal] = nominCounts.label_count(labelVal);
      }
      CatDist.apply_evidence_projection(prob, evidenceFactor, true);
    }
    else if (useLaplace) {
      int numLabels = prob.length - 1;
  
      // No laplace correction for unknown label.  This fixes bug #526924
      MLJ.ASSERT(nominCounts.label_count(Globals.UNKNOWN_CATEGORY_VAL) == 0,"NaiveBayesCat.init_class_prob()");
      prob[Globals.UNKNOWN_CATEGORY_VAL] = 0;
      for (int labelVal = 1; labelVal < prob.length; labelVal++) {
        prob[labelVal] = (double)(nominCounts.label_count(labelVal) + 1)/(trainWeight + numLabels);
      }
    }
    else {
      for (int labelVal = 0; labelVal < prob.length; labelVal++) {
        prob[labelVal] = (double)(nominCounts.label_count(labelVal))/(trainWeight);
      }
    }
    
    // Check that probabilities sum to about 1.0
    double probSum = sumArray(prob);
    MLJ.verify_approx_equal(probSum,1,"NaiveBayesCat.init_class_prob: prob does not sum to one");
  }  /** Compute the KL distance metric for a single attribute.    * If we don't have minimum support, we always return 0    * @param attrNum - the number of the attribute to compute distances.    * @return the distance for the attribute.    */  private double kl_distance(int attrNum)  {    int numLabelVals = get_schema().num_label_values();
    double[] p = new double[numLabelVals];
    double[] q = new double[numLabelVals];
       if(!get_schema().attr_info(attrNum).can_cast_to_nominal()) {
      Error.fatalErr("NaiveBayesCat.kl_distance: this function does not work " +
	 "for real attributes");
    }    double support = nominCounts.attr_count(attrNum, Globals.UNKNOWN_CATEGORY_VAL);
    MLJ.verify_strictly_greater(trainWeight,0.0,"NaiveBayesCat.kl_distance: " +
			       "total train weight is negative");
    if (support < 5) { // @@ make this an option
      return 0;         
    }
    int numLabelValues = get_schema().num_label_values();

    for(int i=0; i < numLabelValues; i++) {
      // Compute p(C) and p(C|?) with laplace correction so we
      //   avoid zeros and can do KL distance.
      q[i] = (nominCounts.label_count(i) + 1)/(trainWeight + numLabelValues);

      MLJ.ASSERT(support > 0,"NaiveBayesCat.kl_distance()");
      p[i]=(nominCounts.val_count(i, attrNum, Globals.UNKNOWN_CATEGORY_VAL) + 1)/(support + numLabelValues); 
    } 

    // now get the distance

    logOptions.LOG(3, "p=" + p + "\nq=" + q + endl);

    double dist = this.kullback_leibler_distance(p, q);
    logOptions.LOG(2, "k-l distance for attribute " + this.get_schema().attr_name(attrNum) +
        " (" + attrNum + "): " + dist + endl);
   
    return dist;
  }  /** Removed function *//*  boolean operator==(Categorizer rhs) {  }*/  /** Removed function *//*  public void make_persistent(PerCategorizer_ dat) {
*/  /** Compute a Kullback Leibler distance metric given an array    * of p(x) and q(x) for all x.

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人国产在线观看| 婷婷久久综合九色综合绿巨人| 蜜桃一区二区三区在线观看| 欧美高清激情brazzers| 日本欧美大码aⅴ在线播放| 欧美岛国在线观看| 国内成人自拍视频| 国产网红主播福利一区二区| 成人18视频日本| 一区二区三区高清在线| 欧美一区二视频| 国产成人精品免费在线| 国产精品成人网| 欧美日韩精品福利| 精品一区中文字幕| 国产精品电影一区二区| 精品少妇一区二区三区免费观看| 久久99国产精品久久99| 中文在线免费一区三区高中清不卡| 91原创在线视频| 日韩高清不卡一区二区| 久久九九影视网| 欧洲视频一区二区| 国产最新精品免费| 亚洲视频中文字幕| 日韩欧美综合在线| jvid福利写真一区二区三区| 五月激情综合婷婷| 国产三级一区二区| 欧美在线影院一区二区| 国产麻豆精品一区二区| 一区二区三区成人在线视频| 欧美精品一区二区精品网| 色综合色狠狠天天综合色| 久久99国产乱子伦精品免费| 亚洲九九爱视频| 久久久欧美精品sm网站| 欧美色涩在线第一页| 高清不卡在线观看av| 亚洲电影一级黄| 国产精品色哟哟网站| 5566中文字幕一区二区电影| 成人h动漫精品| 久久99国内精品| 亚洲国产一区视频| 国产精品美女久久久久久久久久久 | 国产精品久久久久影院亚瑟 | 国产精品毛片大码女人| 欧美一级艳片视频免费观看| 色综合天天综合网国产成人综合天| 美女国产一区二区三区| 亚洲综合精品久久| 中文字幕一区日韩精品欧美| 精品国产乱码久久久久久免费| 在线观看精品一区| 不卡一区二区三区四区| 精品在线播放免费| 美腿丝袜在线亚洲一区| 亚洲成人av一区二区| 中文字幕一区二区日韩精品绯色| 精品国产乱码久久久久久1区2区| 欧美日本韩国一区二区三区视频| 91网上在线视频| 不卡的电视剧免费网站有什么| 久久av资源网| 裸体一区二区三区| 蜜臀av性久久久久av蜜臀妖精| 国产成人精品影视| 久久66热re国产| 另类小说综合欧美亚洲| 青青草成人在线观看| 亚洲福利一区二区| 亚洲国产wwwccc36天堂| 亚洲成av人片在线观看无码| 亚洲国产精品一区二区久久 | 玉米视频成人免费看| 成人欧美一区二区三区1314| 中文字幕欧美一| 亚洲欧洲av另类| 亚洲免费伊人电影| 一区二区三区在线高清| 一区二区三区在线视频观看58| 亚洲另类色综合网站| 一个色在线综合| 亚洲国产成人精品视频| 免费在线观看不卡| 精品一区二区免费| 国产精品亚洲一区二区三区妖精 | 国产精品乱人伦| ...中文天堂在线一区| 亚洲欧美在线aaa| 亚洲精品日产精品乱码不卡| 亚洲午夜激情网页| 免费欧美在线视频| 国产91综合网| 91蜜桃传媒精品久久久一区二区| 欧美中文字幕一区| 日韩午夜在线影院| 国产日韩欧美在线一区| 亚洲欧美国产高清| 视频一区二区三区在线| 国产一区二区三区黄视频 | 亚洲精品国产第一综合99久久| 亚洲自拍偷拍九九九| 免费久久精品视频| 国产成人av在线影院| 在线免费亚洲电影| 日韩精品一区二区三区视频播放 | 国产一区二区三区香蕉| 99久久er热在这里只有精品15| 欧美日韩在线综合| 久久先锋影音av鲁色资源| 日韩码欧中文字| 麻豆精品国产传媒mv男同 | 日韩激情视频网站| 国产成人福利片| 欧美精品日韩一区| 中文字幕的久久| 丝袜诱惑制服诱惑色一区在线观看 | 国产一区二区三区精品视频| 一本久道久久综合中文字幕 | 亚洲高清一区二区三区| 国产在线视频精品一区| 欧美综合在线视频| 欧美国产精品中文字幕| 亚洲第一会所有码转帖| 成人黄色小视频在线观看| 51精品国自产在线| 亚洲免费观看高清完整版在线| 久久99九九99精品| 欧美四级电影网| 日韩美女视频19| 国产一区二区导航在线播放| 欧美日本国产视频| 中文字幕一区二区三区视频| 精品一区二区久久| 欧美美女黄视频| 一区二区三区电影在线播| 777午夜精品视频在线播放| 国产精品久久久久婷婷| 久久99精品久久久| 欧美日韩国产大片| 日韩毛片高清在线播放| 懂色av中文字幕一区二区三区| 日韩欧美中文一区二区| 亚洲第一久久影院| 色哟哟一区二区| 国产精品不卡视频| 成人一区在线观看| 国产午夜精品在线观看| 美女视频一区在线观看| 51精品秘密在线观看| 亚洲福利电影网| 在线一区二区三区四区五区| 亚洲图片另类小说| 不卡欧美aaaaa| 中文字幕不卡在线播放| 国产99久久久国产精品潘金| 久久美女艺术照精彩视频福利播放 | 欧美一区二区三区系列电影| 天天av天天翘天天综合网 | 欧美一区二区三区成人| 午夜精品爽啪视频| 欧美久久久久久蜜桃| 婷婷综合另类小说色区| 欧美精品久久99| 免费欧美在线视频| 欧美成va人片在线观看| 美国精品在线观看| 日韩免费高清av| 国产精品中文字幕日韩精品| 久久久www成人免费无遮挡大片| 国产一区二区三区不卡在线观看| 精品美女在线播放| 国产精品综合网| 欧美国产激情一区二区三区蜜月| 成人精品免费网站| 亚洲天堂2016| 欧美色网站导航| 日韩成人精品视频| 精品国产乱码久久久久久夜甘婷婷 | 国产欧美一区二区三区在线老狼| 国产激情视频一区二区三区欧美| 久久久久国色av免费看影院| 国产成人在线色| 国产精品第四页| 欧美色网一区二区| 日本中文在线一区| 久久久夜色精品亚洲| 99精品在线免费| 亚洲图片欧美色图| 26uuu色噜噜精品一区| av电影天堂一区二区在线| 一区二区三区av电影| 日韩一区二区三区av| 国产91丝袜在线18| 亚洲成a人v欧美综合天堂| 精品国产伦一区二区三区观看方式 | 成人18精品视频| 亚洲va在线va天堂|