资源简介
数据挖掘 贝叶斯算法 C++
贝叶斯算法一般都用MATLAB实现,好不容易找到个C++的,可以用到工程中去
代码片段和文件信息
#include“GetInfo.h“
#define space(s) (s == ‘ ‘ || s == ‘\n‘ || s == ‘\t‘)
#define SkipComment while ( ( c = getc(f) ) != ‘\n‘ )
void GetInfo::getname()
{
char Buffer[1000];
char Fn[100];
int AttCeiling=100;
int ClassCeiling=100;
int ValCeiling;
filename.copy(Fnfilename.length());
Fn[filename.length()]=NULL;
strcat_s(Fn“.names“);
if ( ! ( Nf = fopen(Fn “r“) ) )
Error(0 Fn ““);
ClassName = (string *) calloc(ClassCeiling sizeof(string));
do
{
ReadName(Nf Buffer);
if ( ++MaxClassNo >= ClassCeiling)
{
ClassCeiling += 100;
ClassName = (string *) realloc(ClassName ClassCeiling*sizeof(string));
}
ClassName[MaxClassNo]=string(Buffer);
}
while ( Delimiter == ‘‘ );
/* Get attribute and attribute value names from names file */
AttName = (string *) calloc(AttCeiling sizeof(string));
MaxAttValNo = (short *) calloc(AttCeiling sizeof(short));
AttValName = (string **) calloc(AttCeiling sizeof(string *));
SpecialStatus = (char *) malloc(AttCeiling);
while ( ReadName(Nf Buffer) )
{
if ( Delimiter != ‘:‘ )
Error(1 Buffer ““);
if ( ++MaxAttNo >= AttCeiling )//扩大空间
{
AttCeiling += 100;
AttName = (string *) realloc(AttName AttCeiling*sizeof(string));
MaxAttValNo = (short *) realloc(MaxAttValNo AttCeiling*sizeof(short));
AttValName = (string **) realloc(AttValName AttCeiling*sizeof(string *));
SpecialStatus = (char *) realloc(SpecialStatus AttCeiling);
}
AttName[MaxAttNo] = string(Buffer);
SpecialStatus[MaxAttNo] = 0;
MaxAttValNo[MaxAttNo] = 0;
ValCeiling = 100;
AttValName[MaxAttNo] = (string *) calloc(ValCeiling sizeof(string));
do
{
if ( ! ( ReadName(Nf Buffer) ) )
Error(2 AttName[MaxAttNo] ““);
if ( ++MaxAttValNo[MaxAttNo] >= ValCeiling )
{
ValCeiling += 100;
AttValName[MaxAttNo] =(string *) realloc(AttValName[MaxAttNo] ValCeiling*sizeof(string));
}
AttValName[MaxAttNo][MaxAttValNo[MaxAttNo]] = string(Buffer);
}while ( Delimiter == ‘‘ );
if ( MaxAttValNo[MaxAttNo] == 1 )
{
/* Check for special treatment */
if (!strcmp(Buffer “continuous“) )
{
MaxContAttNo++;
}
else
{
/* Cannot have only one discrete value for an attribute */
Error(3 AttName[MaxAttNo] ““);
}
MaxAttValNo[MaxAttNo] = 0;
}
else if ( MaxAttValNo[MaxAttNo] > MaxDiscrValNo )
MaxDiscrValNo = MaxAttValNo[MaxAttNo];
}
fclose(Nf);
}
void GetInfo::Error(int n string s1 string s2)
/* ----- */
{
cout<<“ERROR: “;
switch(n)
{
case 0: cout<<“cannot open file “< break;
case 1: cout<<“colon expected after attribute name “< break;
case 2: cout<<“unexpected EOF while reading attribute “<< s1<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-07-07 16:09 naive Bayes\
目录 0 2014-07-07 16:09 naive Bayes\debug\
文件 81920 2009-05-22 22:28 naive Bayes\debug\naive Bayes.exe
文件 471384 2009-05-22 22:28 naive Bayes\debug\naive Bayes.ilk
文件 568320 2009-05-22 22:28 naive Bayes\debug\naive Bayes.pdb
目录 0 2014-07-07 16:09 naive Bayes\naive Bayes\
文件 1477632 2009-05-22 22:29 naive Bayes\naive Bayes.ncb
文件 898 2009-05-13 20:28 naive Bayes\naive Bayes.sln
文件 39936 2009-05-22 22:29 naive Bayes\naive Bayes.suo
文件 410 2009-05-22 22:06 naive Bayes\naive Bayes\buycom.data
文件 114 2009-05-22 22:09 naive Bayes\naive Bayes\buycom.names
文件 23 2009-05-22 21:42 naive Bayes\naive Bayes\buytest.data
目录 0 2014-07-07 16:09 naive Bayes\naive Bayes\Debug\
文件 6986 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\BuildLog.htm
文件 82303 2009-05-22 16:05 naive Bayes\naive Bayes\Debug\GetInfo.obj
文件 26312 2009-05-22 17:12 naive Bayes\naive Bayes\Debug\GetModel.obj
文件 32343 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\main.obj
文件 69 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\mt.dep
文件 403 2009-05-18 10:45 naive Bayes\naive Bayes\Debug\naive Bayes.exe.em
文件 468 2009-05-18 10:45 naive Bayes\naive Bayes\Debug\naive Bayes.exe.em
文件 385 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\naive Bayes.exe.intermediate.manifest
文件 78205 2009-05-22 22:25 naive Bayes\naive Bayes\Debug\PredictClass.obj
文件 248832 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\vc80.idb
文件 208896 2009-05-22 22:28 naive Bayes\naive Bayes\Debug\vc80.pdb
文件 13506 2009-05-22 10:27 naive Bayes\naive Bayes\GetInfo.cpp
文件 2622 2009-05-22 10:26 naive Bayes\naive Bayes\GetInfo.h
文件 1177 2009-05-22 14:28 naive Bayes\naive Bayes\GetModel.cpp
文件 401 2009-05-22 17:12 naive Bayes\naive Bayes\GetModel.h
文件 415 2009-05-22 22:06 naive Bayes\naive Bayes\golf.data
文件 118 2009-05-22 22:06 naive Bayes\naive Bayes\golf.names
文件 169 2009-05-22 20:00 naive Bayes\naive Bayes\golftest.data
............此处省略8个文件信息
- 上一篇:VC6.0 TTS
- 下一篇:网络调试工具VS2008 C++源码
评论
共有 条评论