⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtp.c

📁 dTree是一个运行在WinCE上的文件管理软件。类似文件管理器,功能强大
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------  File    : dtp.c  Contents: decision and regression tree pruning  Authors : Christian Borgelt  History : 04.08.1997 file created            28.08.1997 pessimistic pruning added            17.09.1997 option '-a' (aligned output) added            11.01.1998 unknown value characters (option -u) added            08.02.1998 adapted to changed parse functions            09.02.1998 adapted to changed order of pruning methods            23.06.1998 adapted to modified attset functions            29.09.1998 table reading simplified            20.10.1998 output of relative class frequencies added            09.02.1999 input from stdin, output to stdout added            17.04.1999 simplified using the new module 'io'            30.04.1999 log messages improved            17.12.2000 option -q (balance class frequencies) added            18.12.2000 extended to regression trees            23.07.2001 adapted to modified module scan            19.10.2001 conf. level pruning for numeric targets added            01.03.2002 option -k (check largest branch) added            16.08.2003 slight changes in error message output            09.11.2004 execution time output added----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <time.h>#include <assert.h>#ifndef SC_SCAN#define SC_SCAN#endif#include "scan.h"#ifndef AS_RDWR#define AS_RDWR#endif#ifndef AS_PARSE#define AS_PARSE#endif#ifndef TAB_RDWR#define TAB_RDWR#endif#ifndef DT_PRUNE#define DT_PRUNE#endif#ifndef DT_PARSE#define DT_PARSE#endif#include "io.h"#include "dtree.h"#ifdef STORAGE#include "storage.h"#endif/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define PRGNAME     "dtp"#define DESCRIPTION "decision and regression tree pruning"#define VERSION     "version 3.6 (2006.02.07)         " \                    "(c) 1997-2006   Christian Borgelt"/* --- error codes --- */#define OK            0         /* no error */#define E_NONE        0         /* no error */#define E_NOMEM     (-1)        /* not enough memory */#define E_FOPEN     (-2)        /* cannot open file */#define E_FREAD     (-3)        /* read error on file */#define E_FWRITE    (-4)        /* write error on file */#define E_OPTION    (-5)        /* unknown option */#define E_OPTARG    (-6)        /* missing option argument */#define E_ARGCNT    (-7)        /* wrong number of arguments */#define E_STDIN     (-8)        /* double assignment of stdin */#define E_PARSE     (-9)        /* parse error */#define E_BALANCE  (-10)        /* double assignment of stdin */#define E_METHOD   (-11)        /* unknown pruning method */#define E_UNKNOWN  (-12)        /* unknown error */#define SEC_SINCE(t)  ((clock()-(t)) /(double)CLOCKS_PER_SEC)/*----------------------------------------------------------------------  Type Definitions----------------------------------------------------------------------*/typedef struct {                /* --- method information --- */  int  code;                    /* pruning method code */  char *name;                   /* name of the method */} MINFO;                        /* (method information) *//*----------------------------------------------------------------------  Constants----------------------------------------------------------------------*//* --- pruning methods --- */static const MINFO pmtab[] = {  { PM_NONE, "none" },          /* no pruning */  { PM_PESS, "pess" },          /* pessimistic pruning */  { PM_CLVL, "clvl" },          /* confidence level pruning */  { -1,      NULL   }           /* sentinel */};/* --- error messages --- */const char *errmsgs[] = {       /* error messages */  /* E_NONE      0 */  "no error\n",  /* E_NOMEM    -1 */  "not enough memory\n",  /* E_FOPEN    -2 */  "cannot open file %s\n",  /* E_FREAD    -3 */  "read error on file %s\n",  /* E_FWRITE   -4 */  "write error on file %s\n",  /* E_OPTION   -5 */  "unknown option -%c\n",  /* E_OPTARG   -6 */  "missing option argument\n",  /* E_ARGCNT   -7 */  "wrong number of arguments\n",  /* E_STDIN    -8 */  "double assignment of standard input\n",  /* E_PARSE    -9 */  "parse error(s) on file %s\n",  /* E_BALANCE -10 */  "unknown balancing mode %c\n",  /* E_METHOD  -11 */  "unknown pruning method %s\n",  /* E_UNKNOWN -12 */  "unknown error\n"};/*----------------------------------------------------------------------  Global Variables----------------------------------------------------------------------*/const  char   *prgname = NULL;  /* program name for error messages */static SCAN   *scan    = NULL;  /* scanner */static DTREE  *dtree   = NULL;  /* decision/regression tree */static ATTSET *attset  = NULL;  /* attribute set */static TABLE  *table   = NULL;  /* table */static FILE   *out     = NULL;  /* output file *//*----------------------------------------------------------------------  Functions----------------------------------------------------------------------*/static void error (int code, ...){                               /* --- print error message */  va_list    args;              /* list of variable arguments */  const char *msg;              /* error message */  assert(prgname);              /* check the program name */  if (code < E_UNKNOWN) code = E_UNKNOWN;  if (code < 0) {               /* if to report an error, */    msg = errmsgs[-code];       /* get the error message */    if (!msg) msg = errmsgs[-E_UNKNOWN];    fprintf(stderr, "\n%s: ", prgname);    va_start(args, code);       /* get variable arguments */    vfprintf(stderr, msg, args);/* print error message */    va_end(args);               /* end argument evaluation */  }  #ifndef NDEBUG  if (table)  tab_delete(table, 0);  if (dtree)  dt_delete(dtree, 0);  if (attset) as_delete(attset);   /* clean up memory */  if (scan)   sc_delete(scan);     /* and close files */  if (out && (out != stdout)) fclose(out);  #endif  #ifdef STORAGE  showmem("at end of program"); /* check memory usage */  #endif  exit(code);                   /* abort the program */}  /* error() *//*--------------------------------------------------------------------*/static int code (const MINFO *tab, const char *name){                               /* --- get pruning method code */  for ( ; tab->name; tab++)     /* look up name in table */    if (strcmp(tab->name, name) == 0)      return tab->code;         /* return the method code */  return -1;                    /* or an error indicator */}  /* code() *//*--------------------------------------------------------------------*/int main (int argc, char* argv[]){                               /* --- main function */  int    i, k = 0;              /* loop variables, counter */  char   *s;                    /* to traverse options */  char   **optarg = NULL;       /* option argument */  char   *fn_dt   = NULL;       /* name of dec./reg. tree file */  char   *fn_pdt  = NULL;       /* name of output file */  char   *fn_hdr  = NULL;       /* name of table header file */  char   *fn_tab  = NULL;       /* name of table file */  char   *blanks  = NULL;       /* blanks */  char   *fldseps = NULL;       /* field  separators */  char   *recseps = NULL;       /* record separators */  char   *uvchars = NULL;       /* unknown value characters */  char   *mname   = NULL;       /* name of pruning method */  int    method   = 2;          /* pruning method */  float  param    = 0.5F;       /* pruning parameter */  int    maxht    = INT_MAX;    /* maximal height of tree */  int    chklb    = 0;          /* whether to check largest branch */  int    flags    = AS_NOXATT;  /* table file read flags */  int    balance  = 0;          /* flag for balancing class freqs. */  int    maxlen   = 0;          /* maximal output line length */  int    dmode    = 0;          /* description mode */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -