Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d55ccbf7 authored by Satoshi Kataoka's avatar Satoshi Kataoka Committed by Android Git Automerger
Browse files

am 837f46dc: Enable touch coordinate correction for new algorithm

* commit '837f46dc':
  Enable touch coordinate correction for new algorithm
parents be0e013b 837f46dc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -675,7 +675,7 @@ inline static bool isUpperCase(unsigned short c) {
                multiplyIntCapped(typedLetterMultiplier, &finalFreq);
            }
            const float factor =
                    SuggestUtils::getDistanceScalingFactor(static_cast<float>(squaredDistance));
                    SuggestUtils::getLengthScalingFactor(static_cast<float>(squaredDistance));
            if (factor > 0.0f) {
                multiplyRate(static_cast<int>(factor * 100.0f), &finalFreq);
            } else if (squaredDistance == PROXIMITY_CHAR_WITHOUT_DISTANCE_INFO) {
+7 −5
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
        mSampledTimes.clear();
        mSampledInputIndice.clear();
        mSampledLengthCache.clear();
        mSampledDistanceCache_G.clear();
        mSampledNormalizedSquaredLengthCache.clear();
        mSampledNearKeySets.clear();
        mSampledSearchKeySets.clear();
        mSpeedRates.clear();
@@ -122,14 +122,15 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
    if (mSampledInputSize > 0) {
        ProximityInfoStateUtils::initGeometricDistanceInfos(mProximityInfo, mSampledInputSize,
                lastSavedInputSize, verticalSweetSpotScale, &mSampledInputXs, &mSampledInputYs,
                &mSampledNearKeySets, &mSampledDistanceCache_G);
                &mSampledNearKeySets, &mSampledNormalizedSquaredLengthCache);
        if (isGeometric) {
            // updates probabilities of skipping or mapping each key for all points.
            ProximityInfoStateUtils::updateAlignPointProbabilities(
                    mMaxPointToKeyLength, mProximityInfo->getMostCommonKeyWidth(),
                    mProximityInfo->getKeyCount(), lastSavedInputSize, mSampledInputSize,
                    &mSampledInputXs, &mSampledInputYs, &mSpeedRates, &mSampledLengthCache,
                    &mSampledDistanceCache_G, &mSampledNearKeySets, &mCharProbabilities);
                    &mSampledNormalizedSquaredLengthCache, &mSampledNearKeySets,
                    &mCharProbabilities);
            ProximityInfoStateUtils::updateSampledSearchKeySets(mProximityInfo,
                    mSampledInputSize, lastSavedInputSize, &mSampledLengthCache,
                    &mSampledNearKeySets, &mSampledSearchKeySets,
@@ -171,7 +172,7 @@ float ProximityInfoState::getPointToKeyLength(
    const int keyId = mProximityInfo->getKeyIndexOf(codePoint);
    if (keyId != NOT_AN_INDEX) {
        const int index = inputIndex * mProximityInfo->getKeyCount() + keyId;
        return min(mSampledDistanceCache_G[index], mMaxPointToKeyLength);
        return min(mSampledNormalizedSquaredLengthCache[index], mMaxPointToKeyLength);
    }
    if (isIntentionalOmissionCodePoint(codePoint)) {
        return 0.0f;
@@ -183,7 +184,8 @@ float ProximityInfoState::getPointToKeyLength(
float ProximityInfoState::getPointToKeyByIdLength(
        const int inputIndex, const int keyId) const {
    return ProximityInfoStateUtils::getPointToKeyByIdLength(mMaxPointToKeyLength,
            &mSampledDistanceCache_G, mProximityInfo->getKeyCount(), inputIndex, keyId);
            &mSampledNormalizedSquaredLengthCache, mProximityInfo->getKeyCount(), inputIndex,
            keyId);
}

// In the following function, c is the current character of the dictionary word currently examined.
+5 −3
Original line number Diff line number Diff line
@@ -49,8 +49,8 @@ class ProximityInfoState {
              mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
              mIsContinuousSuggestionPossible(false), mSampledInputXs(), mSampledInputYs(),
              mSampledTimes(), mSampledInputIndice(), mSampledLengthCache(),
              mBeelineSpeedPercentiles(), mSampledDistanceCache_G(), mSpeedRates(), mDirections(),
              mCharProbabilities(), mSampledNearKeySets(), mSampledSearchKeySets(),
              mBeelineSpeedPercentiles(), mSampledNormalizedSquaredLengthCache(), mSpeedRates(),
              mDirections(), mCharProbabilities(), mSampledNearKeySets(), mSampledSearchKeySets(),
              mSampledSearchKeyVectors(), mTouchPositionCorrectionEnabled(false),
              mSampledInputSize(0), mMostProbableStringProbability(0.0f) {
        memset(mInputProximities, 0, sizeof(mInputProximities));
@@ -147,7 +147,9 @@ class ProximityInfoState {
        return mIsContinuousSuggestionPossible;
    }

    // TODO: Rename s/Length/NormalizedSquaredLength/
    float getPointToKeyByIdLength(const int inputIndex, const int keyId) const;
    // TODO: Rename s/Length/NormalizedSquaredLength/
    float getPointToKeyLength(const int inputIndex, const int codePoint) const;

    ProximityType getProximityType(const int index, const int codePoint,
@@ -231,7 +233,7 @@ class ProximityInfoState {
    std::vector<int> mSampledInputIndice;
    std::vector<int> mSampledLengthCache;
    std::vector<int> mBeelineSpeedPercentiles;
    std::vector<float> mSampledDistanceCache_G;
    std::vector<float> mSampledNormalizedSquaredLengthCache;
    std::vector<float> mSpeedRates;
    std::vector<float> mDirections;
    // probabilities of skipping or mapping to a key for each point.
+29 −25
Original line number Diff line number Diff line
@@ -225,13 +225,13 @@ namespace latinime {
        const int lastSavedInputSize, const float verticalSweetSpotScale,
        const std::vector<int> *const sampledInputXs,
        const std::vector<int> *const sampledInputYs,
        std::vector<NearKeycodesSet> *SampledNearKeySets,
        std::vector<float> *SampledDistanceCache_G) {
    SampledNearKeySets->resize(sampledInputSize);
        std::vector<NearKeycodesSet> *sampledNearKeySets,
        std::vector<float> *sampledNormalizedSquaredLengthCache) {
    sampledNearKeySets->resize(sampledInputSize);
    const int keyCount = proximityInfo->getKeyCount();
    SampledDistanceCache_G->resize(sampledInputSize * keyCount);
    sampledNormalizedSquaredLengthCache->resize(sampledInputSize * keyCount);
    for (int i = lastSavedInputSize; i < sampledInputSize; ++i) {
        (*SampledNearKeySets)[i].reset();
        (*sampledNearKeySets)[i].reset();
        for (int k = 0; k < keyCount; ++k) {
            const int index = i * keyCount + k;
            const int x = (*sampledInputXs)[i];
@@ -239,10 +239,10 @@ namespace latinime {
            const float normalizedSquaredDistance =
                    proximityInfo->getNormalizedSquaredDistanceFromCenterFloatG(
                            k, x, y, verticalSweetSpotScale);
            (*SampledDistanceCache_G)[index] = normalizedSquaredDistance;
            (*sampledNormalizedSquaredLengthCache)[index] = normalizedSquaredDistance;
            if (normalizedSquaredDistance
                    < ProximityInfoParams::NEAR_KEY_NORMALIZED_SQUARED_THRESHOLD) {
                (*SampledNearKeySets)[i][k] = true;
                (*sampledNearKeySets)[i][k] = true;
            }
        }
    }
@@ -642,11 +642,11 @@ namespace latinime {
// This function basically converts from a length to an edit distance. Accordingly, it's obviously
// wrong to compare with mMaxPointToKeyLength.
/* static */ float ProximityInfoStateUtils::getPointToKeyByIdLength(const float maxPointToKeyLength,
        const std::vector<float> *const SampledDistanceCache_G, const int keyCount,
        const std::vector<float> *const sampledNormalizedSquaredLengthCache, const int keyCount,
        const int inputIndex, const int keyId) {
    if (keyId != NOT_AN_INDEX) {
        const int index = inputIndex * keyCount + keyId;
        return min((*SampledDistanceCache_G)[index], maxPointToKeyLength);
        return min((*sampledNormalizedSquaredLengthCache)[index], maxPointToKeyLength);
    }
    // If the char is not a key on the keyboard then return the max length.
    return static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
@@ -660,8 +660,8 @@ namespace latinime {
        const std::vector<int> *const sampledInputYs,
        const std::vector<float> *const sampledSpeedRates,
        const std::vector<int> *const sampledLengthCache,
        const std::vector<float> *const SampledDistanceCache_G,
        std::vector<NearKeycodesSet> *SampledNearKeySets,
        const std::vector<float> *const sampledNormalizedSquaredLengthCache,
        std::vector<NearKeycodesSet> *sampledNearKeySets,
        std::vector<hash_map_compat<int, float> > *charProbabilities) {
    charProbabilities->resize(sampledInputSize);
    // Calculates probabilities of using a point as a correlated point with the character
@@ -677,9 +677,9 @@ namespace latinime {

        float nearestKeyDistance = static_cast<float>(MAX_VALUE_FOR_WEIGHTING);
        for (int j = 0; j < keyCount; ++j) {
            if ((*SampledNearKeySets)[i].test(j)) {
            if ((*sampledNearKeySets)[i].test(j)) {
                const float distance = getPointToKeyByIdLength(
                        maxPointToKeyLength, SampledDistanceCache_G, keyCount, i, j);
                        maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount, i, j);
                if (distance < nearestKeyDistance) {
                    nearestKeyDistance = distance;
                }
@@ -758,14 +758,15 @@ namespace latinime {
        // Summing up probability densities of all near keys.
        float sumOfProbabilityDensities = 0.0f;
        for (int j = 0; j < keyCount; ++j) {
            if ((*SampledNearKeySets)[i].test(j)) {
            if ((*sampledNearKeySets)[i].test(j)) {
                float distance = sqrtf(getPointToKeyByIdLength(
                        maxPointToKeyLength, SampledDistanceCache_G, keyCount, i, j));
                        maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount, i, j));
                if (i == 0 && i != sampledInputSize - 1) {
                    // For the first point, weighted average of distances from first point and the
                    // next point to the key is used as a point to key distance.
                    const float nextDistance = sqrtf(getPointToKeyByIdLength(
                            maxPointToKeyLength, SampledDistanceCache_G, keyCount, i + 1, j));
                            maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount,
                            i + 1, j));
                    if (nextDistance < distance) {
                        // The distance of the first point tends to bigger than continuing
                        // points because the first touch by the user can be sloppy.
@@ -779,7 +780,8 @@ namespace latinime {
                    // For the first point, weighted average of distances from last point and
                    // the previous point to the key is used as a point to key distance.
                    const float previousDistance = sqrtf(getPointToKeyByIdLength(
                            maxPointToKeyLength, SampledDistanceCache_G, keyCount, i - 1, j));
                            maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount,
                            i - 1, j));
                    if (previousDistance < distance) {
                        // The distance of the last point tends to bigger than continuing points
                        // because the last touch by the user can be sloppy. So we promote the
@@ -798,14 +800,15 @@ namespace latinime {

        // Split the probability of an input point to keys that are close to the input point.
        for (int j = 0; j < keyCount; ++j) {
            if ((*SampledNearKeySets)[i].test(j)) {
            if ((*sampledNearKeySets)[i].test(j)) {
                float distance = sqrtf(getPointToKeyByIdLength(
                        maxPointToKeyLength, SampledDistanceCache_G, keyCount, i, j));
                        maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount, i, j));
                if (i == 0 && i != sampledInputSize - 1) {
                    // For the first point, weighted average of distances from the first point and
                    // the next point to the key is used as a point to key distance.
                    const float prevDistance = sqrtf(getPointToKeyByIdLength(
                            maxPointToKeyLength, SampledDistanceCache_G, keyCount, i + 1, j));
                            maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount,
                            i + 1, j));
                    if (prevDistance < distance) {
                        distance = (distance
                                + prevDistance * ProximityInfoParams::NEXT_DISTANCE_WEIGHT)
@@ -815,7 +818,8 @@ namespace latinime {
                    // For the first point, weighted average of distances from last point and
                    // the previous point to the key is used as a point to key distance.
                    const float prevDistance = sqrtf(getPointToKeyByIdLength(
                            maxPointToKeyLength, SampledDistanceCache_G, keyCount, i - 1, j));
                            maxPointToKeyLength, sampledNormalizedSquaredLengthCache, keyCount,
                            i - 1, j));
                    if (prevDistance < distance) {
                        distance = (distance
                                + prevDistance * ProximityInfoParams::PREV_DISTANCE_WEIGHT)
@@ -882,10 +886,10 @@ namespace latinime {
        for (int j = 0; j < keyCount; ++j) {
            hash_map_compat<int, float>::iterator it = (*charProbabilities)[i].find(j);
            if (it == (*charProbabilities)[i].end()){
                (*SampledNearKeySets)[i].reset(j);
                (*sampledNearKeySets)[i].reset(j);
            } else if(it->second < ProximityInfoParams::MIN_PROBABILITY) {
                // Erases from near keys vector because it has very low probability.
                (*SampledNearKeySets)[i].reset(j);
                (*sampledNearKeySets)[i].reset(j);
                (*charProbabilities)[i].erase(j);
            } else {
                it->second = -logf(it->second);
@@ -899,7 +903,7 @@ namespace latinime {
        const ProximityInfo *const proximityInfo, const int sampledInputSize,
        const int lastSavedInputSize,
        const std::vector<int> *const sampledLengthCache,
        const std::vector<NearKeycodesSet> *const SampledNearKeySets,
        const std::vector<NearKeycodesSet> *const sampledNearKeySets,
        std::vector<NearKeycodesSet> *sampledSearchKeySets,
        std::vector<std::vector<int> > *sampledSearchKeyVectors) {
    sampledSearchKeySets->resize(sampledInputSize);
@@ -916,7 +920,7 @@ namespace latinime {
            if ((*sampledLengthCache)[j] - (*sampledLengthCache)[i] >= readForwordLength) {
                break;
            }
            (*sampledSearchKeySets)[i] |= (*SampledNearKeySets)[j];
            (*sampledSearchKeySets)[i] |= (*sampledNearKeySets)[j];
        }
    }
    const int keyCount = proximityInfo->getKeyCount();
+6 −6
Original line number Diff line number Diff line
@@ -71,25 +71,25 @@ class ProximityInfoStateUtils {
            const std::vector<int> *const sampledInputYs,
            const std::vector<float> *const sampledSpeedRates,
            const std::vector<int> *const sampledLengthCache,
            const std::vector<float> *const SampledDistanceCache_G,
            std::vector<NearKeycodesSet> *SampledNearKeySets,
            const std::vector<float> *const sampledNormalizedSquaredLengthCache,
            std::vector<NearKeycodesSet> *sampledNearKeySets,
            std::vector<hash_map_compat<int, float> > *charProbabilities);
    static void updateSampledSearchKeySets(const ProximityInfo *const proximityInfo,
            const int sampledInputSize, const int lastSavedInputSize,
            const std::vector<int> *const sampledLengthCache,
            const std::vector<NearKeycodesSet> *const SampledNearKeySets,
            const std::vector<NearKeycodesSet> *const sampledNearKeySets,
            std::vector<NearKeycodesSet> *sampledSearchKeySets,
            std::vector<std::vector<int> > *sampledSearchKeyVectors);
    static float getPointToKeyByIdLength(const float maxPointToKeyLength,
            const std::vector<float> *const SampledDistanceCache_G, const int keyCount,
            const std::vector<float> *const sampledNormalizedSquaredLengthCache, const int keyCount,
            const int inputIndex, const int keyId);
    static void initGeometricDistanceInfos(const ProximityInfo *const proximityInfo,
            const int sampledInputSize, const int lastSavedInputSize,
            const float verticalSweetSpotScale,
            const std::vector<int> *const sampledInputXs,
            const std::vector<int> *const sampledInputYs,
            std::vector<NearKeycodesSet> *SampledNearKeySets,
            std::vector<float> *SampledDistanceCache_G);
            std::vector<NearKeycodesSet> *sampledNearKeySets,
            std::vector<float> *sampledNormalizedSquaredLengthCache);
    static void initPrimaryInputWord(const int inputSize, const int *const inputProximities,
            int *primaryInputWord);
    static void initNormalizedSquaredDistances(const ProximityInfo *const proximityInfo,
Loading