📄 cli.c
字号:
char *s; /* to traverse options */ char **optarg = NULL; /* option argument */ char *fn_in = NULL; /* name of input cluster file */ char *fn_dom = NULL; /* name of domain file */ char *fn_hdr = NULL; /* name of table header file */ char *fn_tab = NULL; /* name of table file */ char *fn_cls = NULL; /* name of output cluster file */ char *blanks = NULL; /* blank characters */ char *fldseps = NULL; /* field separators */ char *recseps = NULL; /* record separators */ char *comment = NULL; /* comment characters */ char *trgname = NULL; /* name of optional target attribute */ char *ininame = "points"; /* name of initialization mode */ char *nrmname = "sum1"; /* name of normalization mode */ char *updname = "altopt"; /* name of parameter update method */ char *modname = "none"; /* name of parameter update modifier */ int matinp = 0; /* flag for numerical matrix input */ int clscnt = 2; /* number of clusters */ int type = CLS_CENTER;/* cluster type */ double rfnps[] = {2, 0}; /* radial function parameters */ int gauss = 0; /* flag for Gaussian function */ int nrmmode = 0; /* normalization mode */ double nrmps[] = {1, 0}; /* normalization parameters */ double noise = 0; /* m.s. degree to noise cluster */ int owrite = 0; /* overwrite parameters with options */ int irnorm = 1; /* flag for input range normalization */ int inimode = 0; /* initialization mode */ int seed = (int)time(NULL); /* seed for random numbers */ double range = 0; /* range for random offsets */ double radius = 1.0; /* initial cluster size (radius) */ int method = CLS_MODVAR;/* parameter update method */ int epochs = 1000; /* number of update epochs */ int update = 0; /* number of points between updates */ int conly = 0; /* epochs to update centers only */ int shuffle = 1; /* shuffle data set */ double trmchg = 0; /* maximum change for termination */ double msexp = 2.0; /* membership exponent for adaptation */ double moment = 0; /* momentum term coefficient */ double growth = 1.2; /* growth factor for learning rate */ double shrink = 0.7; /* shrink factor for learning rate */ double maxchg = 1.8; /* maximal change (neural update) */ double rates[] = {0.2,0.2,0.2}; /* learning rates */ double decay[] = {-.2,-.2,-.2}; /* learning rate decay params. */ double regps[] = {0,1,1,0,0}; /* regularization parameters */ double fwexp = 0; /* exponent for feature weighting */ int maxlen = 0; /* maximal output line length */ int dmode = CLS_TITLE; /* description mode */ int exclude = 0; /* number of target fields to exclude */ int attcnt = 0; /* number of attributes */ int tplcnt = 0; /* number of data tuples */ int flags = AS_NOXATT|AS_NONULL; /* table file read flags */ int report = 0; /* flag for intermediate reporting */ MATRIX *submat; /* submatrix for usable columns */ TSINFO *tse; /* error information */ TUPLE *tpl; /* to traverse the tuples */ ATT *att; /* to traverse the attributes */ double chg, c; /* (max.) change of a center coord. */ clock_t t; /* timer for measurements */ 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 given */ printf("usage: %s [options] [-M|domfile [-d|-h hdrfile]] " "tabfile outfile\n", argv[0]); printf("%s\n", DESCRIPTION); printf("%s\n", VERSION); printf("-! print a list of init. and norm. modes " "and update methods\n"); printf("-M input is a numerical matrix " "(default: input is a table)\n"); printf("-c# number of clusters " "(default: %d)\n", clscnt); printf("-v adaptable variances " "(default: unit variances)\n"); printf("-V adaptable covariances " "(default: unit matrix)\n"); printf("-Z adaptable sizes " "(default: fixed sizes)\n"); printf("-j joint size/(co)variances " "(default: individual)\n"); printf("-w adaptable weights/prior probs. " "(default: equal weights)\n"); printf("-G Gaussian radial function " "(default: Cauchy function)\n"); printf("-p#:# radial function parameters " "(default: %g:%g)\n", rfnps[0], rfnps[1]); printf("-N normalize to unit integral " "(default: no normalization)\n"); printf("-y# membership to noise cluster " "(default: %g)\n", noise); printf("-J#:# membership transform parameters " "(default: %g:%g)\n", nrmps[0], nrmps[1]); printf("-E# membership normalization mode " "(default: %s)\n", nrmname); printf("-F# exponent for feature weighting " "(default: %g)\n", fwexp); printf("-x# exponent for data point weight " "(default: %g)\n", msexp); printf("-O overwrite with option values " "(default: parameters read)\n"); printf("-0 fix centers at origin " "(default: free centers)\n"); printf("-1 normalize centers to unit length " "(default: no normalization)\n"); printf("-i# initialization mode " "(default: %s)\n", ininame); printf("-o# random offset range " "(default: %g)\n", range); printf("-S# seed for random numbers " "(default: time)\n"); printf("-I# initial cluster size (radius) " "(default: %g)\n", radius); printf("-e# maximum number of update epochs " "(default: %d)\n", epochs); printf("-Y# epochs to update centers only " "(default: %d)\n", conly); printf("-k# data points between two updates " "(default: %d)\n", update); printf("-s do not shuffle data points " "(default: once per epoch)\n"); printf("-q do not normalize input ranges " "(default: mean=0, var=1)\n"); printf("-a# parameter update method " "(default: %s)\n", updname); printf("-A# parameter update modifier " "(default: %s)\n", modname); printf("-K use modifier only for centers " "(default: all parameters)\n"); printf("-t#:#:# learning rates " "(default: %g:%g:%g)\n", rates[0], rates[1], rates[2]); printf("-D#:#:# learning rates decay parameters " "(default: %g:%g:%g)\n", decay[0], decay[1], decay[2]); printf("-m# momentum coefficient " "(default: %g)\n", moment); printf("-g#:# growth and shrink factor " "(default: %g:%g)\n", growth, shrink); printf("-z# maximal change/learning rate " "(default: %g)\n", maxchg); printf("-T# maximum change for termination " "(default: %g)\n", trmchg); printf("-H# shape regularization parameter " "(default: %g)\n", regps[3]); printf("-R#:#:# size regularization parameters " "(default: %g:%g:%g)\n", regps[0], regps[1], regps[2]); printf("-W# weight regularization parameter " "(default: %g)\n", regps[4]); printf("-X# exclude a target attribute " "(default: use all attributes)\n"); printf("-l# output line length " "(default: no limit)\n"); printf("-b/f/r# blank characters, field and record separators\n" " (default: \" \\t\\r\", \" ,\\t\", \"\\n\")\n"); printf("-C# comment characters (default: \"#\")\n"); printf("-n number of tuple occurrences in last field\n"); printf("domfile file containing domain descriptions\n" " (and optionally an initial cluster set)\n"); printf("-d use default header " "(field names = field numbers)\n"); printf("-h read table header (field names) from hdrfile\n"); printf("hdrfile file containing table header (field names)\n"); printf("tabfile table file to read " "(field names in first record)\n"); printf("outfile file to write induced cluster set to\n"); printf("infile file to read initial cluster set from " "(only with -M)\n"); return 0; /* print a usage message */ } /* and abort the program */ /* remaining option characters: u B P */ /* --- evaluate arguments --- */ for (i = 1; i < argc; i++) { /* traverse arguments */ s = argv[i]; /* get option argument */ if (optarg) { *optarg = s; optarg = NULL; continue; } if ((*s == '-') && *++s) { /* -- if argument is an option */ while (1) { /* traverse characters */ switch (*s++) { /* evaluate option */ case '!': help(); break; case 'M': matinp = 1; break; case 'c': clscnt = (int)strtol(s, &s, 0); break; case 'v': type |= CLS_VARS; break; case 'V': type |= CLS_COVARS; break; case 'Z': type |= CLS_SIZE; break; case 'j': type |= CLS_JOINT; break; case 'w': type |= CLS_WEIGHT; break; case 'G': gauss = 1; break; case 'p': getdblvec(s, &s, 2, rfnps); break; case 'N': type |= CLS_NORM; break; case 'y': noise = strtod(s, &s); break; case 'J': getdblvec(s, &s, 2, nrmps); break; case 'E': optarg = &nrmname; break; case 'F': fwexp = strtod(s, &s); break; case 'O': owrite = 1; break; case '0': method |= CLS_ORIGIN; break; case '1': method |= CLS_UNIT; break; case 'x': msexp = strtod(s, &s); break; case 'i': optarg = &ininame; break; case 'o': range = strtod(s, &s); break; case 'S': seed = (int)strtol(s, &s, 0); break; case 'I': radius = strtod(s, &s); break; case 'e': epochs = (int)strtol(s, &s, 0); break; case 'Y': conly = (int)strtol(s, &s, 0); break; case 'k': update = (int)strtol(s, &s, 0); break; case 's': shuffle = 0; break; case 'P': report = 1; break; case 'q': irnorm = 0; break; case 'a': optarg = &updname; break; case 'A': optarg = &modname; break; case 'K': method &= ~CLS_MODVAR; break; case 't': getdblvec(s, &s, 3, rates); break; case 'D': getdblvec(s, &s, 3, decay); break; case 'm': moment = strtod(s, &s); break; case 'g': getdbls(s, &s, 2, &growth, &shrink); break; case 'z': maxchg = strtod(s, &s); break; case 'T': trmchg = strtod(s, &s); break; case 'H': getdbls(s, &s, 1, regps+3); break; case 'R': getdblvec(s, &s, 3, regps); break; case 'W': getdbls(s, &s, 1, regps+4); break; case 'X': optarg = &trgname; break; case 'l': maxlen = (int)strtol(s, &s, 0); break; case 'b': optarg = &blanks; break; case 'f': optarg = &fldseps; break; case 'r': optarg = &recseps; break; case 'C': optarg = &comment; break; case 'n': flags |= AS_WEIGHT; break; case 'd': flags |= AS_DFLT; break; case 'h': optarg = &fn_hdr; break; default : error(E_OPTION, *--s); break; } /* set option variables */ if (!*s) break; /* if at end of string, abort loop */ if (optarg) { *optarg = s; optarg = NULL; break; } } } /* get option argument */ else { /* -- if argument is no option */ switch (k++) { /* evaluate non-option */ case 0: fn_dom = s; break; case 1: fn_tab = s; break; case 2: fn_cls = s; break; default: error(E_ARGCNT); break; } /* note filenames */ } } if (optarg) error(E_OPTARG); /* check the option argument */ if (matinp) { /* if matrix input */ if ((k != 2) && (k != 3)) /* check the number */ error(E_ARGCNT); /* of arguments */ fn_in = fn_cls; /* shift the file names */ fn_cls = fn_tab; /* (as there is no domain file) */ fn_tab = fn_dom; fn_dom = NULL; if ((!fn_tab || !*fn_tab) && (!fn_in || !*fn_in)) error(E_STDIN); } /* stdin must not be used twice */ else { /* if table version */ if (k != 3) error(E_ARGCNT);/* check the number of arguments */ if (fn_hdr && (strcmp(fn_hdr, "-") == 0)) fn_hdr = ""; /* convert "-" to "" */ i = (!fn_dom || !*fn_dom) ? 1 : 0; if (!fn_tab || !*fn_tab) i++; if ( fn_hdr && !*fn_hdr) i++; if (i > 1) error(E_STDIN); /* stdin must not be used twice */ if (fn_hdr) flags = AS_ATT | (flags & ~AS_DFLT); } /* set the header file flag */ if (rfnps[0] <= 0) error(E_RFNPAR, rfnps[0]); if (rfnps[1] < 0) error(E_RFNPAR, rfnps[1]); if (radius <= 0) error(E_RADIUS, radius); inimode = code(initab, ininame); /* code the initialization mode */ if (inimode < 0) error(E_MODE, ininame); inimode |= method; /* add unit centers/origin flags */ nrmmode = code(nrmtab, nrmname); /* code the normalization mode */ if (nrmmode < 0) error(E_MODE, nrmname); if (nrmps[0] <= -1) error(E_NRMPAR, nrmps[0]); if (nrmps[1] < 0) error(E_NRMPAR, nrmps[1]); if ((nrmps[0] == 0) && (msexp == 0)) error(E_NRMPAR, nrmps[0]); i = code(updtab, updname); /* code the update method */ if (i < 0) error(E_METHOD, updname); method |= i; /* combine method and modifier */ i = code(modtab, modname); /* code the update modifier */ if (i < 0) error(E_MODIFY, modname); if (i != 0) method |= i; /* combine method and modifier */ else method &= ~CLS_MODVAR; if (method & CLS_ORIGIN) conly = 0; if (msexp < 0) error(E_MFEXP, msexp);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -