本文整理汇总了C++中Timer::GetLast_asMSec方法的典型用法代码示例。如果您正苦于以下问题:C++ Timer::GetLast_asMSec方法的具体用法?C++ Timer::GetLast_asMSec怎么用?C++ Timer::GetLast_asMSec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::GetLast_asMSec方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DoPredict
void DoPredict(const char* sPattsFile, Model* pModel, const int32_t nTarget, const char* sRocFile = NULL)
{
ifstream ifs(sPattsFile);
if(!ifs.is_open())
{
cout<<"Failed to open patterns file "<<sPattsFile<<endl;
return;
}
Pattern patt;
string str;
double pred_score[pModel->N_Output()], rmse;
int32_t tp = 0, fp = 0, fn = 0, tn = 0;
int32_t p_off, r_off;
Timer timer;
RocAnalyzer roc;
while(!ifs.eof())
{
std::getline(ifs, str);
if(str.empty())
continue;
// read pattern for testing
if(!patt.FromString(str.c_str()))
continue;
// IMPORTANT!!!
// prediction, calculate pred_score of each label
timer.Start();
for(int32_t i = 0; i < pModel->N_Output(); i++)
pred_score[i] = pModel->Predict(patt.m_x, patt.m_nXCnt, i);
timer.Stop();
// effect evaluation and statistic
rmse = sqrt(Pattern::Error(pred_score, patt.m_y, patt.m_nYCnt));
r_off = Pattern::MaxOff(patt.m_y, patt.m_nYCnt);
p_off = Pattern::MaxOff(pred_score, pModel->N_Output());
if(r_off == nTarget && p_off == nTarget)
{
roc.Insert(_POSITIVE, pred_score[nTarget]);
tp += 1;
}
else if(r_off != nTarget && p_off == nTarget)
{
printf("*** ");
roc.Insert(_NEGATIVE, pred_score[nTarget]);
fp += 1;
}
else if(r_off == nTarget && p_off != nTarget)
{
printf("*** ");
roc.Insert(_POSITIVE, pred_score[nTarget]);
fn += 1;
}
else
{
roc.Insert(_NEGATIVE, pred_score[nTarget]);
tn += 1;
}
printf("(%d) [%s] -> [%s] | RMSE: %.6g | TimeCost(ms): %.3f\n",
tp + fp + fn + tn,
Pattern::ArrayToString(patt.m_y, patt.m_nYCnt).c_str(),
Pattern::ArrayToString(pred_score, pModel->N_Output()).c_str(),
rmse,
timer.GetLast_asMSec());
}
ifs.close();
double precision = (double)tp / (double)(tp + fp);
double recall = (double)tp / (double)(tp + fn);
printf("Precision: %.6g, Recall: %.6g, F1: %.6g, AUC: %.6g, AvgTimeCost(ms): %.3f\n",
precision, recall, (precision * recall * 2.0) / (precision + recall), roc.Auc(), timer.GetTotal_asMSec() / (double)(tp + fp + fn + tn));
// save ROC curve
if(sRocFile)
{
FILE* fp = fopen(sRocFile, "w");
if(fp)
{
vector<pair<double, PNDetTable> > curve;
roc.RocCurve(curve);
fprintf(fp, "AUC;%.6g\n\n", roc.Auc());
fprintf(fp, "Threshold;FPR;TPR;Pr;Recall;F1\n");
for(size_t k = 0; k < curve.size(); k++)
{
fprintf(fp, "%.6g;%.6g;%.6g;%.6g;%.6g;%.6g\n",
curve[k].first,
curve[k].second.FPR(),
curve[k].second.TPR(),
curve[k].second.PosPrecision(),
curve[k].second.PosRecall(),
curve[k].second.PosF1());
}
fclose(fp);
}
}
//.........这里部分代码省略.........