本文整理汇总了C++中NameMap::getNumNames方法的典型用法代码示例。如果您正苦于以下问题:C++ NameMap::getNumNames方法的具体用法?C++ NameMap::getNumNames怎么用?C++ NameMap::getNumNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NameMap
的用法示例。
在下文中一共展示了NameMap::getNumNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: outputMAE
void OutputInfo::outputMAE(InputData* pData)
{
const int numExamples = pData->getNumExamples();
table& g = _gTableMap[pData];
vector<Label>::const_iterator lIt,maxlIt,truelIt;
float maxDiscriminant,mae = 0.0,mse = 0.0,tmpVal;
char maxLabel;
// Get label values: they must be convertible to float
vector<float> labelValues;
NameMap classMap = pData->getClassMap();
for (int l = 0;l < classMap.getNumNames(); ++l)
labelValues.push_back(atof(classMap.getNameFromIdx(l).c_str()));
// Building the strong learner (discriminant function)
for (int i = 0; i < numExamples; ++i){
const vector<Label>& labels = pData->getLabels(i);
maxDiscriminant = -numeric_limits<float>::max();
maxLabel = -100;
for (lIt = labels.begin(); lIt != labels.end(); ++lIt ) {
if ( g[i][lIt->idx] > maxDiscriminant ) {
maxDiscriminant = g[i][lIt->idx];
maxlIt = lIt;
}
if ( lIt->y > maxLabel ) {
maxLabel = lIt->y;
truelIt = lIt;
}
}
tmpVal = labelValues[truelIt->idx] - labelValues[maxlIt->idx];
mae += fabs(tmpVal);
mse += tmpVal * tmpVal;
}
_outStream << '\t' << mae/(float)(numExamples) << '\t' << sqrt(mse/(float)(numExamples));
}
示例2: readHeader
void ArffParser::readHeader( ifstream& in, NameMap& classMap,
vector<NameMap>& enumMaps, NameMap& attributeNameMap,
vector<RawData::eAttributeType>& attributeTypes )
{
bool isData = false;
string tmpStr;
string tmpAttrType;
locale labelsLocale = locale(locale(), new nor_utils::white_spaces("{,}"));
while ( !isData )
{
switch ( getNextTokenType(in) )
{
case TT_DATA:
isData = true;
break;
case TT_COMMENT:
getline(in, tmpStr); // ignore line
break;
case TT_RELATION:
in >> _headerFileName;
break;
case TT_ATTRIBUTE:
in >> tmpStr;
if ( nor_utils::cmp_nocase(tmpStr, "class") )
{
// It's a class!!
char firstChar = 0;
while ( isspace(firstChar = in.get()) && !in.eof() );
in.putback(firstChar);
getline(in, tmpStr);
stringstream ss(tmpStr);
ss.imbue(labelsLocale);
// read the classes
for (;;)
{
ss >> tmpStr;
if ( ss.eof() )
break;
tmpStr = nor_utils::trim(tmpStr);
if (!tmpStr.empty())
classMap.addName(tmpStr);
}
in.putback( '\n' );
}
else if ( nor_utils::cmp_nocase(tmpStr.substr(0,5), "class") )
{
classMap.addName(tmpStr.substr(5));
_hasAttributeClassForm = true;
}
else
{
NameMap enumMap;
in >> tmpAttrType;
if ( nor_utils::cmp_nocase(tmpAttrType, "numeric") ||
nor_utils::cmp_nocase(tmpAttrType, "real") ||
nor_utils::cmp_nocase(tmpAttrType, "integer") )
{
attributeNameMap.addName(tmpStr);
attributeTypes.push_back(RawData::ATTRIBUTE_NUMERIC);
}
else if ( nor_utils::cmp_nocase(tmpAttrType, "string") )
{
if (attributeNameMap.getNumNames() == 0)
_hasName = true;
else
{
cerr << "ERROR: One can specify the name of an example only as the first attribute, otherwise string types are not supported!!" << endl;
exit(1);
}
}
else
{
// enum attributeTypes
// For the time being the enumeration cannot contain spaces, we should
// correct it.
if (tmpAttrType[0] == '{')
{
attributeNameMap.addName(tmpStr);
attributeTypes.push_back(RawData::ATTRIBUTE_ENUM);
stringstream ss(tmpAttrType);
ss.imbue(labelsLocale);
for (;;)
{
ss >> tmpAttrType;
if ( ss.eof() )
break;
tmpAttrType = nor_utils::trim(tmpAttrType);
if (!tmpAttrType.empty())
enumMap.addName(tmpAttrType);
}
}
//.........这里部分代码省略.........