Esempio n. 1
0
        public DistanceResult Intersect(DistanceResult other)
        {
            DistanceResult result = new DistanceResult();

            foreach (int key in Keys)
            {
                double value;
                if (other.TryGetValue(key, out value))
                {
                    double averageValues = this[key] + value;
                    result.Add(key, averageValues);
                }
            }
            return(result);
        }
Esempio n. 2
0
        public override DistanceResult Recognize(double[] input, out List <string> errors)
        {
            errors = new List <string>();
            DistanceResult results = new DistanceResult();

            foreach (int key in registers.Keys)
            {
                double dist      = ComputeDistance(input, registers[key]);
                double threshold = thresholds[key];
                if (dist <= threshold)
                {
                    results.Add(key, dist);
                }
                else
                {
                    errors.Add(GestureDataManager.GetClassName(key) + " failed at " + parameterName + parameterIndex + "  : " + dist + " vs " + threshold);
                }
            }
            if (results.Count == 0)
            {
                results.Add(-1, 0);
            }
            return(results);
        }
Esempio n. 3
0
        public override DistanceResult Recognize(Gesture gesture, out List <string> errors)
        {
            errors = new List <string>();
            Dictionary <string, DistanceResult> results = new Dictionary <string, DistanceResult>();

            foreach (string key in Gesture.parameterKeys)
            {
                UnivariateAlgorithm[] univariateAlgorithms = parametersToAlgorithms[key];
                ParameterValues       parameterValues      = gesture[key];
                double[][]            normalizedValues     = parameterValues.GetNormalizedValues();
                normalizedValues = normalizedValues.Transpose();
                DistanceResult resultsParameter = null;
                for (int i = 0; i < parameterValues.Dimension; i++)
                {
                    List <string>  parameterErrors;
                    DistanceResult tempResult = univariateAlgorithms[i].Recognize(normalizedValues[i], out parameterErrors);
                    errors.Append(parameterErrors);
                    if (resultsParameter == null)
                    {
                        resultsParameter = tempResult;
                    }
                    else
                    {
                        resultsParameter = resultsParameter.Intersect(tempResult);
                    }
                }

                results.Add(key, resultsParameter);
            }
            DistanceResult possibleResults   = null;
            List <int>     impossibleResults = new List <int>();

            foreach (string key in Gesture.parameterKeys)
            {
                if (possibleResults == null)
                {
                    possibleResults = results[key];
                }
                else
                {
                    List <int> keys = possibleResults.Keys.ToList();
                    foreach (int result in keys)
                    {
                        if (!results[key].ContainsKey(result))
                        {
                            impossibleResults.Add(result);
                        }
                        else
                        {
                            possibleResults[result] = possibleResults[result] + results[key][result];
                        }
                    }
                }
            }
            foreach (int classIndex in impossibleResults)
            {
                possibleResults.Remove(classIndex);
            }
            if (possibleResults.Count == 0)
            {
                possibleResults.Add(-1, 0);
            }
            return(possibleResults);
        }