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

📄 cluster1.c

📁 it is the Data Mining Algorithm source code.
💻 C
📖 第 1 页 / 共 5 页
字号:
      for (i = 0; i < n; i++)   /* traverse the dimensions again */        fprintf(file, " %g", c->dif[i]);      fputs(" */", file);       /* print the feature weights and */    } }                         /* finally terminate the comment */  else if (clset->type & CLS_SIZE) { /* if only cluster size */    fprintf(file, ",\n%s            ", indent);    fprintf(file, "  [%g]", mat_get(c->cov, 0, 0));  }                             /* print the isotropic variance */}  /* _descov() *//*--------------------------------------------------------------------*/int cls_desc (CLSET *clset, FILE *file, int mode, int maxlen){                               /* --- describe a set of clusters */  int     i, k;                 /* loop variables */  CLUSTER *c;                   /* to traverse the clusters */  char    *indent = "";         /* indentation string */   assert(clset && file);        /* check the function arguments */  /* --- print a header (as a comment) --- */  if (mode & CLS_TITLE) {       /* if the title flag is set */    i = k = (maxlen > 0) ? maxlen -2 : 70;    fputs("/*", file); while (--i >= 0) fputc('-', file);    fputs("\n  cluster set\n", file);    while (--k >= 0) fputc('-', file); fputs("*/\n", file);  }                             /* print a title header */  if (maxlen <= 0) maxlen = INT_MAX;  #ifdef CLS_EXTFN              /* if to compile extended functions */  if (clset->attmap && !(mode & CLS_RBFNET)) {    fputs("clusters = {\n", file);  /* if based on an attribute set, */    indent = "  ";              /* start the cluster set description */  }                             /* and indent the description itself */  #endif  if (mode & CLS_RBFNET) indent = "  ";  /* --- print scaling parameters --- */  nst_desc(clset->nst, file, indent, maxlen);  /* --- print the function description --- */  fputs(indent,        file);   /* print the indentation */  fputs("function = ", file);   /* and the function name */  fputs((clset->radfn == rf_gauss) ? "gauss" : "cauchy", file);  fprintf(file, "(%g,%g)", clset->rfnps[0], clset->rfnps[1]);  if (clset->type & CLS_NORM)   /* print the function parameters */    fputs(", normalized",file); /* and normalization flag if needed */  fputs(";\n", file);           /* terminate the output line */  /* --- print the noise cluster parameter --- */  if (clset->noise != 0) {      /* if noise cluster parameter given */    fputs(indent, file);        /* write the indentation */    fprintf(file, "noise    = %g;\n", clset->noise);  }                             /* print noise cluster parameter */  /* --- print the normalization mode --- */  if ((clset->norm != CLS_NONE) /* if not default parameters */  ||  (clset->nrmps[0] != 1) || (clset->nrmps[1] != 0)) {    fputs(indent,        file); /* write the indentation and */    fputs("normmode = ", file); /* the normalization mode indicator */    fputs(nrmnames[clset->norm], file);    if ((clset->nrmps[0] != 1)  /* if not standard parameters, */    ||  (clset->nrmps[1] != 0)) /* print normalization parameters */      fprintf(file, "(%g,%g)", clset->nrmps[0], clset->nrmps[1]);    fputs(";\n", file);         /* finally terminate the line */  }  /* --- print the feature weight exponent --- */  if (clset->fwexp > 0) {       /* if a feature weight exponent given */    fputs(indent, file);        /* write the indentation */    fprintf(file, "fwexp    = %g;\n", clset->fwexp);  }                             /* write the feature weight exponent */  /* --- print the feature weight exponent --- */  if (clset->msexp != 2) {      /* if it does not have default value */    fputs(indent, file);        /* write the indentation */    fprintf(file, "msexp    = %g;\n", clset->fwexp);  }                             /* write the feature weight exponent */  /* --- print cluster parameters --- */  fputs(indent,         file);  /* write the indentation and */  fputs("params   = {", file);  /* start the parameter section */  if (clset->fwexp > 0) {       /* if to print feature weights, */    cls_vars  (clset, 1);       /* compute the isotropic variances, */    cls_gauge (clset);          /* measure the cluster sizes, */    cls_resize(clset, 1);       /* resize the clusters, and */    cls_ftwgts(clset);          /* compute the feature weights */  }                             /* (extended parameter output) */  c = clset->cls;               /* traverse the clusters */  for (i = 0; i < clset->clscnt; c++, i++) {    if (i > 0)                  /* start a new output line */      fprintf(file, ",\n%s            ", indent);    fprintf(file, "{ [% g", c->ctr[0]);    for (k = 0; ++k < clset->incnt; )      fprintf(file, ", % g", c->ctr[k]);    fputc(']', file);           /* print the cluster center and */    if (!(clset->type & CLS_JOINT) /* shape and size parameters */    &&   (clset->type & (CLS_COVARS|CLS_VARS|CLS_SIZE)))      _descov(clset, c, indent, file);    if (clset->type & CLS_WEIGHT) {      fputc(',', file);         /* print separating comma */      if ((clset->type & (CLS_VARS|CLS_COVARS))      || !(clset->type & (CLS_VARS|CLS_COVARS|CLS_SIZE)))        fprintf(file, "\n%s             ", indent);      fprintf(file, " %g", mat_getwgt(c->cov));    }                           /* print the cluster weight */    fputs(" }", file);          /* terminate the cluster description */  }  /* --- print joint parameters --- */  if ((clset->type & CLS_JOINT) /* if joint shape and size parameters */  &&  (clset->type & (CLS_COVARS|CLS_VARS|CLS_SIZE)))    _descov(clset, clset->cls, indent, file);  if (!(clset->type & CLS_SIZE))/* if uniform cluster size */    fprintf(file, ",\n%s              %g", indent, clset->cls[0].size);  fputs(" };\n", file);         /* terminate the parameter section */  if (clset->fwexp > 0)         /* if to print feature weights, */    cls_invert(clset);          /* compute inverse matrices */  #ifdef CLS_EXTFN              /* if to compile extended functions */  if (clset->attset && !(mode & CLS_RBFNET))    fputs("};\n", file);        /* terminate the description */  #endif  return ferror(file) ? -1 : 0; /* return the write status */}  /* cls_desc() *//*----------------------------------------------------------------------  Cluster Set Parse Functions----------------------------------------------------------------------*/#ifdef CLS_PARSEstatic int _scales (CLSET *clset, SCAN *scan){                               /* --- get the input scalings */  assert(clset && scan);        /* check the function arguments */  if (clset->nst) return 0;     /* check whether scalings exist */  if ((sc_token(scan) != T_ID)  /* check whether 'scales' follows */  ||  (strcmp(sc_value(scan), "scales") != 0))    return 0;                   /* if not, abort the function */  clset->nst = nst_parse(scan, clset->incnt);  if (!clset->nst) return 1;    /* parse the scaling parameters */  clset->incnt = nst_dim(clset->nst);  return 0;                     /* get the number of dimensions */}  /* _scales() *//*--------------------------------------------------------------------*/static int _function (CLSET *clset, SCAN *scan){                               /* --- parse the function description */  const char *s;                /* buffer for token value */  double     p;                 /* buffer for a parameter */  assert(clset && scan);        /* check the function arguments */  if ((sc_token(scan) != T_ID)  /* check for "function" */  ||  (strcmp(sc_value(scan), "function") != 0))    return 0;                   /* if there is none, abort */  GET_TOK();                    /* consume the "function" keyword */  GET_CHR('=');                 /* consume '=' */  if (sc_token(scan) != T_ID) ERR_STR("cauchy");  s = sc_value(scan);           /* check for a function name */  if      (strcmp(s, "cauchy") == 0) {    clset->radfn = rf_cauchy; clset->drvfn = rfd_cauchy; }  else if (strcmp(s, "gauss")  == 0) {    clset->radfn = rf_gauss;  clset->drvfn = rfd_gauss; }  else ERR_STR("cauchy");       /* decode the function name */  GET_TOK();                    /* and consume it */  GET_CHR('(');                 /* consume '(' */  if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);  p = strtod(sc_value(scan), NULL);  if (p <= 0) ERROR(E_NUMBER);  /* check for a number and */  clset->rfnps[0] = p;          /* get the first parameter, */  GET_TOK();                    /* i.e., the distance exponent */  GET_CHR(',');                 /* consume the separating ',' */  if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);  p = strtod(sc_value(scan), NULL);  if (p < 0) ERROR(E_NUMBER);   /* check for a number and */  clset->rfnps[1] = p;          /* get the second parameter, */  GET_TOK();                    /* i.e., the scaling factor */  GET_CHR(')');                 /* consume the closing ')' */  if (sc_token(scan) == ',') {  /* if a comma follows */    GET_TOK();                  /* consume ',' */    if ((sc_token(scan) != T_ID)    ||  (strcmp(sc_value(scan), "normalized") != 0))      ERR_STR("normalized");    /* check for a normalization flag */    clset->type |= CLS_NORM;    /* set the normalization flag */    GET_TOK();                  /* in the cluster type and */  }                             /* consume the "normalized" keyword */  GET_CHR(';');                 /* consume the closing ';' */  return 0;                     /* return 'ok' */}  /* _function() *//*--------------------------------------------------------------------*/static int _noise (CLSET *clset, SCAN *scan){                               /* --- parse the noise cluster param. */  assert(clset && scan);        /* check the function arguments */  if ((sc_token(scan) != T_ID)  /* check for "noise" */  ||  (strcmp(sc_value(scan), "noise") != 0)) {    clset->noise = 0; return 0; }  GET_TOK();                    /* consume the "noise" keyword */  GET_CHR('=');                 /* consume '=' */  if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);  clset->noise = strtod(sc_value(scan), NULL);  GET_TOK();                    /* get the noise cluster parameter */  GET_CHR(';');                 /* consume the closing ';' */  return 0;                     /* return 'ok' */}  /* _noise() *//*--------------------------------------------------------------------*/static int _normmode (CLSET *clset, SCAN *scan){                               /* --- parse the normalization mode */  int        i;                 /* loop variable */  const char *s;                /* buffer for token value */  double     n;                 /* buffer for a parameter */  assert(clset && scan);        /* check the function arguments */  if ((sc_token(scan) != T_ID)  /* check for "normmode" */  ||  (strcmp(sc_value(scan), "normmode") != 0)) {    clset->norm = CLS_NONE; return 0; }  GET_TOK();                    /* consume the "normmode" keyword */  GET_CHR('=');                 /* consume '=' */  if (sc_token(scan) != T_ID) ERR_STR("sum1");  s = sc_value(scan);           /* check for a norm. mode name */  for (i = sizeof(nrmnames)/sizeof(nrmnames[0]); --i >= 0; )    if (strcmp(s, nrmnames[i]) == 0) { clset->norm = i; break; }  if (i < 0) ERR_STR(nrmnames[CLS_SUM1]);  GET_TOK();                    /* decode the normalization mode */  if (sc_token(scan) == '(') {  /* if a parenthesis follows, */    GET_TOK();                  /* consume the '(' */    if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);    n = strtod(sc_value(scan), NULL);    if (n < 0)                   ERROR(E_NUMBER);     clset->nrmps[0] = n;        /* get the 1st normalization param. */    GET_TOK();                  /* and consume the number */    GET_CHR(',');               /* consume the separating comma */    if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);    n = strtod(sc_value(scan), NULL);    if (n < 0)                   ERROR(E_NUMBER);     clset->nrmps[1] = n;        /* get the 2nd normalization param. */    GET_TOK();                  /* and consume the number */    if (clset->nrmps[0] == 0) { /* if to use a corresponding value */      GET_CHR(',');             /* consume the separating comma */      if (sc_token(scan) != T_NUM) ERROR(E_NUMEXP);      n = strtod(sc_value(scan), NULL);      if (n <= 0)                  ERROR(E_NUMBER);      clset->nrmps[2] = n;      /* get the default for the */      GET_TOK();                /* 1st normalization parameter */    }                           /* and consume the number */    GET_CHR(')');               /* consume the closing ')' */  }  GET_CHR(';');                 /* consume the closing ';' */  return 0;                     /* return 'ok' */}  /* _normmode() *//*--------------------------------------------------------------------

⌨️ 快捷键说明

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