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

Commit 26c80662 authored by Keisuke Kuroyanagi's avatar Keisuke Kuroyanagi
Browse files

Use 2D normal distribution for gesture.

Bug: 13799846
Bug: 10701902
Bug: 9505397

Change-Id: I6c3f84f035f2310f2f7dfec4432ebdb6e50d5df0
parent e3d57ae7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -101,4 +101,5 @@ LATIN_IME_CORE_SRC_FILES := \

LATIN_IME_CORE_TEST_FILES := \
    defines_test.cpp \
    suggest/core/layout/normal_distribution_2d_test.cpp \
    utils/autocorrection_threshold_utils_test.cpp
+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef LATINIME_NORMAL_DISTRIBUTION_2D_H
#define LATINIME_NORMAL_DISTRIBUTION_2D_H

#include <cmath>

#include "defines.h"
#include "suggest/core/layout/geometry_utils.h"
#include "suggest/core/layout/normal_distribution.h"

namespace latinime {

// Normal distribution on a 2D plane. The covariance is always zero, but the distribution can be
// rotated.
class NormalDistribution2D {
 public:
    NormalDistribution2D(const float uX, const float sigmaX, const float uY, const float sigmaY,
            const float theta)
            : mXDistribution(0.0f, sigmaX), mYDistribution(0.0f, sigmaY), mUX(uX), mUY(uY),
              mSinTheta(sinf(theta)), mCosTheta(cosf(theta)) {}

    float getProbabilityDensity(const float x, const float y) const {
        // Shift
        const float shiftedX = x - mUX;
        const float shiftedY = y - mUY;
        // Rotate
        const float rotatedShiftedX = mCosTheta * shiftedX + mSinTheta * shiftedY;
        const float rotatedShiftedY = -mSinTheta * shiftedX + mCosTheta * shiftedY;
        return mXDistribution.getProbabilityDensity(rotatedShiftedX)
                * mYDistribution.getProbabilityDensity(rotatedShiftedY);
    }

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(NormalDistribution2D);

    const NormalDistribution mXDistribution;
    const NormalDistribution mYDistribution;
    const float mUX;
    const float mUY;
    const float mSinTheta;
    const float mCosTheta;
};
} // namespace latinime
#endif // LATINIME_NORMAL_DISTRIBUTION_2D_H
+6 −2
Original line number Diff line number Diff line
@@ -76,8 +76,12 @@ const float ProximityInfoParams::MAX_SPEEDxANGLE_RATE_FOR_STANDARD_DEVIATION = 0
const float ProximityInfoParams::SPEEDxNEAREST_WEIGHT_FOR_STANDARD_DEVIATION = 0.5f;
const float ProximityInfoParams::MAX_SPEEDxNEAREST_RATE_FOR_STANDARD_DEVIATION = 0.15f;
const float ProximityInfoParams::MIN_STANDARD_DEVIATION = 0.37f;
const float ProximityInfoParams::PREV_DISTANCE_WEIGHT = 0.5f;
const float ProximityInfoParams::NEXT_DISTANCE_WEIGHT = 0.6f;
const float ProximityInfoParams::STANDARD_DEVIATION_X_WEIGHT_FOR_FIRST = 1.25f;
const float ProximityInfoParams::STANDARD_DEVIATION_Y_WEIGHT_FOR_FIRST = 0.85f;
const float ProximityInfoParams::STANDARD_DEVIATION_X_WEIGHT_FOR_LAST = 1.4f;
const float ProximityInfoParams::STANDARD_DEVIATION_Y_WEIGHT_FOR_LAST = 0.95f;
const float ProximityInfoParams::STANDARD_DEVIATION_X_WEIGHT = 1.1f;
const float ProximityInfoParams::STANDARD_DEVIATION_Y_WEIGHT = 0.95f;

// Used by ProximityInfoStateUtils::suppressCharProbabilities()
const float ProximityInfoParams::SUPPRESSION_LENGTH_WEIGHT = 1.5f;
+7 −2
Original line number Diff line number Diff line
@@ -78,8 +78,13 @@ class ProximityInfoParams {
    static const float SPEEDxNEAREST_WEIGHT_FOR_STANDARD_DEVIATION;
    static const float MAX_SPEEDxNEAREST_RATE_FOR_STANDARD_DEVIATION;
    static const float MIN_STANDARD_DEVIATION;
    static const float PREV_DISTANCE_WEIGHT;
    static const float NEXT_DISTANCE_WEIGHT;
    // X means gesture's direction. Y means gesture's orthogonal direction.
    static const float STANDARD_DEVIATION_X_WEIGHT_FOR_FIRST;
    static const float STANDARD_DEVIATION_Y_WEIGHT_FOR_FIRST;
    static const float STANDARD_DEVIATION_X_WEIGHT_FOR_LAST;
    static const float STANDARD_DEVIATION_Y_WEIGHT_FOR_LAST;
    static const float STANDARD_DEVIATION_X_WEIGHT;
    static const float STANDARD_DEVIATION_Y_WEIGHT;

    // Used by ProximityInfoStateUtils::suppressCharProbabilities()
    static const float SUPPRESSION_LENGTH_WEIGHT;
+1 −1
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
                    mProximityInfo->getKeyCount(), lastSavedInputSize, mSampledInputSize,
                    &mSampledInputXs, &mSampledInputYs, &mSpeedRates, &mSampledLengthCache,
                    &mSampledNormalizedSquaredLengthCache, &mSampledNearKeySets,
                    &mCharProbabilities);
                    mProximityInfo, &mCharProbabilities);
            ProximityInfoStateUtils::updateSampledSearchKeySets(mProximityInfo,
                    mSampledInputSize, lastSavedInputSize, &mSampledLengthCache,
                    &mSampledNearKeySets, &mSampledSearchKeySets,
Loading