Skip to content
Snippets Groups Projects
Commit bdc9e448 authored by Franck Dary's avatar Franck Dary
Browse files

Added an option to print time

parent cc2b7c14
Branches
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ struct ProgramParameters ...@@ -46,6 +46,7 @@ struct ProgramParameters
static int nbTrain; static int nbTrain;
static bool randomEmbeddings; static bool randomEmbeddings;
static bool printEntropy; static bool printEntropy;
static bool printTime;
static std::string sequenceDelimiterTape; static std::string sequenceDelimiterTape;
static std::string sequenceDelimiter; static std::string sequenceDelimiter;
......
...@@ -163,6 +163,11 @@ std::string float2str(float f, const char * format); ...@@ -163,6 +163,11 @@ std::string float2str(float f, const char * format);
/// @return s without suffix at the end. /// @return s without suffix at the end.
std::string removeSuffix(const std::string & s, const std::string & suffix); std::string removeSuffix(const std::string & s, const std::string & suffix);
/// @brief Return a string with the current system time.
///
/// @return Current system time.
std::string getTime();
/// @brief Macro giving informations about an error. /// @brief Macro giving informations about an error.
#define ERRINFO (getFilenameFromPath(std::string(__FILE__))+ ":l." + std::to_string(__LINE__)).c_str() #define ERRINFO (getFilenameFromPath(std::string(__FILE__))+ ":l." + std::to_string(__LINE__)).c_str()
......
...@@ -39,6 +39,7 @@ float ProgramParameters::dynamicProbability; ...@@ -39,6 +39,7 @@ float ProgramParameters::dynamicProbability;
bool ProgramParameters::showFeatureRepresentation; bool ProgramParameters::showFeatureRepresentation;
bool ProgramParameters::randomEmbeddings; bool ProgramParameters::randomEmbeddings;
bool ProgramParameters::printEntropy; bool ProgramParameters::printEntropy;
bool ProgramParameters::printTime;
int ProgramParameters::iterationSize; int ProgramParameters::iterationSize;
int ProgramParameters::nbTrain; int ProgramParameters::nbTrain;
std::string ProgramParameters::sequenceDelimiterTape; std::string ProgramParameters::sequenceDelimiterTape;
......
#include "util.hpp" #include "util.hpp"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <ctime>
bool isAlpha(char c) bool isAlpha(char c)
{ {
...@@ -360,3 +361,14 @@ std::string removeSuffix(const std::string & s, const std::string & suffix) ...@@ -360,3 +361,14 @@ std::string removeSuffix(const std::string & s, const std::string & suffix)
return result; return result;
} }
std::string getTime()
{
time_t rawtime;
char buffer[80];
time (&rawtime);
strftime(buffer, sizeof(buffer), "%H:%M:%S", localtime(&rawtime));
return std::string(buffer);
}
...@@ -96,7 +96,9 @@ void Trainer::train() ...@@ -96,7 +96,9 @@ void Trainer::train()
{ {
Dict::createFiles(ProgramParameters::expPath, ""); Dict::createFiles(ProgramParameters::expPath, "");
fprintf(stderr, "Training of \'%s\' :\n", tm.name.c_str()); fprintf(stderr, "%sTraining of \'%s\' :\n",
ProgramParameters::printTime ? ("["+getTime()+"] ").c_str() : "",
tm.name.c_str());
auto resetAndShuffle = [this]() auto resetAndShuffle = [this]()
{ {
...@@ -318,6 +320,8 @@ void Trainer::printScoresAndSave(FILE * output) ...@@ -318,6 +320,8 @@ void Trainer::printScoresAndSave(FILE * output)
if (ProgramParameters::interactive) if (ProgramParameters::interactive)
fprintf(stderr, " \r"); fprintf(stderr, " \r");
if (ProgramParameters::printTime)
fprintf(output, "[%s] ", getTime().c_str());
fprintf(output, "Iteration %d/%d :\n", curIter+1, ProgramParameters::nbIter); fprintf(output, "Iteration %d/%d :\n", curIter+1, ProgramParameters::nbIter);
printColumns(output, {names, acc, train, dev, savedStr}); printColumns(output, {names, acc, train, dev, savedStr});
......
...@@ -68,6 +68,7 @@ po::options_description getOptionsDescription() ...@@ -68,6 +68,7 @@ po::options_description getOptionsDescription()
"The name of the buffer's tape that contains the delimiter token for a sequence") "The name of the buffer's tape that contains the delimiter token for a sequence")
("sequenceDelimiter", po::value<std::string>()->default_value("1"), ("sequenceDelimiter", po::value<std::string>()->default_value("1"),
"The value of the token that act as a delimiter for sequences") "The value of the token that act as a delimiter for sequences")
("printTime", "Print time on stderr")
("shuffle", po::value<bool>()->default_value(true), ("shuffle", po::value<bool>()->default_value(true),
"Shuffle examples after each iteration"); "Shuffle examples after each iteration");
...@@ -236,6 +237,7 @@ int main(int argc, char * argv[]) ...@@ -236,6 +237,7 @@ int main(int argc, char * argv[])
ProgramParameters::bdName = vm["bd"].as<std::string>(); ProgramParameters::bdName = vm["bd"].as<std::string>();
ProgramParameters::mcdName = vm["mcd"].as<std::string>(); ProgramParameters::mcdName = vm["mcd"].as<std::string>();
ProgramParameters::debug = vm.count("debug") == 0 ? false : true; ProgramParameters::debug = vm.count("debug") == 0 ? false : true;
ProgramParameters::printTime = vm.count("printTime") == 0 ? false : true;
ProgramParameters::trainName = vm["train"].as<std::string>(); ProgramParameters::trainName = vm["train"].as<std::string>();
ProgramParameters::devName = vm["dev"].as<std::string>(); ProgramParameters::devName = vm["dev"].as<std::string>();
ProgramParameters::lang = vm["lang"].as<std::string>(); ProgramParameters::lang = vm["lang"].as<std::string>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment