?? cluster.h
字號:
/*---------------------------------------------------------------------- File : cluster.h Contents: cluster and cluster set management Author : Christian Borgelt History : 2001.08.17 file created 2001.09.05 cluster size added 2001.09.11 functions cls_reg added 2001.11.08 functions cls_center, cls_covmat etc. added 2002.08.07 parsing function completed 2003.01.30 data normalization variables added 2003.03.11 weight parameter added to function cls_reg 2003.05.15 functions combined into function cls_factors 2003.05.15 membership normalization modes added 2003.05.18 cls_norm made a real function, cls_isovar added 2003.06.08 parameter radius added to function cls_type 2003.08.11 adapted to new module attmap 2003.08.12 adapted to new module nstats 2003.08.15 adapted to new module radfn 2004.02.27 function cls_deletex added 2004.02.28 size and shape regularization added 2004.03.18 normalization parameters added 2004.04.23 field CLUSTER.det removed (var is sufficient) 2004.07.13 definition of CLS_UNIT added 2004.07.28 parameter 'conly' added to function cls_update 2004.08.12 adapted to new module parse 2004.08.18 backpropagation functions added 2007.01.10 use of attribute maps changed 2007.11.26 noise cluster configured with separate function 2008.02.29 redesign for feature weighting completed----------------------------------------------------------------------*/#ifndef __CLUSTER__#define __CLUSTER__#include <stdio.h>#include "matrix.h"#include "radfn.h"#ifdef CLS_PARSE#ifndef NST_PARSE#define NST_PARSE#endif#endif#include "nstats.h"#ifdef CLS_EXTFN#include "attmap.h"#endif/*---------------------------------------------------------------------- Preprocessor Definitions----------------------------------------------------------------------*//* --- prototype flags --- */#define CLS_CENTER 0x00 /* use cluster center (mandatory) */#define CLS_SIZE 0x01 /* use cluster size */#define CLS_VARS 0x02 /* use variances (independent dims.) */#define CLS_COVARS 0x04 /* use covariance matrix */#define CLS_JOINT 0x08 /* use joint (co)variances */#define CLS_WEIGHT 0x10 /* use relative cluster weight */#define CLS_NORM 0x20 /* normalize membership function */#define CLS_ALL 0x3f /* all prototype flags *//* --- initialization modes --- *//* CLS_CENTER 0 *//* center of the data space */#define CLS_UNIFORM 1 /* samples from uniform distribution */#define CLS_DIAG 2 /* diagonal of data space */#define CLS_LATIN 3 /* latin hypercube sampling */#define CLS_POINTS 4 /* given points in data space */#define CLS_MODE 0x0f /* mask for initialization method *//* --- normalization modes --- */#define CLS_NONE 0 /* no normalization */#define CLS_SUM1 1 /* normalize to sum 1 */#define CLS_MAX1 2 /* normalize to maximum 1 */#define CLS_HARD 3 /* hard assignment (winner takes all) *//* --- update methods --- */#define CLS_GRADIENT 0 /* gradient descent/ascent */#define CLS_ALTOPT 1 /* alternating optimization */#define CLS_COMPLRN 2 /* competitive learning */#define CLS_BACKPROP 3 /* error backpropagation */#define CLS_METHOD 0x0f /* mask for update method *//* --- update modifiers --- */#define CLS_EXPAND 0x10 /* expand change by a factor */#define CLS_MOMENTUM 0x20 /* update with momentum term */#define CLS_ADAPTIVE 0x30 /* self-adaptive change factor */#define CLS_RESILIENT 0x40 /* resilient update */#define CLS_QUICK 0x50 /* quickprop analog */#define CLS_MODIFIER 0xf0 /* mask for update modifier *//* --- extended update modifiers --- */#define CLS_UNIT 0x100 /* unit length center vectors */#define CLS_ORIGIN 0x200 /* fix center vectors at origin */#define CLS_MODVAR 0x400 /* use modifier also for (co)vars. */#define CLS_EXTMOD 0xf00 /* mask for extended update modifier *//* --- validity measures --- */#define CLS_OBJFN 0 /* objective function */#define CLS_COVERAGE 1 /* coverage of data points */#define CLS_FDBIDX 2 /* fuzzy Davies-Bouldin index */#define CLS_PCOEFF 3 /* partition coefficient */#define CLS_PCNORM 4 /* normalized partition coefficient */#define CLS_PENTROPY 5 /* partition entropy */#define CLS_FHYPVOL 6 /* fuzzy hyper-volume */#define CLS_PRPEXP 7 /* proportion exponent */#define CLS_XBISEP 8 /* Xie-Beni index / separation */#define CLS_PARTDENS 9 /* partition density */#define CLS_PDAVG 10 /* average partition density */#define CLS_NOISE 11 /* membership sum to noise cluster */#define CLS_VMCNT 12 /* number of validity measures *//* --- description modes --- */#define CLS_TITLE 0x0001 /* print a title (as a comment) */#define CLS_RBFNET 0x0002 /* describe as part of RBF network *//*---------------------------------------------------------------------- Type Definitions----------------------------------------------------------------------*/typedef struct { /* --- a cluster --- */ double *ctr; /* cluster center */ MATRIX *cov; /* covariance matrix */ double *dif; /* difference vector to center */ MATRIX *inv; /* inverse covariance matrix */ double *sum; /* weighted sum of data vectors */ MATRIX *smp; /* weighted sum of matrix products */ double *chc; /* change of center coordinates */ MATRIX *chv; /* change of (co)variances */ double *grc; /* gradient of center coordinates */ MATRIX *grv; /* gradient of (co)variances */ double *buf; /* buffer for computations */ MATRIX *mat; /* ditto */ int ok; /* whether update will be ok */ int dec; /* flag for computed decomposition */ double var; /* equivalent isotropic variance */ double size; /* size (usually equal to var) */ double scale; /* scaling factor for update */ double d2; /* squared distance of data point */ double msd; /* degree of membership of data point */ double val[4]; /* validity measure terms */} CLUSTER; /* (cluster) */typedef struct { /* --- cluster evaluation data --- */ int flags; /* flags for configured measures */ double rad; /* radius for partition density */ double cnt; /* number of processed patterns */ double sum; /* sum of membership degrees */ double sqr; /* sum of squared membership degrees */ double ent; /* entropy sum of membership degrees */ double pxp; /* proportion exponent */ double noise; /* membership sum to noise cluster */} CLSEVAL; /* (cluster evaluation data) */typedef struct { /* --- a set of clusters --- */ int type; /* type of cluster prototypes */ int tnew; /* new cluster type (before setup) */ int incnt; /* number of input attributes */ int clscnt; /* number of clusters */ int init; /* number of initialized clusters */ CLUSTER *cls; /* vector of clusters */ RADFN *radfn; /* radial function (Cauchy or Gauss) */ DERIVFN *drvfn; /* derivative of radial function */ double rfnps[2]; /* parameters of the radial function */ double unit; /* norm. factor for unit integral */ double noise; /* noise cluster parameter */ double ncmsd[2]; /* membership degree to noise cluster */ int norm; /* membership normalization mode */ double nrmps[2]; /* membership normalization params. */ double fwexp; /* feature weight exponent */ double msexp; /* membership exponent for adaptation */ int setup; /* flag for completed setup */ int method; /* parameter update method + modifier */ int eigen; /* flag for eigenvalue decomposition */ int bkprop; /* flag for backpropagation */ double rates[3]; /* learning rates */ double decay[3]; /* learning rate decay parameters */ double moment; /* momentum term */ double growth; /* growth factor */ double shrink; /* shrinkage factor */ double maxfac; /* maximal factor (quick backprop) */ double minchg; /* minimal change/learning rate */ double maxchg; /* maximal change/learning rate */ double regps[5]; /* regularization parameters */ int steps; /* number of update steps */ int resized; /* flag for resized clusters */ NSTATS *nst; /* normalization statistics */ double *vec; /* buffer for a data vector */ double *buf; /* buffer (e.g. for eigenvalues) */ MATRIX *mat; /* buffer for matrix computations */ CLSEVAL eval; /* cluster evaluation data */ #ifdef CLS_EXTFN ATTSET *attset; /* underlying attribute set */ ATTMAP *attmap; /* attribute map for numeric coding */ #endif} CLSET; /* (cluster set) *//*---------------------------------------------------------------------- Functions----------------------------------------------------------------------*/extern CLSET* cls_create (int incnt, int clscnt);extern void cls_delete (CLSET *clset);#ifdef CLS_EXTFNextern CLSET* cls_createx (ATTMAP *attmap, int clscnt);extern void cls_deletex (CLSET *clset, int delas);extern ATTSET* cls_attset (CLSET *clset);extern ATTMAP* cls_attmap (CLSET *clset);#endifextern int cls_incnt (CLSET *clset);extern int cls_clscnt (CLSET *clset);extern NSTATS* cls_nstats (CLSET *clset);extern void cls_reg (CLSET *clset, const double *vec, double weight);extern void cls_value (CLSET *clset, int index, double value);#ifdef CLS_EXTFNextern void cls_regx (CLSET *clset, const TUPLE *tpl);extern void cls_valuex (CLSET *clset, const TUPLE *tpl);#endifextern void cls_type (CLSET *clset, int type, double size);extern void cls_radfn (CLSET *clset, RADFN radfn, DERIVFN drvfn, const double *params);extern void cls_fwexp (CLSET *clset, double fwexp);extern void cls_noise (CLSET *clset, double noise);extern void cls_norm (CLSET *clset, int mode, const double *params);extern void cls_init (CLSET *clset, int mode, double range, double randfn(void), const double *vec);extern void cls_method (CLSET *clset, int method);extern void cls_msexp (CLSET *clset, double msexp);extern void cls_moment (CLSET *clset, double moment);extern void cls_factors (CLSET *clset, double growth, double shrink);extern void cls_limits (CLSET *clset, double minchg, double maxchg);extern void cls_reset (CLSET *clset);extern void cls_lrate (CLSET *clset, const double *rates, const double *decay);extern void cls_regular (CLSET *clset, const double *params);extern int cls_setup (CLSET *clset);extern int cls_exec (CLSET *clset, const double *vec, double *msdegs);extern int cls_aggr (CLSET *clset, const double *vec, double weight);extern void cls_bkprop (CLSET *clset, const double *errs);extern double cls_update (CLSET *clset, int conly);extern void cls_sort (CLSET *clset);extern double* cls_center (CLSET *clset, int cid);extern MATRIX* cls_covmat (CLSET *clset, int cid);extern MATRIX* cls_invmat (CLSET *clset, int cid);extern double cls_isovar (CLSET *clset, int cid);extern double cls_weight (CLSET *clset, int cid);extern double cls_msdeg (CLSET *clset, int cid);extern void cls_evcfg (CLSET *clset, int measure, double param);extern void cls_evaggr (CLSET *clset, const double *vec, double weight);extern double cls_eval (CLSET *clset, int measure);extern void cls_sclcov (CLSET *clset);extern void cls_unscale (CLSET *clset);extern int cls_desc (CLSET *clset, FILE *file, int mode, int maxlen);#ifdef CLS_PARSEextern CLSET* cls_parse (SCAN *scan);#ifdef CLS_EXTFNextern CLSET* cls_parsex (SCAN *scan, ATTMAP *attmap, int hdr);#endif#endif/*---------------------------------------------------------------------- Preprocessor Definitions----------------------------------------------------------------------*/#ifdef CLS_EXTFN#define cls_attset(s) ((s)->attset)#define cls_attmap(s) ((s)->attmap)#endif#define cls_incnt(s) ((s)->incnt)#define cls_clscnt(s) ((s)->clscnt)#define cls_nstats(s) ((s)->nst)#define cls_noise(s,n) ((s)->noise = (n))#define cls_fwexp(s,e) ((s)->fwexp = (e))#define cls_moment(s,m) ((s)->moment = (m))#define cls_reset(s) ((s)->steps = 0)#define cls_center(s,i) ((s)->cls[i].ctr)#define cls_covmat(s,i) ((s)->cls[i].cov)#define cls_invmat(s,i) ((s)->cls[i].inv)#define cls_isovar(s,i) ((s)->cls[i].var)#define cls_size(s,i) ((s)->cls[i].size)#define cls_scale(s,i) ((s)->cls[i].scale)#define cls_weight(s,i) mat_getwgt((s)->cls[i].cov)#define cls_msdeg(s,i) ((s)->cls[i].msd)#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -