public int CompareTo(Gesture other) { return(lower_bound.CompareTo(other.lower_bound)); }
public RecognitionResult Classify(Gesture candidate) { int feature_cnt = candidate.features.Count(); // // calculate lower bounds for each template based on envelop // and sort the list based on the boundaries // var temp_templates = templates; foreach (var t in temp_templates) { float score = 1.0f; for (int ii = 0; ii < feature_cnt; ii++) { Vector <float> fvec = candidate.features[ii]; score *= 1.0f / fvec.DotProduct(t.features[ii]); } t.fscore = score; t.lower_bound = LowerBound(candidate, t); //Debug.Log(t.gname + ":" + t.lower_bound.ToString() + ", " + t.rejection_threshold.ToString() ); } //Debug.Log("\n"); temp_templates = temp_templates.OrderBy(x => x.lower_bound).ToList(); // // now fully evaluate each template // RecognitionResult ret = new RecognitionResult(); foreach (Gesture template in temp_templates) { ret.tests += 1.0f; float fscore = template.fscore * template.lower_bound; //if (template.lower_bound > template.rejection_threshold) if (fscore > template.rejection_threshold) { ret.pruned_by_rejection += 1.0f; //continue; } if (fscore > ret.score) { ret.pruned_by_best_score += 1.0f; //continue; } float score = DTW_Distance( candidate.vecs, template.vecs, Gesture.r); // if (score >= template.rejection_threshold) // continue; score *= template.fscore; if (score < ret.score) { ret.template = template; ret.score = score; } } return(ret); }
public void Add(Gesture alpha) { templates.Add(alpha); }
public float CompareDatasets() { float errors = 0, errors_2D = 0, errors_3D = 0; List <Gesture> original = templates; List <Gesture> only2D = original.FindAll(x => x.Is2D() == true); List <Gesture> only3D = original.FindAll(x => x.Is2D() == false); Console.WriteLine(); Console.WriteLine("Comparing 2D"); templates = only2D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { Console.WriteLine("Nothing " + candidate.gname); errors_2D++; } else if (result.template.gname != candidate.gname) { Console.WriteLine(result.template.gname + " " + candidate.gname); errors_2D++; } templates.Insert(ii, candidate); } Console.WriteLine(); Console.WriteLine("Comparing 3D"); templates = only3D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { Console.WriteLine("Nothing " + candidate.gname); errors_3D++; } else if (result.template.gname != candidate.gname) { Console.WriteLine(result.template.gname + " " + candidate.gname); errors_3D++; } templates.Insert(ii, candidate); } templates = original; Console.WriteLine(); Console.WriteLine("Comparing All"); for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { Console.WriteLine("Nothing " + candidate.gname); errors++; } else if (result.template.gname != candidate.gname) { Console.WriteLine(result.template.gname + " " + candidate.gname); errors++; } templates.Insert(ii, candidate); } Console.WriteLine(); Console.WriteLine("Error Rates:"); errors = errors / templates.Count; errors_2D = errors_2D / only2D.Count; errors_3D = errors_3D / only3D.Count; Console.WriteLine("2D: \t" + errors_2D); Console.WriteLine("3D: \t" + errors_3D); Console.WriteLine("All:\t" + errors); return(errors / (templates.Count)); }
public void EvaluateUserDependentPairwiseSpeakers(string path, string uname) { List <UserDataSet> alldata = DataLoader.LoadGestureDataFrom(path); var temp = templates; Console.WriteLine("CrossValidate\t\t2D\t\t3D\t\tAll"); var l2de = new List <float>(); var l3de = new List <float>(); var le = new List <float>(); var cnt = alldata[0].TrainingSamples[0].RawData[0].Count() / 33; for (int mm = 0; mm < cnt; mm++) { for (int nn = mm + 1; nn < cnt; nn++) { foreach (UserDataSet ud in alldata) { if (uname == "" || ud.Path.Contains(uname)) { templates.Clear(); foreach (GestureSample gs in ud.TrainingSamples) { if (gs.Gesture == GestureType.mu || gs.Gesture == GestureType.p || gs.Gesture == GestureType.q || gs.Gesture == GestureType.circle) { continue; } List <Vector <float> > data = new List <Vector <float> >(); foreach (var rd in gs.RawData) { var first = rd.Skip(mm * 33).Take(33).ToArray(); var second = rd.Skip(nn * 33).Take(33).ToArray(); var max = Math.Max(first.Max(), second.Max()); var merged = first.Concat(second).Select(x => x / max); data.Add(Vector <float> .Build.DenseOfArray(merged.ToArray())); } Add(data, gs.Gesture.ToString()); } Normalize(); float errors = 0, errors_2D = 0, errors_3D = 0; List <Gesture> original = templates; List <Gesture> only2D = original.FindAll(x => x.Is2D() == true); List <Gesture> only3D = original.FindAll(x => x.Is2D() == false); templates = only2D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors_2D++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors_2D++; } templates.Insert(ii, candidate); } templates = only3D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors_3D++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors_3D++; } templates.Insert(ii, candidate); } templates = original; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors++; } templates.Insert(ii, candidate); } errors = errors / templates.Count; errors_2D = errors_2D / only2D.Count; errors_3D = errors_3D / only3D.Count; l2de.Add(errors_2D); l3de.Add(errors_3D); le.Add(errors); templates.Clear(); } } templates = temp; Console.WriteLine("Average\t" + (mm + 1) + " " + (nn + 1) + " " + l2de.Average().ToString("0.00") + "\t" + l3de.Average().ToString("0.00") + "\t" + le.Average().ToString("0.00")); } } }
public void EvaluateUserDependent(string path, string uname) { List <UserDataSet> alldata = DataLoader.LoadGestureDataFrom(path); var temp = templates; Console.WriteLine("CrossValidate\t\t2D\t\t3D\t\tAll"); var l2de = new List <float>(); var l3de = new List <float>(); var le = new List <float>(); var count_map = new Dictionary <Tuple <string, string>, int>(); foreach (UserDataSet ud in alldata) { if (uname == "" || ud.Path.Contains(uname)) { templates.Clear(); foreach (GestureSample gs in ud.TrainingSamples) { if (gs.Gesture == GestureType.mu || gs.Gesture == GestureType.p || gs.Gesture == GestureType.q || gs.Gesture == GestureType.circle) { continue; } List <Vector <float> > data = new List <Vector <float> >(); foreach (var rd in gs.RawData) { data.Add(Vector <float> .Build.DenseOfArray(rd)); } Add(data, gs.Gesture.ToString()); } Normalize(); float errors = 0, errors_2D = 0, errors_3D = 0; List <Gesture> original = templates; List <Gesture> only2D = original.FindAll(x => x.Is2D() == true); List <Gesture> only3D = original.FindAll(x => x.Is2D() == false); templates = only2D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors_2D++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors_2D++; } //count_map[Tuple.Create(candidate.gname, result.template.gname)] = count_map.ContainsKey(Tuple.Create(candidate.gname, result.template.gname)) // ? count_map[Tuple.Create(candidate.gname, result.template.gname)]+1 : 1; templates.Insert(ii, candidate); } templates = only3D; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors_3D++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors_3D++; } //count_map[Tuple.Create(candidate.gname, result.template.gname)] = count_map.ContainsKey(Tuple.Create(candidate.gname, result.template.gname)) // ? count_map[Tuple.Create(candidate.gname, result.template.gname)]+1 : 1; templates.Insert(ii, candidate); } templates = original; for (int ii = 0; ii < templates.Count; ii++) { Gesture candidate = templates[ii]; templates.RemoveAt(ii); var result = Classify(candidate); if (result.template == null) { errors++; templates.Insert(ii, candidate); continue; } else if (result.template.gname != candidate.gname) { errors++; } count_map[Tuple.Create(candidate.gname, result.template.gname)] = count_map.ContainsKey(Tuple.Create(candidate.gname, result.template.gname)) ? count_map[Tuple.Create(candidate.gname, result.template.gname)] + 1 : 1; templates.Insert(ii, candidate); } errors = errors / templates.Count; errors_2D = errors_2D / only2D.Count; errors_3D = errors_3D / only3D.Count; l2de.Add(errors_2D); l3de.Add(errors_3D); le.Add(errors); Console.WriteLine(ud.Path + "\t" + errors_2D.ToString("0.00") + "\t" + errors_3D.ToString("0.00") + "\t" + errors.ToString("0.00")); templates.Clear(); } } templates = temp; Console.WriteLine("Average\t" + l2de.Average().ToString("0.00") + "\t" + l3de.Average().ToString("0.00") + "\t" + le.Average().ToString("0.00")); foreach (var key in count_map.OrderBy(x => x.Key.Item1).ThenBy(x => x.Key.Item2)) { if (key.Value > 0) { Console.WriteLine(key); } } }