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

📄 attributeinfo.c

📁 C语言的朴素贝叶斯分类器代码
💻 C
字号:
#include "attributeInfo.h"AttributeInfo *AttributeInfoTable::searchInfo(Description v){	for(AttributeInfo *tmp=table[hash(v)]; tmp; tmp=tmp->next)		if(v==tmp->value) return tmp;	return NULL;}AttributeInfo *AttributeInfoTable::searchInfo(int hashVal, Description v){	for(AttributeInfo *tmp=table[hashVal]; tmp; tmp=tmp->next)		if(v==tmp->value) return tmp;	return NULL;}AttributeInfoTable::AttributeInfoTable(	SupervisedDataTable &tbl, int col, ClassInfoTable &cTbl){	n_Class = cTbl.numOfClasses();//	cTable  = &cTbl;	sTable  = &tbl;//	cSTable = new ClassSummary(cTbl);	int row = tbl.numOfInstances();	int classCol = tbl.numOfAttributes();#ifdef DBG	cout << "classCol="<<classCol<<endl;#endif	initHashTable();	n_Values = 0;	for(int r=0; r<row; r++)	{		Description currDescription = tbl.value(r, col);		int hashValue = hash(currDescription);		AttributeInfo *tmp = searchInfo(hashValue, currDescription);		if(tmp==NULL) { // not found, new distinct value			tmp = new AttributeInfo(currDescription, n_Class);			tmp->next = table[hashValue];			table[hashValue] = tmp;			n_Values++; // count the number of distinct values		}		tmp->inc(cTbl.classLabel(tbl.value(r, classCol)));	}}void AttributeInfo::print(ClassSummary &cSTbl){#ifdef DBG	cout << "==== AttributeInfo ==== >>"<< endl;#endif	cout << "P(" << value << "|Ci)";	for(int c=0; c<n_Class; c++)	{#ifdef DBG		cout << "P(" << value << "|" <<cSTbl.getDescription(c)						<< ")=";#endif		cout << "\t" << count[c] << "/" << cSTbl.getCount(c);	}	cout << endl;}void AttributeInfoTable::print(ClassSummary *cSTable){#ifdef DBG	cout << "==== AttributeInfo Table ====" << endl;#endif	for(int r=0; r<MAX_HASH_SIZE; r++)	{		if(table[r]) {#ifdef DBG			cout << "[" << r <<"] " ;#endif			for(AttributeInfo *tmp=table[r]; tmp; tmp=tmp->next)				tmp->print(*cSTable); // class summary table		}	}}void AttributeInfoTable::initHashTable(){	for(int r=0; r<MAX_HASH_SIZE; r++)		table[r] = NULL;}

⌨️ 快捷键说明

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