本文整理汇总了C++中Metric::getAccuracy方法的典型用法代码示例。如果您正苦于以下问题:C++ Metric::getAccuracy方法的具体用法?C++ Metric::getAccuracy怎么用?C++ Metric::getAccuracy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Metric
的用法示例。
在下文中一共展示了Metric::getAccuracy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: train
//.........这里部分代码省略.........
srand(0);
std::vector<int> indexes;
for (int i = 0; i < inputSize; ++i)
indexes.push_back(i);
static Metric eval, metric_dev, metric_test;
static vector<Example> subExamples;
int devNum = devExamples.size(), testNum = testExamples.size();
for (int iter = 0; iter < m_options.maxIter; ++iter) {
std::cout << "##### Iteration " << iter << std::endl;
random_shuffle(indexes.begin(), indexes.end());
eval.reset();
for (int updateIter = 0; updateIter < batchBlock; updateIter++) {
subExamples.clear();
int start_pos = updateIter * m_options.batchSize;
int end_pos = (updateIter + 1) * m_options.batchSize;
if (end_pos > inputSize)
end_pos = inputSize;
for (int idy = start_pos; idy < end_pos; idy++) {
subExamples.push_back(trainExamples[indexes[idy]]);
}
int curUpdateIter = iter * batchBlock + updateIter;
dtype cost = m_classifier.process(subExamples, curUpdateIter);
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;
}
示例2: train
//.........这里部分代码省略.........
int maxIter = m_options.maxIter * (inputSize / m_options.batchSize + 1);
int oneIterMaxRound = (inputSize + m_options.batchSize -1) / m_options.batchSize;
std::cout << "maxIter = " << maxIter << std::endl;
int devNum = devInsts.size(), testNum = testInsts.size();
static vector<vector<string> > decodeInstResults;
static vector<string> curDecodeInst;
static bool bCurIterBetter;
static vector<vector<string> > subInstances;
static vector<vector<CAction> > subInstGoldActions;
for (int iter = 0; iter < maxIter; ++iter) {
std::cout << "##### Iteration " << iter << std::endl;
srand(iter);
random_shuffle(indexes.begin(), indexes.end());
std::cout << "random: " << indexes[0] << ", " << indexes[indexes.size() - 1] << std::endl;
bool bEvaluate = false;
if(m_options.batchSize == 1){
eval.reset();
bEvaluate = true;
for (int idy = 0; idy < inputSize; idy++) {
subInstances.clear();
subInstGoldActions.clear();
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 ((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();
示例3: train
void Segmentor::train(const string& trainFile, const string& devFile, const string& testFile, const string& modelFile, const string& optionFile, const string& lexiconFile) {
if (optionFile != "")
m_options.load(optionFile);
m_options.showOptions();
vector<Instance> trainInsts, devInsts, testInsts;
m_pipe.readInstances(trainFile, trainInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (devFile != "")
m_pipe.readInstances(devFile, devInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
if (testFile != "")
m_pipe.readInstances(testFile, testInsts, m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
vector<vector<Instance> > otherInsts(m_options.testFiles.size());
for (int idx = 0; idx < m_options.testFiles.size(); idx++) {
m_pipe.readInstances(m_options.testFiles[idx], otherInsts[idx], m_classifier.MAX_SENTENCE_SIZE - 2, m_options.maxInstance);
}
createAlphabet(trainInsts);
m_classifier.init(m_options.delta);
m_classifier.setDropValue(m_options.dropProb);
vector<vector<CAction> > trainInstGoldactions;
getGoldActions(trainInsts, trainInstGoldactions);
double bestPostagFmeasure = 0;
int inputSize = trainInsts.size();
std::vector<int> indexes;
for (int i = 0; i < inputSize; ++i)
indexes.push_back(i);
static Metric eval;
static Metric segMetric_dev, segMetric_test;
static Metric postagMetric_dev, postagMetric_test;
int maxIter = m_options.maxIter * (inputSize / m_options.batchSize + 1);
int oneIterMaxRound = (inputSize + m_options.batchSize - 1) / m_options.batchSize;
std::cout << "maxIter = " << maxIter << std::endl;
int devNum = devInsts.size(), testNum = testInsts.size();
static vector<CResult> decodeInstResults;
static CResult curDecodeInst;
static bool bCurIterBetter;
static vector<Instance > subInstances;
static vector<vector<CAction> > subInstGoldActions;
for (int iter = 0; iter < maxIter; ++iter) {
std::cout << "##### Iteration " << iter << std::endl;
srand(iter);
random_shuffle(indexes.begin(), indexes.end());
std::cout << "random: " << indexes[0] << ", " << indexes[indexes.size() - 1] << std::endl;
bool bEvaluate = false;
if (m_options.batchSize == 1) {
eval.reset();
bEvaluate = true;
for (int idy = 0; idy < inputSize; idy++) {
subInstances.clear();
subInstGoldActions.clear();
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 ((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);
}
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]]);
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())
//.........这里部分代码省略.........
示例4: train
//.........这里部分代码省略.........
int devNum = devExamples.size(), testNum = testExamples.size();
int maxIter = m_options.maxIter;
if (m_options.batchSize > 1)
maxIter = m_options.maxIter * (inputSize / m_options.batchSize + 1);
double cost = 0.0;
std::cout << "maxIter = " << maxIter << std::endl;
for (int iter = 0; iter < m_options.maxIter; ++iter) {
std::cout << "##### Iteration " << iter << std::endl;
eval.reset();
if (m_options.batchSize == 1) {
random_shuffle(indexes.begin(), indexes.end());
for (int updateIter = 0; updateIter < inputSize; updateIter++) {
subExamples.clear();
int start_pos = updateIter;
int end_pos = (updateIter + 1);
if (end_pos > inputSize)
end_pos = inputSize;
for (int idy = start_pos; idy < end_pos; idy++) {
subExamples.push_back(trainExamples[indexes[idy]]);
}
int curUpdateIter = iter * inputSize + updateIter;
cost = m_classifier.process(subExamples, curUpdateIter);
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 instances: " << inputSize << std::endl;
std::cout << "Cost = " << cost << ", SA Correct(%) = " << eval.getAccuracy() << std::endl;
}
m_classifier.updateParams(m_options.regParameter, m_options.adaAlpha, m_options.adaEps);
}
} else {
cost = 0.0;
for (int updateIter = 0; updateIter < m_options.verboseIter; updateIter++) {
random_shuffle(indexes.begin(), indexes.end());
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);