示例#1
0
        // TODO: I really hate this pattern.  Find a way to accomplish this without
        // either using obnoxious patterns or opening the door for confusing usage.
        public bool TryRecognizeTrajectory(Trajectory trajectory, out string result)
        {
            var descriptor = new TrajectoryDescriptor(trajectory, this.vectorsAlphabet, this.levenshteinAlphabet);

            result = null;

            var allowableMatches = this.knownStrings.Where(pair => pair.Value.GetMatchCost(descriptor) < MAXIMUM_ALLOWABLE_MATCH_COST);

            if (allowableMatches.Count() == 0)
            {
                return(false);
            }
            else
            {
                float bestDistance = float.MaxValue;
                foreach (var pair in allowableMatches)
                {
                    float distance = pair.Value.GetMatchMinimumEditDistance(descriptor);
                    if (distance < bestDistance)
                    {
                        result       = pair.Key;
                        bestDistance = distance;
                    }
                }
                return(result != null);
            }
        }
示例#2
0
            public float Distance(TrajectoryDescriptor other)
            {
                Debug.Assert(this.Strings.Count == other.Strings.Count);

                float totalDistance = 0;

                for (int idx = 0; idx < this.Strings.Count; idx++)
                {
                    float weight = Mathf.Pow(2f, idx);
                    totalDistance += this.Strings[idx].Distance(other.Strings[idx]);
                }

                return(totalDistance);
            }
示例#3
0
            // TODO: Try best match score?  Sum of squared distances?
            public float GetMatchCost(TrajectoryDescriptor descriptor)
            {
                float cost = descriptor.Distance(this.Descriptors[this.centroidIdx]);

                return(cost / this.averageLevenshteinDistance); // Linear error metric, for now.
            }
示例#4
0
 public float GetMatchMinimumEditDistance(TrajectoryDescriptor descriptor)
 {
     return(this.Descriptors.Min(desc => desc.Distance(descriptor)));
 }
示例#5
0
 public void Add(TrajectoryDescriptor descriptor)
 {
     this.Descriptors.Add(descriptor);
     this.RecalculateRepresentations(this.Descriptors);
 }