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

📄 wbcview.c

📁 BCView - Bayes Classifier Visualization Download xbcview Linux executable (218 kb) wbcview.exe W
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------  File    : wbcview.c  Contents: Bayes classifier visualization program for Windows  Author  : Christian Borgelt  History : 28.01.2000 file created from winskel.c            30.01.2000 adapted to data files without a class column            13.04.2003 clustering result visualization added            19.03.2004 bug in command line evaluation fixed            27.04.2004 redrawing simplified with function bvn_dist            15.05.2004 changable data marker size added            24.04.2004 bug in command line evaluation fixed----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <math.h>#include <time.h>#include <assert.h>#include <windows.h>#include <commdlg.h>#include "wbcview.rh"#include "wshades.h"#include "bcload.h"/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define PRGNAME     "WBCView"   /* main window title */#ifndef PATH_MAX#define PATH_MAX    1024        /* max. len. of a path name */#endif#define	M_PI        3.14159265358979323846  /* \pi *//* --- abbreviations --- */#define HINST       HINSTANCE#define MKIRSC      MAKEINTRESOURCE#define SDIMSG      SendDlgItemMessage#define WINSTYLE    WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN/* --- extensions --- */#define MINXEXT     160         /* minimal x-extension of window */#define MINYEXT     120         /* minimal y-extension of window */#define INITXEXT    320         /* initial horizontal extension */#define INITYEXT    320         /* initial vertical   extension *//* --- edit box functions --- */#define edt_set(h,i,s)    SetDlgItemText(h, i, s)#define edt_get(h,i,s,n)  GetDlgItemText(h, i, s, n)#define int_set(h,i,n)    SetDlgItemInt(h, i, n, 0)#define int_get(h,i)      GetDlgItemInt(h, i, NULL, 0)/* --- check box functions --- */#define chk_set(h,i,s)    CheckDlgButton(h, i, s)#define chk_get(h,i)      IsDlgButtonChecked(h, i)/* --- combo box functions --- */#define cmb_add(h,i,s)    SDIMSG(h, i, CB_ADDSTRING,    0, (LPARAM)(s))#define cmb_rem(h,i,k)    SDIMSG(h, i, CB_DELETESTRING, k, 0)#define cmb_set(h,i,k)    SDIMSG(h, i, CB_SETCURSEL,    k, 0)#define cmb_get(h,i)      SDIMSG(h, i, CB_GETCURSEL,    0, 0)/* --- data formats --- */#define FR_ATTS        0        /* attribute names in first record */#define FR_DATA        1        /* data tuple in first record */#define FR_COMMENT     2        /* comment in first record *//* --- marker flags --- */#define MRK_DATA    0x01        /* mark data points */#define MRK_COLOR   0x02        /* use color on colored shades */#define MRK_CENTER  0x10        /* mark centers of distributions */#define MRK_ELL1S   0x20        /* draw 1 sigma ellipses */#define MRK_ELL2S   0x40        /* draw 2 sigma ellipses */#define MRK_ELL3S   0x80        /* draw 3 sigma ellipses *//* --- distribution types --- */#define DT_PROB        0        /* probabilistic */#define DT_FUZZY       1        /* fuzzy (probabilistic) */#define DT_POSS        2        /* fuzzy (possibilistic) *//* --- error codes --- */#define OK             0        /* no error */#define E_NONE         0        /* no error */#define E_NOMEM      (-1)       /* not enough memory */#define E_FOPEN      (-2)       /* cannot open file */#define E_FREAD      (-3)       /* read error on file */#define E_FWRITE     (-4)       /* write error on file */#define E_COLOR      (-9)       /* cannot allocate colors */#define E_UNKNOWN   (-21)       /* unkown error *//*----------------------------------------------------------------------  Constants----------------------------------------------------------------------*//* --- error messages --- */static const char *errmsgs[] ={ /* error message texts */  /* E_NONE      0 */  "no error",  /* E_NOMEM    -1 */  "not enough memory",  /* E_FOPEN    -2 */  "cannot open file:\n%s",  /* E_FREAD    -3 */  "read error on file:\n%s",  /* E_FWRITE   -4 */  "write error on file:\n%s",  /* E_PARSE    -5 */  "parse error on file:\n%s",  /* E_CREATE   -6 */  "cannot create classifier",  /* E_ATTCNT   -7 */  "no numeric attribute",  /* E_DATA     -8 */  "a classifier must be loaded first",  /* E_COLOR    -9 */  "cannot allocate colors",  /*    -11 to -15 */  NULL, NULL, NULL, NULL, NULL,  /* E_VALUE   -16 */  "file %s, record %d:\n"                         "illegal value %s in field %d",  /* E_FLDCNT  -17 */  "file %s, record %d:\n"                         "%s%d field(s) instead of %d",  /* E_EMPFLD  -18 */  "file %s, record %d:\n"                         "empty name%s in field %d",  /* E_DUPFLD  -19 */  "file %s, record %d:\n"                         "duplicate field name %s",  /* E_MISFLD  -20 */  "file %s, record %d:\n"                         "missing field %s",  /* E_UNKNOWN -21 */  "unknown error" };/*----------------------------------------------------------------------  Global Variables----------------------------------------------------------------------*/static HINST   hinst    = NULL; /* program instance handle */static HWND    hmain    = NULL; /* handle of main window */static char    buf[PATH_MAX +1024];  /* buffer for various purposes *//* --- color and marker information --- */static SHADES  *shades  = NULL; /* color shades for normal dists. */static SHADES  *datcols = NULL; /* colors for data points */static HBRUSH  *brushes = NULL; /* colored brushes for data points */static HBRUSH  br_grey  = NULL; /* grey default brush */static PIXEL   grey     = RGB(128, 128, 128);static HPEN    p_white  = NULL; /* white default pen */static HPEN    p_black  = NULL; /* black default pen */static int     mrkflgs  = 0x73; /* flags for markers */static int     mrksize  = 5;    /* size of data markers */static struct {                 /* --- color information --- */  int    dist;                  /* distribution type */  int    shdbase;               /* shade base */  int    shdcnt;                /* number of shades */  int    colcnt;                /* number of colors */  double coloff;                /* color offset (in degrees) */  double ndwgt;                 /* weight of distribution */  double cowgt;                 /* complement of this weight */} colinfo = { DT_PROB, SHD_WHITE, 32, 1, 0.0, 0.8, 0.2 };/*----------------------------------------------------------------------  Color Functions----------------------------------------------------------------------*/static void col_delete (void){                               /* --- delete color shades */  int i;                        /* loop variable */  if (datcols) { shd_delete(datcols); datcols = NULL; }  if (shades)  { shd_delete(shades);  shades  = NULL; }  if (brushes) {    for (i = colinfo.colcnt; --i >= 0; )      DeleteObject(brushes[i]);    free(brushes); brushes = NULL;  }                             /* delete all shades/colors */}  /* col_delete() *//*--------------------------------------------------------------------*/static int col_create (void){                               /* --- create color shades */  int clscnt;                   /* number of classes/clusters */  if (!attset) return 0;        /* check for an existing classifier */  col_delete();                 /* delete existing shades/colors */  if      (nbc) clscnt = nbc_clscnt(nbc);  else if (fbc) clscnt = fbc_clscnt(fbc);  else          clscnt = cls_clscnt(clset);  if (colinfo.colcnt > 0)       /* get the number of classes/clusters */    colinfo.colcnt = clscnt;    /* and note the number of colors */  shades = shd_create(colinfo.coloff,  colinfo.colcnt,                      colinfo.shdbase, colinfo.shdcnt);  if (!shades) return -1;       /* create color shades for distribs. */  datcols = shd_create(colinfo.coloff, clscnt, SHD_BLACK, 1);  if (!datcols) { col_delete(); return -1; }  brushes = (HBRUSH*)malloc(clscnt *sizeof(HBRUSH));  if (!brushes) { col_delete(); return -1; }  while (--clscnt >= 0)         /* get colors for data points */    brushes[clscnt] = CreateSolidBrush(shd_pixel(datcols, clscnt, 0));  return 0;                     /* return 'ok' */}  /* col_create() *//*----------------------------------------------------------------------  Error Reporting Function----------------------------------------------------------------------*/static void error (int code, ...){                               /* --- print error message */  va_list    args;              /* list of variable arguments */  const char *msg;              /* error message */  int        n;                 /* length of the formatted message */  if ((code > 0) || (code < E_UNKNOWN))    code = E_UNKNOWN;           /* check error code */  msg = errmsgs[-code];         /* get error message data */  if (!msg) msg = errmsgs[-E_UNKNOWN];  va_start(args, code);         /* get list of variable arguments */  vsprintf(buf, msg, args);     /* get and format message */  va_end(args);                 /* end variable argument evaluation */  n = strlen(buf) +1;           /* load alert box title */  LoadString(hinst, CS_ALERT, buf +n, sizeof(buf) -n);  MessageBox(hmain, buf, buf+n, MB_OK|MB_ICONERROR);}  /* error() */                /* show alert box *//*----------------------------------------------------------------------  Drawing Function----------------------------------------------------------------------*/

⌨️ 快捷键说明

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