Beispiel #1
0
        public IList <TrainFeature> Train()
        {
            var path       = @"..\..\data\trainlist.txt";
            var input      = new FileStream(path, FileMode.Open, FileAccess.Read);
            var fileReader = new StreamReader(input);

            char[] splitter = { ' ' };
            var    strLine  = "";

            var trainList = new List <TrainFeature>();

            while (!fileReader.EndOfStream)
            {
                strLine = fileReader.ReadLine();
                if (strLine == null)
                {
                    break;
                }

                var strToken       = strLine.Split(splitter, StringSplitOptions.None);
                var inkPath        = strToken[0];
                var classId        = Convert.ToInt32(strToken[1]);
                var traceGroup     = _inkFile.ReadFromInkFile(inkPath);
                var prepTraceGroup = _preProc.PreProcess(traceGroup);
                var feature        = _featureExtractor.ExtractFeature(prepTraceGroup);

                trainList.Add(new TrainFeature {
                    ClassId = classId, ShapeFeatures = feature
                });
            }

            return(trainList);
        }
Beispiel #2
0
        public IList <RecoResult> Recognize(TraceGroup testTraceGroup)
        {
            var testPreProcTraceGroup = _preProc.PreProcess(testTraceGroup);
            var testFeature           = _featureExtractor.ExtractFeature(testPreProcTraceGroup);

            var distanceList = new List <KeyValuePair <int, float> >();

            foreach (var train in _trainList)
            {
                var d = _featureExtractor.ComputeEuclideanDistance(train.ShapeFeatures, testFeature);
                distanceList.Add(new KeyValuePair <int, float>(train.ClassId, d));
            }

            distanceList.Sort((f1, f2) => f1.Value.CompareTo(f2.Value));

            var tempRecoResult = new List <RecoResult>();
            var sumSimiliarity = 0f;

            for (var i = 0; i < distanceList.Count; i++)
            {
                var foundDuplicated = tempRecoResult.Find(c => c.ShapeId == distanceList[i].Key);
                if (foundDuplicated == null)
                {
                    sumSimiliarity += distanceList[i].Value;
                    tempRecoResult.Add(new RecoResult {
                        ShapeId = distanceList[i].Key, ConfidenceLevel = distanceList[i].Value
                    });

                    if (tempRecoResult.Count == _numOfChoice)
                    {
                        break;
                    }
                }
            }

            for (var i = 0; i < _numOfChoice; i++)
            {
                tempRecoResult[i].ConfidenceLevel = (sumSimiliarity - tempRecoResult[i].ConfidenceLevel) / sumSimiliarity;
            }

            return(tempRecoResult);
        }