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 Tuple <int, string, int, DateTime>[] GetTopScores(int seed, int numScores) { //public getter method that reads the top numScores scores from the file and returns them //first we need to read in the scores String[] scores = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "/saved_scores.txt"); Tuple <int, string, int, DateTime>[] tupleScores = new Tuple <int, string, int, DateTime> [scores.Count()]; //now we need to iterate over the scores, turn them into tuples for (int i = 0; i < scores.Count(); i++) { string[] splitString = scores[i].Split(':'); Tuple <int, string, int, DateTime> score = Tuple.Create(int.Parse(splitString[0]), splitString[1], int.Parse(splitString[2]), DateTime.Parse(splitString[3])); tupleScores[i] = (score); } //now we sort the list //code for sorting from MSDN, found here: //https://msdn.microsoft.com/en-us/library/bb534966(v=vs.110).aspx //also filtering out results with With keyword, code for that found here: //https://stackoverflow.com/questions/22449888/filtering-a-tuple-based-on-item-3-in-the-tuple?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa tupleScores.OrderBy(tuple => tuple.Item1).Where(tuple => tuple.Item3 == seed); Tuple <int, string, int, DateTime>[] topTupleScores = new Tuple <int, string, int, DateTime> [numScores]; int j = 0; foreach (Tuple <int, string, int, DateTime> tuple in tupleScores.Take(numScores)) { topTupleScores[j] = tuple; j++; } //in case there aren't enough scores for the daily scoreboard, we'll pad it with junk values while (j < numScores - 1) { topTupleScores[j] = new Tuple <int, string, int, DateTime>(int.MaxValue, "", 0, DateTime.MinValue); } return(topTupleScores); }
public static Tuple <int, string, int, DateTime>[] GetAllTimeTopScores(int numScores) { //public getter method that reads all time top numScores scores from the file and returns them //doesn't discriminate by seed //first we need to read in the scores String[] scores = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "/saved_scores.txt"); Tuple <int, string, int, DateTime>[] tupleScores = new Tuple <int, string, int, DateTime> [scores.Count()]; //now we need to iterate over the scores, turn them into tuples for (int i = 0; i < scores.Count(); i++) { string[] splitString = scores[i].Split(':'); Tuple <int, string, int, DateTime> score = Tuple.Create(int.Parse(splitString[0]), splitString[1], int.Parse(splitString[2]), DateTime.Parse(splitString[3])); tupleScores[i] = (score); } //now we sort the list Tuple <int, string, int, DateTime>[] topTupleScores = new Tuple <int, string, int, DateTime> [numScores]; int j = 0; foreach (Tuple <int, string, int, DateTime> tuple in tupleScores.Take(numScores)) { topTupleScores[j] = tuple; j++; } //if there aren't enough scores, we'll add some junk ones while (j < numScores - 1) { topTupleScores[j] = new Tuple <int, string, int, DateTime>(int.MaxValue, "", 0, DateTime.MinValue); } return(topTupleScores); }
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; }
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); }