Skip to content

Commit

Permalink
Wow, caching works?
Browse files Browse the repository at this point in the history
  • Loading branch information
naiaden committed Feb 15, 2017
1 parent c165d8a commit 9710982
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
16 changes: 7 additions & 9 deletions EntropyInterpolationStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ double EntropyInterpolationStrategy::get(const Pattern& context)
{
int contextSize = context.size();

std::map<Pattern, double>::const_iterator i = weights.find(context);
if(i == weights.end())
auto it = weights.find(context);
if(it != weights.end())
{
return it->second;
}
else
{
double entropySum = 0.0;

Expand All @@ -54,15 +58,9 @@ double EntropyInterpolationStrategy::get(const Pattern& context)

L_S << "Entropyi: get(" << contextSize << ") sum:" << sum << " entropysum:" << entropySum << " entropy:" << entropy << "\n";

// weights[context] = entropy;
weights.emplace(std::make_pair(context, entropy));
weights[context] = entropy;

return entropy;

// add to map
} else
{
return i->second;
}
}

Expand Down
6 changes: 5 additions & 1 deletion EntropyInterpolationStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "InterpolationStrategy.h"
#include "LanguageModel.h"

#include <patternstore.h>
#include <unordered_map>

namespace SLM {

class EntropyInterpolationStrategy: public InterpolationStrategy {
Expand All @@ -21,7 +24,8 @@ class EntropyInterpolationStrategy: public InterpolationStrategy {
double get(const Pattern& context);
std::string name() const;
protected:
std::map<Pattern, double> weights;
//std::map<const Pattern, double> weights;
std::unordered_map<Pattern, double> weights;
SLM::LanguageModel* lm;
};

Expand Down

0 comments on commit 9710982

Please sign in to comment.