本文整理汇总了C++中Metric::print方法的典型用法代码示例。如果您正苦于以下问题:C++ Metric::print方法的具体用法?C++ Metric::print怎么用?C++ Metric::print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Metric
的用法示例。
在下文中一共展示了Metric::print方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
//.........这里部分代码省略.........
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((curUpdateIter + 1) % m_options.verboseIter == 0) {
//m_classifier.checkgrads(subExamples, curUpdateIter+1);
std::cout << "current: " << updateIter + 1 << ", total block: " << batchBlock << std::endl;
std::cout << "Cost = " << cost << ", Tag Correct(%) = " << eval.getAccuracy() << std::endl;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
if (devNum > 0) {
bCurIterBetter = false;
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_dev.reset();
for (int idx = 0; idx < devExamples.size(); idx++) {
vector<string> result_labels;
predict(devExamples[idx].m_features, result_labels, devInsts[idx].words);
if (m_options.seg)
devInsts[idx].SegEvaluate(result_labels, metric_dev);
else
devInsts[idx].Evaluate(result_labels, metric_dev);
if (!m_options.outBest.empty()) {
curDecodeInst.copyValuesFrom(devInsts[idx]);
curDecodeInst.assignLabel(result_labels);
decodeInstResults.push_back(curDecodeInst);
}
}
metric_dev.print();
if (!m_options.outBest.empty() && metric_dev.getAccuracy() > bestDIS) {
m_pipe.outputAllInstances(devFile + m_options.outBest, decodeInstResults);
bCurIterBetter = true;
}
if (testNum > 0) {
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_test.reset();
for (int idx = 0; idx < testExamples.size(); idx++) {
vector<string> result_labels;
predict(testExamples[idx].m_features, result_labels, testInsts[idx].words);
if (m_options.seg)
testInsts[idx].SegEvaluate(result_labels, metric_test);
else
testInsts[idx].Evaluate(result_labels, metric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
curDecodeInst.copyValuesFrom(testInsts[idx]);
curDecodeInst.assignLabel(result_labels);
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl;
metric_test.print();
if (!m_options.outBest.empty() && bCurIterBetter) {
m_pipe.outputAllInstances(testFile + m_options.outBest, decodeInstResults);
}
}
示例2: train
//.........这里部分代码省略.........
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((idy + 1) % (m_options.verboseIter*10) == 0) {
std::cout << "current: " << idy + 1 << ", Cost = " << cost << ", Correct(%) = " << eval.getAccuracy() << std::endl;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps, m_options.clip);
}
std::cout << "current: " << iter + 1 << ", Correct(%) = " << eval.getAccuracy() << std::endl;
}
else{
if(iter == 0)eval.reset();
subInstances.clear();
subInstGoldActions.clear();
for (int idy = 0; idy < m_options.batchSize; idy++) {
subInstances.push_back(trainInsts[indexes[idy]].chars);
subInstGoldActions.push_back(trainInstGoldactions[indexes[idy]]);
}
double cost = m_classifier.train(subInstances, subInstGoldActions);
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((iter + 1) % (m_options.verboseIter) == 0) {
std::cout << "current: " << iter + 1 << ", Cost = " << cost << ", Correct(%) = " << eval.getAccuracy() << std::endl;
eval.reset();
bEvaluate = true;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps, m_options.clip);
}
if (bEvaluate && devNum > 0) {
bCurIterBetter = false;
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_dev.reset();
for (int idx = 0; idx < devInsts.size(); idx++) {
predict(devInsts[idx], curDecodeInst);
devInsts[idx].evaluate(curDecodeInst, metric_dev);
if (!m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "dev:" << std::endl;
metric_dev.print();
if (!m_options.outBest.empty() && metric_dev.getAccuracy() > bestFmeasure) {
m_pipe.outputAllInstances(devFile + m_options.outBest, decodeInstResults);
bCurIterBetter = true;
}
if (testNum > 0) {
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_test.reset();
for (int idx = 0; idx < testInsts.size(); idx++) {
predict(testInsts[idx], curDecodeInst);
testInsts[idx].evaluate(curDecodeInst, metric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl;
metric_test.print();
if (!m_options.outBest.empty() && bCurIterBetter) {
m_pipe.outputAllInstances(testFile + m_options.outBest, decodeInstResults);
}
}
for (int idx = 0; idx < otherInsts.size(); idx++) {
std::cout << "processing " << m_options.testFiles[idx] << std::endl;
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_test.reset();
for (int idy = 0; idy < otherInsts[idx].size(); idy++) {
predict(otherInsts[idx][idy], curDecodeInst);
otherInsts[idx][idy].evaluate(curDecodeInst, metric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl;
metric_test.print();
if (!m_options.outBest.empty() && bCurIterBetter) {
m_pipe.outputAllInstances(m_options.testFiles[idx] + m_options.outBest, decodeInstResults);
}
}
if (m_options.saveIntermediate && metric_dev.getAccuracy() > bestFmeasure) {
std::cout << "Exceeds best previous DIS of " << bestFmeasure << ". Saving model file.." << std::endl;
bestFmeasure = metric_dev.getAccuracy();
writeModelFile(modelFile);
}
}
}
}
示例3: train
//.........这里部分代码省略.........
}
else {
if (iter == 0)
eval.reset();
subInstances.clear();
subInstGoldActions.clear();
for (int idy = 0; idy < m_options.batchSize; idy++) {
subInstances.push_back(trainInsts[indexes[idy]]);
subInstGoldActions.push_back(trainInstGoldactions[indexes[idy]]);
}
double cost = m_classifier.train(subInstances, subInstGoldActions);
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
if ((iter + 1) % (m_options.verboseIter) == 0) {
std::cout << "current: " << iter + 1 << ", Cost = " << cost << ", Correct(%) = " << eval.getAccuracy() << std::endl;
eval.reset();
bEvaluate = true;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
if (bEvaluate && devNum > 0) {
bCurIterBetter = false;
if (!m_options.outBest.empty())
decodeInstResults.clear();
segMetric_dev.reset();
postagMetric_dev.reset();
for (int idx = 0; idx < devInsts.size(); idx++) {
predict(devInsts[idx], curDecodeInst);
devInsts[idx].evaluate(curDecodeInst, segMetric_dev, postagMetric_dev);
if (!m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "dev:" << std::endl << "Seg: ";
segMetric_dev.print();
std::cout << "Postag: ";
postagMetric_dev.print();
if (!m_options.outBest.empty() && postagMetric_dev.getAccuracy() > bestPostagFmeasure) {
m_pipe.outputAllInstances(devFile + m_options.outBest, decodeInstResults);
bCurIterBetter = true;
}
if (testNum > 0) {
if (!m_options.outBest.empty())
decodeInstResults.clear();
segMetric_test.reset();
postagMetric_test.reset();
for (int idx = 0; idx < testInsts.size(); idx++) {
predict(testInsts[idx], curDecodeInst);
testInsts[idx].evaluate(curDecodeInst, segMetric_test, postagMetric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl << "Seg: ";
segMetric_test.print();
std::cout << "Postag: ";
postagMetric_test.print();
if (!m_options.outBest.empty() && bCurIterBetter) {
m_pipe.outputAllInstances(testFile + m_options.outBest, decodeInstResults);
}
}
for (int idx = 0; idx < otherInsts.size(); idx++) {
std::cout << "processing " << m_options.testFiles[idx] << std::endl;
if (!m_options.outBest.empty())
decodeInstResults.clear();
segMetric_test.reset();
postagMetric_test.reset();
for (int idy = 0; idy < otherInsts[idx].size(); idy++) {
predict(otherInsts[idx][idy], curDecodeInst);
otherInsts[idx][idy].evaluate(curDecodeInst, segMetric_test, postagMetric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl << "Seg: ";
segMetric_test.print();
std::cout << "Postag: ";
postagMetric_test.print();
if (!m_options.outBest.empty() && bCurIterBetter) {
m_pipe.outputAllInstances(m_options.testFiles[idx] + m_options.outBest, decodeInstResults);
}
}
if (m_options.saveIntermediate && postagMetric_dev.getAccuracy() > bestPostagFmeasure) {
std::cout << "Exceeds best previous DIS of " << bestPostagFmeasure << ". Saving model file.." << std::endl;
bestPostagFmeasure = postagMetric_dev.getAccuracy();
writeModelFile(modelFile);
}
}
}
}
示例4: train
//.........这里部分代码省略.........
subExamples.clear();
for (int idy = 0; idy < m_options.batchSize; idy++) {
subExamples.push_back(trainExamples[indexes[idy]]);
}
int curUpdateIter = iter * m_options.verboseIter + updateIter;
cost += m_classifier.process(subExamples, curUpdateIter);
//m_classifier.checkgrads(subExamples, curUpdateIter);
eval.overall_label_count += m_classifier._eval.overall_label_count;
eval.correct_label_count += m_classifier._eval.correct_label_count;
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
std::cout << "current iter: " << iter + 1 << ", total iter: " << maxIter << std::endl;
std::cout << "Cost = " << cost << ", SA Correct(%) = " << eval.getAccuracy() << std::endl;
}
if (devNum > 0) {
bCurIterBetter = false;
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_dev.reset();
for (int idx = 0; idx < devExamples.size(); idx++) {
string result_label;
double confidence = predict(devExamples[idx].m_features, result_label);
devInsts[idx].Evaluate(result_label, metric_dev);
if (!m_options.outBest.empty()) {
curDecodeInst.copyValuesFrom(devInsts[idx]);
curDecodeInst.assignLabel(result_label, confidence);
decodeInstResults.push_back(curDecodeInst);
}
}
metric_dev.print();
if ((!m_options.outBest.empty() && metric_dev.getAccuracy() > bestDIS)) {
m_pipe.outputAllInstances(devFile + m_options.outBest, decodeInstResults);
bCurIterBetter = true;
}
if (testNum > 0) {
if (!m_options.outBest.empty())
decodeInstResults.clear();
metric_test.reset();
for (int idx = 0; idx < testExamples.size(); idx++) {
string result_label;
double confidence = predict(testExamples[idx].m_features, result_label);
testInsts[idx].Evaluate(result_label, metric_test);
if (bCurIterBetter && !m_options.outBest.empty()) {
curDecodeInst.copyValuesFrom(testInsts[idx]);
curDecodeInst.assignLabel(result_label, confidence);
decodeInstResults.push_back(curDecodeInst);
}
}
std::cout << "test:" << std::endl;
metric_test.print();
if ((!m_options.outBest.empty() && bCurIterBetter)) {
m_pipe.outputAllInstances(testFile + m_options.outBest, decodeInstResults);
}
}
for (int idx = 0; idx < otherExamples.size(); idx++) {
std::cout << "processing " << m_options.testFiles[idx] << std::endl;
if (!m_options.outBest.empty())