?? dtp.c
字號:
/*---------------------------------------------------------------------- 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----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.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.4 (2004.05.26) " \ "(c) 1997-2004 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 *//*---------------------------------------------------------------------- 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. */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -