diff --git a/MLP/src/MLP.cpp b/MLP/src/MLP.cpp index 5b7bd0b881e55bb12006fdcb2e8b5dd455c86944..57d2c2bdb018e609f3e243a2f823adce78929230 100644 --- a/MLP/src/MLP.cpp +++ b/MLP/src/MLP.cpp @@ -1,6 +1,7 @@ #include "MLP.hpp" #include "File.hpp" #include "util.hpp" +#include "ProgramParameters.hpp" #include <dynet/param-init.h> #include <dynet/io.h> @@ -82,6 +83,7 @@ void MLP::initDynet() MLP::MLP(int nbInputs, const std::string & topology, int nbOutputs) { + randomSeed = ProgramParameters::seed; std::string topo = topology; std::replace(topo.begin(), topo.end(), '(', ' '); std::replace(topo.begin(), topo.end(), ')', ' '); @@ -109,7 +111,7 @@ MLP::MLP(int nbInputs, const std::string & topology, int nbOutputs) layers.emplace_back(layers.back().output_dim, nbOutputs, 0.0, Activation::LINEAR); - trainer.reset(new dynet::AmsgradTrainer(model, 0.001, 0.9, 0.999, 1e-8)); + trainer.reset(new dynet::AmsgradTrainer(model, 0.0001, 0.9, 0.999, 1e-8)); initDynet(); @@ -386,6 +388,7 @@ void MLP::loadParameters(const std::string & filename) MLP::MLP(const std::string & filename) { + randomSeed = ProgramParameters::seed; trainer.reset(new dynet::AmsgradTrainer(model, 0.001, 0.9, 0.999, 1e-8)); initDynet(); diff --git a/decoder/src/macaon_decode.cpp b/decoder/src/macaon_decode.cpp index 3c4c0049db3b7b725420e7d475b64d6633e076c2..ab4ecb55d61c7e4fa3a9d5eb5c3df7c4c2dc5451 100644 --- a/decoder/src/macaon_decode.cpp +++ b/decoder/src/macaon_decode.cpp @@ -94,28 +94,29 @@ int main(int argc, char * argv[]) po::variables_map vm = checkOptions(od, argc, argv); - std::string tmFilename = vm["tm"].as<std::string>(); - std::string bdFilename = vm["bd"].as<std::string>(); - std::string mcdFilename = vm["mcd"].as<std::string>(); - std::string inputFilename = vm["input"].as<std::string>(); - std::string lang = vm["lang"].as<std::string>(); - std::string expName = vm["expName"].as<std::string>(); + ProgramParameters::expName = vm["expName"].as<std::string>(); + ProgramParameters::tmName = vm["tm"].as<std::string>(); + ProgramParameters::bdName = vm["bd"].as<std::string>(); + ProgramParameters::input = vm["input"].as<std::string>(); + ProgramParameters::mcdName = vm["mcd"].as<std::string>(); + ProgramParameters::debug = vm.count("debug") == 0 ? false : true; + ProgramParameters::lang = vm["lang"].as<std::string>(); const char * MACAON_DIR = std::getenv("MACAON_DIR"); std::string slash = "/"; - std::string expPath = MACAON_DIR + slash + lang + slash + "bin/" + expName + slash; - bool debugMode = vm.count("debug") == 0 ? false : true; + ProgramParameters::expPath = MACAON_DIR + slash + ProgramParameters::lang + slash + "bin/" + ProgramParameters::expName + slash; - tmFilename = expPath + tmFilename; - bdFilename = expPath + bdFilename; + ProgramParameters::tmFilename = ProgramParameters::expPath + ProgramParameters::tmName; + ProgramParameters::bdFilename = ProgramParameters::expPath + ProgramParameters::bdName; + ProgramParameters::mcdFilename = ProgramParameters::mcdName; - TransitionMachine tapeMachine(tmFilename, false, expPath); + TransitionMachine tapeMachine(false); - BD bd(bdFilename, mcdFilename); - Config config(bd, expPath); - config.readInput(inputFilename); + BD bd(ProgramParameters::bdFilename, ProgramParameters::mcdFilename); + Config config(bd); + config.readInput(ProgramParameters::input); - Decoder decoder(tapeMachine, bd, config, debugMode); + Decoder decoder(tapeMachine, bd, config, ProgramParameters::debug); decoder.decode(); diff --git a/maca_common/include/Dict.hpp b/maca_common/include/Dict.hpp index 1a3d16b2063d552dfab79d0dbbb6aca2cc750df1..d547a3d7e402b800457f07b24e130f57c275c342 100644 --- a/maca_common/include/Dict.hpp +++ b/maca_common/include/Dict.hpp @@ -194,10 +194,10 @@ class Dict static Dict * getDict(const std::string & name); /// @brief Read and construct multiple Dict from a file. /// + /// @param directory The directory in which we will find the file. /// @param filename The name of the file containing the Dict descriptions. /// @param trainMode Wheter or not the program is in train mode (values will be updated) - /// @param expPath The absolute path of the current experience. - static void readDicts(const std::string & filename, bool trainMode, const std::string & expPath); + static void readDicts(const std::string & directory, const std::string & filename, bool trainMode); /// @brief Save every Dict whose name starts with the prefix to their corresponding files. /// /// @param directory The directory in which we will save every Dict. diff --git a/maca_common/include/ProgramParameters.hpp b/maca_common/include/ProgramParameters.hpp new file mode 100644 index 0000000000000000000000000000000000000000..591eea307b71eda9587fb359d352254f8556daf4 --- /dev/null +++ b/maca_common/include/ProgramParameters.hpp @@ -0,0 +1,37 @@ +/// @file ProgramParameters.hpp +/// @author Franck Dary +/// @version 1.0 +/// @date 2018-09-27 +#ifndef PROGRAMPARAMETERS__H +#define PROGRAMPARAMETERS__H + +#include <string> + +struct ProgramParameters +{ + static std::string input; + static std::string expName; + static std::string expPath; + static std::string tmFilename; + static std::string tmName; + static std::string bdFilename; + static std::string bdName; + static std::string mcdFilename; + static std::string mcdName; + static bool debug; + static std::string trainFilename; + static std::string trainName; + static std::string devFilename; + static std::string devName; + static std::string lang; + static int nbIter; + static int seed; + static bool removeDuplicates; + static bool shuffleExamples; + + private : + + ProgramParameters(); +}; + +#endif diff --git a/maca_common/src/Dict.cpp b/maca_common/src/Dict.cpp index b962a0486b0169192b66b7d41e3a087c6c16dbaf..56a36561dba9ce74536e9b76a6dc3a4d143f2986 100644 --- a/maca_common/src/Dict.cpp +++ b/maca_common/src/Dict.cpp @@ -1,6 +1,7 @@ #include "Dict.hpp" #include "File.hpp" #include "util.hpp" +#include "ProgramParameters.hpp" std::string Dict::currentClassifierName; std::string Dict::nullValueStr = "_nullVALUEstr_"; @@ -350,7 +351,7 @@ Dict * Dict::getDict(const std::string & name) return nullptr; } -void Dict::readDicts(const std::string & filename, bool trainMode, const std::string & expPath) +void Dict::readDicts(const std::string & directory, const std::string & filename, bool trainMode) { char buffer[1024]; char name[1024]; @@ -397,7 +398,7 @@ void Dict::readDicts(const std::string & filename, bool trainMode, const std::st exit(1); } - getDict(Policy::Final, expPath + name + ".dict"); + getDict(Policy::Final, directory + name + ".dict"); } } } diff --git a/maca_common/src/ProgramParameters.cpp b/maca_common/src/ProgramParameters.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b639570dfaa16b6848dce77cf6faf6cd95385d16 --- /dev/null +++ b/maca_common/src/ProgramParameters.cpp @@ -0,0 +1,25 @@ +#include "ProgramParameters.hpp" + +ProgramParameters::ProgramParameters() +{ +} + +std::string ProgramParameters::input; +std::string ProgramParameters::expName; +std::string ProgramParameters::expPath; +std::string ProgramParameters::tmFilename; +std::string ProgramParameters::tmName; +std::string ProgramParameters::bdFilename; +std::string ProgramParameters::bdName; +std::string ProgramParameters::mcdFilename; +std::string ProgramParameters::mcdName; +bool ProgramParameters::debug; +std::string ProgramParameters::trainFilename; +std::string ProgramParameters::trainName; +std::string ProgramParameters::devFilename; +std::string ProgramParameters::devName; +std::string ProgramParameters::lang; +int ProgramParameters::nbIter; +int ProgramParameters::seed; +bool ProgramParameters::removeDuplicates; +bool ProgramParameters::shuffleExamples; diff --git a/trainer/include/Trainer.hpp b/trainer/include/Trainer.hpp index 6efd1574028d7b19dbec7f93c9d221580d3f0c85..1ca9132747529d7715bbdcdfa243736ba737f715 100644 --- a/trainer/include/Trainer.hpp +++ b/trainer/include/Trainer.hpp @@ -13,11 +13,6 @@ /// @brief An object capable of training a TransitionMachine given a BD initialized with training examples. class Trainer { - public : - - /// @brief The absolute path in which this experience (training) is taking place - std::string expPath; - private : /// @brief The TransitionMachine that will be trained. @@ -36,12 +31,6 @@ class Trainer /// Can be nullptr if dev is not used in this training. Config * devConfig; - /// @brief If true, will print infos on stderr - bool debugMode; - - /// @brief If true, duplicates examples will be removed from the training set. - bool removeDuplicates; - /// @brief For each classifier, a pair of number examples seen / number examples successfully classified std::map< std::string, std::pair<int, int> > trainCounter; @@ -57,9 +46,6 @@ class Trainer /// @brief Current iteration. int curIter; - /// @brief Number of iterations. - int nbIter; - public : /// @brief The FeatureDescritpion of a Config. @@ -82,9 +68,7 @@ class Trainer /// @param tm The TransitionMachine to use. /// @param bd The BD to use. /// @param config The config to use. - /// @param debugMode If true, infos will be printed on stderr. - /// @param removeDuplicates If true, duplicates examples will be removed from the training set. - Trainer(TransitionMachine & tm, BD & bd, Config & config, bool debugMode, bool removeDuplicates); + Trainer(TransitionMachine & tm, BD & bd, Config & config); /// @brief Construct a new Trainer with a dev set. /// /// @param tm The TransitionMachine to use. @@ -92,9 +76,7 @@ class Trainer /// @param config The Config corresponding to bd. /// @param devBD The BD corresponding to the dev dataset. /// @param devConfig The Config corresponding to devBD. - /// @param debugMode If true, infos will be printed on stderr. - /// @param removeDuplicates If true, duplicates examples will be removed from the training set. - Trainer(TransitionMachine & tm, BD & bd, Config & config, BD * devBD, Config * devConfig, bool debugMode, bool removeDuplicates); + Trainer(TransitionMachine & tm, BD & bd, Config & config, BD * devBD, Config * devConfig); /// @brief Train the TransitionMachine one example at a time. /// @@ -103,9 +85,7 @@ class Trainer /// the devBD if available, and each Classifier will be saved only if its score /// on the current epoch is its all time best.\n /// When a Classifier is saved that way, all the Dict involved are also saved. - /// @param nbIter The number of epochs. - /// @param mustShuffle Whether or not to shuffle examples between each epoch. - void train(int nbIter, bool mustShuffle); + void train(); }; #endif diff --git a/trainer/src/Trainer.cpp b/trainer/src/Trainer.cpp index c541924e6826d064fdeff3ffcbaeb3ba5651f5da..02daf5fe6f73a6749714b7393e285446b5c48191 100644 --- a/trainer/src/Trainer.cpp +++ b/trainer/src/Trainer.cpp @@ -1,19 +1,15 @@ #include "Trainer.hpp" #include "util.hpp" -Trainer::Trainer(TransitionMachine & tm, BD & bd, Config & config, bool debugMode, bool removeDuplicates) +Trainer::Trainer(TransitionMachine & tm, BD & bd, Config & config) : tm(tm), trainBD(bd), trainConfig(config) { this->devBD = nullptr; this->devConfig = nullptr; - this->debugMode = debugMode; - this->removeDuplicates = removeDuplicates; } -Trainer::Trainer(TransitionMachine & tm, BD & bd, Config & config, BD * devBD, Config * devConfig, bool debugMode, bool removeDuplicates) : tm(tm), trainBD(bd), trainConfig(config), devBD(devBD), devConfig(devConfig) +Trainer::Trainer(TransitionMachine & tm, BD & bd, Config & config, BD * devBD, Config * devConfig) : tm(tm), trainBD(bd), trainConfig(config), devBD(devBD), devConfig(devConfig) { - this->debugMode = debugMode; - this->removeDuplicates = removeDuplicates; } std::map<std::string, float> Trainer::getScoreOnDev() @@ -26,7 +22,7 @@ std::map<std::string, float> Trainer::getScoreOnDev() std::map< std::string, std::pair<int, int> > counts; - if (debugMode) + if (ProgramParameters::debug) fprintf(stderr, "Computing score on dev set\n"); while (!devConfig->isFinal()) @@ -76,7 +72,7 @@ std::map<std::string, float> Trainer::getScoreOnDev() std::string actionName = pAction; Action * action = classifier->getAction(actionName); - if (debugMode) + if (ProgramParameters::debug) { devConfig->printForDebug(stderr); fprintf(stderr, "pAction=<%s> action=<%s>\n", pAction.c_str(), actionName.c_str()); @@ -96,21 +92,19 @@ std::map<std::string, float> Trainer::getScoreOnDev() return scores; } -void Trainer::train(int nbIter, bool mustShuffle) +void Trainer::train() { - this->nbIter = nbIter; - - Dict::saveDicts(expPath, ""); + Dict::saveDicts(ProgramParameters::expPath, ""); fprintf(stderr, "Training of \'%s\' :\n", tm.name.c_str()); - for (curIter = 0; curIter < nbIter; curIter++) + for (curIter = 0; curIter < ProgramParameters::nbIter; curIter++) { tm.reset(); trainConfig.reset(); - if(mustShuffle) + if(ProgramParameters::shuffleExamples) trainConfig.shuffle("EOS", "1"); while (!trainConfig.isFinal()) @@ -200,7 +194,7 @@ void Trainer::train(int nbIter, bool mustShuffle) actionName = zeroCostActions[rand() % zeroCostActions.size()]; } - if (debugMode) + if (ProgramParameters::debug) { trainConfig.printForDebug(stderr); fprintf(stderr, "pAction=<%s> oAction=<%s> nb=%lu action=<%s>\n", pAction.c_str(), oAction.c_str(), zeroCostActions.size(), actionName.c_str()); @@ -269,8 +263,8 @@ void Trainer::printScoresAndSave(FILE * output) if (saved[cla->name]) { - cla->save(expPath + cla->name + ".model"); - Dict::saveDicts(expPath, cla->name); + cla->save(ProgramParameters::expPath + cla->name + ".model"); + Dict::saveDicts(ProgramParameters::expPath, cla->name); } } @@ -284,7 +278,7 @@ void Trainer::printScoresAndSave(FILE * output) } fprintf(stderr, " \r"); - fprintf(output, "Iteration %d/%d :\n", curIter+1, nbIter); + fprintf(output, "Iteration %d/%d :\n", curIter+1, ProgramParameters::nbIter); printColumns(output, {names, acc, train, dev, savedStr}); } diff --git a/trainer/src/macaon_train.cpp b/trainer/src/macaon_train.cpp index 9c8e31d513c7d6bad15ce165a8301a875f14a2b5..1686e3b0321790171a4807ae464439142e588c9c 100644 --- a/trainer/src/macaon_train.cpp +++ b/trainer/src/macaon_train.cpp @@ -10,6 +10,7 @@ #include "Config.hpp" #include "TransitionMachine.hpp" #include "Trainer.hpp" +#include "ProgramParameters.hpp" namespace po = boost::program_options; @@ -103,57 +104,53 @@ int main(int argc, char * argv[]) po::variables_map vm = checkOptions(od, argc, argv); - std::string BDfilename = vm["bd"].as<std::string>(); - std::string MCDfilename = vm["mcd"].as<std::string>(); - std::string tmFilename = vm["tm"].as<std::string>(); - std::string trainFilename = vm["train"].as<std::string>(); - std::string devFilename = vm["dev"].as<std::string>(); - std::string expName = vm["expName"].as<std::string>(); - std::string lang = vm["lang"].as<std::string>(); - int nbIter = vm["nbiter"].as<int>(); - int randomSeed = vm["seed"].as<int>(); - bool mustShuffle = vm["shuffle"].as<bool>(); - bool removeDuplicates = vm["duplicates"].as<bool>(); - bool debugMode = vm.count("debug") == 0 ? false : true; + ProgramParameters::expName = vm["expName"].as<std::string>(); + ProgramParameters::tmName = vm["tm"].as<std::string>(); + ProgramParameters::bdName = vm["bd"].as<std::string>(); + ProgramParameters::mcdName = vm["mcd"].as<std::string>(); + ProgramParameters::debug = vm.count("debug") == 0 ? false : true; + ProgramParameters::trainName = vm["train"].as<std::string>(); + ProgramParameters::devName = vm["dev"].as<std::string>(); + ProgramParameters::lang = vm["lang"].as<std::string>(); + ProgramParameters::nbIter = vm["nbiter"].as<int>(); + ProgramParameters::seed = vm["seed"].as<int>(); + ProgramParameters::removeDuplicates = vm["duplicates"].as<bool>(); + ProgramParameters::shuffleExamples = vm["shuffle"].as<bool>(); const char * MACAON_DIR = std::getenv("MACAON_DIR"); std::string slash = "/"; - std::string expPath = MACAON_DIR + slash + lang + slash + "bin/" + expName + slash; + ProgramParameters::expPath = MACAON_DIR + slash + ProgramParameters::lang + slash + "bin/" + ProgramParameters::expName + slash; - BDfilename = expPath + BDfilename; - MCDfilename = expPath + MCDfilename; - tmFilename = expPath + tmFilename; - trainFilename = expPath + trainFilename; - devFilename = expPath + devFilename; + ProgramParameters::tmFilename = ProgramParameters::expPath + ProgramParameters::tmName; + ProgramParameters::bdFilename = ProgramParameters::expPath + ProgramParameters::bdName; + ProgramParameters::mcdFilename = ProgramParameters::expPath + ProgramParameters::mcdName; + ProgramParameters::trainFilename = ProgramParameters::expPath + ProgramParameters::trainName; + ProgramParameters::devFilename = ProgramParameters::expPath + ProgramParameters::devName; - // Setting the random seed - MLP::randomSeed = randomSeed; + TransitionMachine transitionMachine(true); - TransitionMachine tapeMachine(tmFilename, true, expPath); - - BD trainBD(BDfilename, MCDfilename); - Config trainConfig(trainBD, expPath); - trainConfig.readInput(trainFilename); + BD trainBD(ProgramParameters::bdFilename, ProgramParameters::mcdFilename); + Config trainConfig(trainBD); + trainConfig.readInput(ProgramParameters::trainFilename); std::unique_ptr<BD> devBD; std::unique_ptr<Config> devConfig; std::unique_ptr<Trainer> trainer; - if(devFilename.empty()) + if(ProgramParameters::devFilename.empty()) { - trainer.reset(new Trainer(tapeMachine, trainBD, trainConfig, debugMode, removeDuplicates)); + trainer.reset(new Trainer(transitionMachine, trainBD, trainConfig)); } else { - devBD.reset(new BD(BDfilename, MCDfilename)); - devConfig.reset(new Config(*devBD.get(), expPath)); - devConfig->readInput(devFilename); - trainer.reset(new Trainer(tapeMachine, trainBD, trainConfig, devBD.get(), devConfig.get(), debugMode, removeDuplicates)); + devBD.reset(new BD(ProgramParameters::bdFilename, ProgramParameters::mcdFilename)); + devConfig.reset(new Config(*devBD.get())); + devConfig->readInput(ProgramParameters::devFilename); + trainer.reset(new Trainer(transitionMachine, trainBD, trainConfig, devBD.get(), devConfig.get())); } - trainer->expPath = expPath; - trainer->train(nbIter, mustShuffle); + trainer->train(); return 0; } diff --git a/transition_machine/include/Classifier.hpp b/transition_machine/include/Classifier.hpp index 2b0319e27e44d448a3cc3ef6136038eb3ebeb73a..0fe1664496fe82961846d27569ae2f5684877651 100644 --- a/transition_machine/include/Classifier.hpp +++ b/transition_machine/include/Classifier.hpp @@ -12,6 +12,7 @@ #include "ActionSet.hpp" #include "Oracle.hpp" #include "MLP.hpp" +#include "ProgramParameters.hpp" /// @brief Given a Config, a Classifier is capable of weighting its ActionSet. class Classifier @@ -80,8 +81,7 @@ class Classifier /// /// @param filename The name of the file containing the Classifier. /// @param trainMode Whether or not the program is in train mode. - /// @param expPath The absolute path of the current experience. - Classifier(const std::string & filename, bool trainMode, const std::string & expPath); + Classifier(const std::string & filename, bool trainMode); /// @brief Give a weight to each Action of the ActionSet, given a Config. /// /// @param config The Config to take into account. diff --git a/transition_machine/include/Config.hpp b/transition_machine/include/Config.hpp index 7913b743792dd2dbcd966fea45f6b46ba134fd8f..04af68828869ad614cea429d3880a69faaf30dd4 100644 --- a/transition_machine/include/Config.hpp +++ b/transition_machine/include/Config.hpp @@ -57,16 +57,13 @@ class Config int head; /// @brief The name of the input file used to fill the tapes. std::string inputFilename; - /// @brief The absolute path of the current experiment. - std::string expPath; public : /// @brief Construct a new Config. /// /// @param bd The BD that describes the tapes of this Config. - /// @param expPath The absolute path of the current experiment. - Config(BD & bd, const std::string & expPath); + Config(BD & bd); /// @brief Get a Tape by its name. /// /// @param name The name of the Tape. diff --git a/transition_machine/include/TransitionMachine.hpp b/transition_machine/include/TransitionMachine.hpp index 3fd06fab869553f677d89d3c5652872bff1a2289..a990d63fea9d29791fb79ead066515353071ac73 100644 --- a/transition_machine/include/TransitionMachine.hpp +++ b/transition_machine/include/TransitionMachine.hpp @@ -79,10 +79,8 @@ class TransitionMachine /// @brief Read and construct a new TransitionMachine from a file. /// - /// @param filename The name of the file containing the TransitionMachine. /// @param trainMode Whether or not the program is in train mode. - /// @param expPath The absolute path of the current experiment. - TransitionMachine(const std::string & filename, bool trainMode, const std::string & expPath); + TransitionMachine(bool trainMode); /// @brief Get the current TransitionMachine state. /// /// @return The current state. diff --git a/transition_machine/src/Classifier.cpp b/transition_machine/src/Classifier.cpp index 80b27bc58b15711e10ab137624763b11fba9eff2..583620f490227dd63a6f80055376b3182d4361b5 100644 --- a/transition_machine/src/Classifier.cpp +++ b/transition_machine/src/Classifier.cpp @@ -2,7 +2,7 @@ #include "File.hpp" #include "util.hpp" -Classifier::Classifier(const std::string & filename, bool trainMode, const std::string & expPath) +Classifier::Classifier(const std::string & filename, bool trainMode) { this->trainMode = trainMode; @@ -13,7 +13,7 @@ Classifier::Classifier(const std::string & filename, bool trainMode, const std:: exit(1); }; - File file(expPath + filename, "r"); + File file(ProgramParameters::expPath + filename, "r"); FILE * fd = file.getDescriptor(); char buffer[1024]; @@ -40,7 +40,7 @@ Classifier::Classifier(const std::string & filename, bool trainMode, const std:: if(fscanf(fd, "Oracle Filename : %s\n", buffer2) != 1) badFormatAndAbort(ERRINFO); - oracle = Oracle::getOracle(buffer, expPath + std::string("/") + buffer2); + oracle = Oracle::getOracle(buffer, ProgramParameters::expPath + std::string("/") + buffer2); } else oracle = Oracle::getOracle(buffer); @@ -55,12 +55,12 @@ Classifier::Classifier(const std::string & filename, bool trainMode, const std:: if(fscanf(fd, "Feature Model : %s\n", buffer) != 1) badFormatAndAbort(ERRINFO); - fm.reset(new FeatureModel(expPath + buffer)); + fm.reset(new FeatureModel(ProgramParameters::expPath + buffer)); if(fscanf(fd, "Action Set : %s\n", buffer) != 1) badFormatAndAbort(ERRINFO); - as.reset(new ActionSet(expPath + buffer, false)); + as.reset(new ActionSet(ProgramParameters::expPath + buffer, false)); if(fscanf(fd, "Topology : %s\n", buffer) != 1) badFormatAndAbort(ERRINFO); @@ -119,7 +119,7 @@ void Classifier::initClassifier(Config & config) if(!trainMode) { - mlp.reset(new MLP(config.expPath + name + ".model")); + mlp.reset(new MLP(ProgramParameters::expPath + name + ".model")); return; } diff --git a/transition_machine/src/Config.cpp b/transition_machine/src/Config.cpp index badbbbada01dbc681968b8d02f8996de0cb4c82d..e9f03eb15be2cee4f71ff752bcb0ebcb63712f40 100644 --- a/transition_machine/src/Config.cpp +++ b/transition_machine/src/Config.cpp @@ -1,10 +1,10 @@ #include "Config.hpp" #include "File.hpp" +#include "ProgramParameters.hpp" #include <algorithm> -Config::Config(BD & bd, const std::string & expPath) : bd(bd), tapes(bd.getNbLines()) +Config::Config(BD & bd) : bd(bd), tapes(bd.getNbLines()) { - this->expPath = expPath; this->currentStateName = nullptr; head = 0; for(unsigned int i = 0; i < tapes.size(); i++) diff --git a/transition_machine/src/TransitionMachine.cpp b/transition_machine/src/TransitionMachine.cpp index 2f4f0cdbd60067257b73427ee864cbb9f7956e4b..e3f8f93a572ab11f0bab9e3885539f293c71c880 100644 --- a/transition_machine/src/TransitionMachine.cpp +++ b/transition_machine/src/TransitionMachine.cpp @@ -3,8 +3,10 @@ #include "util.hpp" #include <cstring> -TransitionMachine::TransitionMachine(const std::string & filename, bool trainMode, const std::string & expPath) +TransitionMachine::TransitionMachine(bool trainMode) { + std::string filename = ProgramParameters::tmFilename; + auto badFormatAndAbort = [&filename](const std::string & errInfo) { fprintf(stderr, "ERROR (%s) : file %s bad format. Aborting.\n", errInfo.c_str(), filename.c_str()); @@ -31,7 +33,7 @@ TransitionMachine::TransitionMachine(const std::string & filename, bool trainMod if(fscanf(fd, "Dicts : %[^\n]\n", buffer) != 1) badFormatAndAbort(ERRINFO); - Dict::readDicts(expPath + buffer, trainMode, expPath); + Dict::readDicts(ProgramParameters::expPath, ProgramParameters::expPath + buffer, trainMode); // Reading %CLASSIFIERS if(fscanf(fd, "%%%s\n", buffer) != 1 || buffer != std::string("CLASSIFIERS")) @@ -43,7 +45,7 @@ TransitionMachine::TransitionMachine(const std::string & filename, bool trainMod if(fscanf(fd, "%s %s\n", buffer, buffer2) != 2) badFormatAndAbort(ERRINFO); - str2classifier.emplace(buffer, std::unique_ptr<Classifier>(new Classifier(buffer2, trainMode, expPath))); + str2classifier.emplace(buffer, std::unique_ptr<Classifier>(new Classifier(buffer2, trainMode))); classifiers.emplace_back(str2classifier[buffer].get()); }