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

📄 lvqx.c

📁 LVQ - Learning Vector Quantization Demonstration Download xlvq Linux executable (128 kb) wlvq.ex
💻 C
📖 第 1 页 / 共 2 页
字号:
    #else    printf("-c#      name of the vector index field "                    "(default: \"%s\")\n", vecname);    printf("-m#      name of neuron activation field\n");    printf("-a       align fields (default: do not align)\n");    printf("-w       do not write field names to output file\n");    #endif    printf("-o#      output format for neuron activations "                    "(default: \"%s\")\n", outfmt);    printf("-b/f/r#  blank characters, field and record separators\n"           "         (default: \" \\t\\r\", \" \\t\", \"\\n\")\n");    printf("lvqfile  file to read reference vectors from\n");    #ifdef MATVERSION    printf("patfile  pattern file to read (no header, only numbers)\n");    printf("outfile  file to write extended patterns to\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");    printf("outfile  file to write extended tuples to\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 */          #ifdef MATVERSION          case 'c': vecidx    = 1;             break;          case 'm': nactiv    = 1;             break;          case 'p': optarg    = &patfmt;       break;          case 'o': optarg    = &outfmt;       break;          #else          case 'c': optarg    = &vecname;      break;          case 'm': optarg    = &actname;      break;          case 'o': optarg    = &outfmt;       break;          case 'a': outflags |=  AS_ALIGN;     break;          case 'w': outflags &= ~AS_ATT;       break;          #endif          case 'b': optarg    = &blanks;       break;          case 'f': optarg    = &fldseps;      break;          case 'r': optarg    = &recseps;      break;          #ifndef MATVERSION          case 'd': inflags  |= 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_lvq = s;      break;        case  1: fn_pat = s;      break;        case  2: fn_out = s;      break;        default: error(E_ARGCNT); break;      }                         /* note filenames */    }  }  if (optarg) error(E_OPTARG);  /* check option argument and */  if (k != 3) error(E_ARGCNT);  /* the number of arguments */  #ifdef MATVERSION  if ((!fn_lvq || !*fn_lvq) && (!fn_pat || !*fn_pat))    error(E_STDIN);             /* stdin must not be used twice */  #else  if (fn_hdr && (strcmp(fn_hdr, "-") == 0))    fn_hdr = "";                /* convert "-" to "" */  i = (!fn_lvq || !*fn_lvq) ? 1 : 0;  if  (!fn_pat || !*fn_pat) i++;  if  ( fn_hdr && !*fn_hdr) i++;/* check assignments of stdin: */  if (i > 1) error(E_STDIN);    /* stdin must not be used twice */  if (fn_hdr)                   /* set the header file flag */    inflags = AS_ATT | (inflags & ~AS_DFLT);  if ((outflags & AS_ATT) && (outflags & AS_ALIGN))    outflags |= AS_ALNHDR;      /* set align to header flag */  #endif  /* --- read reference vectors --- */  scan = sc_create(fn_lvq);     /* create a scanner */  if (!scan) error((!fn_lvq || !*fn_lvq) ? E_NOMEM : E_FOPEN, fn_lvq);  fprintf(stderr, "\nreading %s ... ", sc_fname(scan));  if (sc_nexter(scan) < 0) error(E_PARSE, sc_fname(scan));  #ifdef MATVERSION  lvq = lvq_parse(scan, -1);    /* parse the input network */  #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));  lvq = lvq_parsex(scan, attset, 0);  #endif                        /* parse the neural network */  if (!lvq || !sc_eof(scan)) error(E_PARSE, sc_fname(scan));  #ifdef MATVERSION  dimcnt = lvq_dim(lvq);        /* get the number of dimensions */  veccnt = lvq_cnt(lvq);        /* and the number of ref. vectors */  fprintf(stderr, "[%d vector(s)] done.\n", veccnt);  #else  fprintf(stderr, "[%d attribute(s), ", as_attcnt(attset));  fprintf(stderr, "%d vector(s)] done.\n", lvq_cnt(lvq));  #endif  sc_delete(scan); scan = NULL; /* delete the scanner */  #ifdef MATVERSION  /* --- process patterns --- */  if (fn_pat && *fn_pat)        /* if a file name is given, */    in = fopen(fn_pat, "r");    /* open the file for reading */  else {                        /* if no file name is given, */    in = stdin; fn_pat = "<stdin>"; }      /* use std. input */  fprintf(stderr, "\nreading %s ... ", fn_pat);  if (!in) error(E_FOPEN, fn_pat);  if (fn_out && *fn_out)        /* if a file name is given, */    out = fopen(fn_out, "w");   /* open the file for writing */  else {                        /* if no file name is given, */    out = stdout; fn_out = "<stdout>"; }  /* use std. output */  if (!out) error(E_FOPEN, fn_out);  tfscan = tfs_create();        /* create a table file scanner and */  if (!tfscan) error(E_NOMEM);  /* set the separator characters */  if (blanks)  seps[0] = tfs_chars(tfscan, TFS_BLANK,  blanks);  if (fldseps) seps[1] = tfs_chars(tfscan, TFS_FLDSEP, fldseps);  if (recseps) seps[2] = tfs_chars(tfscan, TFS_RECSEP, recseps);  err = tfs_err(tfscan);        /* get the error information */  pat = vec_readx(tfscan, in, &valcnt);  if (!pat) {                   /* read the first training pattern */    if (err->code >= 0) error(E_FREAD, fn_pat);    error(err->code, fn_pat, 1, err->s, err->fld, err->exp); }  else {                        /* if a pattern could be read */    if (valcnt != dimcnt) error(E_PATSIZE, valcnt);  }                             /* check the pattern size */  do {                          /* pattern read loop */    for (i = 0; i < valcnt; i++) {      if (i > 0) fputc(seps[1], out);      fprintf(out, patfmt, pat[i]);    }                           /* print the pattern elements */    fputc(seps[0], out);        /* print a separating blank */    i = lvq_exec(lvq,pat,NULL); /* execute the neural network */    if (vecidx) {               /* if to print a vector index */      fputc(seps[1], out);      /* print the index of the neuron */      fprintf(out, "%d", i);    /* with the highest activation */      if (nactiv) {             /* if the neuron activ. flag is set */        fputc(seps[1], out);    /* print a separator */        fprintf(out, outfmt, lvq_activ(lvq, i));      } }                       /* print the neuron activation */    else {                      /* if to print all neuron activations */      for (k = 0; k < veccnt; k++) {        fputc(seps[1], out);    /* traverse the clusters */        fprintf(out, outfmt, lvq_activ(lvq, k));      }                         /* print the neuron activations */    }                           /* to the different clusters */    fputc(seps[2], out);        /* and terminate the record */    patcnt++;                   /* count pattern and read next */  } while (vec_read(pat, valcnt, tfscan, in) == 0);  if (err->code < 0)            /* check for an error */    error(err->code, fn_pat, patcnt+1, err->s, err->fld, err->exp);  if (tfs_delim(tfscan) != TFS_EOF)  /* check for end of file */    error(E_VALUE, fn_pat, patcnt+1, "\"\"", 1);  if (out != stdout) {          /* if not written to standard output, */    k = fclose(out); out = NULL;/* close the output file */    if (k != 0) error(E_FWRITE, fn_out);  }                             /* check for successful writing */  if (in != stdin) {            /* if not read from standard input, */    fclose(in); in = NULL; }    /* close the input file */  fprintf(stderr, "[%d pattern(s)] done.\n", patcnt);  #else  /* --- read table header --- */  as_chars(attset, blanks, fldseps, recseps, "");  in = io_hdr(attset, fn_hdr, fn_pat, inflags, 1);  if (!in) error(1);            /* read the table header */  if ((outflags & AS_ALIGN)     /* if to align output file */  &&  (in != stdin)) {          /* and not to read from stdin */    i = AS_INST | (inflags & ~(AS_ATT|AS_DFLT));    while (as_read(attset, in, i) == 0);    fclose(in);                 /* determine the column widths */    fprintf(stderr, "done.\n"); /* and print a success message */    in = io_hdr(attset, fn_hdr, fn_pat, inflags, 1);    if (!in) error(1);          /* reread the table header */  }                             /* (necessary because of first tuple) */  /* --- process patterns --- */  if (fn_out && *fn_out)        /* if a file name is given, */    out = fopen(fn_out, "w");   /* open the file for writing */  else {                        /* if no file name is given, */    out = stdout; fn_out = "<stdout>"; }  /* use std. output */  if (!out) error(E_FOPEN, fn_out);  k = AS_INFO1|AS_RDORD|outflags;  if (outflags & AS_ATT)        /* if to write table header */    as_write(attset, out, k, infout);  k = AS_INST | (k & ~AS_ATT);  /* write the attribute names */  f = AS_INST | (inflags & ~(AS_ATT|AS_DFLT));  i = ((inflags & AS_DFLT) && !(inflags & AS_ATT))    ? 0 : as_read(attset, in, f);  while (i == 0) {              /* record read loop */    tplcnt++;                   /* count tuple and sum its weight */    tplwgt += as_getwgt(attset);    lvq_valuex(lvq, NULL);      /* set the data from a tuple */    if (as_write(attset, out, k, infout) != 0)      error(E_FWRITE, fn_out);  /* write tuple to output file */    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 += (inflags & (AS_ATT|AS_DFLT)) ? 1 : 2;    io_error(i, fn_pat, 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 */  if (out != stdout) {          /* if not written to standard output */    i = fclose(out); out = NULL;/* close the output file */    if (i) error(E_FWRITE, fn_out);  }                             /* print a success message */  fprintf(stderr, "[%d/%g tuple(s)] done.\n", tplcnt, tplwgt);  #endif  /* --- clean up --- */  #ifndef NDEBUG  #ifdef MATVERSION  tfs_delete(tfscan);           /* delete the table file scanner */  #else  as_delete(attset);            /* delete the attribute set */  #endif  lvq_delete(lvq);              /* delete the neural network */  #endif  return 0;                     /* return 'ok' */}  /* main() */

⌨️ 快捷键说明

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