Merge "Create more aggressive probability tables."

main
Keisuke Kuroyanagi 2014-02-26 11:18:43 +00:00 committed by Android (Google) Code Review
commit 7919a594fc
2 changed files with 44 additions and 6 deletions

View File

@ -148,7 +148,15 @@ const ForgettingCurveUtils::ProbabilityTable ForgettingCurveUtils::sProbabilityT
return (TimeKeeper::peekCurrentTime() - timestamp) / TIME_STEP_DURATION_IN_SECONDS; return (TimeKeeper::peekCurrentTime() - timestamp) / TIME_STEP_DURATION_IN_SECONDS;
} }
const int ForgettingCurveUtils::ProbabilityTable::PROBABILITY_TABLE_COUNT = 1; const int ForgettingCurveUtils::ProbabilityTable::PROBABILITY_TABLE_COUNT = 4;
const int ForgettingCurveUtils::ProbabilityTable::WEAK_PROBABILITY_TABLE_ID = 0;
const int ForgettingCurveUtils::ProbabilityTable::MODEST_PROBABILITY_TABLE_ID = 1;
const int ForgettingCurveUtils::ProbabilityTable::STRONG_PROBABILITY_TABLE_ID = 2;
const int ForgettingCurveUtils::ProbabilityTable::AGGRESSIVE_PROBABILITY_TABLE_ID = 3;
const int ForgettingCurveUtils::ProbabilityTable::MODEST_BASE_PROBABILITY = 32;
const int ForgettingCurveUtils::ProbabilityTable::STRONG_BASE_PROBABILITY = 35;
const int ForgettingCurveUtils::ProbabilityTable::AGGRESSIVE_BASE_PROBABILITY = 40;
ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() { ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() {
mTables.resize(PROBABILITY_TABLE_COUNT); mTables.resize(PROBABILITY_TABLE_COUNT);
@ -156,8 +164,8 @@ ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() {
mTables[tableId].resize(MAX_LEVEL + 1); mTables[tableId].resize(MAX_LEVEL + 1);
for (int level = 0; level <= MAX_LEVEL; ++level) { for (int level = 0; level <= MAX_LEVEL; ++level) {
mTables[tableId][level].resize(MAX_ELAPSED_TIME_STEP_COUNT + 1); mTables[tableId][level].resize(MAX_ELAPSED_TIME_STEP_COUNT + 1);
const float initialProbability = const float initialProbability = getBaseProbabilityForLevel(tableId, level);
static_cast<float>(MAX_COMPUTED_PROBABILITY / (1 << (MAX_LEVEL - level))); const float endProbability = getBaseProbabilityForLevel(tableId, level - 1);
for (int timeStepCount = 0; timeStepCount <= MAX_ELAPSED_TIME_STEP_COUNT; for (int timeStepCount = 0; timeStepCount <= MAX_ELAPSED_TIME_STEP_COUNT;
++timeStepCount) { ++timeStepCount) {
if (level == 0) { if (level == 0) {
@ -166,7 +174,8 @@ ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() {
} }
const int elapsedTime = timeStepCount * TIME_STEP_DURATION_IN_SECONDS; const int elapsedTime = timeStepCount * TIME_STEP_DURATION_IN_SECONDS;
const float probability = initialProbability const float probability = initialProbability
* powf(2.0f, -1.0f * static_cast<float>(elapsedTime) * powf(initialProbability / endProbability,
-1.0f * static_cast<float>(elapsedTime)
/ static_cast<float>(TIME_STEP_DURATION_IN_SECONDS / static_cast<float>(TIME_STEP_DURATION_IN_SECONDS
* (MAX_ELAPSED_TIME_STEP_COUNT + 1))); * (MAX_ELAPSED_TIME_STEP_COUNT + 1)));
mTables[tableId][level][timeStepCount] = mTables[tableId][level][timeStepCount] =
@ -176,4 +185,23 @@ ForgettingCurveUtils::ProbabilityTable::ProbabilityTable() : mTables() {
} }
} }
/* static */ int ForgettingCurveUtils::ProbabilityTable::getBaseProbabilityForLevel(
const int tableId, const int level) {
if (tableId == WEAK_PROBABILITY_TABLE_ID) {
// Max probability is 127.
return static_cast<float>(MAX_COMPUTED_PROBABILITY / (1 << (MAX_LEVEL - level)));
} else if (tableId == MODEST_PROBABILITY_TABLE_ID) {
// Max probability is 128.
return static_cast<float>(MODEST_BASE_PROBABILITY * (level + 1));
} else if (tableId == STRONG_PROBABILITY_TABLE_ID) {
// Max probability is 140.
return static_cast<float>(STRONG_BASE_PROBABILITY * (level + 1));
} else if (tableId == AGGRESSIVE_PROBABILITY_TABLE_ID) {
// Max probability is 160.
return static_cast<float>(AGGRESSIVE_BASE_PROBABILITY * (level + 1));
} else {
return NOT_A_PROBABILITY;
}
}
} // namespace latinime } // namespace latinime

View File

@ -68,8 +68,18 @@ class ForgettingCurveUtils {
DISALLOW_COPY_AND_ASSIGN(ProbabilityTable); DISALLOW_COPY_AND_ASSIGN(ProbabilityTable);
static const int PROBABILITY_TABLE_COUNT; static const int PROBABILITY_TABLE_COUNT;
static const int WEAK_PROBABILITY_TABLE_ID;
static const int MODEST_PROBABILITY_TABLE_ID;
static const int STRONG_PROBABILITY_TABLE_ID;
static const int AGGRESSIVE_PROBABILITY_TABLE_ID;
static const int MODEST_BASE_PROBABILITY;
static const int STRONG_BASE_PROBABILITY;
static const int AGGRESSIVE_BASE_PROBABILITY;
std::vector<std::vector<std::vector<int> > > mTables; std::vector<std::vector<std::vector<int> > > mTables;
static int getBaseProbabilityForLevel(const int tableId, const int level);
}; };
static const int MULTIPLIER_TWO_IN_PROBABILITY_SCALE; static const int MULTIPLIER_TWO_IN_PROBABILITY_SCALE;