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

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

?? entropy.java

?? 本程序是用java語言編寫的數據挖掘分類算法中的決策樹分類方法c4.5程序代碼
?? 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精品国产一区二区人妖| 国产一区二区看久久| 91原创在线视频| 国产精品国产三级国产aⅴ原创| 国产成人啪免费观看软件| 国产亚洲成av人在线观看导航| 国产综合色视频| 国产欧美日韩精品一区| av中文一区二区三区| 亚洲免费电影在线| 欧美美女黄视频| 青青草原综合久久大伊人精品 | 欧美精品色一区二区三区| 亚洲一区二区视频在线观看| 欧美日韩亚洲综合在线 | 婷婷中文字幕综合| 欧美一卡在线观看| 国产91精品一区二区麻豆亚洲| 中文字幕av资源一区| 在线国产电影不卡| 麻豆久久久久久久| 国产精品国产精品国产专区不片| 色哟哟国产精品| 日本不卡一区二区| 国产欧美精品一区二区色综合| 不卡在线观看av| 亚洲aⅴ怡春院| 日本一区二区三区国色天香 | 日韩午夜精品视频| 国产成人精品一区二区三区四区 | 1024精品合集| 欧美日韩国产乱码电影| 国产在线播放一区二区三区| 亚洲免费在线看| 日韩美女视频在线| 91亚洲精品乱码久久久久久蜜桃| 日韩成人免费电影| 国产精品久久影院| 日韩欧美亚洲国产精品字幕久久久| 成熟亚洲日本毛茸茸凸凹| 天天操天天干天天综合网| 久久综合精品国产一区二区三区| 一本色道久久综合亚洲精品按摩| 久久精品二区亚洲w码| 亚洲免费观看高清| 久久久www成人免费无遮挡大片| 欧美性一级生活| 成人av高清在线| 精品一区二区久久| 亚洲国产精品久久久久婷婷884| 久久精品亚洲乱码伦伦中文| 亚洲天天做日日做天天谢日日欢 | 久久奇米777| 免费成人美女在线观看| 中文无字幕一区二区三区| 欧美日韩电影在线播放| av电影在线观看不卡| 九一久久久久久| 男女视频一区二区| 制服丝袜中文字幕一区| 一区二区三区在线播| 国产精品一区二区黑丝| 91精品国产色综合久久不卡电影| 欧美国产综合一区二区| 另类小说一区二区三区| 91精品国产综合久久精品图片 | 一区二区三区四区乱视频| 国产精品资源在线| 日韩欧美成人一区| 免费观看91视频大全| 7777精品伊人久久久大香线蕉的| 亚洲精品国产第一综合99久久 | 精品福利av导航| 日韩有码一区二区三区| 欧洲一区二区三区在线| 亚洲欧美日韩中文字幕一区二区三区 | 污片在线观看一区二区| 在线免费不卡电影| 亚洲小说春色综合另类电影| 欧美在线一二三四区| 亚洲小少妇裸体bbw| 欧美三级电影网| 亚洲精品国产精华液| 欧美日韩国产大片| 美日韩一级片在线观看| 精品国产一二三区| 国产91精品露脸国语对白| 中文字幕一区三区| 91成人免费在线| 三级久久三级久久久| 欧美变态tickle挠乳网站| 国产一区在线精品| 精品少妇一区二区| 激情六月婷婷综合| 日韩三级视频在线看| 国产福利一区二区三区| 国产日韩精品一区二区三区在线| 毛片av一区二区| 精品少妇一区二区三区在线视频| 日本成人中文字幕在线视频 | 欧美日韩国产成人在线91| 亚洲一区二区五区| 国产在线国偷精品免费看| 国产精品网站在线| 成人精品免费看| 国产精品麻豆欧美日韩ww| 本田岬高潮一区二区三区| 国产精品家庭影院| 91成人在线观看喷潮| 亚洲午夜国产一区99re久久| 欧美在线高清视频| 午夜精品视频一区| 日韩欧美国产高清| 国产精品99久久久久久久vr | 国产精品资源站在线| 国产精品女主播av| 91首页免费视频| 亚洲高清免费观看| 欧美精品一区二区三区高清aⅴ | 中文字幕精品三区| 豆国产96在线|亚洲| 亚洲天堂a在线| 欧美日韩久久久一区| 亚洲bt欧美bt精品777| 日韩三级精品电影久久久| 春色校园综合激情亚洲| 亚洲妇熟xx妇色黄| 久久久久久久久久久99999| 99re热视频这里只精品| 日本不卡一区二区三区 | 精品久久久影院| 国产精品一区二区久久精品爱涩| 亚洲色欲色欲www在线观看| 欧美日韩免费观看一区二区三区| 美国毛片一区二区三区| 国产精品美女久久久久久久久| 99国产精品一区| 国产乱理伦片在线观看夜一区| 亚洲免费在线视频| 精品国产一区二区三区忘忧草| 成人精品国产一区二区4080| 日韩精品视频网站| 国产精品久久久久桃色tv| 欧美一区二区日韩| 91亚洲精品乱码久久久久久蜜桃| 麻豆专区一区二区三区四区五区| 亚洲欧洲成人精品av97| 欧美电影免费观看高清完整版在线| 波多野结衣亚洲一区| 奇米精品一区二区三区四区 | 欧美日韩成人综合天天影院| 国产91精品露脸国语对白| 日本vs亚洲vs韩国一区三区二区| 亚洲婷婷综合色高清在线| 精品处破学生在线二十三| 色哟哟国产精品| 91福利视频久久久久| 国产成人a级片| 狂野欧美性猛交blacked| 污片在线观看一区二区| 亚洲精品国产品国语在线app| 亚洲同性gay激情无套| 欧美—级在线免费片| 欧美精品一区二区三区四区| 3d动漫精品啪啪一区二区竹菊| 91蝌蚪porny九色| 成人午夜又粗又硬又大| 99re成人精品视频| 北条麻妃一区二区三区| 成人性生交大片| 成人av电影免费观看| 高清在线成人网| 国产综合色视频| 91蜜桃传媒精品久久久一区二区| 粉嫩在线一区二区三区视频| 国产一区视频网站| 国产精品综合在线视频| 久久精品国产一区二区三区免费看| 国产激情一区二区三区四区| 精彩视频一区二区三区| 免费成人小视频| 久久99精品久久只有精品| 久久精品久久精品| 久久99精品久久久久婷婷| 成a人片国产精品| 色婷婷综合视频在线观看| 91福利精品视频| 制服丝袜亚洲播放| 欧美一区二区三区在线看| 2023国产精华国产精品| 久久五月婷婷丁香社区| 国产精品天美传媒沈樵| 亚洲三级在线免费| 26uuu色噜噜精品一区二区| 亚洲精品久久久蜜桃| 日日摸夜夜添夜夜添国产精品 | 日韩精品一区二区三区四区视频 | 欧美mv和日韩mv的网站| 亚洲国产成人私人影院tom| 亚洲精品国产无天堂网2021|