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

Fixed remaining bugs

parent 049b00be
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
#include "util.hpp" #include "util.hpp"
#include "Error.hpp" #include "Error.hpp"
#include "ActionBank.hpp" #include "ActionBank.hpp"
#include "ProgramOutput.hpp"
#include <chrono> #include <chrono>
//TODO : Faire se rejoindre les beam en debut de phrase, et faire la moyenne de totalentropy sur le nb d'actions de la phrase.
Decoder::Decoder(TransitionMachine & tm, Config & config) Decoder::Decoder(TransitionMachine & tm, Config & config)
: tm(tm), config(config) : tm(tm), config(config)
{ {
...@@ -183,12 +186,14 @@ struct BeamNode ...@@ -183,12 +186,14 @@ struct BeamNode
{ {
totalEntropy = 0.0; totalEntropy = 0.0;
config.setOutputFile(nullptr); config.setOutputFile(nullptr);
config.totalEntropy = totalEntropy;
} }
BeamNode(BeamNode & other, Action * action, float proba) : tm(other.tm), config(other.config) BeamNode(BeamNode & other, Action * action, float proba) : tm(other.tm), config(other.config)
{ {
totalEntropy = other.totalEntropy + proba; totalEntropy = other.totalEntropy + proba;
this->action = action; this->action = action;
config.setOutputFile(nullptr); config.setOutputFile(nullptr);
config.totalEntropy = totalEntropy;
} }
}; };
...@@ -200,6 +205,8 @@ void Decoder::decode() ...@@ -200,6 +205,8 @@ void Decoder::decode()
decodeBeam(); decodeBeam();
else else
decodeNoBeam(); decodeNoBeam();
ProgramOutput::instance.print(stdout);
} }
void Decoder::decodeNoBeam() void Decoder::decodeNoBeam()
...@@ -252,6 +259,7 @@ void Decoder::decodeNoBeam() ...@@ -252,6 +259,7 @@ void Decoder::decodeNoBeam()
config.printTheRest(); config.printTheRest();
if (ProgramParameters::interactive)
fprintf(stderr, " \n"); fprintf(stderr, " \n");
} }
...@@ -354,6 +362,7 @@ void Decoder::decodeBeam() ...@@ -354,6 +362,7 @@ void Decoder::decodeBeam()
beam[0]->config.printTheRest(); beam[0]->config.printTheRest();
if (ProgramParameters::interactive)
fprintf(stderr, " \n"); fprintf(stderr, " \n");
} }
...@@ -13,9 +13,14 @@ void ProgramOutput::addLine(const std::string & line, float entropy, unsigned in ...@@ -13,9 +13,14 @@ void ProgramOutput::addLine(const std::string & line, float entropy, unsigned in
{ {
lines.emplace_back(line); lines.emplace_back(line);
entropies.emplace_back(entropy); entropies.emplace_back(entropy);
while (index > outputIndexes.size()-1) while ((int)index > ((int)outputIndexes.size())-1)
outputIndexes.emplace_back(-1); outputIndexes.emplace_back(-1);
if (outputIndexes[index] == -1 || entropies[outputIndexes[index]] < entropy) if (outputIndexes[index] == -1 || entropies[outputIndexes[index]] < entropy)
{
if (outputIndexes[index] != -1)
fprintf(stderr, "REMPLACED ! <%u>\n", index);
outputIndexes[index] = lines.size()-1; outputIndexes[index] = lines.size()-1;
} }
}
...@@ -156,6 +156,8 @@ class Config ...@@ -156,6 +156,8 @@ class Config
LimitedStack<std::size_t> hashHistory; LimitedStack<std::size_t> hashHistory;
/// @brief The sequence of Actions that made that Config. /// @brief The sequence of Actions that made that Config.
LimitedStack< std::pair<std::string, Action> > pastActions; LimitedStack< std::pair<std::string, Action> > pastActions;
/// @brief Measure of how much the model is confident in the predictons made in this Config.
float totalEntropy;
public : public :
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "File.hpp" #include "File.hpp"
#include "ProgramParameters.hpp" #include "ProgramParameters.hpp"
#include "Action.hpp" #include "Action.hpp"
#include "ProgramOutput.hpp"
Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(10), pastActions(100) Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(10), pastActions(100)
{ {
...@@ -15,6 +16,7 @@ Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(1 ...@@ -15,6 +16,7 @@ Config::Config(BD & bd, const std::string inputFilename) : bd(bd), hashHistory(1
inputAllRead = false; inputAllRead = false;
for(int i = 0; i < bd.getNbLines(); i++) for(int i = 0; i < bd.getNbLines(); i++)
tapes.emplace_back(bd.getNameOfLine(i), bd.lineIsKnown(i)); tapes.emplace_back(bd.getNameOfLine(i), bd.lineIsKnown(i));
this->totalEntropy = 0;
} }
Config::Config(const Config & other) : bd(other.bd), hashHistory(other.hashHistory), pastActions(other.pastActions) Config::Config(const Config & other) : bd(other.bd), hashHistory(other.hashHistory), pastActions(other.pastActions)
...@@ -28,6 +30,7 @@ Config::Config(const Config & other) : bd(other.bd), hashHistory(other.hashHisto ...@@ -28,6 +30,7 @@ Config::Config(const Config & other) : bd(other.bd), hashHistory(other.hashHisto
this->outputFile = other.outputFile; this->outputFile = other.outputFile;
this->lastIndexPrinted = other.lastIndexPrinted; this->lastIndexPrinted = other.lastIndexPrinted;
this->tapes = other.tapes; this->tapes = other.tapes;
this->totalEntropy = other.totalEntropy;
this->inputFilename = other.inputFilename; this->inputFilename = other.inputFilename;
this->inputAllRead = other.inputAllRead; this->inputAllRead = other.inputAllRead;
...@@ -216,7 +219,7 @@ void Config::printAsOutput(FILE * output, int dataIndex, int realIndex) ...@@ -216,7 +219,7 @@ void Config::printAsOutput(FILE * output, int dataIndex, int realIndex)
} }
} }
fprintf(stderr, "Print %d\n", realIndex); ProgramOutput::instance.addLine(toPrint, totalEntropy, realIndex);
} }
void Config::moveHead(int mvt) void Config::moveHead(int mvt)
...@@ -565,19 +568,15 @@ void Config::printTheRest() ...@@ -565,19 +568,15 @@ void Config::printTheRest()
int tapeSize = tapes[0].size(); int tapeSize = tapes[0].size();
int goalPrintIndex = lastIndexPrinted; int goalPrintIndex = lastIndexPrinted;
int realIndex = tapeSize - ((()-())+()); int realIndex = tapeSize - 1 - ((((tapes[0].dataSize()-(goalPrintIndex == -1 ? 0 : 0)))-(goalPrintIndex+1))+(goalPrintIndex));
for (int i = goalPrintIndex+1; i < (tapes[0].dataSize()-(goalPrintIndex == -1 ? 1 : 0)); i++) for (int i = goalPrintIndex+1; i < (tapes[0].dataSize()-(goalPrintIndex == -1 ? 1 : 0)); i++)
{ {
printAsOutput(outputFile, i, 0); printAsOutput(outputFile, i, realIndex);
fprintf(stderr, "i=%d tapeSize=%d dataSize=%d\n", i, tapeSize, tapes[0].dataSize());
fprintf(stderr, "calcul = %d\n", realIndex);
realIndex++; realIndex++;
} }
for (int i = 0; i < goalPrintIndex; i++) for (int i = 0; i < goalPrintIndex; i++)
{ {
printAsOutput(outputFile, i, 0); printAsOutput(outputFile, i, realIndex);
fprintf(stderr, "i=%d tapeSize=%d dataSize=%d\n", i, tapeSize, tapes[0].dataSize());
fprintf(stderr, "calcul = %d\n", realIndex);
realIndex++; realIndex++;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment