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

📄 cli.c

📁 聚类算法全集以及内附数据集
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------  File    : cli.c  Contents: probabilistic and fuzzy cluster induction  Author  : Christian Borgelt  History : 15.09.2001 file created from file mlpt.c            09.09.2002 neural network update methods added            30.01.2003 data normalization moved to cluster.c            20.03.2003 bug in function msfnpar fixed            15.05.2003 options -n, -g, -z changed, options -q, -j added            16.05.2003 noise clustering added (option -y)            07.06.2003 cluster size scaling factor added            16.08.2003 slight changes in error message output            25.02.2004 source files cli.c amd mcli.c combined            18.03.2004 normalization parameters added            19.03.2004 cluster weight regularization added            06.04.2004 parameters for competitive learning added            13.07.2004 normalization of center vectors added            27.07.2004 option -C added (epochs to update centers only)----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <float.h>#include <time.h>#include <assert.h>#include "params.h"#ifdef MATVERSION#ifndef MAT_READ#define MAT_READ#endif#else  /* #ifdef MATVERSION */#ifndef AS_RDWR#define AS_RDWR#endif#ifndef AS_PARSE#define AS_PARSE#endif#ifndef TAB_RDWR#define TAB_RDWR#endif#include "io.h"#ifndef CLS_EXTFN#define CLS_EXTFN#endif#endif /* #ifdef MATVERSION */#ifndef CLS_PARSE#define CLS_PARSE#endif#include "cluster.h"#ifdef STORAGE#include "storage.h"#endif/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define PRGNAME     "cli"#define DESCRIPTION "probabilistic and fuzzy cluster induction"#define VERSION     "version 2.11 (2004.09.04)        " \                    "(c) 2001-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)        /* 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 error */#define E_MODE     (-10)        /* illegal init. or norm. mode */#define E_RFNPAR   (-11)        /* illegal radial function parameter */#define E_NRMPAR   (-12)        /* illegal normalization parameter */#define E_MSEXP    (-13)        /* illegal membership exponent */#define E_METHOD   (-14)        /* illegal update method */#define E_MODIFY   (-15)        /* illegal update modifier */#define E_PATCNT   (-18)        /* pattern file is empty */#define E_MOMENT   (-19)        /* illegal momentum coefficient */#define E_RADIUS   (-20)        /* illegal initial radius */#define E_REGPAR   (-21)        /* illegal regularization parameter */#define E_LRATE    (-22)        /* illegal learning rate */#define E_UPDPAR   (-23)        /* illegal update parameter */#define E_EPOCHS   (-24)        /* illegal number of epochs */#define E_UNKTRG   (-25)        /* unknown target attribute */#define E_UNKNOWN  (-26)        /* unknown error *//*----------------------------------------------------------------------  Type Definitions----------------------------------------------------------------------*/typedef struct {                /* --- mode information --- */  int  code;                    /* code of mode */  char *name;                   /* name of mode */  char *desc;                   /* description */} MODEINFO;                     /* (mode information) *//*----------------------------------------------------------------------  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_MODE    -10 */  "unknown mode/method %s\n",  /* E_RFNPAR  -11 */  "illegal radial function parameter %g\n",  /* E_NRMPAR  -12 */  "illegal normalization parameter %g\n",  /* E_MSEXP   -13 */  "illegal membership exponent %g\n",  /* E_METHOD  -14 */  "unknown parameter update method %s\n",  /* E_MODIFY  -15 */  "unknown parameter update modifier %s\n",  /* E_VALUE   -16 */  "file %s, record %d: "                         "illegal value %s in field %d\n",  /* E_FLDCNT  -17 */  "file %s, record %d: "                         "%s%d field(s) instead of %d\n",  /* E_PATCNT  -18 */  "pattern file is empty\n",  /* E_MOMENT  -19 */  "illegal momentum coefficient %g\n",  /* E_RADIUS  -20 */  "illegal initial radius %g\n",  /* E_REGPAR  -21 */  "illegal regularization parameter %g\n",  /* E_LRATE   -22 */  "illegal learning rate %g\n",  /* E_UPDPAR  -23 */  "illegal update parameter %g\n",  /* E_EPOCHS  -24 */  "illegal number of epochs: %d\n",  /* E_UNKTRG  -25 */  "unknown target attribute %s\n",  /* E_UNKNOWN -26 */  "unknown error\n"};static const MODEINFO initab[] = { /* table of initialization modes */  { CLS_CENTER,  "center",  "center of the data space"                },  { CLS_UNIFORM, "uniform", "samples from a uniform distribution"     },  { CLS_DIAG,    "diag",    "points on the diagonal of the data space"},  { CLS_LATIN,   "latin",   "latin hypercube sampling"                },  { CLS_POINTS,  "points",  "randomly chosen points of the data set"  },  { -1,          NULL,      NULL   /* sentinel */                     },};static const MODEINFO nrmtab[] = { /* table of normalization modes */  { CLS_NONE,    "none",    "no normalization"       },  { CLS_SUM1,    "sum1",    "normalize to sum 1"     },  { CLS_MAX1,    "max1",    "normalize to maximum 1" },  { CLS_HARD,    "hard",    "hard assignment"        },  { -1,          NULL,      NULL   /* sentinel */    },};static const MODEINFO updtab[] = { /* table of update methods *//*{ CLS_GRADIENT,  "gradient",  "gradient based method"    }, */  { CLS_ALTOPT,    "altopt",    "alternating optimization" },  { CLS_COMPLRN,   "complrn",   "competitive learning"     },  { -1,            NULL,        NULL   /* sentinel */      },};static const MODEINFO modtab[] = { /* table of update modifiers */  { CLS_NONE,      "none",      "standard update"             },  { CLS_EXPAND,    "expand",    "expand change by a factor"   },  { CLS_MOMENTUM,  "momentum",  "update with momentum term"   },  { CLS_ADAPTIVE,  "adaptive",  "self-adaptive change factor" },  { CLS_RESILIENT, "resilient", "resilient update"            },  { CLS_QUICK,     "quick",     "quickprop analog"            },  { -1,            NULL,        NULL   /* sentinel */         },};/*----------------------------------------------------------------------  Global Variables----------------------------------------------------------------------*/const  char   *prgname = NULL;  /* program name for error messages */#ifdef MATVERSIONstatic FILE   *in      = NULL;  /* input file */static TFSCAN *tfscan  = NULL;  /* table file scanner */static MATRIX *matrix  = NULL;  /* matrix of training patterns */#elsestatic ATTSET *attset  = NULL;  /* attribute set */static TABLE  *table   = NULL;  /* table of training patterns */#endifstatic SCAN   *scan    = NULL;  /* scanner for initial cluster set */static CLSET  *clset   = NULL;  /* cluster set */static FILE   *out     = NULL;  /* output file *//*----------------------------------------------------------------------  Random Number Functions----------------------------------------------------------------------*/#ifdef DRAND48                  /* if library for drand48() available */extern void   srand48 (long seed);extern double drand48 (void);   /* use drand48 functions */#define dseed(s) srand48((long)(s))#define drand    drand48#else                           /* if only standard rand() available */#define dseed(s) srand((unsigned)(s))static double drand (void){ return rand()/(RAND_MAX +1.0); }#endif/*----------------------------------------------------------------------  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_delete(clset);     /* and close files */  #ifdef MATVERSION  if (matrix) mat_delete(matrix);  if (tfscan) tfs_delete(tfscan);  #else  if (table)  tab_delete(table, 0);  if (attset) as_delete(attset);  #endif  if (scan)   sc_delete(scan);  #ifdef MATVERSION  if (in  && (in  != stdin))  fclose(in);  #endif  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 void help (void){                               /* --- print help on init. modes */  int i;                        /* loop variable */  fprintf(stderr, "\n");        /* terminate startup message */  printf("list of initialization modes (option -i#):\n");  printf("(choice of initial positions of the cluster centers;\n");  printf("a random offset can be added with the option -o#)\n");  printf("  name        initialization mode\n");  for (i = 0; initab[i].name; i++) /* list of initialization modes */    printf("  %-10s  %s\n", initab[i].name, initab[i].desc);  printf("list of membership normalization modes (option -j#)\n");  printf("  name        membership normalization mode\n");  for (i = 0; nrmtab[i].name; i++) /* list of normalization modes */    printf("  %-10s  %s\n", nrmtab[i].name, nrmtab[i].desc);  printf("list of parameter update methods (option -a#)\n");  printf("  name        parameter update method\n");  for (i = 0; updtab[i].name; i++) /* list of update methods */    printf("  %-10s  %s\n", updtab[i].name, updtab[i].desc);  printf("list of parameter update modifiers (option -A#)\n");  printf("  name        parameter update method\n");  for (i = 0; modtab[i].name; i++) /* list of update modifiers */    printf("  %-10s  %s\n", modtab[i].name, modtab[i].desc);  exit(0);                      /* abort the program */}  /* help() *//*--------------------------------------------------------------------*/static int code (const MODEINFO *tab, const char *name)

⌨️ 快捷键说明

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