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

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

?? entropy.java

?? c4.5 ID3 分類決策數 公用java包 share
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
package shared;
import java.lang.*;
import java.util.*;

/** This class handles all of the Entropy based calculations. All logs
 * are base 2 (other bases just scale the entropy). The reason for using
 * log_bin is simply that the examples in Quinlan's C4.5 book use it, and
 * those examples were used for testing.  It's also a measure of the
 * number of "bits" in information theory, so it's appealing in that sense
 * too. The computation is based on:                                           <BR>
 * 1. "Boolean Feature Discovery in Empirical Learning" / Pagallo and
 * Haussler.                                                                   <BR>
 * 2. "A First Course in Probability, 2nd Edition" / Ross, pages 354-359.
 *                                                                            <BR>
 * 3. "C4.5: Programs for Machine Learning" / Ross Quinlan, pages 18-24.
 *                                                                            <BR>
 * @author James Louis 5/21/2001	Java implementations.
 * @author Cliff Brunk 5/25/96 Added weight to find_best_threshold and
 * get_split_score.
 * @author Eric Eros 12/05/96 Revised find_best_threshold to use
 * SplitAttr, and to use RealAndLabelColumn and SplitAttr.
 * @author Chia-Hsin Li Revised find_best_threshold to allow multiple
 * InstanceLists.
 * @author Brian, Ronny Kohavi 9/04/93 Initial revision
 */
public class Entropy {
    
    /** Constant for binary log calculations.
     */
    static public double M_LOG2E = 1.4426950408889634074;
    
    /** Automatically determine a good lower bound for minSplit, based on the
     * total weight of an instance list at the start of training.
     * @param totalWeight	The total weight of instances in this
     * InstanceList partition.
     * @return A lower bound for minSplit.
     */
    public static double auto_lbound_min_split(double totalWeight) {
        double k = 1.851;
        double m = 8.447;
        if (totalWeight < 1)
            return 1;
        return Math.max(1.0, k*log_bin(totalWeight)-m);
    }
    
    /** Returns the log base two of the supplied number.
     * @param num	The number for which a log is requested.
     * @return The log base two of the supplied number.
     */
    public static double log_bin(double num) {
        //      return Math.log(num)/ Math.log(2);
        return Math.log(num) * M_LOG2E;
    }
    
    /** Compute the best threshold for RealAndLabelColumn(s). Initially, all
     * instances are at the right hand side of splitDist and
     * splitAndLabelDist. To find the best threshold, we shift the instances
     * from right to left and calculate their conditional entropy. Then we
     * pick up the one with minimum conditional entropy and return
     * bestThreshold and minCondEntropy as results. When two entropies are
     * equal, we prefer the one that splits instances equally into two bins
     * in the hope of making the tree shallower. Tests show minor effect but
     * it does help pima for different leaf counts.
     * @param realAndLabelColumn The column of real values and their associated labels
     * @param minSplit The split value for which conditional entropy is minimal.
     * @param split The scores for all available splits.
     * @param bestThreshold The real value that is the best threshold over the supplied real values.
     * @param bestSplitIndex Index of the best split in the supplied RealAndLabelColumn.
     * @param numDistinctValues The number of non-equal values.
     * @param smoothInst The index of the instance to be smoothed toward.
     * @param smoothFactor The amount of normalization done towards the specified instance index.
     */
    public static void find_best_threshold(RealAndLabelColumn realAndLabelColumn,
    double minSplit, SplitScore split,
    DoubleRef bestThreshold, IntRef bestSplitIndex,
    IntRef numDistinctValues, int smoothInst,
    double smoothFactor) {
        if (minSplit < 0)
            Error.fatalErr("find_best_threshold:  minSplit(" +minSplit+ ") must be at least 0");
        bestThreshold.value = Globals.UNDEFINED_REAL;
        bestSplitIndex.value = 0;
        numDistinctValues.value = 0;
        double totalKnownWeight = realAndLabelColumn.known_weight();
        if (realAndLabelColumn.known_weight()<(2 * minSplit)) {
            split.reset();
            return;
        }
        Vector scores = new Vector();
        double[][] sAndLDist = get_score_array(realAndLabelColumn,
        split, minSplit,
        scores, numDistinctValues,
        smoothInst, smoothFactor);
        if (sAndLDist == null)
            return;
        double bestScore = find_best_score(totalKnownWeight,
        scores, minSplit, bestSplitIndex);
        if (bestScore > Globals.UNDEFINED_REAL) {
            bestThreshold.value =
            ((double)(realAndLabelColumn.index(bestSplitIndex.value - 1).value)+
            (double)(realAndLabelColumn.index(bestSplitIndex.value).value))/ 2;
            for(int k = 1 ; k <= bestSplitIndex.value ; k++) {
                AttrLabelPair alp = realAndLabelColumn.index(k - 1);
                int lab = alp.label;
                double weight = alp.weight;
                sAndLDist[lab][Globals.RIGHT_NODE] -= weight;
                sAndLDist[lab][Globals.LEFT_NODE] += weight;
                if (MLJ.approx_equal(sAndLDist[lab][Globals.RIGHT_NODE],0))
                    sAndLDist[lab][Globals.RIGHT_NODE]= 0;
            }
            sAndLDist = split.set_split_and_label_dist(sAndLDist);
        }
        else {
            split.reset();
            sAndLDist = null;
        }
        MLJ.ASSERT(sAndLDist == null, "Entropy::find_best_threshold: sAndLDist == null");
    }
    
    /** Calculates the distribution array for the given sorted
     * RealAndLabelColumn. This function then progresses through the input array,
     * shifting counts from the right to the left (in the distributions).
     * When the Real values in the input array change, the potential score of
     * a split at that value is calculated, and stored in the output array,
     * outScores. At the end, outScores contains the discrete thresholds, the
     * scores associated with a split at each of these thresholds, and the
     * indices into the original array.
     * @param realAndLabelColumn The supplied column of real values and their associated label values.
     * @param split The scores for all available splits.
     * @param minSplit The split value for which conditional entropy is minimal.
     * @param outScores The scores after smoothing.
     * @param numDistinctValues The number of non-equal values.
     * @param smoothInst The index of the instance to be smoothed towards.
     * @param smoothFactor The amount of normalization done towards the specified instance index.
     * @return The split and label distribution.
     */
    public static double[][] get_score_array(RealAndLabelColumn realAndLabelColumn,
    SplitScore split, double minSplit,
    Vector outScores,
    IntRef numDistinctValues, int smoothInst,
    double smoothFactor) {
        int numLabels = realAndLabelColumn.label_count();
        double[][] splitAndLabelDist = new double[numLabels+1][3];
        Matrix.initialize(0,splitAndLabelDist);
        double[] splitDist = new double[3];
        realAndLabelColumn.init_dist_counts(splitAndLabelDist, splitDist);
        double[] labelDist = new double[splitAndLabelDist.length];
        Matrix.sum_rows(labelDist,splitAndLabelDist);
        int numUsedLabels = 0;
        for(int labelNum = 0 ;
        labelNum < splitAndLabelDist.length ;
        labelNum++)
            if (labelDist[labelNum] > 0)
                ++numUsedLabels;
        if (numUsedLabels < 2) {
            split.reset();
            return null;
        }
        double theEntropy = entropy(labelDist);
        
        double[][] sAndLDist = new double[splitAndLabelDist.length][splitAndLabelDist[0].length];
        for(int i = 0 ; i < splitAndLabelDist.length ; i++)
            for(int j = 0 ; j < splitAndLabelDist[0].length ; j++)
                sAndLDist[i][j] = splitAndLabelDist[i][j];
        numDistinctValues.value = 0;
        fill_scores(realAndLabelColumn, split, minSplit, theEntropy,
        outScores, numDistinctValues, splitAndLabelDist, splitDist);
        if (sAndLDist != null && smoothInst != 0)
            smooth_scores(outScores, smoothInst, smoothFactor);
        return sAndLDist;
    }
    
    /** Normalizes the scores towards the instance at the supplied index.
     * @param scores The set of scores to be smoothed.
     * @param smoothInst The index of the instance to be smoothed towards.
     * @param smoothFactor The amount of normalization done towards the specified instance index.
     */
    public static void smooth_scores(Vector scores, int smoothInst, double smoothFactor) {
        double[] oldScores = new double[smoothInst+1];
        MLJArray.init_values(-1,oldScores);
        int numThresholds = scores.size();
        
        for(int i = 0 ; i < numThresholds ; i++) {
            double summedScores =((ThresholdInfo)scores.get(i)).score;
            double summedFactor = 1;
            double currFactor = smoothFactor;
            for(int left = 1 ; i - left >= 0 && left <= smoothInst ; left++) {
                summedScores +=(currFactor *((ThresholdInfo)scores.get(i - left)).score);
                summedFactor += currFactor;
                currFactor *= smoothFactor;
            }
            currFactor = smoothFactor;
            for(int right = 1 ; i + right < numThresholds && right <= smoothInst ; right++) {
                summedScores +=(currFactor *((ThresholdInfo)scores.get(i + right)).score);
                summedFactor += currFactor;
                currFactor *= smoothFactor;
            }
            if (i > smoothInst) {
                ((ThresholdInfo)scores.get(i - smoothInst - 1)).score = oldScores[smoothInst];
            }
            for(int j = smoothInst - 1 ; j >= 0 ; j--) {
                oldScores[j+1] = oldScores[j];
            }
            if (MLJ.approx_equal(summedFactor, 0.0))
                Error.fatalErr("smooth_scores: divisor (summedFactor) too close to zero");
            oldScores[0] = summedScores/  summedFactor;
        }
        for(int j = 0 ; j < smoothInst+1 ; j++) {
            if (numThresholds - smoothInst - 1 + j >= 0)
                ((ThresholdInfo)scores.get(numThresholds - smoothInst - 1 + j)).score = oldScores[smoothInst - j];
        }
    }
    
    /** Fills the Vector of scores with the scores for all the thresholds.
     * The number of distinct values is only true for the range of numbers if
     * the relevant range that does not include minSplit on the right and left.
     * @param realAndLabelColumn The column of real values and their associated labels over which thresholds are
     * created.
     * @param split The SplitScore used for scoring this threshold split.
     * @param minSplit The minimum value for splits.
     * @param theEntropy The Entropy value
     * @param outScores The Vector of scores to be filled.
     * @param numDistinctValues The number of distinct real values for this attribute.
     * @param splitAndLabelDist Distributions over each split and label pair.
     * @param splitDist The distribution over splits.
     */
    public static void fill_scores(RealAndLabelColumn realAndLabelColumn,
    SplitScore split, double minSplit, double theEntropy,
    Vector outScores, IntRef numDistinctValues, double[][] splitAndLabelDist,
    double[] splitDist) {
        double totalWeight = realAndLabelColumn.total_weight();
        int numKnownInstances = realAndLabelColumn.known_count();
        float lastSeen = realAndLabelColumn.index(0).value;
        int threshIndex = 0;
        // We start at 1 because we're comparing a split just before this
        //   element
        for(int k = 1 ; k < numKnownInstances ; k++) {
            AttrLabelPair alp = realAndLabelColumn.index(k - 1);
            float value = alp.value;
            int lab = alp.label;
            double weight = alp.weight;
            float nextValue = realAndLabelColumn.index(k).value;
            splitDist[Globals.RIGHT_NODE] -= weight;
            splitDist[Globals.LEFT_NODE] += weight;
            if (MLJ.approx_equal((float)splitDist[Globals.RIGHT_NODE], 0.0))
                splitDist[Globals.RIGHT_NODE] = 0;
            splitAndLabelDist[lab][Globals.RIGHT_NODE] -= weight;
            splitAndLabelDist[lab][Globals.LEFT_NODE] += weight;
            if (MLJ.approx_equal((float)splitAndLabelDist[lab][Globals.RIGHT_NODE], 0.0))
                splitAndLabelDist[lab][Globals.RIGHT_NODE] = 0;
            double deltaAttr =(double)nextValue -(double)(lastSeen);
            MLJ.ASSERT(deltaAttr >= 0, "Entropy::fill_scores: deltaAttr >= 0 : deltaAttr == " +deltaAttr);
            if (deltaAttr < 2 * MLJ.storedRealEpsilon)
                continue;
            lastSeen = nextValue;
            if (nextValue - value < MLJ.storedRealEpsilon)
                continue;
            if (splitDist[Globals.RIGHT_NODE] >= minSplit && splitDist[Globals.LEFT_NODE] >= minSplit)
                numDistinctValues.value = numDistinctValues.value + 1;
            
            ThresholdInfo outScore = new ThresholdInfo();
            outScores.add(threshIndex++,outScore);
            outScore.index = k;
            outScore.weight = splitDist[Globals.LEFT_NODE];
            outScore.score = split.score(splitAndLabelDist, splitDist, null, theEntropy, totalWeight);
        }
    }
    
    /** Compute the entropy H(Y) for label Y. Giving us an InstanceList forces counters.
     * If you don't give us the total instances, we count (slightly less efficient).
     * Entropy without the sum acts a bit differently by allowing nodes with 0
     * instances and returning entropy -1. The reason is that the caller shouldn't be
     * required to compute the sum just for this.
     *

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品福利在线导航| 国产伦精品一区二区三区免费| 国产日韩成人精品| 久久―日本道色综合久久| 精品免费一区二区三区| 日本久久精品电影| 欧美日韩国产成人在线91| 欧美福利电影网| 4438x成人网最大色成网站| 911精品国产一区二区在线| 91精品免费在线观看| 欧美一卡二卡在线| 久久欧美中文字幕| 国产精品久久久久久亚洲伦| 亚洲乱码国产乱码精品精可以看| 亚洲精选视频在线| 亚洲成人激情社区| 麻豆精品视频在线观看| 国产激情视频一区二区三区欧美| www..com久久爱| 一区二区免费在线| 欧美aaa在线| 大白屁股一区二区视频| 在线观看免费视频综合| 69堂国产成人免费视频| 国产精品一区2区| 99久久伊人网影院| 欧美久久久久久久久中文字幕| 日韩欧美123| 中文字幕在线一区二区三区| 亚洲成人7777| 成人性生交大片免费看在线播放 | 日韩美女精品在线| 亚洲成人综合视频| 国产精华液一区二区三区| 91福利资源站| 久久久久久久久久美女| 一区二区成人在线视频| 韩国成人福利片在线播放| 国产午夜亚洲精品理论片色戒| 1024亚洲合集| 久草这里只有精品视频| 在线观看91精品国产入口| 精品国产乱码久久久久久久| 一区二区三区高清| 成人天堂资源www在线| 欧美一区二区三区在线观看视频| 国产精品嫩草影院com| 青青草精品视频| 欧美在线观看18| 高清成人免费视频| 欧美老女人在线| 亚洲图片激情小说| 国产成人精品亚洲日本在线桃色 | 欧美大片顶级少妇| 亚洲成人综合视频| 91美女在线看| 国产精品污污网站在线观看| 狠狠色丁香九九婷婷综合五月| 在线观看区一区二| 91蜜桃网址入口| 国产精品免费视频一区| 国产精品影视天天线| 欧美日韩国产片| 一区二区三区中文字幕| a亚洲天堂av| 中文字幕巨乱亚洲| 国产一区二区美女| 久久精品人人做人人综合| 另类专区欧美蜜桃臀第一页| 欧美三级中文字幕| 亚洲第一精品在线| 亚洲综合激情另类小说区| 91浏览器在线视频| 一区二区三区在线视频观看| 色综合天天狠狠| 玉米视频成人免费看| 在线观看av不卡| 婷婷国产在线综合| 欧美一区二区高清| 久草这里只有精品视频| 久久综合99re88久久爱| 国产乱人伦偷精品视频不卡| 久久新电视剧免费观看| 久久精品亚洲麻豆av一区二区| 国产精品自拍一区| 中文字幕av免费专区久久| 成人av电影观看| 一区二区三区在线观看国产 | 欧美不卡视频一区| 国产一区二区三区日韩| 国产日韩一级二级三级| 国产成人午夜99999| 夜夜亚洲天天久久| 亚洲成人av在线电影| 欧美一区二区三区思思人| 蜜臀国产一区二区三区在线播放| 欧美精品v国产精品v日韩精品| 亚洲福利视频一区| 日韩精品一区二区三区视频| 国产成人av电影在线观看| 最好看的中文字幕久久| 91精品国产品国语在线不卡| 国产一区二区三区四| 亚洲免费av高清| 欧美mv日韩mv国产网站app| 国产宾馆实践打屁股91| 欧美视频一区二区三区在线观看| 蜜桃视频第一区免费观看| 国产精品热久久久久夜色精品三区| 色综合中文综合网| 3d成人h动漫网站入口| 国产呦萝稀缺另类资源| √…a在线天堂一区| 日韩写真欧美这视频| 99久久国产综合精品麻豆| 捆绑紧缚一区二区三区视频| 国产精品看片你懂得| 日韩视频一区二区三区| 一本大道综合伊人精品热热| 肉色丝袜一区二区| 亚洲国产成人一区二区三区| 欧美一区二区啪啪| 在线观看91精品国产入口| 国产成人午夜精品5599| 美日韩一区二区三区| 亚洲综合偷拍欧美一区色| 国产精品久久久一本精品| 日韩欧美的一区二区| 欧美伊人久久大香线蕉综合69| 国产精品一区免费视频| 青青草97国产精品免费观看无弹窗版| 亚洲欧美日韩国产另类专区| 久久精品视频在线免费观看| 精品久久久影院| 欧美一区二区免费视频| 欧美日韩一区成人| 色av成人天堂桃色av| 成+人+亚洲+综合天堂| 国产呦精品一区二区三区网站| 日韩**一区毛片| 亚洲网友自拍偷拍| 一区二区三区四区国产精品| 亚洲视频一区在线| 不卡一区在线观看| 久草热8精品视频在线观看| 日韩不卡一二三区| 亚洲va中文字幕| 亚洲午夜羞羞片| 色八戒一区二区三区| 国产不卡视频一区二区三区| 久久狠狠亚洲综合| 国产乱子伦一区二区三区国色天香 | 调教+趴+乳夹+国产+精品| 国产视频911| 国产欧美一区二区精品忘忧草| 欧美sm美女调教| 久久精品一区二区三区不卡牛牛 | 99久久久无码国产精品| 国产成人啪免费观看软件| 国产中文字幕精品| 国产一区二区成人久久免费影院| 久99久精品视频免费观看| 日韩制服丝袜av| 激情综合色播五月| 国产精品一区在线| 狠狠狠色丁香婷婷综合激情| 久久99精品国产麻豆婷婷 | 国产精品免费久久久久| 国产午夜精品久久久久久久| 久久久综合激的五月天| 久久久91精品国产一区二区精品| 久久久久久久综合狠狠综合| 国产日产欧美一区| 亚洲欧美日韩国产综合在线| 一区二区三区色| 日韩精品亚洲一区| 国产乱人伦精品一区二区在线观看 | 91精品国产综合久久小美女| 91网站在线观看视频| 精品视频在线免费看| 日韩三级在线免费观看| 国产精品视频观看| 亚洲综合一二三区| 国产麻豆午夜三级精品| 在线观看日韩高清av| 亚洲精品一区在线观看| 亚洲欧洲综合另类| 久久99精品久久久| 色乱码一区二区三区88| 日韩免费视频线观看| 亚洲人精品午夜| 蜜臀av性久久久久蜜臀av麻豆| 成人一级片网址| 欧美一区二区三区四区五区| 中文文精品字幕一区二区| 亚洲一区欧美一区| 国产在线精品不卡| 欧美亚男人的天堂| 欧美国产日本视频|