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

Fixed bugs

parent 37acfeb0
No related branches found
No related tags found
No related merge requests found
...@@ -139,12 +139,13 @@ void computeSpeed(std::chrono::time_point<std::chrono::system_clock> & pastTime, ...@@ -139,12 +139,13 @@ void computeSpeed(std::chrono::time_point<std::chrono::system_clock> & pastTime,
void computeAndPrintSequenceEntropy(Config & config, bool & justFlipped, Errors & errors, float & entropyAccumulator, int & nbActionsInSequence) void computeAndPrintSequenceEntropy(Config & config, bool & justFlipped, Errors & errors, float & entropyAccumulator, int & nbActionsInSequence)
{ {
if (ProgramParameters::printEntropy || ProgramParameters::errorAnalysis) if (config.getHead() >= 1 && config.getTape(ProgramParameters::sequenceDelimiterTape)[-1] != ProgramParameters::sequenceDelimiter)
{
if (config.getHead() >= 1 && config.getTape(ProgramParameters::sequenceDelimiterTape)[config.getHead()-1] != ProgramParameters::sequenceDelimiter)
justFlipped = false; justFlipped = false;
if ((config.getHead() >= 1 && config.getTape(ProgramParameters::sequenceDelimiterTape)[config.getHead()-1] == ProgramParameters::sequenceDelimiter && !justFlipped)) if ((config.getHead() >= 1 && config.getTape(ProgramParameters::sequenceDelimiterTape)[-1] == ProgramParameters::sequenceDelimiter && !justFlipped))
justFlipped = true;
if (justFlipped && (ProgramParameters::printEntropy || ProgramParameters::errorAnalysis))
{ {
justFlipped = true; justFlipped = true;
errors.newSequence(); errors.newSequence();
...@@ -155,7 +156,6 @@ void computeAndPrintSequenceEntropy(Config & config, bool & justFlipped, Errors ...@@ -155,7 +156,6 @@ void computeAndPrintSequenceEntropy(Config & config, bool & justFlipped, Errors
entropyAccumulator = 0.0; entropyAccumulator = 0.0;
} }
} }
}
void computeAndRecordEntropy(Config & config, Classifier::WeightedActions & weightedActions, float & entropyAccumulator) void computeAndRecordEntropy(Config & config, Classifier::WeightedActions & weightedActions, float & entropyAccumulator)
{ {
...@@ -180,7 +180,8 @@ struct BeamNode ...@@ -180,7 +180,8 @@ struct BeamNode
Config config; Config config;
Action * action; Action * action;
int nbActions; int nbActions;
bool justFlipped;
int lastFlippedIndex;
double getEntropy() double getEntropy()
{ {
...@@ -189,15 +190,31 @@ struct BeamNode ...@@ -189,15 +190,31 @@ struct BeamNode
return totalEntropy / nbActions; return totalEntropy / nbActions;
} }
void setFlipped()
{
if (config.getHead() > lastFlippedIndex && config.getTape(ProgramParameters::sequenceDelimiterTape)[-1] == ProgramParameters::sequenceDelimiter)
{
justFlipped = true;
lastFlippedIndex = config.getHead();
}
else
{
justFlipped = false;
}
}
BeamNode(TransitionMachine & tm, Config & config) : tm(tm), config(config) BeamNode(TransitionMachine & tm, Config & config) : tm(tm), config(config)
{ {
justFlipped = false;
totalEntropy = 0.0; totalEntropy = 0.0;
nbActions = 0; nbActions = 0;
lastFlippedIndex = 0;
config.setOutputFile(nullptr); config.setOutputFile(nullptr);
config.totalEntropy = totalEntropy; 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)
{ {
justFlipped = false;
lastFlippedIndex = other.lastFlippedIndex;
totalEntropy = other.totalEntropy + proba; totalEntropy = other.totalEntropy + proba;
this->action = action; this->action = action;
nbActions = other.nbActions + 1; nbActions = other.nbActions + 1;
...@@ -288,6 +305,7 @@ void Decoder::decodeBeam() ...@@ -288,6 +305,7 @@ void Decoder::decodeBeam()
std::vector< std::shared_ptr<BeamNode> > beam; std::vector< std::shared_ptr<BeamNode> > beam;
std::vector< std::shared_ptr<BeamNode> > otherBeam; std::vector< std::shared_ptr<BeamNode> > otherBeam;
std::vector< std::shared_ptr<BeamNode> > justFlippedBeam;
beam.emplace_back(new BeamNode(tm, config)); beam.emplace_back(new BeamNode(tm, config));
auto sortBeam = [&beam]() auto sortBeam = [&beam]()
...@@ -331,9 +349,6 @@ void Decoder::decodeBeam() ...@@ -331,9 +349,6 @@ void Decoder::decodeBeam()
break; break;
} }
if (mustContinue)
continue;
beam = otherBeam; beam = otherBeam;
sortBeam(); sortBeam();
beam.resize(std::min((int)beam.size(), ProgramParameters::beamSize)); beam.resize(std::min((int)beam.size(), ProgramParameters::beamSize));
...@@ -363,11 +378,26 @@ void Decoder::decodeBeam() ...@@ -363,11 +378,26 @@ void Decoder::decodeBeam()
computeAndRecordEntropy(config, node->weightedActions, entropyAccumulator); computeAndRecordEntropy(config, node->weightedActions, entropyAccumulator);
computeAndPrintSequenceEntropy(config, justFlipped, errors, entropyAccumulator, nbActionsInSequence); computeAndPrintSequenceEntropy(config, justFlipped, errors, entropyAccumulator, nbActionsInSequence);
} }
node->setFlipped();
} }
if (justFlipped) for (unsigned int i = 0; i < beam.size(); i++)
{ {
beam.resize(std::min(1,(int)beam.size())); if (beam[i]->justFlipped)
{
justFlippedBeam.push_back(beam[i]);
beam[i] = beam[beam.size()-1];
beam.pop_back();
i--;
}
}
if ((int)justFlippedBeam.size() >= ProgramParameters::beamSize)
{
beam = justFlippedBeam;
justFlippedBeam.clear();
sortBeam();
beam.resize(1);
if (!beam.empty()) if (!beam.empty())
{ {
beam[0]->totalEntropy = 0.0; beam[0]->totalEntropy = 0.0;
......
...@@ -17,10 +17,6 @@ void ProgramOutput::addLine(const std::string & line, float entropy, unsigned in ...@@ -17,10 +17,6 @@ void ProgramOutput::addLine(const std::string & line, float entropy, unsigned in
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;
} }
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment