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

📄 clx.c

📁 it is the Data Mining Algorithm source code.
💻 C
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------  File    : clx.c  Contents: probabilistic and fuzzy cluster induction  Author  : Christian Borgelt  History : 2003.01.30 file created            2003.01.31 cluster index output added            2003.03.11 hard cluster assigment added            2003.05.17 normalization parameters moved to cluster file            2003.08.16 slight changes in error message output            2004.02.25 source files clx.c und mclx.c combined            2004.04.22 bug concerning additional field reading fixed            2006.01.28 conditional compilation simplified            2007.01.22 alignment of membership degrees added            2007.02.14 adapted to changed module tabscan            2007.03.16 table and matrix version combined            2008.03.01 redesign for feature weighting finished----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <math.h>#include <time.h>#include <assert.h>#ifndef AS_RDWR#define AS_RDWR#endif#ifndef AS_PARSE#define AS_PARSE#endif#include "io.h"#ifndef MAT_READ#define MAT_READ#endif#ifndef CLS_PARSE#define CLS_PARSE#endif#ifndef CLS_EXTFN#define CLS_EXTFN#endif#include "cluster.h"/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define PRGNAME     "clx"#define DESCRIPTION "probabilistic and fuzzy cluster execution"#define VERSION     "version 3.0 (2008.04.11)         " \                    "(c) 2003-2008   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)        /* file open failed */#define E_FREAD     (-3)        /* file read failed */#define E_FWRITE    (-4)        /* file write failed */#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 errors on input file */#define E_PATCNT   (-10)        /* no pattern found */#define E_UNKNOWN  (-18)        /* unknown error *//*----------------------------------------------------------------------  Constants----------------------------------------------------------------------*/static 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_PATCNT  -10 */  "no pattern in file %s\n",  /*    -11 to -15 */  NULL, NULL, NULL, NULL, NULL,  /* E_VALUE   -16 */  "file %s, record %d: "                         "invalid value %s in field %d\n",  /* E_FLDCNT  -17 */  "file %s, record %d: "                         "%s%d field(s) instead of %d\n",  /* E_UNKNOWN -18 */  "unknown error\n",};/*----------------------------------------------------------------------  Global Variables----------------------------------------------------------------------*/const  char    *prgname = NULL; /* program name for error messages */static char    *clsname = NULL; /* name of cluster index field */static char    *msdname = NULL; /* name of membership degree field */static FILE    *in      = NULL; /* input  file */static FILE    *out     = NULL; /* output file */static ATTSET  *attset  = NULL; /* attribute set */static ATTMAP  *attmap  = NULL; /* attribute map */static SCAN    *scan    = NULL; /* scanner for cluster set desc. */static TABSCAN *tscan   = NULL; /* table scanner */static CLSET   *clset   = NULL; /* cluster set */static char    *fmt = "%g";     /* format for numbers */static char    buf[64];         /* buffer for formatting *//*----------------------------------------------------------------------  Main 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 the error message */    va_end(args);               /* end argument evaluation */  }  #ifndef NDEBUG                     /* clean up memory */  if (clset)  cls_deletex(clset, 0); /* and close files */  if (tscan)  ts_delete(tscan);  if (attmap) am_delete(attmap);  if (attset) as_delete(attset);  if (scan)   sc_delete(scan);  if (in  && (in  != stdin))  fclose(in);  if (out && (out != stdout)) fclose(out);  #endif  exit(code);                   /* abort the program */}  /* error() *//*--------------------------------------------------------------------*/static void infout (ATTSET *set, FILE *file, int mode, const char *seps){                               /* --- write additional information */  static int wd = 0;            /* field width */  int i, k, n;                  /* loop variables, buffer */  if (mode & AS_ATT) {          /* if to write the header */    wd = 0;                     /* initialize the field width */    if (clsname) {              /* if to write only a cluster index */      fputs(clsname, file);     /* write the cluster index field name */      if (msdname) {            /* if to add the membership degree */        fputc(seps[1], file);   /* print a separator */        fputs(msdname, file);   /* and the membership degree */      } }    else {                      /* if to write all membership degrees */      if (!msdname) msdname = "";      if (mode & AS_ALIGN)      /* determine width of numbers */        wd = sprintf(buf, fmt, DBL_EPSILON);      if (mode & AS_ALNHDR) {   /* if to align to header */        k = sprintf(buf, "%d", cls_clscnt(clset)-1) +strlen(msdname);        if (k > wd) wd = k;     /* determine width of field names */      }                         /* and update the field width */      for (n = cls_clscnt(clset), i = 0; i < n; i++) {        fputc(seps[1], file);   /* traverse the clusters */        k = fprintf(file, "%s%d", msdname, i);        while (++k <= wd) fputc(seps[0], file);      }                         /* print a separator and */    } }                         /* the membership field names */  else {                        /* if to write a data tuple */    i = cls_exec(clset, NULL, NULL);  /* execute the cluster set */    if (clsname) {              /* if to write only a cluster index */      fprintf(file, "%d", i);   /* write the cluster index */      if (msdname) {            /* if to add the membership degree */        fputc(seps[1], file);   /* print a separator */        fprintf(file, fmt, cls_msdeg(clset, i));      } }                       /* print the membership degree */    else {                      /* if to write all membership degrees */      for (n = cls_clscnt(clset), i = 0; i < n; i++) {        fputc(seps[1], file);   /* traverse the clusters */        k = fprintf(file, fmt, cls_msdeg(clset, i));        while (++k <= wd) fputc(seps[0], file);      }                         /* print a separator */    }                           /* and the membership degree */  }}  /* infout() *//*--------------------------------------------------------------------*/int main (int argc, char *argv[]){                               /* --- main function */  int    i, k = 0;              /* loop variables, counters */  char   *s;                    /* to traverse options */  char   **optarg = NULL;       /* option argument */  char   *fn_cls  = NULL;       /* name of cluster set file */  char   *fn_hdr  = NULL;       /* name of table header file */  char   *fn_in   = NULL;       /* name of input  table file */  char   *fn_out  = NULL;       /* name of output table file */  char   *blanks  = NULL;       /* blank   characters */  char   *fldseps = NULL;       /* field   separators */  char   *recseps = NULL;       /* record  separators */  char   *comment = NULL;       /* comment characters */  char   seps[4]  = "  \n";     /* separator characters */  int    matinp   = 0;          /* flag for numerical matrix input */  int    clsidx   = 0;          /* flag for cluster index output */  int    msdeg    = 0;          /* flag for membership degree */  int    patcnt   = 0;          /* number of test patterns */  int    inflags  = 0;          /* table file read  flags */  int    outflags = AS_ATT, f;  /* table file write flags */  int    tplcnt   = 0;          /* number of tuples */  double tplwgt   = 0.0;        /* weight of tuples */  int    attcnt;                /* number of attributes */  int    clscnt;                /* number of clusters */  double *pat;                  /* to traverse the patterns */  ATT    *att;                  /* to traverse the attributes */  TSINFO *tse;                  /* error information */  prgname = argv[0];            /* get program name for error msgs. */  /* --- print startup/usage message --- */  if (argc > 1) {               /* if arguments are given */    fprintf(stderr, "%s - %s\n", argv[0], DESCRIPTION);    fprintf(stderr, VERSION); } /* print a startup message */  else {                        /* if no argument is given */    printf("usage: %s [options] clsfile "                    "[-d|-h hdrfile] tabfile outfile\n", argv[0]);    printf("%s\n", DESCRIPTION);    printf("%s\n", VERSION);    printf("-c#      name of the cluster index field "                    "(default: membership degrees)\n");

⌨️ 快捷键说明

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