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

📄 defns.h

📁 这是数据挖掘算法的cubist算法的具体实现.运行在dos下.
💻 H
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************//*									 *//*	Source code for use with Cubist Release 2.04			 *//*	--------------------------------------------			 *//*		   Copyright RuleQuest Research 2007			 *//*									 *//*	This code is provided "as is" without warranty of any kind,	 *//*	either express or implied.  All use is at your own risk.	 *//*									 *//*************************************************************************//*************************************************************************//*									 *//*		Definitions used by Cubist				 *//*              --------------------------				 *//*									 *//*************************************************************************/#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include <time.h>#ifdef WIN32#include <windows.h>#endif/*************************************************************************//*									 *//*		Constants, macros etc.					 *//*									 *//*************************************************************************/#define	 CUBIST#define  MAXN     50		/* max number neighbors allowing for ties */#define	 Nil	   0		/* null pointer */#define	 false	   0#define	 true	   1#define	 Width	   80		/* approx max width of output */#define  EXCLUDE   1		/* special attribute status: do not use */#define  SKIP	   2		/* do not use in models */#define  DISCRETE  4		/* ditto: collect values as data read */#define  ORDERED   8		/* ditto: ordered discrete values */#define  DATEVAL   16		/* ditto: YYYY/MM/DD or YYYY-MM-DD */#define  STIMEVAL  32		/* ditto: HH:MM:SS */#define	 TSTMPVAL  64		/* date time */#define	 UNKNOWN   1.5777218104420236e-30	/* unlikely value! */#define	 NA	   1#define	 BrDiscr   1		/* test on discrete attribute */#define	 BrThresh  2		/* threshold test on continuous attribute */#define	 BrSubset  3		/* subset test on discrete attribute */#define  Plural(n)		((n) != 1 ? "s" : "")#define  AllocZero(N,T)		(T *) Pcalloc(N, sizeof(T))#define  Alloc(N,T)		AllocZero(N,T)  /* for safety */#define  Realloc(V,N,T)		V = (T *) Prealloc(V, (N)*sizeof(T))#define	 Max(a,b)               ((a)>(b) ? a : b) #define	 Min(a,b)               ((a)<(b) ? a : b) #define	 Bit(b)			(1 << (b))#define	 In(b,s)		((s[(b) >> 3]) & Bit((b) & 07))#define	 ClearBits(n,s)		memset(s,0,n)#define	 CopyBits(n,f,t)	memcpy(t,f,n)#define	 SetBit(b,s)		(s[(b) >> 3] |= Bit((b) & 07))#define	 ForEach(v,f,l)		for(v=f ; v<=l ; ++v) #define	 StatBit(a,b)		(SpecialStatus[a]&(b))#define	 Exclude(a)		StatBit(a,EXCLUDE)#define	 Skip(a)		StatBit(a,EXCLUDE|SKIP)#define  Discrete(a)		(MaxAttVal[a] || StatBit(a,DISCRETE))#define  Continuous(a)		(! MaxAttVal[a] && ! StatBit(a,DISCRETE))#define	 Ordered(a)		StatBit(a,ORDERED)#define	 DateVal(a)		StatBit(a,DATEVAL)#define	 TimeVal(a)		StatBit(a,STIMEVAL)#define	 TStampVal(a)		StatBit(a,TSTMPVAL)#define  NotApplic(c,a)		(DVal(c,a)==NA)#define	 NotApplicVal(AV)	(AV._discr_val==NA)#define  Space(s)		(s==' ' || s=='\n' || s=='\r' || s=='\t')#define  SkipComment		while ( (c = InChar(f)) != '\n' && c != EOF )#define	 Free(x)		{free(x); x=Nil;}#define  FreeUnlessNil(p)	if((p)!=Nil) free(p)#define  CheckClose(f)		if(f) {fclose(f); f=Nil;}#define	 Before(n1,n2)		(n1->Tested < n2->Tested ||\				 n1->Tested == n2->Tested && n1->Cut < n2->Cut)#define	 NOFILE		 0#define	 BADATTNAME	 1#define	 EOFINATT	 2#define	 SINGLEATTVAL	 3#define	 BADATTVAL	 4#define	 BADNUMBER	 5#define	 DUPATTNAME	 6#define	 NOMEM		 8#define	 TOOMANYVALS	 9#define	 BADDISCRETE	10#define	 NOTARGET	11#define	 BADTARGET	12#define	 LONGNAME	13#define	 HITEOF		14#define	 MISSNAME	15#define	 BADDATE	16#define	 BADTIME	17#define	 BADTSTMP	18#define	 UNKNOWNATT	19#define	 BADDEF1	20#define	 BADDEF2	21#define	 BADDEF3	22#define	 SAMEATT	23#define	 BADDEF4	24#define	 MODELFILE	30#define	 CWTATTERR	31#define	 Of		stdout#define	 Goodbye(x)	exit(x)#define	 CharWidth(S)	((int) strlen(S))/*************************************************************************//*									 *//*		Type definitions					 *//*									 *//*************************************************************************/typedef  unsigned char	Boolean, BranchType, *Set;typedef	 char		*String;typedef  int	ItemNo;		/* data item number */typedef  int	ItemCount;	/* count of cases */typedef  int	DiscrValue,	/* discrete attribute value (0 = ?) */		Attribute;	/* attribute number, 1..MaxAtt */#ifdef USEDOUBLEtypedef	 double	ContValue;	/* continuous attribute value */#define	 PREC	14		/* precision */#elsetypedef	 float	ContValue;	/* continuous attribute value */#define	 PREC	 7		/* precision */#endif				/* Attribute values are packed into a union:				     DVal = (int) discrete value				     CVal = (float) continuous value				     SVal = (int) offset in IgnoredVals				   Missing and non-applicable values are:				     discrete:				       not applicable:	DVal = NA				       missing:		DVal = 0				     continuous:				       not applicable:	DVal = NA				       missing:		CVal = UNKNOWN  */typedef  union _attribute_value	 {	    ContValue	_cont_val;	    DiscrValue	_discr_val;	 }	 AttValue, *Description;#define  CVal(Case,Attribute)   Case[Attribute]._cont_val#define  DVal(Case,Attribute)   Case[Attribute]._discr_val#define  SVal(Case,Attribute)   Case[Attribute]._discr_val#define  Class(Case)		(*Case)._cont_val#define	 PredVal(Case)		Case[MaxAtt+1]._cont_val#define	 DRef(Case)		Case[MaxAtt+1]._cont_valtypedef  int	RuleNo;			/* rule number */typedef  struct _condrec	 {	    BranchType	NodeType;	/* test type */	    Attribute	Tested;		/* attribute tested */	    ContValue	Cut;		/* threshold (if relevant) */	    Set		Subset;		/* subset (if relevant) */	    int		TestValue;	/* specified outcome of test */	 }	 CondRec, *Condition;typedef  struct _rulerec	 {	    RuleNo	RNo;		/* rule number */	    int		MNo,		/* member number for committee models */			Size;		/* number of conditions */	    Condition	*Lhs;		/* conditions themselves */	    double	*Rhs;		/* model given by rule */	    ItemCount	Cover;		/* number of cases covered */	    float	Mean,		/* mean value of cases matching rule */			LoVal,		/* lowest value in data */			HiVal,		/* highest value in data */			LoLim,		/* lower bound on predictions */			HiLim,		/* upper bound on predictions */			EstErr;		/* estimated error */	 }	 RuleRec, *CRule;typedef  struct _oldrulerec	 {	    RuleNo	RNo;		/* rule number */	    int		Size;		/* number of conditions */	    Condition	*Lhs;		/* conditions themselves */	    double	*Rhs;		/* model given by rule */	    ItemCount	Cover;		/* number of cases covered */	    float	Mean,		/* mean value of cases matching rule */			LoVal,		/* lowest value in data */			HiVal,		/* highest value in data */			LoLim,		/* lower bound on predictions */			HiLim,		/* upper bound on predictions */			EstErr;		/* estimated error */	 }	 OldRuleRec;typedef struct _rulesetrec	 {	    RuleNo	SNRules;	/* number of rules */	    CRule	*SRule;		/* rules */	 }	 RuleSetRec, *RRuleSet;typedef	 struct _indexrec	*Index;typedef	 struct _indexrec

⌨️ 快捷键说明

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