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

📄 lvq.h

📁 LVQ - Learning Vector Quantization Demonstration Download xlvq Linux executable (128 kb) wlvq.ex
💻 H
字号:
/*----------------------------------------------------------------------  File    : lvq.h  Contents: learning vector quantization with some extensions  Author  : Christian Borgelt  History : 17.02.2003 file created from file cluster.h            11.03.2003 weight parameter added to function lvq_reg            15.03.2003 organization of quantization prototypes changed            15.05.2003 activation normalization modes added            07.06.2003 function lvq_scale added            08.06.2003 parameter radius added to function lvq_type            11.08.2003 adapted to new module attmap            12.08.2003 adapted to new module nstats            15.08.2003 adapted to new module radfn----------------------------------------------------------------------*/#ifndef __LVQ__#define __LVQ__#include <stdio.h>#ifdef LVQ_PARSE#ifndef NST_PARSE#define NST_PARSE#endif#endif#include "matrix.h"#include "nstats.h"#include "radfn.h"#ifdef LVQ_EXTFN#include "attmap.h"#endif/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*//* --- prototype flags --- */#define LVQ_CENTER     0x00     /* use prototype center (mandatory) */#define LVQ_SIZE       0x01     /* use prototype size (radius) *//* --- initialization modes --- *//*      LVQ_CENTER        0        center of the data space */#define LVQ_UNIFORM       1     /* samples from uniform distribution */#define LVQ_DIAG          2     /* diagonal of data space */#define LVQ_LATIN         3     /* latin hypercube sampling */#define LVQ_POINTS        4     /* given points in data space *//* --- normalization modes --- */#define LVQ_NONE          0     /* no normalization */#define LVQ_SUM1          1     /* normalize to sum 1 */#define LVQ_MAX1          2     /* normalize to maximum 1 */#define LVQ_HARD          3     /* hard assignment/winner takes all *//* --- update methods --- */#define LVQ_DIST          0     /* average distance to center */#define LVQ_SQUARE        1     /* average squared distance */#define LVQ_VAR           2     /* isotropic variance */#define LVQ_WEIGHT        3     /* weight of assigned patterns */#define LVQ_REPLACE  0x8000     /* replace old radius with new *//* --- description modes --- */#define LVQ_TITLE    0x0001     /* print a title (as a comment) *//*----------------------------------------------------------------------  Type Definitions----------------------------------------------------------------------*/typedef struct {                /* --- quantization prototype --- */  double *ctr;                  /* center (reference vector) */  double *dif;                  /* difference vector to center */  double *chg;                  /* change of center coordinates */  double var;                   /* variance (squared radius) */  double wgt;                   /* (relative) prototype weight */  double d2;                    /* squared distance of pattern */  double act;                   /* neuron activation */  double sqr;                   /* weighted sum of squared distances */  double sum;                   /* weighted sum of distances */  double spw;                   /* sum of (assigned) pattern weights */  double buf;                   /* buffer for variance/radius update */} QPROT;                        /* (quantization prototype) */typedef struct {                /* --- LVQ network --- */  int    dim;                   /* number of dimensions */  int    cnt;                   /* number of neurons */  int    init;                  /* number of initialized neurons */  int    type;                  /* current type of prototypes */  int    mode;                  /* normalization mode */  int    method;                /* parameter update method */  int    steps;                 /* number of update steps */  RADFN  *actfn;                /* activation function */  double params[3];             /* parameters of the act. function */  double wtarf;                 /* winner takes all radius factor */  double lrate;                 /* initial learning rate */  double lrcur;                 /* current learning rate */  double decay;                 /* learning rate decay parameter */  double exp;                   /* exponent for neuron activation */  double szscl;                 /* prototype size scaling factor */  double reg;                   /* sum of (regist.) pattern weights */  double spw;                   /* sum of (processed) pattern weights */  NSTATS *nst;                  /* simple numerical statistics */  double *vec;                  /* buffer for a data vector */  double *buf;                  /* buffer for init./aggregation */  QPROT  *qps;                  /* quantization prototypes */  #ifdef LVQ_EXTFN  ATTSET *attset;               /* underlying attribute set */  ATTMAP *attmap;               /* attribute map */  #endif} LVQNET;                       /* (LVQ network) *//*----------------------------------------------------------------------  Functions----------------------------------------------------------------------*/extern LVQNET* lvq_create  (int dim, int cnt);extern void    lvq_delete  (LVQNET *lvq);extern int     lvq_dim     (LVQNET *lvq);extern int     lvq_cnt     (LVQNET *lvq);#ifdef LVQ_EXTFNextern LVQNET* lvq_createx (ATTSET *attset, int marked, int cnt);extern ATTSET* lvq_attset  (LVQNET *lvq);#endifextern void    lvq_value   (LVQNET *lvq, int index, double value);extern void    lvq_reg     (LVQNET *lvq, double *vec, double weight);#ifdef LVQ_EXTFNextern void    lvq_valuex  (LVQNET *lvq, const TUPLE *tpl);extern void    lvq_regx    (LVQNET *lvq, const TUPLE *tpl);#endifextern void    lvq_range   (LVQNET *lvq, int index,                            double min, double max);extern void    lvq_expand  (LVQNET *lvq, int index, double factor);extern void    lvq_type    (LVQNET *lvq, int type, double radius);extern void    lvq_actfn   (LVQNET *lvq, RADFN actfn, double *params);extern void    lvq_norm    (LVQNET *lvq, int mode, double wtarf);extern void    lvq_init    (LVQNET *lvq, int mode, double range,                            double randfn(void), double *vec);extern void    lvq_exp     (LVQNET *lvq, double exp);extern void    lvq_scale   (LVQNET *lvq, double scale);extern void    lvq_method  (LVQNET *lvq, int method);extern void    lvq_lrate   (LVQNET *lvq, double lrate, double decay);extern int     lvq_exec    (LVQNET *lvq, double *vec, double *acts);extern int     lvq_aggr    (LVQNET *lvq, double *vec, double weight);extern double  lvq_update  (LVQNET *lvq);extern double* lvq_center  (LVQNET *lvq, int pid);extern double  lvq_var     (LVQNET *lvq, int pid);extern double  lvq_activ   (LVQNET *lvq, int pid);extern int     lvq_desc    (LVQNET *lvq, FILE *file,                            int mode, int maxlen);#ifdef LVQ_PARSEextern LVQNET* lvq_parse   (SCAN *scan, int dim);#ifdef LVQ_EXTFNextern LVQNET* lvq_parsex  (SCAN *scan, ATTSET *attset, int marked);#endif#endif/*----------------------------------------------------------------------  Preprocessor Definitions----------------------------------------------------------------------*/#define lvq_dim(n)         ((n)->dim)#define lvq_cnt(n)         ((n)->cnt)#ifdef LVQ_EXTFN#define lvq_attset(n)      ((n)->attset)#endif#define lvq_range(n,i,a,b) nst_range((n)->nst, i, a, b)#define lvq_expand(n,i,f)  nst_expand((n)->nst, i, f)#define lvq_norm(n,m,f)    ((n)->mode   = (m), (n)->wtarf = (f))#define lvq_exp(n,e)       ((n)->exp    = (e))#define lvq_scale(n,s)     ((n)->szscl  = (s))#define lvq_method(n,m)    ((n)->method = (m))#define lvq_lrate(n,r,d)   ((n)->lrcur  = fabs((n)->lrate = (r)), \                            (n)->decay  = (d))#define lvq_center(n,i)    ((n)->qps[i].ctr)#define lvq_var(n,i)       ((n)->qps[i].var)#define lvq_activ(n,i)     ((n)->qps[i].act)#endif

⌨️ 快捷键说明

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