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

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

?? entropy.java

?? java數據挖掘算法
?? 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一区二区三区免费野_久草精品视频
亚洲高清免费在线| 欧美自拍丝袜亚洲| 99久久久国产精品免费蜜臀| 欧美亚洲一区二区在线观看| 欧美国产日韩精品免费观看| 日本视频在线一区| 一本色道综合亚洲| 国产三级精品视频| 免费一区二区视频| 欧美日韩一区成人| 亚洲精品久久久蜜桃| 国产精品乱码一区二区三区软件| 视频一区二区中文字幕| 91年精品国产| 日韩理论电影院| 波多野结衣中文字幕一区| 精品精品国产高清一毛片一天堂| 日韩—二三区免费观看av| 色噜噜偷拍精品综合在线| 国产欧美日韩久久| 国产不卡免费视频| www国产精品av| 激情久久久久久久久久久久久久久久| 日韩中文字幕不卡| 777欧美精品| 日本成人在线不卡视频| 欧美一区在线视频| 蜜臀久久99精品久久久久久9| 欧美日韩国产成人在线免费| 亚洲一级不卡视频| 欧美午夜电影网| 午夜伊人狠狠久久| 91麻豆精品国产无毒不卡在线观看 | 久久久久久久久久久99999| 日韩欧美国产综合| 亚洲6080在线| 91麻豆精品国产91久久久久| 午夜国产精品一区| 欧美一区二区视频在线观看2020| 五月天久久比比资源色| 91精品国产入口| 免费观看久久久4p| 久久精品一区二区三区四区| 国产成人精品亚洲777人妖| 国产99久久久精品| 一区二区三区欧美久久| 欧美日韩视频在线观看一区二区三区| 亚洲成人福利片| 精品国产一区二区三区四区四 | 中文字幕一区不卡| 91热门视频在线观看| 亚洲一区二区三区三| 欧美日韩高清不卡| 精品亚洲国内自在自线福利| 成人小视频在线| 亚洲小说欧美激情另类| 日韩一级黄色大片| 不卡影院免费观看| 高清国产一区二区| 亚洲国产中文字幕| 久久久美女艺术照精彩视频福利播放| 成人免费高清视频| 丝瓜av网站精品一区二区 | 激情久久五月天| 中文字幕一区二区不卡| 91精品国产综合久久香蕉的特点| 国产精品18久久久久| 一区二区在线电影| 2023国产一二三区日本精品2022| 色综合久久久久久久久久久| 奇米色一区二区三区四区| 欧美国产日韩精品免费观看| 欧美丝袜丝交足nylons图片| 国产在线乱码一区二区三区| 亚洲精品视频免费观看| 精品国产sm最大网站免费看| 一本一道综合狠狠老| 国产一区二区三区最好精华液| 亚洲美女精品一区| 欧美激情资源网| 欧美一级片在线看| 欧美天堂一区二区三区| www.66久久| 激情偷乱视频一区二区三区| 亚洲成人一二三| 国产精品免费视频观看| 欧美精品一区二区三区在线播放 | 久久精品在这里| 欧美日韩久久一区二区| 成年人国产精品| 国产主播一区二区| 日本中文在线一区| 亚洲综合久久av| 国产精品亚洲人在线观看| 精品播放一区二区| 欧美老女人第四色| 欧亚洲嫩模精品一区三区| 亚洲日本在线a| 中文字幕不卡在线观看| 精品999久久久| 欧美大片在线观看| 欧美一卡二卡三卡| 91精品啪在线观看国产60岁| 久久久久国产精品麻豆| 日韩三级精品电影久久久| 欧美日韩亚洲综合一区| 色视频欧美一区二区三区| 91啪亚洲精品| 91久久精品网| 在线国产电影不卡| 欧美三区免费完整视频在线观看| 色94色欧美sute亚洲线路一ni| 亚洲天堂成人在线观看| 国产精品久久久久影院色老大| 国产目拍亚洲精品99久久精品| 国产亚洲欧洲一区高清在线观看| 欧美成人女星排名| 久久久久久一二三区| 精品黑人一区二区三区久久 | 日本韩国精品在线| 色噜噜久久综合| 在线免费观看成人短视频| 欧美在线999| 欧美日韩高清一区二区三区| 91精品国产综合久久久久久久 | 91成人在线精品| 亚洲国产成人av网| 天天影视涩香欲综合网| 午夜精品一区二区三区免费视频| 午夜激情一区二区| 韩国女主播成人在线观看| 国产福利一区在线| 99视频有精品| 欧美日韩国产一二三| 亚洲欧美经典视频| 日韩国产成人精品| 国产精品中文字幕欧美| av一区二区不卡| 欧美三级在线视频| 久久人人爽爽爽人久久久| 国产精品你懂的在线| 夜夜爽夜夜爽精品视频| 久久www免费人成看片高清| 成人激情小说网站| 欧美日韩aaaaa| 久久久精品国产免大香伊| 国产精品欧美一区二区三区| 亚洲一区二区三区视频在线| 韩国成人精品a∨在线观看| av成人老司机| 日韩一区二区三区观看| 国产精品素人一区二区| 亚洲二区在线观看| 国产成人av一区二区三区在线 | av综合在线播放| 91超碰这里只有精品国产| 中文在线资源观看网站视频免费不卡 | 欧美大黄免费观看| 亚洲欧洲av另类| 久久99精品一区二区三区三区| 色综合色综合色综合色综合色综合| 欧美猛男男办公室激情| 成人免费小视频| 国产毛片一区二区| 精品视频在线视频| 国产精品美女久久久久久久久久久| 视频一区在线播放| 91浏览器在线视频| 26uuu久久天堂性欧美| 亚洲va韩国va欧美va精品 | 欧美日韩亚洲丝袜制服| 国产精品久久久久一区二区三区共| 奇米影视一区二区三区| 在线免费一区三区| 亚洲人快播电影网| 国产精品一区二区男女羞羞无遮挡| 欧美性xxxxx极品少妇| 亚洲欧美日韩精品久久久久| 国产精品第一页第二页第三页| 久久国产尿小便嘘嘘尿| 欧美日韩电影在线| 亚洲黄色片在线观看| 99re热视频这里只精品| 国产午夜久久久久| 激情欧美一区二区| 国产一区二三区好的| 国产精品中文有码| 久久综合九色综合欧美就去吻| 日韩av电影一区| 69精品人人人人| 天堂在线一区二区| 国产精品热久久久久夜色精品三区| 国产一区二区三区最好精华液| 91精品婷婷国产综合久久性色 | 亚洲精品欧美综合四区| 本田岬高潮一区二区三区| 国产女主播在线一区二区| 国产精品综合一区二区三区| 久久久美女毛片| 成人污视频在线观看|