本文整理汇总了C++中hash_set::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_set::empty方法的具体用法?C++ hash_set::empty怎么用?C++ hash_set::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_set
的用法示例。
在下文中一共展示了hash_set::empty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkgradRowSparse
void LinearSNNClassifier::checkgradRowSparse(const vector<Example>& examples, mat& Wd, const mat& gradWd, const string& mark, int iter,
const hash_set<int>& sparseRowIndexes, const mat& ft) {
//Random randWdRowcheck = new Random(iter + "Row".hashCode() + hash));
int charseed = mark.length();
for (int i = 0; i < mark.length(); i++) {
charseed = (int) (mark[i]) * 5 + charseed;
}
srand(iter + charseed);
std::vector<int> idRows, idCols;
idRows.clear();
idCols.clear();
if (sparseRowIndexes.empty()) {
for (int i = 0; i < Wd.n_rows; ++i)
idRows.push_back(i);
} else {
hash_set<int>::iterator it;
for (it = sparseRowIndexes.begin(); it != sparseRowIndexes.end(); ++it)
idRows.push_back(*it);
}
for (int idx = 0; idx < Wd.n_cols; idx++)
idCols.push_back(idx);
random_shuffle(idRows.begin(), idRows.end());
random_shuffle(idCols.begin(), idCols.end());
int check_i = idRows[0], check_j = idCols[0];
double orginValue = Wd(check_i, check_j);
Wd(check_i, check_j) = orginValue + 0.001;
double lossAdd = 0.0;
for (int i = 0; i < examples.size(); i++) {
Example oneExam = examples[i];
lossAdd += computeScore(oneExam);
}
Wd(check_i, check_j) = orginValue - 0.001;
double lossPlus = 0.0;
for (int i = 0; i < examples.size(); i++) {
Example oneExam = examples[i];
lossPlus += computeScore(oneExam);
}
double mockGrad = (lossAdd - lossPlus) / (0.002 * ft(check_i, check_j));
mockGrad = mockGrad / examples.size();
double computeGrad = gradWd(check_i, check_j);
printf("Iteration %d, Checking gradient for %s[%d][%d]:\t", iter, mark.c_str(), check_i, check_j);
printf("mock grad = %.18f, computed grad = %.18f\n", mockGrad, computeGrad);
Wd(check_i, check_j) = orginValue;
}