Example #1
0
        public void LearnAndApply(
                ICollection<string> seedPaths, Tuple<string, string>[] learningSets,
                LearningExperiment[] experiments) {
            var projectPaths =
                    learningSets.Take(ProjectCount).Select(
                            t => {
                                var url = t.Item1;
                                var path = Fixture.GetGitRepositoryPath(url);
                                Git.Clone(path, url);
                                Git.Checkout(path, t.Item2);
                                return path;
                            }).ToList();
            var failedCount = 0;
            foreach (var exp in experiments) {
                var learningResult = LearnWithoutClearing(
                        seedPaths, exp, projectPaths.Take(ProjectCountToLearn).ToList());

                var w = CreateWriter(exp.GetType().Name + "_classifier_" +
                                     ProjectCountToLearn + "_" + ProjectCount + ".txt");
                w.WriteLine(learningResult.Classifier.GetClassifierSummary());
                w.Flush();

                var writer = CreateWriter(exp.GetType().Name + "_apply_" +
                                          ProjectCountToLearn + "_" + ProjectCount + ".csv");
                foreach (var projectPath in projectPaths.Skip(ProjectCountToLearn)) {
                    var codePaths = Directory.GetFiles(projectPath, SearchPattern,
                            SearchOption.AllDirectories);
                    writer.Write(DateTime.Now);
                    writer.Write(",");
                    writer.Write(projectPath);
                    writer.Write(",");
                    var classificationResult = exp.Apply(codePaths, SearchPattern,
                            learningResult.FeatureEncoder,
                            learningResult.Classifier, writer);
                    var features =
                            learningResult.Classifier.GetAllAcceptingFeatureStrings(
                                    learningResult.FeatureEncoder);
                    writer.Write(classificationResult.WrongElementCount);
                    writer.Write(",");
                    writer.Write(classificationResult.WrongVectorCount);
                    writer.Write(",");
                    writer.WriteLine();
                    writer.Flush();
                    if (classificationResult.WrongElementCount > 0) {
                        failedCount++;
                        PrintWrongResults(classificationResult, learningResult);
                    }
                    Console.WriteLine(exp.GetType().Name);
                    Assert.That(failedCount, Is.EqualTo(0));
                }
            }
        }
        public static double Match(List<Minutia> minutiae1, List<Minutia> minutiae2)
        {
            var tasks =
                new Tuple<Minutia, Minutia, Minutia, Minutia>[6000];

            var sw = new Stopwatch();
            sw.Start();
            double max = 0;
            int count = -1;
            Parallel.ForEach(minutiae1, new ParallelOptions() {MaxDegreeOfParallelism = 4},
                             core1 =>
                                 {
                                     foreach (var to1 in minutiae1)
                                     {
                                         if (core1 == to1) continue;
                                         var angle1 = DetermineAngle(core1, to1);
                                         var length1 = DetermineDistance(core1, to1);

                                         foreach (var core2 in minutiae2)
                                         {
                                             var others2 = minutiae2.Except(new List<Minutia>() {core2});
                                             foreach (var to2 in others2)
                                             {
                                                 if (core2 == to2) continue;
                                                 var angle2 = DetermineAngle(core2, to2);
                                                 if (Math.Abs(angle1 - angle2) > AngleToleranceBox)
                                                     continue;
                                                 var length2 = DetermineDistance(core2, to2);
                                                 if (Math.Abs(length1 - length2) > DistanceToleranceBox) continue;
                                                 int localCount = Interlocked.Increment(ref count);
                                                 tasks[localCount] = Tuple.Create(core1, to1, core2, to2);
                                             }
                                         }
                                     }
                                 });
            object _lock = new object();
            Parallel.ForEach(tasks.Take(count), new ParallelOptions() {MaxDegreeOfParallelism = 4},
                             x =>
                                 {
                                     var angle1 = DetermineAngle(x.Item1, x.Item2);
                                     var angle2 = DetermineAngle(x.Item3, x.Item4);
                                     var score = TranslateAndMatch(minutiae1, x.Item1, minutiae2, x.Item3, angle2 - angle1);
                                     lock(_lock)
                                     {
                                         if (score > max) max = score;
                                     }
                                 });

            sw.Stop();
            return max;
        }