/* uit_progress: * Display a progress report to the user consisting of information * provided by the trainer: iteration count and objective function value, and * some information computed here on the current model performance. * This function returns true if the trainer have to keep training the model * and false if he must stop, so this is were we will implement the trainer * independant stoping criterion. */ bool uit_progress(mdl_t *mdl) { // First we just compute the error rate on devel or train data double te, se; tag_eval(mdl, &te, &se); // If requested, check the error rate stoping criterion. We check if the // error rate is stable enought over a few iterations. bool res = true; if (mdl->opt->stopwin != 0) { mdl->werr[mdl->wpos] = te; mdl->wpos = (mdl->wpos + 1) % mdl->opt->stopwin; mdl->wcnt++; if (mdl->wcnt >= mdl->opt->stopwin) { double emin = 200.0, emax = -100.0; for (uint32_t i = 0; i < mdl->opt->stopwin; i++) { emin = min(emin, mdl->werr[i]); emax = max(emax, mdl->werr[i]); } if (emax - emin < mdl->opt->stopeps) res = false; } } return (uit_stop) ? false : res; }
/* uit_progress: * Display a progress repport to the user consisting of some informations * provided by the trainer: iteration count and objective function value, and * some informations computed here on the current model performances. * This function return true if the trainer have to keep training the model * and false if he must stop, so this is were we will implement the trainer * independant stoping criterion. */ bool uit_progress(mdl_t *mdl, uint32_t it, double obj) { // First we just compute the error rate on devel or train data double te, se; tag_eval(mdl, &te, &se); // Next, we compute the number of active features uint64_t act = 0; for (uint64_t f = 0; f < mdl->nftr; f++) if (mdl->theta[f] != 0.0) act++; // Compute timings. As some training algorithms are multi-threaded, we // cannot use ansi/c function and must rely on posix one to sum time // spent in main thread and in child ones. tms_t now; gettimeofday(&now, NULL); double tm = (now.tv_sec + (double)now.tv_usec * 1.0e-6) - (mdl->timer.tv_sec + (double)mdl->timer.tv_usec * 1.0e-6); mdl->total += tm; mdl->timer = now; // And display progress report info(" [%4"PRIu32"]", it); info(obj >= 0.0 ? " obj=%-10.2f" : " obj=NA", obj); info(" act=%-8"PRIu64, act); info(" err=%5.2f%%/%5.2f%%", te, se); info(" time=%.2fs/%.2fs", tm, mdl->total); info("\n"); // If requested, check the error rate stoping criterion. We check if the // error rate is stable enought over a few iterations. bool res = true; if (mdl->opt->stopwin != 0) { mdl->werr[mdl->wpos] = te; mdl->wpos = (mdl->wpos + 1) % mdl->opt->stopwin; mdl->wcnt++; if (mdl->wcnt >= mdl->opt->stopwin) { double emin = 200.0, emax = -100.0; for (uint32_t i = 0; i < mdl->opt->stopwin; i++) { emin = min(emin, mdl->werr[i]); emax = max(emax, mdl->werr[i]); } if (emax - emin < mdl->opt->stopeps) res = false; } } // And return if (uit_stop) return false; return res; }