📄 cle.c
字号:
"(default: %g)\n", radius); printf("-b/f/r# blank characters, field and record separators\n" " (default: \" \\t\\r\", \" \\t\", \"\\n\")\n"); printf("clsfile file to read cluster set description from\n"); #ifdef MATVERSION printf("patfile pattern file to read (no header, only numbers)\n"); #else 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"); #endif return 0; /* print a usage message */ } /* and abort the program */ /* --- 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 'x': msexp = strtod(s, &s); break; case 'p': radius = strtod(s, &s); break; case 'b': optarg = &blanks; break; case 'f': optarg = &fldseps; break; case 'r': optarg = &recseps; break; #ifndef MATVERSION case 'd': flags |= AS_DFLT; break; case 'h': optarg = &fn_hdr; break; #endif 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_cls = s; break; case 1: fn_in = s; break; default: error(E_ARGCNT); break; } /* note filenames */ } } if (optarg) error(E_OPTARG); /* check option argument and */ if (k != 2) error(E_ARGCNT); /* the number of arguments */ i = (!fn_cls || !*fn_cls) ? 1 : 0; if (!fn_in || !*fn_in ) i++; #ifndef MATVERSION if (fn_hdr) { /* set the header file flag */ flags = AS_ATT | (flags & ~AS_DFLT); if (strcmp(fn_hdr, "-") == 0) fn_hdr = ""; if (!*fn_hdr) i++; /* convert "-" to "" and */ } /* count assignment of stdin */ #endif /* check assignments of stdin: */ if (i > 1) error(E_STDIN); /* stdin must not be used twice */ if (msexp < 0) error(E_MSEXP, msexp); /* --- read cluster set --- */ scan = sc_create(fn_cls); /* create a scanner */ if (!scan) error((!fn_cls || !*fn_cls) ? E_NOMEM : E_FOPEN, fn_cls); fprintf(stderr, "\nreading %s ... ", sc_fname(scan)); if (sc_nexter(scan) < 0) error(E_PARSE, sc_fname(scan)); #ifdef MATVERSION clset = cls_parse(scan); /* parse the input cluster set */ #else attset = as_create("domains", att_delete); if (!attset) error(E_NOMEM); /* create an attribute set */ if ((as_parse(attset, scan, AT_ALL) != 0) || (as_attcnt(attset) <= 0)) /* parse the attribute set */ error(E_PARSE, sc_fname(scan)); clset = cls_parsex(scan, attset, 0); #endif /* parse the cluster set */ if (!clset || !sc_eof(scan)) error(E_PARSE, sc_fname(scan)); #ifdef MATVERSION attcnt = cls_incnt(clset); /* get the number of attributes */ #else attcnt = as_attcnt(attset); /* get the number of attributes */ #endif clscnt = cls_clscnt(clset); /* get the number of clusters */ fprintf(stderr, "[%d attribute(s), ", attcnt); fprintf(stderr, "%d cluster(s)] done.", clscnt); sc_delete(scan); scan = NULL; /* delete the scanner */ cls_msexp(clset, msexp); /* set the membership exponent */ for (i = CLS_VMCNT; --i >= 0; ) cls_evcfg(clset, i,radius); /* configure the evaluation */ #ifdef MATVERSION /* --- process patterns --- */ if (fn_in && *fn_in) /* if an file name is given, */ in = fopen(fn_in, "r"); /* open the file for reading */ else { /* if no fine name is given, */ in = stdin; fn_in = "<stdin>"; } /* use std. input */ fprintf(stderr, "\nreading %s ... ", fn_in); if (!in) error(E_FOPEN, fn_in); tfscan = tfs_create(); /* create a table file scanner and */ if (!tfscan) error(E_NOMEM); /* set the separator characters */ if (blanks) tfs_chars(tfscan, TFS_BLANK, blanks); if (fldseps) tfs_chars(tfscan, TFS_FLDSEP, fldseps); if (recseps) tfs_chars(tfscan, TFS_RECSEP, recseps); err = tfs_err(tfscan); /* get the error information */ pat = vec_readx(tfscan, in, &attcnt); if (!pat) { /* read the first training pattern */ if (err->code >= 0) error(E_FREAD, fn_in); error(err->code, fn_in, 1, err->s, err->fld, err->exp); } /* check for success */ do { /* pattern read loop */ cls_evaggr(clset, pat, 1); /* aggregate the pattern */ patcnt++; /* count pattern and read next */ } while (vec_read(pat, attcnt, tfscan, in) == 0); if (err->code < 0) /* check for an error */ error(err->code, fn_in, patcnt +1, err->s, err->fld, err->exp); if (tfs_delim(tfscan) != TFS_EOF) /* check for end of file */ error(E_VALUE, fn_in, patcnt +1, "\"\"", 1); if (in != stdin) fclose(in); /* close the input file and */ in = NULL; /* clear the file variable */ fprintf(stderr, "[%d pattern(s)] done.\n", patcnt); #else /* --- process patterns --- */ fprintf(stderr, "\n"); /* terminate previous log message */ as_chars(attset, blanks, fldseps, recseps, ""); in = io_hdr(attset, fn_hdr, fn_in, flags|AS_NOXATT, 1); if (!in) error(1); /* read the table header */ k = AS_INST | (k & ~AS_ATT); /* write the attribute names */ f = AS_INST | (flags & ~(AS_ATT|AS_DFLT)); i = ((flags & AS_DFLT) && !(flags & AS_ATT)) ? 0 : as_read(attset, in, f); while (i == 0) { /* record read loop */ tplcnt++; /* count tuple and sum its weight */ tplwgt += w = as_getwgt(attset); as_desc(attset, stdout, 0, 0); cls_valuex(clset, NULL); /* set the data from a tuple */ cls_evaggr(clset, NULL, w); /* and aggregate the pattern */ i = as_read(attset, in, f); /* try to read the next record */ } if (i < 0) { /* if an error occurred, */ err = as_err(attset); /* get the error information */ tplcnt += (flags & (AS_ATT|AS_DFLT)) ? 1 : 2; io_error(i, fn_in, tplcnt, err->s, err->fld, err->exp); error(1); /* print an error message */ } /* and abort the program */ if (in != stdin) fclose(in); /* close the table file and */ in = NULL; /* clear the file variable */ fprintf(stderr, "[%d/%g tuple(s)] done.\n", tplcnt, tplwgt); #endif /* --- compute and print evaluations --- */ printf("objfn (min): %g\n", cls_eval(clset, CLS_OBJFN)); printf("coverage(max): %g\n", cls_eval(clset, CLS_COVERAGE)); printf("fdbidx (min): %g\n", cls_eval(clset, CLS_FDBIDX)); printf("pcoeff (max): %g\n", cls_eval(clset, CLS_PCOEFF));#if 0 printf("pcnorm (max): %g\n", cls_eval(clset, CLS_PCNORM));#endif printf("pentropy(min): %g\n", cls_eval(clset, CLS_PENTROPY)); printf("fhypvol (min): %g\n", cls_eval(clset, CLS_FHYPVOL)); printf("prpexp (max): %g\n", cls_eval(clset, CLS_PRPEXP)); printf("sepdeg (min): %g\n", cls_eval(clset, CLS_SEPDEG)); printf("partdens(max): %g\n", cls_eval(clset, CLS_PARTDENS)); printf("pdavg (max): %g\n", cls_eval(clset, CLS_PDAVG));#if 0 printf("noise (min): %g\n", cls_eval(clset, CLS_NOISE));#endif /* --- clean up --- */ #ifndef NDEBUG #ifdef MATVERSION tfs_delete(tfscan); /* delete the table file scanner */ #else as_delete(attset); /* delete the attribute set */ #endif cls_delete(clset); /* delete the cluster set */ #endif return 0; /* return 'ok' */} /* main() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -