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

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

?? id3_proto.c

?? ID3源碼
?? C
字號:
/*
* FILE: id3.c
*
* Author: Andrew Colin
*
* DISCLAIMER: No liability is assumed by the author for any use made
* of this program.
*
* DISTRIBUTION: Any use may be made of this program, as long as the
* clear acknowledgment is made to the author in code and runtime
* executables
*/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <string.h>
#include <conio.h>
#include <time.h>

#include "id3.h"
#include "proto.h"

/*-------------------------------------------------------------------*/

MATRIX *build_matrix (UINT width, UINT height)
{
    MATRIX *_matrix;
    UINT i;

    _matrix = (MATRIX*) malloc (sizeof (MATRIX));
    if (!_matrix)
        err_exit (__FILE__, __LINE__);

    _matrix->width  = width;
    _matrix->height = height;

    _matrix->data = (REAL**) malloc (height * sizeof (REAL*));
    if (_matrix->data == NULL)
        err_exit(__FILE__, __LINE__);

    for (i=0; i<height; i++)
    {
        _matrix->data[i] = (REAL*) malloc (width * sizeof(REAL));
        if (_matrix->data[i] == NULL)
            err_exit(__FILE__, __LINE__);
    }
    return _matrix;
}

/*-------------------------------------------------------------------*/

/*
* Standard error handler function
*/

void err_exit (CHAR* file, UINT line)
{
    printf("\n Fatal error in file %s, line %u", file, line);
    exit(0);
}

/*-------------------------------------------------------------------*/

void file_size (CHAR *file_name, UINT *width, UINT *height)
/*
* Given the name of a file of numeric data, this routine counts
* the numbers of rows and columns. It's assumed that the number
* of entries is the same in each row, and an error is flagged if this
* is not the case.
*
*/
{
    FILE *f;
    UINT buf_size = 0xFF, _width = 0;
    CHAR *buffer, *ptr;

    *width = *height = 0;

    buffer = (CHAR*) malloc (buf_size * sizeof (CHAR));
    if (buffer == NULL)
        err_exit (__FILE__, __LINE__);

    /* Open price file - abort if filename invalid */
    f = fopen(file_name, "r");
    if (f == NULL)
    {
        printf("\n File not found : %s\n", file_name);
        err_exit (__FILE__, __LINE__);
    }

    /* Get number of entries in first row */
    if (fgets(buffer, buf_size, f) != NULL)
    {
        ++*height;
        ptr = strtok (buffer, " ,");
        while (ptr != NULL)
        {
            ++*width;
            ptr = strtok (NULL, " ,");
        }
    }

    /* Count numbers of subsequent rows */
    while (!feof(f))
    {
        if (fgets(buffer, buf_size, f) != NULL)
        {
            if (strlen(buffer) > strlen("\n"))  /* if line is more than a NL char */
            {
                ++*height;
                _width = 0;
                ptr = strtok (buffer, " ,");
                while (ptr != NULL)
                {
                    ++_width;
                    ptr = strtok (NULL, " ,");
                }

                if (*width != _width)
                {
                    printf("\n Number of entries in file %s did not agree", file_name);
                    err_exit (__FILE__, __LINE__);
                }
            }
        }
    }
    free (buffer);
}

/*-------------------------------------------------------------------*/

void free_matrix (MATRIX *_matrix)
{
    UINT i;
    for (i=0; i<_matrix->height; i++)
        free (_matrix->data[i]);

    free (_matrix->data);
    free (_matrix);
}

/*-------------------------------------------------------------------*/

void free_tags ( CHAR** varname, UINT width)
{
    UINT i;
    for (i=0; i<width; i++)
        free(varname[i]);
    free (varname);
}

/*-------------------------------------------------------------------*/

void free_tree ( NODE  *node )
{
    /*
     *  Frees the memory allocated to a tree structure
     */

    if (node == NULL)
        return;
    else
    {
        free_tree (node->on);
        free_tree (node->off);
        free(node);
    }

}

/*-------------------------------------------------------------------*/

NODE* ID3 ( MATRIX *matrix, NODE* parent, UINT target, UINT state)

/* Routine to build a decision tree, based on Quinlan's ID3 algorithm. */
// 建立決策樹
{
    NEGENTROPY negentropy_struct;
    NODE *node;
    UINT n_vars = matrix->width, n_samples = matrix->height, i, j, split;
    REAL **data = matrix->data;
    REAL best_threshold, min_negentropy, _negentropy;

    /* Allocate memory for this node */
    node = (NODE*) malloc (sizeof(NODE));
    if (!node)
        err_exit (__FILE__, __LINE__);

    /* Set up links in decision tree */
    node->parent = parent;  /* Set address of parent node */

    if (parent != NULL) /* parent to child; not relevant for root node */
    {
        /* Pass address of this node to the parent node */
        if (state == ON)
            parent->on = node;
        else
            if (state == OFF)
                parent->off = node;
    }

    /*
     * Select attribute with lowest negentropy for splitting. Scan through
     * ALL attributes (except the target) and ALL data samples. This is
     * pretty inefficient for data sets with repeated values, but will do
     * for illustrative purposes
     */

    min_negentropy = 1.0;

    for (i=0; i<n_vars; i++)
    {

        for (j=0; j<n_samples; j++) 
        {

            if (i != target) 
            {

                /* Set trial values for this node... */
                node->idx = i;
                node->threshold = data[j][i];

                /* ...and calculate the negentropy of this partition */
                negentropy_struct = negentropy (data, n_samples, node, target);

                _negentropy = negentropy_struct.ne;

                /* If this negentropy is lower than any other, retain the
                       index and threshold for future use */
                if (_negentropy <min_negentropy) 
                {
					printf("%d\n",_negentropy);
                    min_negentropy = _negentropy;
                    split = i;
                    best_threshold = data[j][i];
                }

            } /*if (i != target)*/

        } /*for (j=0; j<n_samples; j++)*/

    } /*for (i=0; i<n_vars; i++)*/

    /* Save the combination of best attribute and threshold value */
    node->idx = split;
    node->threshold = best_threshold;

    /*
     * If the negentropy routine found itself at an end-of-branch
     * for the decision tree, the 'status' flag in 'negentropy_struct'
     * is set to ON or OFF and the node labelled accordingly. Otherwise,
     * ID3 continues to call itself until all end-of-branch nodes are
     * found.
     */

    if  (negentropy_struct.status != INACTIVE) 
    {
        node->on = node->off = NULL;
        node->idx = negentropy_struct.status;
    }
    else
    {
        node->on  = ID3 (matrix, node, target, ON);
        node->off = ID3 (matrix, node, target, OFF);
    }

    return node;
}

/*-------------------------------------------------------------------*/

void main (int argv, char *argc[])
{

    MATRIX	*matrix;
    NODE	*node;
    UINT	target, n_vars, n_samples;
	CHAR	data_file[13]="data.txt", tag_file[13]="vag.txt";
   // CHAR	data_file[13], tag_file[13];  /* Longest file name in DOS */
    CHAR	**tag_names;

    /* Set up file names */
  //  if (argv != 2)
    //{
   //     printf("\nUsage: id3 [datafile]");
  //      exit(0);
   // }
  //  else
  //  {
  //      printf("\nWelcome to ID3");
  //      printf("\nLast compiled on %s, %s", __DATE__, __TIME__);
  //      printf("\n");
  //      strcpy(data_file, argc[1]);
  //      strcpy(tag_file,  argc[1]);
  //     strcat(data_file, ".dat");
  //    strcat(tag_file,  ".tag");
  //}
//



    /* Read dimensions of data file */ // 讀數(shù)據(jù)文件的尺寸
    file_size (data_file, &n_vars, &n_samples);

    /* Read labels for columns of data */ //讀標(biāo)簽
    tag_names = read_tags (tag_file, n_vars);

    /* Allocate storage for data... */ //為數(shù)據(jù)分派存儲
    matrix = build_matrix (n_vars, n_samples);

    /* ...and read it from disk */ //從文件讀matrix
    read_matrix (data_file, matrix);

    /* Classification target is last column */
    target = n_vars - 1;

    /* Return root of decision tree - ID3 continues to call itself
       recursively */

    node = ID3 ( matrix, NULL, target, 0 );

    print_tree(node, tag_names);

    printf("\n");

    free_tags (tag_names, n_vars);
    free_matrix(matrix);
    free_tree (node);
}

/*-------------------------------------------------------------------*/

NEGENTROPY negentropy ( REAL **data,
    UINT   n_samples,
    NODE   *local,
    UINT   target)
{
    /*
     * Calculates the entropy of classification of an attribute, given
     * a table of attributes already used, the attribute on which splitting
     * is to be taken, and the target attribute. Entropy is calculated in
     * bits, so logs are taken to base 2 by dividing by LN_2.
     *
     * The returned value always lies in the (closed) range [0, 1].
     */

    NEGENTROPY ret_val;
    NODE *_node, *_parent;
    UINT on_ctr, off_ctr, p1, p2, i, _match;
    REAL p_on, p_off, negentropy_on, negentropy_off;

    on_ctr = off_ctr = p1 = p2 = 0;

    /* Scan through all supplied data samples */
    for (i=0; i<n_samples; i++) 
    {

        /*
         * If pattern matches the current position in the decision tree,
         * then use this vector. The match is determined by passing up
         * the decision tree and checking whether 'data[idx] >= threshold'
         * matches at each step, where idx and threshold are taken from
         * each node in turn.
         */

        _match = 1;
        _node = local;
        while (_node->parent != NULL) 
        { /* If at the root node, all entries match*/
            _parent = _node->parent;
            if (_node == _parent->on) 
            { /* if parent node is ON */
                if (data[i][_parent->idx] < _parent->threshold)
                    _match = 0;
            }
            else
                if (_node == _parent->off) 
                { /* if parent node is OFF */
                    if (data[i][_parent->idx] >= _parent->threshold)
                        _match = 0;
                }
            _node = _parent;
        }

        if (_match) 
        {
            if (data[i][local->idx] >= local->threshold) 
            {
                on_ctr++;
                if (data[i][target] >= 0.5)
                    p1++;
            }
            else 
            {
                off_ctr++;
                if (data[i][target] >= 0.5)
                    p2++;
            }
        }
    }   /* for (i=0; i<n_samples; i++) */

    /* 1: Entropy of subtable with activation ON */

    /*
     * We now have the numbers of samples that match this part of the
     * decision tree, and the number of samples for which the supplied
     * condition are true. From these quantities we can find the negentropy of
     * this partition.
     */

    if (on_ctr > 0)
    {
        p_on  = (REAL) p1 / (REAL) on_ctr;
        p_off = 1 - p_on;
        negentropy_on = -entropy (p_on) - entropy (p_off);
    }
    else
        negentropy_on = 0.0;

    /* 2: Entropy of subtable with activation OFF */

    if (off_ctr > 0)
    {
        p_on  = (REAL) p2 / (REAL) off_ctr;
        p_off = 1 - p_on;
        negentropy_off = -entropy (p_on) - entropy (p_off);
    }
    else
        negentropy_off = 0.0;

    ret_val.ne = (negentropy_on * on_ctr + negentropy_off * off_ctr);
    ret_val.ne /= (on_ctr + off_ctr);

    /*
     * If all values examined were the same, set 'ret_val.status' to
     * the target value since this will be an end-of-branch node
     */

    if ((p1 == on_ctr) && (p2 == off_ctr))
        ret_val.status = ON;
    else if ((p1 == 0) && (p2 == 0))
        ret_val.status = OFF;
    else
        ret_val.status = INACTIVE;

    return ret_val;

}

/*-------------------------------------------------------------------*/

void print_tree (NODE *node, CHAR** tag_names)
{
    /*
     * Displays algebraic equivalent of the decision tree
     */

    if (node->on == NULL) 
    {
        if (node->idx == ON)
            printf("ON");
        else if (node->idx == OFF)
            printf("OFF");
        return;
    }

    else
        printf("if { %s >= %1.2f then ", tag_names[node->idx], node->threshold);

    print_tree ( node->on, tag_names );
    printf(" else ");
    print_tree ( node->off, tag_names );
    printf( " } " );
}

/*-------------------------------------------------------------------*/

void read_matrix (CHAR filename[], MATRIX *matrix)

{

    UINT i, j;
    UINT height = matrix->height;
    UINT width  = matrix->width;
    REAL **data = matrix->data;
    FILE *f;

    /* Open price file */
    if ((f = fopen(filename, "r")) == NULL) 
    {
        printf("\n File not found : %s\n", filename);
        err_exit (__FILE__, __LINE__);
    }

    for (i=0; i<height; i++)
        for (j=0; j<width; j++)
        {
            fscanf(f, "%lf\n", &data[i][j] );
        }

    fclose(f);

}

/*-------------------------------------------------------------------*/

CHAR **read_tags (CHAR *tag_file, UINT width)
{
    FILE *f;
    CHAR **_varname;
    UINT i;
    CHAR buffer[0xFF];

    f = fopen(tag_file, "r");
    if (f == NULL)
    {
        printf("\n File not found : %s\n", tag_file);
        err_exit (__FILE__, __LINE__);
    }

    _varname = (CHAR**) malloc (width * sizeof (CHAR*));
    for (i=0; i<width; i++)
        _varname[i] = (CHAR*) malloc (0xFF * sizeof (CHAR));

    i = 0;
    while (!feof(f))
    {
        if (fgets(buffer, 0xFF, f) != NULL)
        {
            if (strlen(buffer) > strlen("\n"))
            {
                if (i>width-1)
                {
                    printf("\nMore variable names were detected than data items.");
                    printf("\nPlease correct this problem before proceeding");
                    exit(0);
                }
                sscanf (buffer, "%[a-zA-Z0-9-_;:!@#$%^&*(){}[]]", _varname[i]);
                i++;
            }
        }
    }

    if (i<width) 
    {
        printf("\nFewer variable names than data items were detected.");
        printf("\nPlease correct this problem before proceeding");
        exit(0);
    }

    fclose (f);

    return _varname;

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美极品少妇xxxxⅹ高跟鞋 | 欧美吻胸吃奶大尺度电影| 婷婷夜色潮精品综合在线| 亚洲欧美日韩人成在线播放| 欧美一区二区三区免费在线看 | 欧美蜜桃一区二区三区| 国产福利不卡视频| 亚洲一区在线视频| 2021中文字幕一区亚洲| 91精品国产综合久久国产大片| 成人精品视频一区二区三区 | 精品人伦一区二区色婷婷| 色婷婷av一区二区三区gif| 国产毛片精品视频| 日本午夜一本久久久综合| 夜夜爽夜夜爽精品视频| 欧美国产欧美综合| 欧美精品一区二区在线观看| 91精品国产一区二区| 94色蜜桃网一区二区三区| 国产精品一级二级三级| 欧美aa在线视频| 午夜精品一区二区三区三上悠亚| 国产精品国产三级国产有无不卡| 日韩一区二区三区视频| 欧美日韩一本到| 91啪九色porn原创视频在线观看| 国产一区二区三区久久悠悠色av| 日本中文字幕一区| 日本亚洲电影天堂| 视频一区欧美日韩| 日本午夜一区二区| 免费在线观看不卡| 麻豆freexxxx性91精品| 麻豆精品视频在线| 捆绑调教美女网站视频一区| 青草av.久久免费一区| 日本成人中文字幕| 美洲天堂一区二卡三卡四卡视频 | 高清视频一区二区| 国产成人在线视频网站| 国产成人精品一区二区三区四区 | 韩国三级在线一区| 美日韩一区二区| 久久国产人妖系列| 国产一区二区精品久久99| 国产精品一二三区在线| 国产成人精品1024| 99久久婷婷国产综合精品电影 | 九九热在线视频观看这里只有精品| 图片区小说区区亚洲影院| 视频一区中文字幕| 免费看欧美美女黄的网站| 久久99在线观看| 成人精品电影在线观看| eeuss国产一区二区三区| 91丨九色porny丨蝌蚪| 欧美在线一二三四区| 欧美视频一区二区三区四区| 欧美精品在线一区二区三区| 日韩午夜小视频| 国产欧美一区二区精品忘忧草| 久久精品视频在线免费观看| 中文字幕免费观看一区| 亚洲欧美国产高清| 亚洲第一电影网| 免费在线观看一区二区三区| 国产精品1区2区| 色域天天综合网| 日韩一级黄色片| 亚洲国产精品黑人久久久| 亚洲情趣在线观看| 日韩高清一区在线| 成人综合在线视频| 成人精品一区二区三区四区| 91视频com| 国产麻豆视频一区二区| 99国产精品久久久久| 欧美色网站导航| 国产精品成人一区二区三区夜夜夜| 国产精品不卡在线观看| 亚洲私人影院在线观看| 亚洲高清视频在线| 麻豆精品国产传媒mv男同 | 国产精品资源在线| 99国内精品久久| 91精品国产免费久久综合| 欧美一级片在线看| 欧美国产欧美综合| 婷婷国产在线综合| 成人黄色综合网站| 91精品在线一区二区| 国产午夜精品久久| 亚洲成人免费视| 91麻豆自制传媒国产之光| 91精品国产手机| 亚洲自拍欧美精品| 风间由美一区二区三区在线观看 | 国产亲近乱来精品视频| 精品少妇一区二区三区视频免付费 | 国产精品乡下勾搭老头1| 91.成人天堂一区| 国产日韩欧美不卡在线| 日韩综合在线视频| 成人av电影免费在线播放| 欧美日韩国产高清一区二区三区 | 欧洲亚洲精品在线| 亚洲国产成人在线| 久久福利视频一区二区| 欧美日韩夫妻久久| 亚洲成av人片在线| 欧美中文字幕亚洲一区二区va在线| 欧美成人三级电影在线| 热久久国产精品| 欧美三片在线视频观看| 一区二区在线免费观看| 色综合天天综合网天天狠天天| 久久久久成人黄色影片| 日韩1区2区3区| 91麻豆精品91久久久久同性| 一区二区三区中文字幕电影| 欧美日韩一区二区三区免费看| 青青草91视频| 91麻豆精品国产91久久久久久久久| 一级做a爱片久久| 4438成人网| 国产最新精品免费| 国产精品欧美极品| 精品婷婷伊人一区三区三| 婷婷综合五月天| 久久久久久久久岛国免费| 成人亚洲精品久久久久软件| 亚洲精品国产一区二区精华液| 91黄色在线观看| 久草这里只有精品视频| 国产精品久久久久久久久晋中 | 欧美日本国产一区| 亚洲无人区一区| 色一区在线观看| www.欧美.com| 日韩一区二区影院| 亚洲精品中文字幕乱码三区 | 91免费视频网址| 国产精品久久福利| 91视频免费观看| 一区二区三区在线免费视频| 在线精品视频一区二区三四| 亚洲一区二区三区在线看| 欧美日韩中文国产| 免费观看一级欧美片| 日韩欧美国产三级| 亚洲欧美日韩综合aⅴ视频| 国产精品丝袜久久久久久app| 91啪九色porn原创视频在线观看| 久久精品二区亚洲w码| 亚洲激情成人在线| 成人欧美一区二区三区小说 | 久草这里只有精品视频| 亚洲男人天堂一区| 国产午夜精品一区二区三区嫩草| 91一区二区在线| 懂色一区二区三区免费观看| 美女网站一区二区| 日韩高清在线观看| 无吗不卡中文字幕| 亚洲成av人片一区二区三区| 亚洲精品成人悠悠色影视| 国产精品久久三| 亚洲三级在线免费| 亚洲精品欧美专区| 亚洲成人av福利| 亚洲一区影音先锋| 亚洲va国产天堂va久久en| 久草在线在线精品观看| 亚洲成人精品一区二区| 日韩精品免费视频人成| 日韩va欧美va亚洲va久久| 视频一区视频二区中文字幕| 日日夜夜精品免费视频| 毛片不卡一区二区| 国产高清在线观看免费不卡| 国模套图日韩精品一区二区| 国产成人精品午夜视频免费| 久久成人免费日本黄色| 日韩av在线免费观看不卡| 午夜欧美2019年伦理| 午夜精品久久久| 国产一区二区精品久久| 成人精品免费视频| 亚洲一区二区欧美日韩| 日韩欧美综合一区| 国产一区二区三区精品视频| 91麻豆精品91久久久久同性| a在线欧美一区| 老司机一区二区| 亚洲第一搞黄网站| 国产精品福利一区| 欧美成人一区二区| 欧美日韩在线电影| gogogo免费视频观看亚洲一|