本文整理汇总了C++中SparseVector::coeffRef方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseVector::coeffRef方法的具体用法?C++ SparseVector::coeffRef怎么用?C++ SparseVector::coeffRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseVector
的用法示例。
在下文中一共展示了SparseVector::coeffRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
// Read an event line. An event line consists of:
//
// - The event frequency/weight.
// - The number of non-zero features.
// - Feature/value pairs.
//
pair<double, SparseVector<double> > DataSet::readEvent(string const &eventLine)
{
std::vector<std::string> lineParts = stringSplit(eventLine);
if (lineParts.size() < 2)
throw runtime_error(ERR_INCORRECT_EVENT + eventLine);
double eventProb = parseString<double>(lineParts[0]);
size_t nFeatures = parseString<size_t>(lineParts[1]);
if ((nFeatures * 2) + 2 != lineParts.size())
throw runtime_error(ERR_INCORRECT_NFEATURES + eventLine);
SparseVector<double> fVals;
for (size_t i = 0; i < (2 * nFeatures); i += 2)
{
size_t fId = parseString<size_t>(lineParts[i + 2]);
double fVal = parseString<double>(lineParts[i + 3]);
fVals.coeffRef(fId) = fVal;
}
return make_pair(eventProb, fVals);
}