| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013, The Android Open Source Project |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. |
| 15 */ |
| 16 |
| 17 #ifndef LATINIME_FORGETTING_CURVE_UTILS_H |
| 18 #define LATINIME_FORGETTING_CURVE_UTILS_H |
| 19 |
| 20 #include <vector> |
| 21 |
| 22 #include "third_party/prediction/defines.h" |
| 23 #include "third_party/prediction/suggest/policyimpl/dictionary/utils/historical_
info.h" |
| 24 |
| 25 namespace latinime { |
| 26 |
| 27 class HeaderPolicy; |
| 28 |
| 29 class ForgettingCurveUtils { |
| 30 public: |
| 31 static const HistoricalInfo createUpdatedHistoricalInfo( |
| 32 const HistoricalInfo* const originalHistoricalInfo, |
| 33 const int newProbability, |
| 34 const HistoricalInfo* const newHistoricalInfo, |
| 35 const HeaderPolicy* const headerPolicy); |
| 36 |
| 37 static const HistoricalInfo createHistoricalInfoToSave( |
| 38 const HistoricalInfo* const originalHistoricalInfo, |
| 39 const HeaderPolicy* const headerPolicy); |
| 40 |
| 41 static int decodeProbability(const HistoricalInfo* const historicalInfo, |
| 42 const HeaderPolicy* const headerPolicy); |
| 43 |
| 44 static int getProbability(const int encodedUnigramProbability, |
| 45 const int encodedBigramProbability); |
| 46 |
| 47 static bool needsToKeep(const HistoricalInfo* const historicalInfo, |
| 48 const HeaderPolicy* const headerPolicy); |
| 49 |
| 50 static bool needsToDecay(const bool mindsBlockByDecay, |
| 51 const int unigramCount, |
| 52 const int bigramCount, |
| 53 const HeaderPolicy* const headerPolicy); |
| 54 |
| 55 AK_FORCE_INLINE static int getUnigramCountHardLimit( |
| 56 const int maxUnigramCount) { |
| 57 return static_cast<int>(static_cast<float>(maxUnigramCount) * |
| 58 UNIGRAM_COUNT_HARD_LIMIT_WEIGHT); |
| 59 } |
| 60 |
| 61 AK_FORCE_INLINE static int getBigramCountHardLimit(const int maxBigramCount) { |
| 62 return static_cast<int>(static_cast<float>(maxBigramCount) * |
| 63 BIGRAM_COUNT_HARD_LIMIT_WEIGHT); |
| 64 } |
| 65 |
| 66 private: |
| 67 DISALLOW_IMPLICIT_CONSTRUCTORS(ForgettingCurveUtils); |
| 68 |
| 69 class ProbabilityTable { |
| 70 public: |
| 71 ProbabilityTable(); |
| 72 |
| 73 int getProbability(const int tableId, |
| 74 const int level, |
| 75 const int elapsedTimeStepCount) const { |
| 76 return mTables[tableId][level][elapsedTimeStepCount]; |
| 77 } |
| 78 |
| 79 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(ProbabilityTable); |
| 81 |
| 82 static const int PROBABILITY_TABLE_COUNT; |
| 83 static const int WEAK_PROBABILITY_TABLE_ID; |
| 84 static const int MODEST_PROBABILITY_TABLE_ID; |
| 85 static const int STRONG_PROBABILITY_TABLE_ID; |
| 86 static const int AGGRESSIVE_PROBABILITY_TABLE_ID; |
| 87 |
| 88 static const int WEAK_MAX_PROBABILITY; |
| 89 static const int MODEST_BASE_PROBABILITY; |
| 90 static const int STRONG_BASE_PROBABILITY; |
| 91 static const int AGGRESSIVE_BASE_PROBABILITY; |
| 92 |
| 93 std::vector<std::vector<std::vector<int>>> mTables; |
| 94 |
| 95 static int getBaseProbabilityForLevel(const int tableId, const int level); |
| 96 }; |
| 97 |
| 98 static const int MULTIPLIER_TWO_IN_PROBABILITY_SCALE; |
| 99 static const int DECAY_INTERVAL_SECONDS; |
| 100 |
| 101 static const int MAX_LEVEL; |
| 102 static const int MIN_VISIBLE_LEVEL; |
| 103 static const int MAX_ELAPSED_TIME_STEP_COUNT; |
| 104 static const int DISCARD_LEVEL_ZERO_ENTRY_TIME_STEP_COUNT_THRESHOLD; |
| 105 |
| 106 static const float UNIGRAM_COUNT_HARD_LIMIT_WEIGHT; |
| 107 static const float BIGRAM_COUNT_HARD_LIMIT_WEIGHT; |
| 108 |
| 109 static const ProbabilityTable sProbabilityTable; |
| 110 |
| 111 static int backoff(const int unigramProbability); |
| 112 static int getElapsedTimeStepCount(const int timestamp, |
| 113 const int durationToLevelDown); |
| 114 static int clampToVisibleEntryLevelRange(const int level); |
| 115 static int clampToValidLevelRange(const int level); |
| 116 static int clampToValidCountRange(const int count, |
| 117 const HeaderPolicy* const headerPolicy); |
| 118 static int clampToValidTimeStepCountRange(const int timeStepCount); |
| 119 }; |
| 120 } // namespace latinime |
| 121 #endif /* LATINIME_FORGETTING_CURVE_UTILS_H */ |
| OLD | NEW |