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

Documented TapeMachine

parent fd09a8a4
Branches
No related tags found
No related merge requests found
/// @file TapeMachine.hpp
/// @author Franck Dary
/// @version 1.0
/// @date 2018-08-07
#ifndef TAPEMACHINE__H #ifndef TAPEMACHINE__H
#define TAPEMACHINE__H #define TAPEMACHINE__H
#include "Classifier.hpp" #include "Classifier.hpp"
/// @brief The purpose of a TapeMachine is to predict a sequence of Action, that will transform an initial Config into a terminal Config.
/// The terminal Config will contains more information than the initial one, for
/// instance if the initial Config consists of words, the final Config could consist of words + their part of speech tags.\n
/// The TapeMachine is made of states, linked together by Transition. Every step is associated with a Classifier.\n
/// The predictions are made by classifiers, which at each step give a weight to every possible Action. The most probable Action will then be chosen and the corresponding Transition will be taken.\n
class TapeMachine class TapeMachine
{ {
public : public :
class State; class State;
/// @brief A Transition from one state to another.
struct Transition struct Transition
{ {
/// @brief The other end of the Transition.
State * dest; State * dest;
/// @brief The prefix of the Action name that will trigger the choice of this Transition.
std::string actionPrefix; std::string actionPrefix;
/// @brief The relative movement that will be applied to the Config head when taking this transition.
int headMvt; int headMvt;
/// @brief Construct a new Transition.
///
/// @param dest The other end of the Transition.
/// @param prefix The prefix of the Action name that will trigger the choice of this Transition.
/// @param mvt The relative movement that will be applied to the Config head when taking this transition.
Transition(State * dest, const std::string & prefix, int mvt); Transition(State * dest, const std::string & prefix, int mvt);
}; };
/// @brief A State of the TapeMachine. Can be seen as a graph node.
struct State struct State
{ {
/// @brief The name of this State.
std::string name; std::string name;
/// @brief The Classifier used in this State.
Classifier * classifier; Classifier * classifier;
/// @brief All the outgoing Transition from this State.
std::vector<Transition> transitions; std::vector<Transition> transitions;
/// @brief Construct a new State.
///
/// @param name The name of this State.
/// @param classifier The Classifier used in this State.
State(const std::string & name, Classifier * classifier); State(const std::string & name, Classifier * classifier);
}; };
private : private :
/// @brief Whether or not the program is in train mode.
bool trainMode; bool trainMode;
/// @brief Store the Classifier by their name.
std::map< std::string, std::unique_ptr<Classifier> > str2classifier; std::map< std::string, std::unique_ptr<Classifier> > str2classifier;
/// @brief Store the State by their name.
std::map< std::string, std::unique_ptr<State> > str2state; std::map< std::string, std::unique_ptr<State> > str2state;
/// @brief Pointer to the current State.
State * currentState; State * currentState;
/// @brief List of all the different classifiers.
std::vector<Classifier*> classifiers; std::vector<Classifier*> classifiers;
public : public :
/// @brief The name of this TapeMachine.
std::string name; std::string name;
public : public :
/// @brief Read and construct a new TapeMachine from a file.
///
/// @param filename The name of the file containing the TapeMachine.
/// @param trainMode Whether or not the program is in train mode.
/// @param expPath The absolute path of the current experiment.
TapeMachine(const std::string & filename, bool trainMode, const std::string & expPath); TapeMachine(const std::string & filename, bool trainMode, const std::string & expPath);
/// @brief Get the current TapeMachine state.
///
/// @return The current state.
State * getCurrentState(); State * getCurrentState();
/// @brief Get the Transition to take given the predicted Action.
///
/// @param action The predicted Action.
///
/// @return The outgoing Transition to take given the predicted Action.
Transition * getTransition(const std::string & action); Transition * getTransition(const std::string & action);
/// @brief Take the given Transition.
///
/// @param transition The Transition to take.
void takeTransition(Transition * transition); void takeTransition(Transition * transition);
/// @brief Return all the Classifier used by this TapeMachine.
///
/// @return All the Classifier used by this TapeMachine.
std::vector<Classifier*> & getClassifiers(); std::vector<Classifier*> & getClassifiers();
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment