📄 liesamplerecognise.cpp
字号:
if(strcmp(trimstring,"*") != 0)
{
if(atof(trimstring) > atof(pStringTable[i][k]))
break; //l比下限小,不匹配,退出该循环
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');
trimstring.Remove(']');
if(strcmp(trimstring,"*") != 0)
if(atof(trimstring) <= atof(pStringTable[i][k]))
break; //比上限大,退出该循环
//应该加 continue
continue; //added by li e
}//end if
else if(strcmp(pDataType[k],"String")==0 )
{//属性类型为字符串型
if(strcmp(tempstring,pStringTable[i][k])==0)
continue;
else break;
}
/* if(tempstring[0] == '{')
{//比较是否在一个字符串组中,如果不在跳出,如果在,继续
int m = 0;
trimstring = tempstring;
trimstring.Delete(0,1);
pos = trimstring.Find(',');
while(pos != -1)
{
compstring = trimstring.Left(pos);
trimstring.Delete(0,pos+1);
if(strcmp(compstring,pStringTable[i][k]) == 0)
{
m =1;
break;
}//end if
pos = trimstring.Find(',');
}//end while
if(m == 0)
{
trimstring.Remove('}');
if(strcmp(trimstring,pStringTable[i][k]) != 0)
break;
}//end if
continue; //added by li e
}//end if
else if(tempstring[0] == '-')
continue; */
else
{//为整数浮点数的情况,如果不等,跳出。如果等,go on
if(strcmp(pDataType[k],"Integer")==0)
if(atoi(pRuleTable[j][k]) != atoi(pStringTable[i][k]))
break;
if(strcmp(pDataType[k],"Float")==0)
{
float a1=(float)atof(pRuleTable[j][k]);
float a2=(float)atof(pStringTable[i][k]);
if(a1!=a2)
break;
}
}//end else
}//end for
if(k == iAttNum) //表示全部找完,而且完全匹配
{
temp[j] = 1; //与第j个规则匹配,temp[j]赋值为1
temp1 = j; //temp赋值为j
n++; //n值加1
}//end if
}//end for(j)
if(n != 0 && bBlock) //存在匹配的规则,而且有 Blocks
{
for(j = 0;j < iBlockNum;j++)
{
for(k = 0;k < iAttNum;k++)
{
if((strcmp(pBlockTable[j][k],"-")== 0 )
|| (strcmp(pStringTable[i][k],"-")== 0 ))
continue;//封锁事实或样例属性为'-'
tempstring = pBlockTable[j][k];//tempstring为CString类
if(tempstring[0] == '[')
{
pos = tempstring.Find(',');
trimstring = tempstring.Left(pos);
trimstring.Remove('[');
if(strcmp(trimstring,"*") != 0)
{
if(atof(trimstring) > atof(pStringTable[i][k]))
break;
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');
trimstring.Remove(']');
if(strcmp(trimstring,"*") != 0)
if(atof(trimstring) <= atof(pStringTable[i][k]))
break;
}//end if
/* else if(tempstring[0] == '{')
{
int m = 0;
trimstring = tempstring;
trimstring.Delete(0,1);
pos = trimstring.Find(',');
while(pos != -1)
{
compstring = trimstring.Left(pos);
trimstring.Delete(0,pos+1);
if(strcmp(compstring,pStringTable[i][k]) == 0)
{
m =1;
break;
}//end if
pos = trimstring.Find(',');
}//end while
if(m == 0)
{
trimstring.Remove('}');
if(strcmp(trimstring,pStringTable[i][k]) != 0)
break;
}//end if
}//end if
*/
else if(strcmp(pDataType[k],"String")==0 )
{//属性类型为字符串型
if(strcmp(tempstring,pStringTable[i][k])==0)
continue;
else break;
}
else
if(atoi(pBlockTable[j][k]) != atoi(pStringTable[i][k]))
break;
}//end for
if(k == iAttNum) //如果块匹配
{//删除对应封锁规则
trimstring = pBlockTable[j][iAttNum];
trimstring.Delete(0,5);
if(temp[atoi(trimstring)] == 1)
{
temp[atoi(trimstring)] = 0;
n--;
}//end if
}//end if
}//end for(j)
}//end if(n != 0 && bBlock)
if(n == 0)
{//无规则匹配
strcpy(pRecogniseResultTable[i][0],"未识别");
strcpy(pRecogniseResultTable[i][1],"-");
if(bTest)
iDentifyNone++;//未识别数加一
continue;
}//end if
if(n == 1)
{//规则匹配数为1
for(j = 0;j < iRuleNum;j++)
{
if(temp[j] == 1)
break;
}//end for
if(bTest)
{
if(strcmp(pRuleTable[j][iAttNum],pStringTable[i][iAttNum]) == 0)
iDentifyRight++;//决策相等时,决策正确数加一
else
iDentifyError++;//决策不等时,决策错误数加一
}
strcpy(pRecogniseResultTable[i][0],pRuleTable[j][iAttNum]);//统计识别值
_itoa(temp1+1,pRecogniseResultTable[i][1],10);
//在pRecogniseResultTable[i][1]中以十进制字符串形式存储temp1+1,即规则序号
continue;
}//end if
//以下处理有多条规则匹配时
temp1 = -1;
bcollision=false;
if(bTest)
for(j = 0;j < iRuleNum;j++)
{
for(int j1 = 0;j1 < iRuleNum;j1++)
if(j1!=j && temp[j1]==1 && temp[j]==1)
if(atoi(pRuleTable[j][iAttNum])!=atoi(pRuleTable[j1][iAttNum]))
{//决策不等,冲突
bcollision=true;
break;
}
if(bcollision)
{
iTestConflict++;//冲突数目加一
break;
}
}
for(j = 0;j < iRuleNum;j++)
{//少数优先策略
if(temp[j] == 1)
{
if(temp1 == -1)
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);//信任度
coveragenum = atoi(pRuleTable[j][iAttNum+2]);//覆盖度
totalnum = atoi(pRuleTable[j][iAttNum+3]);//整个样例
strcpy(d,pRuleTable[j][iAttNum]);//决策
}//end if
else
if(atof(d)==atof(pRuleTable[j][iAttNum])) //一致规则
{//一致的就选择可信度最大的
if(reliability< (float)atof(pRuleTable[j][iAttNum+1]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}
else
{
if(reliability == (float)atof(pRuleTable[j][iAttNum+1]))
{//可信度相同时选择频度小的那条规则
if(totalnum > atoi(pRuleTable[j][iAttNum+3]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
else
{
if(totalnum == atoi(pRuleTable[j][iAttNum+3]))
{
if(reliability < (float)atof(pRuleTable[j][iAttNum+1]))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
else
{
if(totalnum > atoi(pRuleTable[j][iAttNum+3]))
{
if(reliability < (float)atof(pRuleTable[j][iAttNum+1]))
{//j出现的频率小而可信度高,则选j
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
else
{//出现频度大的规则可信度高.选a/b*b大的
if(coveragenum/(float)(totalnum*totalnum) <
atoi(pRuleTable[j][iAttNum+2])/(float)(atoi(pRuleTable[j][iAttNum+3])*atoi(pRuleTable[j][iAttNum+3])))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end else
}//end if
else
{
if(reliability < (float)atof(pRuleTable[j][iAttNum+1]))
{
if(coveragenum/(float)(totalnum*totalnum) <
atoi(pRuleTable[j][iAttNum+2])/(float)(atoi(pRuleTable[j][iAttNum+3])*atoi(pRuleTable[j][iAttNum+3])))
{
temp1 = j;
reliability = (float)atof(pRuleTable[j][iAttNum+1]);
coveragenum = atoi(pRuleTable[j][iAttNum+2]);
totalnum = atoi(pRuleTable[j][iAttNum+3]);
strcpy(d,pRuleTable[j][iAttNum]);
}//end if
}//end if
}//end else
}//end else
}//end else
}//end else
}//end if
}//end for//少数优先策略
if(bTest)
{
if(strcmp(d,pStringTable[i][iAttNum]) == 0)//i测试样例决策和规则的决策相等?
{
if(bcollision)
iTestRight++;//测试正确数加一
iDentifyRight++;//正确识别数加一
}//end if
else
{
if(bcollision)
iTestError++;//错误测试数目加一
iDentifyError++;//错误识别数目加一
}//end else
}
strcpy(pRecogniseResultTable[i][0],d);//识别值
_itoa(temp1+1,pRecogniseResultTable[i][1],10);//识别该样例的规则序号
}//end for
delete[] temp;
delete[] d;
}
void CLieSampleRecognise::SampleRecogniseMany()
{//多数优先策略
TRACE("sample recognise few\n");
int i,j,k;
int* temp;
int temp1 = -1;
float reliability; //reliability
int totalnum;
int coveragenum; //覆盖数
int n = 0;
int pos;
char* d;
try
{
pRecogniseResultTable = new char**[iTestNum]; //result table
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory11!",MB_OK|MB_ICONSTOP);
e->Delete();
return;
}
for(i = 0;i < iTestNum;i++)
pRecogniseResultTable[i] = new char*[2];//识别结果
for(i = 0;i < iTestNum;i++)
{
try
{
pRecogniseResultTable[i][0] = new char[MAX];
pRecogniseResultTable[i][1] = new char[MAX];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return;
}
}
try
{
d = new char[MAX];
temp = new int[iRuleNum];
}
catch(CMemoryException* e)
{
::MessageBeep(MB_ICONHAND);
AfxMessageBox("Out of memory!",MB_OK|MB_ICONSTOP);
e->Delete();
return;
}
CString tempstring;
CString trimstring;
CString compstring;
for(i = 0;i < iTestNum;i++)
{//对每个测试样本
n = 0;
bool bcollision=false;
for(j = 0;j < iRuleNum;j++)
temp[j] = 0; //initialize temp[] to zero
for(j = 0;j < iRuleNum;j++)
{//遍历每条规则,找出匹配规则
//------added by li e ,2001.6.27---------------
if ( IsRuleAttAllNull(j) )
{
/* if( IsTestAttAllNull(i) )
{
for(int xxx=0;xxx<j;xxx++)
temp[xxx]=0;
temp[j]=1;
temp1=j;
n=1;
// 此处continue已经没有意义
//因为规则集中已经不再有全为空的情况.
//而其余的规则肯定和该测试(识别)数据不匹配
}
break;
*/
temp[j]=1;//特殊,对规则全为遗失属性值的情况
temp1=j;
n++;
continue;
}
/// end li e 2001.6.27------------
for(k = 0;k < iAttNum;k++)
{//每个条件属性
if(strcmp(pRuleTable[j][k],"-") == 0
|| strcmp(pStringTable[i][k],"-") == 0)
continue;//规则为‘-且长度为1,继续该循环
tempstring = pRuleTable[j][k];//不为空的情况
if(tempstring[0] == '[' && strcmp(pDataType[k],"String")!=0 )//为连续区间
{//比较范围情况[XXX,XXX),如果在这个范围,go on,否则跳出
pos = tempstring.Find(',');
trimstring = tempstring.Left(pos);
trimstring.Remove('[');
if(strcmp(trimstring,"*") != 0)
{
if(atof(trimstring) > atof(pStringTable[i][k]))
break; //l比下限小,不匹配,退出该循环
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');
trimstring.Remove(']');
if(strcmp(trimstring,"*") != 0)
if(atof(trimstring) <= atof(pStringTable[i][k]))
break; //比上限大,退出该循环
//应该加 continue
continue; //added by li e
}//end if
else if(strcmp(pDataType[k],"String")==0 )
{//属性类型为字符串型
if(strcmp(tempstring,pStringTable[i][k])==0)
continue;
else break;
}
/* if(tempstring[0] == '{')
{//比较是否在一个字符串组中,如果不在跳出,如果在,继续
int m = 0;
trimstring = tempstring;
trimstring.Delete(0,1);
pos = trimstring.Find(',');
while(pos != -1)
{
compstring = trimstring.Left(pos);
trimstring.Delete(0,pos+1);
if(strcmp(compstring,pStringTable[i][k]) == 0)
{
m =1;
break;
}//end if
pos = trimstring.Find(',');
}//end while
if(m == 0)
{
trimstring.Remove('}');
if(strcmp(trimstring,pStringTable[i][k]) != 0)
break;
}//end if
continue; //added by li e
}//end if
else if(tempstring[0] == '-')
continue; */
else
{//为整数浮点数的情况,如果不等,跳出。如果等,go on
if(strcmp(pDataType[k],"Integer")==0)
if(atoi(pRuleTable[j][k]) != atoi(pStringTable[i][k]))
break;
if(strcmp(pDataType[k],"Float")==0)
{
float a1=(float)atof(pRuleTable[j][k]);
float a2=(float)atof(pStringTable[i][k]);
if(a1!=a2)
break;
}
}//end else
}//end for
if(k == iAttNum) //表示全部找完,而且完全匹配
{
temp[j] = 1; //与第j个规则匹配,temp[j]赋值为1
temp1 = j; //temp赋值为j
n++; //n值加1
}//end if
}//end for(j)
if(n != 0 && bBlock) //存在匹配的规则,而且有 Blocks
{
for(j = 0;j < iBlockNum;j++)
{
for(k = 0;k < iAttNum;k++)
{
if((strcmp(pBlockTable[j][k],"-")== 0 )
|| (strcmp(pStringTable[i][k],"-")== 0 ))
continue;//封锁事实或样例属性为'-'
tempstring = pBlockTable[j][k];//tempstring为CString类
if(tempstring[0] == '[')
{
pos = tempstring.Find(',');
trimstring = tempstring.Left(pos);
trimstring.Remove('[');
if(strcmp(trimstring,"*") != 0)
{
if(atof(trimstring) > atof(pStringTable[i][k]))
break;
}//end if
trimstring = tempstring;
trimstring.Delete(0,pos+1);
trimstring.Remove(')');
trimstring.Remove(']');
if(strcmp(trimstring,"*") != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -